Rev 3675 | Rev 4590 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
205 | heavyiron | 1 | format binary |
542 | diamond | 2 | include '../../macros.inc' |
205 | heavyiron | 3 | use32 |
3675 | GerdtR | 4 | db 'MENUET01' |
5 | dd 1 |
||
6 | dd start |
||
7 | dd i_end |
||
8 | dd used_mem |
||
9 | dd used_mem |
||
10 | dd i_param |
||
11 | dd 0 |
||
205 | heavyiron | 12 | |
3675 | GerdtR | 13 | ;----------------------------------------------------------------------------- |
14 | |||
15 | REG_MODE_CPU equ 1 |
||
16 | REG_MODE_MMX equ 2 |
||
17 | REG_MODE_SSE equ 3 |
||
18 | REG_MODE_AVX equ 4 |
||
19 | |||
20 | ;----------------------------------------------------------------------------- |
||
21 | |||
22 | include 'gui.inc' ; GUI routines |
||
23 | |||
24 | ;----------------------------------------------------------------------------- |
||
25 | ; Find command in list |
||
26 | |||
27 | find_cmd: |
||
28 | ; all commands are case-insensitive |
||
29 | push edi |
||
30 | |||
31 | .x4: |
||
32 | mov al, [edi] |
||
33 | cmp al, 0 |
||
34 | jz .x5 |
||
35 | cmp al, 'A' |
||
36 | jb @f |
||
37 | cmp al, 'Z' |
||
38 | ja @f |
||
39 | or al, 20h |
||
40 | |||
41 | @@: |
||
42 | stosb |
||
43 | jmp .x4 |
||
44 | |||
45 | ; find command |
||
46 | .x5: |
||
47 | pop edi |
||
48 | |||
49 | .x6: |
||
50 | cmp dword [esi], 0 |
||
51 | jz .x7 |
||
52 | push esi |
||
53 | mov esi, [esi] |
||
54 | lodsb |
||
55 | movzx ecx, al |
||
56 | push edi |
||
57 | repz cmpsb |
||
58 | pop edi |
||
59 | pop esi |
||
60 | jz .x8 |
||
61 | add esi, 17 |
||
62 | jmp .x6 |
||
63 | |||
64 | .x7: |
||
65 | stc |
||
66 | |||
67 | .x8: |
||
68 | ret |
||
69 | |||
205 | heavyiron | 70 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3675 | GerdtR | 71 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
205 | heavyiron | 72 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
73 | |||
3675 | GerdtR | 74 | ;----------------------------------------------------------------------------- |
75 | ; Help event |
||
205 | heavyiron | 76 | |
3675 | GerdtR | 77 | OnHelp: |
78 | mov esi, help_msg |
||
79 | mov edi, [curarg] |
||
80 | cmp byte [edi], 0 |
||
81 | jz .x |
||
82 | mov esi, help_groups |
||
83 | call find_cmd |
||
84 | jc .nocmd |
||
85 | mov esi, [esi+12] |
||
205 | heavyiron | 86 | |
3675 | GerdtR | 87 | .x: |
88 | jmp put_message |
||
205 | heavyiron | 89 | |
3675 | GerdtR | 90 | .nocmd: |
91 | mov esi, aUnknownCommand |
||
92 | jmp .x |
||
205 | heavyiron | 93 | |
3675 | GerdtR | 94 | ;----------------------------------------------------------------------------- |
95 | ; Quit event |
||
96 | OnQuit: |
||
97 | mcall -1 |
||
205 | heavyiron | 98 | |
3675 | GerdtR | 99 | ;----------------------------------------------------------------------------- |
100 | ; Working with debug context |
||
205 | heavyiron | 101 | |
3675 | GerdtR | 102 | get_new_context: |
103 | mov esi, context |
||
104 | mov edi, oldcontext |
||
105 | mov ecx, 10 |
||
106 | rep movsd |
||
205 | heavyiron | 107 | |
3675 | GerdtR | 108 | get_context: |
109 | ;push 1 |
||
110 | ;pop ebx |
||
111 | ;push 69 |
||
112 | ;pop eax |
||
113 | ;mov ecx, [debuggee_pid] |
||
114 | ;mov esi, context |
||
115 | ;push 28h |
||
116 | ;pop edx |
||
117 | mcall 69, 1, [debuggee_pid], 28h, context |
||
118 | ret |
||
205 | heavyiron | 119 | |
3675 | GerdtR | 120 | set_context: |
121 | ;push 2 |
||
122 | ;pop ebx |
||
123 | ;push 69 |
||
124 | ;pop eax |
||
125 | ;mov ecx, [debuggee_pid] |
||
126 | ;mov esi, context |
||
127 | ;push 28h |
||
128 | ;pop edx |
||
129 | mcall 69, 2, [debuggee_pid], 28h, context |
||
130 | ret |
||
205 | heavyiron | 131 | |
3675 | GerdtR | 132 | get_dump: |
133 | mov edi, dumpdata |
||
134 | mov esi, [edi-4] |
||
135 | mov edx, dump_height*10h |
||
136 | mov ecx, edx |
||
137 | xor eax, eax |
||
138 | push edi |
||
139 | rep stosb |
||
140 | pop edi |
||
141 | ;mov ecx, [debuggee_pid] |
||
142 | ;mov al, 69 |
||
143 | ;push 6 |
||
144 | ;pop ebx |
||
145 | mcall 69, 6, [debuggee_pid] |
||
146 | cmp eax, -1 |
||
147 | jnz @f |
||
148 | mov esi, read_mem_err |
||
149 | call put_message |
||
150 | xor eax, eax |
||
205 | heavyiron | 151 | |
3675 | GerdtR | 152 | @@: |
153 | mov [edi-8], eax |
||
154 | ; call restore_from_breaks |
||
155 | ; ret |
||
205 | heavyiron | 156 | |
3675 | GerdtR | 157 | ; in: edi=buffer,eax=size,esi=address |
158 | restore_from_breaks: |
||
159 | mov ebx, breakpoints |
||
205 | heavyiron | 160 | |
3675 | GerdtR | 161 | @@: |
162 | test byte [ebx+4], 1 |
||
163 | jz .cont ; ignore invalid |
||
164 | test byte [ebx+4], 2 or 8 |
||
165 | jnz .cont ; ignore disabled and memory breaks |
||
166 | mov ecx, [ebx] |
||
167 | sub ecx, esi |
||
168 | cmp ecx, eax |
||
169 | jae .cont |
||
170 | mov dl, [ebx+5] |
||
171 | mov [edi+ecx], dl |
||
205 | heavyiron | 172 | |
3675 | GerdtR | 173 | .cont: |
174 | add ebx, 6 |
||
175 | cmp ebx, breakpoints+breakpoints_n*6 |
||
176 | jb @b |
||
177 | ret |
||
205 | heavyiron | 178 | |
3675 | GerdtR | 179 | ;----------------------------------------------------------------------------- |
180 | ; Load executable event |
||
205 | heavyiron | 181 | |
3675 | GerdtR | 182 | OnLoad: |
183 | mov esi, [curarg] |
||
205 | heavyiron | 184 | |
3675 | GerdtR | 185 | OnLoadInit: |
186 | mov edi, loadname |
||
187 | or [prgname_len], -1 |
||
188 | mov [prgname_ptr], edi |
||
205 | heavyiron | 189 | |
3675 | GerdtR | 190 | .copyname: |
191 | lodsb |
||
192 | stosb |
||
193 | inc [prgname_len] |
||
194 | cmp al, '/' |
||
195 | jnz @f |
||
196 | or [prgname_len], -1 |
||
197 | mov [prgname_ptr], edi |
||
205 | heavyiron | 198 | |
3675 | GerdtR | 199 | @@: |
200 | cmp al, ' ' |
||
201 | ja .copyname |
||
202 | mov byte [edi-1], 0 |
||
203 | and [load_params], 0 |
||
204 | dec esi |
||
205 | call get_arg.skip_spaces |
||
206 | cmp al, 0 |
||
207 | jz @f |
||
208 | mov [load_params], esi |
||
205 | heavyiron | 209 | |
3675 | GerdtR | 210 | @@: |
211 | and [dumppos], 0 |
||
212 | mov ecx, [symbols] |
||
213 | jecxz do_reload |
||
214 | mcall 68, 13 |
||
215 | and [symbols], 0 |
||
216 | and [num_symbols], 0 |
||
205 | heavyiron | 217 | |
3675 | GerdtR | 218 | ; TODO: make it local |
219 | do_reload: |
||
220 | ;push 18 |
||
221 | ;pop eax |
||
222 | ;push 7 |
||
223 | ;pop ebx |
||
224 | mcall 18, 7 |
||
225 | mov [dbgwnd], eax |
||
226 | xchg ecx, eax |
||
227 | ;push 70 |
||
228 | ;pop eax |
||
229 | ;mov ebx, fn70_load_block |
||
230 | mcall 70, fn70_load_block |
||
231 | test eax, eax |
||
232 | jns .load_ok |
||
205 | heavyiron | 233 | |
3675 | GerdtR | 234 | .load_err: |
235 | push eax |
||
236 | mov esi, load_err_msg |
||
237 | call put_message |
||
238 | pop eax |
||
239 | not eax |
||
240 | cmp eax, 0x20 |
||
241 | jae .unk_err |
||
242 | mov esi, [load_err_msgs+eax*4] |
||
243 | test esi, esi |
||
244 | jnz put_message |
||
205 | heavyiron | 245 | |
3675 | GerdtR | 246 | .unk_err: |
247 | mov esi, unk_err_msg |
||
248 | inc eax |
||
249 | push eax |
||
250 | call put_message_nodraw |
||
251 | jmp draw_messages |
||
205 | heavyiron | 252 | |
3675 | GerdtR | 253 | .load_ok: |
254 | mov [debuggee_pid], eax |
||
255 | mov [bSuspended], 1 |
||
256 | push ecx |
||
257 | call get_context |
||
258 | mov edi, oldcontext |
||
259 | mov ecx, 10 |
||
260 | rep movsd |
||
205 | heavyiron | 261 | |
3675 | GerdtR | 262 | ; activate debugger window |
263 | pop ecx |
||
264 | ;mov bl, 3 |
||
265 | ;push 18 |
||
266 | ;pop eax |
||
267 | mcall 18, 3 |
||
268 | call redraw_title |
||
269 | call draw_registers.redraw |
||
270 | ; read and draw dump of memory |
||
271 | call get_dump |
||
272 | call draw_dump.redraw |
||
273 | call update_disasm_eip_force |
||
274 | mov esi, load_succ_msg |
||
275 | push [debuggee_pid] |
||
276 | call put_message_nodraw |
||
277 | call draw_messages |
||
278 | ; try to load symbols |
||
279 | mov esi, loadname |
||
280 | mov edi, symbolsfile |
||
281 | push edi |
||
205 | heavyiron | 282 | |
3675 | GerdtR | 283 | @@: |
284 | lodsb |
||
285 | stosb |
||
286 | test al, al |
||
287 | jnz @b |
||
288 | lea ecx, [edi-1] |
||
205 | heavyiron | 289 | |
3675 | GerdtR | 290 | @@: |
291 | dec edi |
||
292 | cmp edi, symbolsfile |
||
293 | jb @f |
||
294 | cmp byte [edi], '/' |
||
295 | jz @f |
||
296 | cmp byte [edi], '.' |
||
297 | jnz @b |
||
298 | mov ecx, edi |
||
205 | heavyiron | 299 | |
3675 | GerdtR | 300 | @@: |
301 | mov dword [ecx], '.dbg' |
||
302 | mov byte [ecx+4], 0 |
||
303 | pop esi |
||
304 | mov ebp, esi |
||
305 | call OnLoadSymbols.silent |
||
306 | |||
307 | ; now test for packed progs |
||
308 | cmp [disasm_buf_size], 100h |
||
309 | jz @f |
||
310 | ret |
||
205 | heavyiron | 311 | |
3675 | GerdtR | 312 | @@: |
313 | mov esi, mxp_nrv_sig |
||
314 | mov ebp, disasm_buffer |
||
315 | mov edi, ebp |
||
316 | push 3 |
||
317 | pop ecx |
||
318 | repz cmpsb |
||
319 | jnz .not_mxp_nrv |
||
320 | cmpsb |
||
321 | mov cl, mxp_nrv_sig_size-4 |
||
322 | repz cmpsb |
||
323 | mov esi, mxp_nrv_name |
||
324 | jz .packed |
||
205 | heavyiron | 325 | |
3675 | GerdtR | 326 | .not_mxp_nrv: |
327 | mov esi, mxp_sig |
||
328 | mov edi, ebp |
||
329 | mov cl, mxp_sig_size |
||
330 | repz cmpsb |
||
331 | mov esi, mxp_name |
||
332 | jz .packed |
||
205 | heavyiron | 333 | |
3675 | GerdtR | 334 | .not_mxp: |
335 | mov esi, mxp_lzo_sig1 |
||
336 | mov edi, ebp |
||
337 | mov cl, mxp_lzo_sig1_size |
||
338 | repz cmpsb |
||
339 | mov esi, mxp_lzo_name |
||
340 | jz .packed |
||
341 | mov esi, mxp_lzo_sig2 |
||
342 | mov edi, ebp |
||
343 | mov cl, 8 |
||
344 | repz cmpsb |
||
345 | jnz .not_mxp_lzo |
||
346 | cmpsb |
||
347 | mov cl, mxp_lzo_sig2_size - 9 |
||
348 | repz cmpsb |
||
349 | mov esi, mxp_lzo_name |
||
350 | jz .packed |
||
205 | heavyiron | 351 | |
3675 | GerdtR | 352 | .not_mxp_lzo: |
353 | mov esi, mtappack_name |
||
354 | cmp dword [ebp], 0xBF5E246A |
||
355 | jnz .not_mtappack |
||
356 | cmp dword [ebp+8], 0xEC4E8B57 |
||
357 | jnz .not_mtappack1 |
||
358 | cmp dword [ebp+12], 0x8D5EA4F3 |
||
359 | jnz .not_mtappack1 |
||
360 | cmp byte [ebp+12h], 0xE9 |
||
361 | jz .packed |
||
362 | |||
363 | .not_mtappack1: |
||
364 | cmp word [ebp+8], 0xB957 |
||
365 | jnz .not_mtappack |
||
366 | cmp dword [ebp+14], 0x575EA4F3 |
||
367 | jnz .not_mtappack2 |
||
368 | cmp byte [ebp+17h], 0xE9 |
||
369 | jz .packed |
||
370 | |||
371 | .not_mtappack2: |
||
372 | cmp dword [ebp+14], 0x5F8DA4F3 |
||
373 | jnz .not_mtappack3 |
||
374 | cmp word [ebp+18], 0xE9FC |
||
375 | jz .packed |
||
376 | |||
377 | .not_mtappack3: |
||
378 | cmp word [ebp+14], 0xA4F3 |
||
379 | jnz .not_mtappack |
||
380 | cmp byte [ebp+15h], 0xE9 |
||
381 | jz .packed |
||
382 | |||
383 | .not_mtappack: |
||
384 | ret |
||
385 | |||
386 | .packed: |
||
387 | push esi |
||
388 | mov esi, aPacked1 |
||
389 | call put_message_nodraw |
||
390 | pop esi |
||
391 | call put_message_nodraw |
||
392 | mov esi, aPacked2 |
||
393 | call put_message |
||
394 | call hide_cursor |
||
395 | ;push 40 |
||
396 | ;pop eax |
||
397 | ;push 7 |
||
398 | ;pop ebx |
||
399 | mcall 40, 7 |
||
400 | |||
401 | .wait: |
||
402 | ;push 10 |
||
403 | ;pop eax |
||
404 | mcall 10 |
||
405 | dec eax |
||
406 | jz .redraw |
||
407 | dec eax |
||
408 | jz .key |
||
409 | or eax, -1 |
||
410 | mcall |
||
411 | |||
412 | .redraw: |
||
413 | call draw_window |
||
414 | call hide_cursor |
||
415 | jmp .wait |
||
416 | |||
417 | .key: |
||
418 | mov al, 2 |
||
419 | mcall |
||
420 | cmp ah, 'y' |
||
421 | jz .yes |
||
422 | cmp ah, 'Y' |
||
423 | jz .yes |
||
424 | cmp ah, 0xD |
||
425 | jz .yes |
||
426 | cmp ah, 'n' |
||
427 | jz .no |
||
428 | cmp ah, 'N' |
||
429 | jnz .wait |
||
430 | |||
431 | .no: |
||
432 | ;push 40 |
||
433 | ;pop eax |
||
434 | ;mov ebx, 0x107 |
||
435 | mcall 40, 0x107 |
||
436 | call draw_cursor |
||
437 | mov esi, aN_str |
||
438 | jmp put_message |
||
439 | |||
440 | .yes: |
||
441 | ;push 40 |
||
442 | ;pop eax |
||
443 | ;mov ebx, 0x107 |
||
444 | mcall 40, 0x107 |
||
445 | call draw_cursor |
||
446 | mov esi, aY_str |
||
447 | call put_message |
||
448 | call OnUnpack |
||
449 | ret |
||
450 | |||
451 | ;----------------------------------------------------------------------------- |
||
452 | ; Searching signatures |
||
453 | |||
205 | heavyiron | 454 | mxp_nrv_sig: |
3675 | GerdtR | 455 | xor eax, eax |
456 | mov ecx, 0x95 ; 0xA1 for programs with parameters |
||
457 | mov [eax], ecx |
||
458 | add ecx, [eax+24h] |
||
459 | push 40h |
||
460 | pop esi |
||
461 | mov edi, [eax+20h] |
||
462 | push edi |
||
463 | rep movsb |
||
464 | jmp dword [esp] |
||
465 | pop esi |
||
466 | add esi, [eax] |
||
467 | xor edi, edi |
||
468 | |||
205 | heavyiron | 469 | mxp_nrv_sig_size = $ - mxp_nrv_sig |
470 | |||
471 | mxp_sig: |
||
3675 | GerdtR | 472 | mov ecx, 1CBh |
473 | push 46h |
||
474 | pop esi |
||
475 | mov edi, [20h] |
||
476 | rep movsb |
||
477 | mov ecx, [24h] |
||
478 | rep movsb |
||
479 | jmp dword [20h] |
||
480 | mov eax, [20h] |
||
481 | add eax, 1CBh |
||
482 | push eax |
||
483 | push dword [24h] |
||
484 | push 0 |
||
485 | push 8 |
||
486 | call $+0x25 |
||
487 | |||
205 | heavyiron | 488 | mxp_sig_size = $ - mxp_sig |
489 | |||
490 | mxp_lzo_sig1: |
||
3675 | GerdtR | 491 | xor eax, eax |
492 | mov ebp, 0FFh |
||
493 | mov ecx, 175h |
||
494 | mov [eax], ecx |
||
495 | add ecx, [eax+24h] |
||
496 | push 45h |
||
497 | pop esi |
||
498 | mov edi, [eax+20h] |
||
499 | push edi |
||
500 | rep movsb |
||
501 | jmp dword [esp] |
||
502 | pop ebx |
||
503 | add ebx, [eax] |
||
504 | xor edi, edi |
||
505 | cmp byte [ebx], 11h |
||
506 | jbe $+0x1A |
||
507 | |||
205 | heavyiron | 508 | mxp_lzo_sig1_size = $ - mxp_lzo_sig1 |
3675 | GerdtR | 509 | |
205 | heavyiron | 510 | mxp_lzo_sig2: |
3675 | GerdtR | 511 | xor eax, eax |
512 | mov ebp, 0FFh |
||
513 | mov ecx, 188h ; or 177h |
||
514 | mov [eax], ecx |
||
515 | add ecx, [eax+24h] |
||
516 | push 44h |
||
517 | pop esi |
||
518 | mov edi, [eax+20h] |
||
519 | rep movsb |
||
520 | jmp dword [eax+20h] |
||
521 | mov ebx, [eax+20h] |
||
522 | add ebx, [eax] |
||
523 | |||
205 | heavyiron | 524 | mxp_lzo_sig2_size = $ - mxp_lzo_sig2 |
525 | |||
3675 | GerdtR | 526 | ;----------------------------------------------------------------------------- |
527 | ; Reload executable event |
||
528 | |||
205 | heavyiron | 529 | OnReload: |
3675 | GerdtR | 530 | cmp [debuggee_pid], 0 |
531 | jnz terminate_reload |
||
532 | mov esi, need_debuggee |
||
533 | cmp byte [loadname], 0 |
||
534 | jnz do_reload |
||
535 | jz put_message |
||
536 | |||
537 | ; TODO: make it local |
||
205 | heavyiron | 538 | terminate_reload: |
3675 | GerdtR | 539 | mov [bReload], 1 |
540 | |||
541 | ;----------------------------------------------------------------------------- |
||
542 | ; Terminate process event |
||
543 | |||
205 | heavyiron | 544 | OnTerminate: |
3675 | GerdtR | 545 | ;mov ecx, [debuggee_pid] |
546 | ;push 8 |
||
547 | ;pop ebx |
||
548 | ;push 69 |
||
549 | ;pop eax |
||
550 | mcall 69, 8, [debuggee_pid] |
||
551 | ret |
||
552 | ;----------------------------------------------------------------------------- |
||
553 | ; Suspend process event |
||
205 | heavyiron | 554 | |
555 | AfterSuspend: |
||
3675 | GerdtR | 556 | mov [bSuspended], 1 |
557 | call get_new_context |
||
558 | call get_dump |
||
559 | call redraw_title |
||
560 | call draw_registers.redraw |
||
561 | call draw_dump.redraw |
||
562 | call update_disasm_eip |
||
563 | ret |
||
205 | heavyiron | 564 | |
565 | OnSuspend: |
||
3675 | GerdtR | 566 | ;mov ecx, [debuggee_pid] |
567 | ;push 4 |
||
568 | ;pop ebx |
||
569 | ;push 69 |
||
570 | ;pop eax |
||
571 | mcall 69, 4, [debuggee_pid] |
||
572 | call AfterSuspend |
||
573 | mov esi, aSuspended |
||
574 | jmp put_message |
||
575 | |||
576 | ;----------------------------------------------------------------------------- |
||
577 | ; Resume process event |
||
578 | |||
205 | heavyiron | 579 | DoResume: |
3675 | GerdtR | 580 | ;mov ecx, [debuggee_pid] |
581 | ;push 5 |
||
582 | ;pop ebx |
||
583 | ;push 69 |
||
584 | ;pop eax |
||
585 | mcall 69, 5, [debuggee_pid] |
||
586 | mov [bSuspended], 0 |
||
587 | ret |
||
588 | |||
205 | heavyiron | 589 | OnResume: |
3675 | GerdtR | 590 | mov esi, [curarg] |
591 | cmp byte [esi], 0 |
||
592 | jz GoOn |
||
593 | call calc_expression |
||
594 | jc .ret |
||
595 | mov eax, ebp |
||
596 | push eax |
||
597 | call find_enabled_breakpoint |
||
598 | pop eax |
||
599 | jz GoOn |
||
600 | mov bl, 5 ; valid enabled one-shot |
||
601 | call add_breakpoint |
||
602 | jnc GoOn |
||
603 | mov esi, aBreakpointLimitExceeded |
||
604 | call put_message |
||
605 | |||
606 | .ret: |
||
607 | ret |
||
608 | |||
205 | heavyiron | 609 | GoOn: |
3675 | GerdtR | 610 | ; test for enabled breakpoint at eip |
611 | mov eax, [_eip] |
||
612 | call find_enabled_breakpoint |
||
613 | jnz .nobreak |
||
614 | ; temporarily disable breakpoint, make step, enable breakpoint, continue |
||
615 | inc eax |
||
616 | mov [temp_break], eax |
||
617 | mov [bAfterGo], 1 |
||
618 | dec eax |
||
619 | call disable_breakpoint |
||
620 | call get_context |
||
621 | or byte [_eflags+1], 1 ; set TF |
||
622 | call set_context |
||
623 | and byte [_eflags+1], not 1 |
||
624 | call DoResume |
||
625 | ret |
||
626 | |||
627 | .nobreak: |
||
628 | call DoResume |
||
629 | call redraw_title |
||
630 | call draw_registers.redraw |
||
631 | call draw_dump.redraw |
||
632 | ret |
||
633 | |||
634 | ;----------------------------------------------------------------------------- |
||
635 | ; Detach process event |
||
636 | |||
205 | heavyiron | 637 | OnDetach: |
3675 | GerdtR | 638 | ;mov ecx, [debuggee_pid] |
639 | ;push 3 |
||
640 | ;pop ebx |
||
641 | ;push 69 |
||
642 | ;pop eax |
||
643 | mcall 69, 3, [debuggee_pid] |
||
644 | and [debuggee_pid], 0 |
||
645 | call redraw_title |
||
646 | call draw_registers.redraw |
||
647 | call draw_dump.redraw |
||
648 | call free_symbols |
||
649 | mov esi, aContinued |
||
650 | jmp put_message |
||
205 | heavyiron | 651 | |
652 | after_go_exception: |
||
3675 | GerdtR | 653 | push eax |
654 | mov eax, [temp_break] |
||
655 | dec eax |
||
656 | push esi |
||
657 | call enable_breakpoint |
||
658 | ; in any case, clear TF and RF |
||
659 | call get_new_context |
||
660 | and [_eflags], not 10100h ; clear TF,RF |
||
661 | call set_context |
||
662 | xor edx, edx |
||
663 | mov [temp_break], edx |
||
664 | xchg dl, [bAfterGo] |
||
665 | pop esi |
||
666 | pop eax |
||
667 | cmp dl, 2 |
||
668 | jnz @f |
||
669 | lodsd |
||
670 | push esi |
||
671 | call get_dump |
||
672 | jmp exception.done |
||
205 | heavyiron | 673 | |
3675 | GerdtR | 674 | @@: |
675 | test eax, eax |
||
676 | jz .notint1 |
||
677 | ; if exception is result of single step, simply ignore it and continue |
||
678 | test dword [esi], 0xF |
||
679 | jnz dbgmsgstart.5 |
||
680 | lodsd |
||
681 | push esi |
||
682 | mov esi, oldcontext |
||
683 | mov edi, context |
||
684 | mov ecx, 28h/4 |
||
685 | rep movsd |
||
686 | call DoResume |
||
687 | jmp dbgmsgend |
||
688 | |||
689 | .notint1: |
||
690 | ; in other case, work as without temp_break |
||
691 | lodsd |
||
692 | push esi |
||
693 | push eax |
||
694 | jmp exception.4 |
||
695 | |||
696 | .notour: |
||
697 | |||
698 | ; TODO: split it out |
||
205 | heavyiron | 699 | debugmsg: |
3675 | GerdtR | 700 | neg [dbgbufsize] |
701 | mov esi, dbgbuf |
||
702 | |||
703 | ; TODO: make it local |
||
205 | heavyiron | 704 | dbgmsgstart: |
3675 | GerdtR | 705 | lodsd |
706 | ; push eax esi |
||
707 | ; push dword [esi] |
||
708 | ; mov esi, dbgmsg_str |
||
709 | ; call put_message_nodraw |
||
710 | ; pop esi eax |
||
711 | add esi, 4 |
||
712 | dec eax |
||
713 | jz exception |
||
714 | dec eax |
||
715 | jz terminated |
||
716 | mov [bSuspended], 1 |
||
717 | cmp [bAfterGo], 0 |
||
718 | jnz after_go_exception |
||
719 | push esi |
||
720 | call get_new_context |
||
721 | and [_eflags], not 10100h ; clear TF,RF |
||
722 | call set_context |
||
723 | pop esi |
||
724 | |||
725 | ; TODO: WTF? Need for meaning label names |
||
726 | .5: |
||
727 | push esi |
||
728 | call get_dump |
||
729 | pop esi |
||
730 | lodsd |
||
731 | xor ecx, ecx |
||
732 | |||
733 | .6: |
||
734 | bt eax, ecx |
||
735 | jnc .7 |
||
736 | mov ebx, [drx_break+ecx*4] |
||
737 | test ebx, ebx |
||
738 | jz .7 |
||
739 | pushad |
||
740 | dec ebx |
||
741 | push ebx |
||
742 | mov esi, aBreakStop |
||
743 | call put_message_nodraw |
||
744 | popad |
||
745 | |||
746 | .7: |
||
747 | inc ecx |
||
748 | cmp cl, 4 |
||
749 | jb .6 |
||
750 | push esi |
||
751 | jmp exception.done_draw |
||
752 | |||
753 | ; TODO: make it local |
||
205 | heavyiron | 754 | terminated: |
3675 | GerdtR | 755 | push esi |
756 | mov esi, terminated_msg |
||
757 | call put_message |
||
758 | and [debuggee_pid], 0 |
||
759 | and [temp_break], 0 |
||
760 | mov [bAfterGo], 0 |
||
761 | xor eax, eax |
||
762 | mov ecx, breakpoints_n*6/4+4 |
||
763 | mov edi, breakpoints |
||
764 | rep stosd |
||
765 | cmp [bReload], 1 |
||
766 | sbb [bReload], -1 |
||
767 | jnz exception.done |
||
768 | call free_symbols |
||
769 | jmp exception.done |
||
770 | |||
205 | heavyiron | 771 | exception: |
3675 | GerdtR | 772 | mov [bSuspended], 1 |
773 | cmp [bAfterGo], 0 |
||
774 | jnz after_go_exception |
||
775 | lodsd |
||
776 | push esi |
||
777 | push eax |
||
778 | call get_new_context |
||
779 | and [_eflags], not 10100h ; clear TF,RF |
||
780 | call set_context |
||
781 | |||
782 | ; TODO: fix for useful name |
||
783 | .4: |
||
784 | call get_dump |
||
785 | pop eax |
||
786 | ; int3 command generates exception 0D, #GP |
||
787 | push eax |
||
788 | cmp al, 0Dh |
||
789 | jnz .notdbg |
||
790 | ; check for 0xCC byte at eip |
||
791 | push 0 |
||
792 | ;push 69 |
||
793 | ;pop eax |
||
794 | ;push 6 |
||
795 | ;pop ebx |
||
796 | ;mov ecx, [debuggee_pid] |
||
797 | ;mov edi, esp |
||
798 | ;mov esi, [_eip] |
||
799 | ;push 1 |
||
800 | ;pop edx |
||
801 | mcall 69, 6, [debuggee_pid], 1, [_eip], esp |
||
802 | pop eax |
||
803 | cmp al, 0xCC |
||
804 | jnz .notdbg |
||
805 | ; this is either dbg breakpoint or int3 cmd in debuggee |
||
806 | mov eax, [_eip] |
||
807 | call find_enabled_breakpoint |
||
808 | jnz .user_int3 |
||
809 | ; dbg breakpoint; clear if one-shot |
||
810 | pop ecx |
||
811 | push eax |
||
812 | mov esi, aBreakStop |
||
813 | test byte [edi+4], 4 |
||
814 | jz .put_msg_eax |
||
815 | pop ecx |
||
816 | call clear_breakpoint |
||
817 | jmp .done |
||
818 | |||
819 | .user_int3: |
||
820 | mov eax, [_eip] |
||
821 | inc [_eip] |
||
822 | pop ecx |
||
823 | push eax |
||
824 | call set_context |
||
825 | mov esi, aUserBreak |
||
826 | jmp .put_msg_eax |
||
827 | |||
828 | .notdbg: |
||
829 | mov esi, aException |
||
830 | |||
831 | .put_msg_eax: |
||
832 | call put_message_nodraw |
||
833 | |||
834 | .done_draw: |
||
835 | call draw_messages |
||
836 | |||
837 | .done: |
||
838 | ;push 18 |
||
839 | ;pop eax |
||
840 | ;push 3 |
||
841 | ;pop ebx |
||
842 | ;mov ecx, [dbgwnd] |
||
843 | mcall 18, 3, [dbgwnd] ; activate dbg window |
||
844 | call redraw_title |
||
845 | call draw_registers.redraw |
||
846 | call draw_dump.redraw |
||
847 | call update_disasm_eip |
||
848 | |||
205 | heavyiron | 849 | dbgmsgend: |
3675 | GerdtR | 850 | pop esi |
851 | mov ecx, [dbgbuflen] |
||
852 | add ecx, dbgbuf |
||
853 | cmp esi, ecx |
||
854 | jnz dbgmsgstart |
||
855 | and [dbgbuflen], 0 |
||
856 | neg [dbgbufsize] |
||
857 | cmp [bReload], 2 |
||
858 | jnz @f |
||
859 | mov [bReload], 0 |
||
860 | call do_reload |
||
205 | heavyiron | 861 | |
3675 | GerdtR | 862 | @@: |
863 | jmp waitevent |
||
864 | |||
865 | ; TODO: make it local |
||
205 | heavyiron | 866 | CtrlF7: |
3675 | GerdtR | 867 | cmp [debuggee_pid], 0 |
868 | jz .no |
||
869 | call OnStep |
||
870 | |||
871 | .no: |
||
872 | jmp waitevent |
||
873 | |||
874 | ; TODO: make it local |
||
205 | heavyiron | 875 | CtrlF8: |
3675 | GerdtR | 876 | cmp [debuggee_pid], 0 |
877 | jz CtrlF7.no |
||
878 | call OnProceed |
||
879 | jmp CtrlF7.no |
||
205 | heavyiron | 880 | |
3675 | GerdtR | 881 | ;----------------------------------------------------------------------------- |
882 | ; Step execution event |
||
883 | |||
884 | ;Here we get [ |
||
205 | heavyiron | 885 | OnStep: |
3675 | GerdtR | 886 | cmp [bSuspended], 0 |
887 | jz .running |
||
888 | cmp [step_num], 0 |
||
889 | jg .stepone |
||
890 | mov esi, [curarg] |
||
4285 | tserj | 891 | cmp esi, 0 |
892 | jz .stepone |
||
3675 | GerdtR | 893 | cmp byte [esi], 0 |
894 | jz .stepone |
||
895 | call get_hex_number |
||
896 | jc .ret |
||
897 | cmp eax, 0 ; check if lesser or equal than 0 |
||
898 | jle .ret |
||
899 | mov [step_num], eax |
||
900 | mov [curarg], 0 |
||
205 | heavyiron | 901 | |
3675 | GerdtR | 902 | .stepone: |
903 | call get_context |
||
904 | or byte [_eflags+1], 1 ; set TF |
||
905 | call set_context |
||
906 | and byte [_eflags+1], not 1 |
||
907 | ; if instruction at eip is "int xx", set one-shot breakpoint immediately after |
||
908 | mov eax, [_eip] |
||
909 | call find_enabled_breakpoint |
||
910 | jnz @f |
||
911 | cmp byte [edi+5], 0xCD |
||
912 | jz .int |
||
913 | |||
914 | @@: |
||
915 | push 0 |
||
916 | ;push 69 |
||
917 | ;pop eax |
||
918 | ;push 6 |
||
919 | ;pop ebx |
||
920 | ;mov ecx, [debuggee_pid] |
||
921 | ;push 3 |
||
922 | ;pop edx |
||
923 | ;mov edi, esp |
||
924 | ;mov esi, [_eip] |
||
925 | mcall 69, 6, [debuggee_pid], 3, [_eip], esp |
||
926 | cmp eax, edx |
||
927 | pop eax |
||
928 | jnz .doit |
||
929 | cmp al, 0xCD |
||
930 | jz .int |
||
931 | cmp ax, 0x050F |
||
932 | jz .syscall |
||
933 | cmp ax, 0x340F |
||
934 | jz .sysenter |
||
935 | |||
936 | ; resume process |
||
937 | .doit: |
||
938 | call GoOn |
||
939 | cmp [bAfterGo], 0 |
||
940 | jz @f |
||
941 | mov [bAfterGo], 2 |
||
942 | |||
943 | @@: |
||
944 | mov eax, [step_num] |
||
945 | dec eax |
||
946 | cmp eax, 0 |
||
947 | jle .ret |
||
948 | mov [step_num], eax |
||
949 | jmp .stepone |
||
950 | |||
951 | .ret: |
||
952 | mov [step_num], 0 |
||
953 | ret |
||
954 | |||
955 | ; return address is [ebp-4] |
||
956 | .sysenter: |
||
957 | push 0 |
||
958 | ;push 69 |
||
959 | ;pop eax |
||
960 | inc edx ; read 4 bytes |
||
961 | mov esi, [_ebp] |
||
962 | sub esi, 4 |
||
963 | mcall 69 |
||
964 | cmp eax, edx |
||
965 | pop eax |
||
966 | jnz .syscall |
||
967 | push eax |
||
968 | and byte [_eflags+1], not 1 |
||
969 | call set_context |
||
970 | pop eax |
||
971 | jmp @f |
||
972 | |||
973 | .syscall: |
||
974 | and byte [_eflags+1], not 1 ; clear TF - avoid system halt (!) |
||
975 | call set_context |
||
976 | |||
977 | .int: |
||
978 | mov eax, [_eip] |
||
979 | inc eax |
||
980 | inc eax |
||
981 | |||
982 | @@: |
||
983 | push eax |
||
984 | call find_enabled_breakpoint |
||
985 | pop eax |
||
986 | jz .doit |
||
987 | ; there is no enabled breakpoint yet; set temporary breakpoint |
||
988 | mov bl, 5 |
||
989 | call add_breakpoint |
||
990 | jmp .doit |
||
991 | |||
992 | .running: |
||
993 | mov esi, aRunningErr |
||
994 | jmp put_message |
||
995 | |||
996 | ;----------------------------------------------------------------------------- |
||
997 | ; Proceed process event |
||
998 | |||
205 | heavyiron | 999 | OnProceed: |
3675 | GerdtR | 1000 | cmp [bSuspended], 0 |
1001 | jz OnStep.running |
||
1002 | cmp [proc_num], 0 |
||
1003 | jg .procone |
||
1004 | mov esi, [curarg] |
||
4285 | tserj | 1005 | cmp esi, 0 |
1006 | jz .procone |
||
3675 | GerdtR | 1007 | cmp byte [esi], 0 |
1008 | jz .procone |
||
1009 | call get_hex_number |
||
1010 | jc .ret |
||
1011 | cmp eax, 0 ; check if lesser than 0 |
||
1012 | jle .ret |
||
1013 | mov [proc_num], eax |
||
1014 | mov [curarg], 0 |
||
205 | heavyiron | 1015 | |
3675 | GerdtR | 1016 | .procone: |
1017 | mov esi, [_eip] |
||
205 | heavyiron | 1018 | |
3675 | GerdtR | 1019 | @@: |
1020 | call get_byte_nobreak |
||
1021 | jc OnStep.stepone |
||
1022 | inc esi |
||
1023 | ; skip prefixes |
||
1024 | call is_prefix |
||
1025 | jz @b |
||
1026 | cmp al, 0xE8 ; call |
||
1027 | jnz @f |
||
1028 | add esi, 4 |
||
1029 | jmp .doit |
||
205 | heavyiron | 1030 | |
3675 | GerdtR | 1031 | ; A4,A5 = movs; A6,A7 = cmps |
1032 | @@: |
||
1033 | cmp al, 0xA4 |
||
1034 | jb @f |
||
1035 | cmp al, 0xA8 |
||
1036 | jb .doit |
||
205 | heavyiron | 1037 | |
3675 | GerdtR | 1038 | ; AA,AB = stos; AC,AD = lods; AE,AF = scas |
1039 | @@: |
||
1040 | cmp al, 0xAA |
||
1041 | jb @f |
||
1042 | cmp al, 0xB0 |
||
1043 | jb .doit |
||
205 | heavyiron | 1044 | |
3675 | GerdtR | 1045 | ; E0 = loopnz; E1 = loopz; E2 = loop |
1046 | @@: |
||
1047 | cmp al, 0xE0 |
||
1048 | jb .noloop |
||
1049 | cmp al, 0xE2 |
||
1050 | ja .noloop |
||
1051 | inc esi |
||
1052 | jmp .doit |
||
205 | heavyiron | 1053 | |
3675 | GerdtR | 1054 | ; FF /2 = call |
1055 | .noloop: |
||
1056 | cmp al, 0xFF |
||
1057 | jnz OnStep.stepone |
||
1058 | call get_byte_nobreak |
||
1059 | jc OnStep.stepone |
||
1060 | inc esi |
||
1061 | mov cl, al |
||
1062 | and al, 00111000b |
||
1063 | cmp al, 00010000b |
||
1064 | jnz OnStep.stepone |
||
1065 | ; skip instruction |
||
1066 | mov al, cl |
||
1067 | and eax, 7 |
||
1068 | shr cl, 6 |
||
1069 | jz .mod0 |
||
1070 | jp .doit |
||
1071 | cmp al, 4 |
||
1072 | jnz @f |
||
1073 | inc esi |
||
205 | heavyiron | 1074 | |
3675 | GerdtR | 1075 | @@: |
1076 | inc esi |
||
1077 | dec cl |
||
1078 | jz @f |
||
1079 | add esi, 3 |
||
205 | heavyiron | 1080 | |
3675 | GerdtR | 1081 | @@: |
1082 | jmp .doit |
||
205 | heavyiron | 1083 | |
3675 | GerdtR | 1084 | .mod0: |
1085 | cmp al, 4 |
||
1086 | jnz @f |
||
1087 | call get_byte_nobreak |
||
1088 | jc OnStep.stepone |
||
1089 | inc esi |
||
1090 | and al, 7 |
||
205 | heavyiron | 1091 | |
3675 | GerdtR | 1092 | @@: |
1093 | cmp al, 5 |
||
1094 | jnz .doit |
||
1095 | add esi, 4 |
||
205 | heavyiron | 1096 | |
3675 | GerdtR | 1097 | .doit: |
1098 | ; insert one-shot breakpoint at esi and resume |
||
1099 | call get_byte_nobreak |
||
1100 | jc OnStep.stepone |
||
1101 | mov eax, esi |
||
1102 | call find_enabled_breakpoint |
||
1103 | jz @f |
||
1104 | mov eax, esi |
||
1105 | mov bl, 5 |
||
1106 | call add_breakpoint |
||
1107 | jmp OnStep.doit |
||
1108 | |||
1109 | @@: |
||
1110 | mov eax, [proc_num] |
||
1111 | dec eax |
||
1112 | cmp eax, 0 |
||
1113 | jle .ret |
||
1114 | mov [proc_num], eax |
||
1115 | jmp .procone |
||
1116 | |||
1117 | .ret: |
||
1118 | mov [proc_num], 0 |
||
1119 | ret |
||
1120 | |||
1121 | ;----------------------------------------------------------------------------- |
||
1122 | ; Read next byte of machine code |
||
1123 | |||
1124 | get_byte_nobreak: |
||
1125 | mov eax, esi |
||
1126 | call find_enabled_breakpoint |
||
1127 | jnz .nobreak |
||
1128 | mov al, [edi+5] |
||
1129 | clc |
||
1130 | ret |
||
1131 | |||
1132 | .nobreak: |
||
1133 | ;push 69 |
||
1134 | ;pop eax |
||
1135 | ;push 6 |
||
1136 | ;pop ebx |
||
1137 | ;mov ecx, [debuggee_pid] |
||
1138 | xor edx, edx |
||
1139 | push edx |
||
1140 | inc edx |
||
1141 | mov edi, esp |
||
1142 | mcall 69, 6, [debuggee_pid] |
||
1143 | dec eax |
||
1144 | clc |
||
1145 | jz @f |
||
1146 | stc |
||
1147 | |||
1148 | @@: |
||
1149 | pop eax |
||
1150 | ret |
||
1151 | |||
1152 | include 'parser.inc' |
||
1153 | |||
1154 | ;----------------------------------------------------------------------------- |
||
1155 | ; Calculate expression event |
||
1156 | |||
205 | heavyiron | 1157 | OnCalc: |
3675 | GerdtR | 1158 | mov esi, [curarg] |
1159 | call calc_expression |
||
1160 | jc .ret |
||
1161 | push ebp |
||
1162 | mov esi, calc_string |
||
1163 | call put_message_nodraw |
||
1164 | jmp draw_messages |
||
1165 | |||
1166 | .ret: |
||
1167 | ret |
||
205 | heavyiron | 1168 | |
3675 | GerdtR | 1169 | ;----------------------------------------------------------------------------- |
1170 | ; Dump memory event |
||
1171 | |||
205 | heavyiron | 1172 | OnDump: |
3675 | GerdtR | 1173 | mov esi, [curarg] |
1174 | cmp byte [esi], 0 |
||
1175 | jnz .param |
||
1176 | add [dumppos], dump_height*10h |
||
1177 | jmp .doit |
||
1178 | |||
1179 | .param: |
||
1180 | call calc_expression |
||
1181 | jc .ret |
||
1182 | mov [dumppos], ebp |
||
205 | heavyiron | 1183 | |
3675 | GerdtR | 1184 | .doit: |
1185 | call get_dump |
||
1186 | call draw_dump.redraw |
||
1187 | |||
1188 | .ret: |
||
1189 | ret |
||
1190 | |||
1191 | ;----------------------------------------------------------------------------- |
||
1192 | ; Dissassemble block of executable event |
||
1193 | |||
205 | heavyiron | 1194 | OnUnassemble: |
3675 | GerdtR | 1195 | mov esi, [curarg] |
1196 | cmp byte [esi], 0 |
||
1197 | jnz .param |
||
1198 | mov eax, [disasm_start_pos] |
||
1199 | mov ecx, disasm_height |
||
1200 | mov [disasm_cur_pos], eax |
||
205 | heavyiron | 1201 | |
3675 | GerdtR | 1202 | .l: |
1203 | mov eax, [disasm_cur_pos] |
||
1204 | call find_symbol |
||
1205 | jc @f |
||
1206 | dec ecx |
||
1207 | jz .m |
||
1208 | |||
1209 | @@: |
||
1210 | push ecx |
||
1211 | call disasm_instr |
||
1212 | pop ecx |
||
1213 | jc .err |
||
1214 | loop .l |
||
1215 | |||
1216 | .m: |
||
1217 | mov eax, [disasm_cur_pos] |
||
1218 | jmp .doit |
||
1219 | |||
1220 | .param: |
||
1221 | call calc_expression |
||
1222 | jc .ret |
||
1223 | mov eax, ebp |
||
1224 | |||
1225 | .doit: |
||
1226 | push eax |
||
1227 | push [disasm_start_pos] |
||
1228 | mov [disasm_start_pos], eax |
||
1229 | call update_disasm |
||
1230 | pop [disasm_start_pos] |
||
1231 | pop eax |
||
1232 | cmp [disasm_cur_str], 0 |
||
1233 | jz @f |
||
1234 | mov [disasm_start_pos], eax |
||
1235 | |||
1236 | .ret: |
||
1237 | ret |
||
1238 | |||
1239 | @@: |
||
1240 | call update_disasm |
||
1241 | |||
1242 | .err: |
||
1243 | mov esi, aInvAddr |
||
1244 | jmp put_message |
||
1245 | |||
1246 | ;----------------------------------------------------------------------------- |
||
1247 | ; Access to register value event |
||
1248 | |||
205 | heavyiron | 1249 | OnReg: |
3675 | GerdtR | 1250 | mov esi, [curarg] |
1251 | call get_arg.skip_spaces |
||
1252 | call find_reg |
||
1253 | jnc @f |
||
205 | heavyiron | 1254 | |
3675 | GerdtR | 1255 | .err: |
1256 | mov esi, RSyntax |
||
1257 | jmp put_message |
||
1258 | |||
1259 | @@: |
||
1260 | call get_arg.skip_spaces |
||
1261 | test al, al |
||
1262 | jz .err |
||
1263 | cmp al, '=' |
||
1264 | jnz @f |
||
1265 | inc esi |
||
1266 | call get_arg.skip_spaces |
||
1267 | test al, al |
||
1268 | jz .err |
||
1269 | |||
1270 | @@: |
||
1271 | push edi |
||
1272 | call calc_expression |
||
1273 | pop edi |
||
1274 | jc .ret |
||
1275 | ; now edi=register id, ebp=value |
||
1276 | cmp [bSuspended], 0 |
||
1277 | mov esi, aRunningErr |
||
1278 | jz put_message |
||
1279 | xchg eax, ebp |
||
1280 | cmp edi, 24 |
||
1281 | jz .eip |
||
1282 | sub edi, 4 |
||
1283 | jb .8lo |
||
1284 | sub edi, 4 |
||
1285 | jb .8hi |
||
1286 | sub edi, 8 |
||
1287 | jb .16 |
||
1288 | mov [_eax+edi*4], eax |
||
1289 | jmp .ret |
||
1290 | |||
1291 | .16: |
||
1292 | mov word [_eax+(edi+8)*4], ax |
||
1293 | jmp .ret |
||
1294 | |||
1295 | .8lo: |
||
1296 | mov byte [_eax+(edi+4)*4], al |
||
1297 | jmp .ret |
||
1298 | |||
1299 | .8hi: |
||
1300 | mov byte [_eax+(edi+4)*4+1], al |
||
1301 | jmp .ret |
||
1302 | |||
1303 | .eip: |
||
1304 | mov [_eip], eax |
||
1305 | call update_disasm_eip |
||
1306 | |||
1307 | .ret: |
||
1308 | call set_context |
||
1309 | jmp draw_registers.redraw |
||
1310 | |||
1311 | ;----------------------------------------------------------------------------- |
||
1312 | ; Breakpoints manipulation |
||
205 | heavyiron | 1313 | OnBp: |
3675 | GerdtR | 1314 | mov esi, [curarg] |
1315 | call calc_expression |
||
1316 | jc .ret |
||
1317 | xchg eax, ebp |
||
1318 | push eax |
||
1319 | call find_breakpoint |
||
1320 | inc eax |
||
1321 | pop eax |
||
1322 | jz .notfound |
||
1323 | mov esi, aDuplicateBreakpoint |
||
1324 | jmp .sayerr |
||
205 | heavyiron | 1325 | |
3675 | GerdtR | 1326 | .notfound: |
1327 | mov bl, 1 |
||
1328 | call add_breakpoint |
||
1329 | jnc .ret |
||
1330 | mov esi, aBreakpointLimitExceeded |
||
1331 | |||
1332 | .sayerr: |
||
1333 | call put_message |
||
1334 | |||
1335 | .ret: |
||
1336 | jmp draw_disasm.redraw |
||
1337 | |||
205 | heavyiron | 1338 | OnBpmb: |
3675 | GerdtR | 1339 | mov dh, 0011b |
1340 | jmp DoBpm |
||
1341 | |||
205 | heavyiron | 1342 | OnBpmw: |
3675 | GerdtR | 1343 | mov dh, 0111b |
1344 | jmp DoBpm |
||
1345 | |||
205 | heavyiron | 1346 | OnBpmd: |
3675 | GerdtR | 1347 | mov dh, 1111b |
1348 | |||
205 | heavyiron | 1349 | DoBpm: |
3675 | GerdtR | 1350 | mov esi, [curarg] |
1351 | cmp byte [esi], 'w' |
||
1352 | jnz @f |
||
1353 | and dh, not 2 |
||
1354 | inc esi |
||
205 | heavyiron | 1355 | |
3675 | GerdtR | 1356 | @@: |
1357 | push edx |
||
1358 | call calc_expression |
||
1359 | pop edx |
||
1360 | jnc @f |
||
1361 | ret |
||
1362 | |||
1363 | ; ebp = expression, dh = flags |
||
1364 | @@: |
||
1365 | movzx eax, dh |
||
1366 | shr eax, 2 |
||
1367 | test ebp, eax |
||
1368 | jz @f |
||
1369 | mov esi, aUnaligned |
||
1370 | jmp put_message |
||
1371 | |||
1372 | @@: |
||
1373 | mov eax, ebp |
||
1374 | mov bl, 0Bh |
||
1375 | call add_breakpoint |
||
1376 | jnc @f |
||
1377 | mov esi, aBreakpointLimitExceeded |
||
1378 | jmp put_message |
||
1379 | |||
1380 | ; now find index |
||
1381 | @@: |
||
1382 | push eax |
||
1383 | xor ecx, ecx |
||
1384 | |||
1385 | .l1: |
||
1386 | cmp [drx_break+ecx*4], 0 |
||
1387 | jnz .l2 |
||
1388 | ;push 69 |
||
1389 | ;pop eax |
||
1390 | push ecx |
||
1391 | mov dl, cl |
||
1392 | ;mov ecx, [debuggee_pid] |
||
1393 | mov esi, ebp |
||
1394 | ;push 9 |
||
1395 | ;pop ebx |
||
1396 | mcall 69, 9, [debuggee_pid] |
||
1397 | test eax, eax |
||
1398 | jz .ok |
||
1399 | pop ecx |
||
1400 | |||
1401 | .l2: |
||
1402 | inc ecx |
||
1403 | cmp ecx, 4 |
||
1404 | jb .l1 |
||
1405 | pop eax |
||
1406 | call clear_breakpoint |
||
1407 | mov esi, aBreakpointLimitExceeded |
||
1408 | jmp put_message |
||
1409 | |||
1410 | .ok: |
||
1411 | pop ecx |
||
1412 | pop eax |
||
1413 | and byte [edi], not 2 ; breakpoint is enabled |
||
1414 | shl dl, 6 |
||
1415 | or dl, dh |
||
1416 | mov byte [edi+1], dl |
||
1417 | inc eax |
||
1418 | mov [drx_break+ecx*4], eax |
||
1419 | ret |
||
1420 | |||
205 | heavyiron | 1421 | OnBc: |
3675 | GerdtR | 1422 | mov esi, [curarg] |
205 | heavyiron | 1423 | |
3675 | GerdtR | 1424 | @@: |
1425 | call get_hex_number |
||
1426 | jc OnBp.ret |
||
1427 | call clear_breakpoint |
||
1428 | jmp @b |
||
1429 | |||
205 | heavyiron | 1430 | OnBd: |
3675 | GerdtR | 1431 | mov esi, [curarg] |
205 | heavyiron | 1432 | |
3675 | GerdtR | 1433 | @@: |
1434 | call get_hex_number |
||
1435 | jc OnBp.ret |
||
1436 | call disable_breakpoint |
||
1437 | jmp @b |
||
1438 | |||
205 | heavyiron | 1439 | OnBe: |
3675 | GerdtR | 1440 | mov esi, [curarg] |
205 | heavyiron | 1441 | |
3675 | GerdtR | 1442 | @@: |
1443 | call get_hex_number |
||
1444 | jc OnBp.ret |
||
1445 | push eax |
||
1446 | call find_enabled_breakpoint |
||
1447 | pop eax |
||
1448 | jz .err |
||
1449 | call enable_breakpoint |
||
1450 | jmp @b |
||
1451 | |||
1452 | .err: |
||
1453 | mov esi, OnBeErrMsg |
||
1454 | jmp put_message |
||
1455 | |||
1456 | ; TODO: split it out in parser.inc |
||
205 | heavyiron | 1457 | get_hex_number: |
3675 | GerdtR | 1458 | call get_arg.skip_spaces |
1459 | xor ecx, ecx |
||
1460 | xor edx, edx |
||
205 | heavyiron | 1461 | |
3675 | GerdtR | 1462 | @@: |
1463 | lodsb |
||
1464 | call is_hex_digit |
||
1465 | jc .ret |
||
1466 | shl edx, 4 |
||
1467 | or dl, al |
||
1468 | inc ecx |
||
1469 | jmp @b |
||
1470 | |||
1471 | .ret: |
||
1472 | dec esi |
||
1473 | cmp ecx, 1 |
||
1474 | xchg eax, edx |
||
1475 | ret |
||
1476 | |||
1477 | ;----------------------------------------------------------------------------- |
||
1478 | ; Breakpoints list event |
||
1479 | |||
205 | heavyiron | 1480 | OnBl: |
3675 | GerdtR | 1481 | mov esi, [curarg] |
1482 | cmp byte [esi], 0 |
||
1483 | jz .listall |
||
1484 | call get_hex_number |
||
1485 | jc .ret |
||
1486 | cmp eax, breakpoints_n |
||
1487 | jae .err |
||
1488 | push eax |
||
1489 | add eax, eax |
||
1490 | lea edi, [breakpoints + eax + eax*2] |
||
1491 | pop eax |
||
1492 | test byte [edi+4], 1 |
||
1493 | jz .err |
||
1494 | call show_break_info |
||
205 | heavyiron | 1495 | |
3675 | GerdtR | 1496 | .ret: |
1497 | ret |
||
1498 | |||
1499 | .err: |
||
1500 | mov esi, aInvalidBreak |
||
1501 | jmp put_message |
||
1502 | |||
1503 | .listall: |
||
1504 | mov edi, breakpoints |
||
1505 | xor eax, eax |
||
1506 | |||
1507 | @@: |
||
1508 | test byte [edi+4], 1 |
||
1509 | jz .cont |
||
1510 | push edi eax |
||
1511 | call show_break_info |
||
1512 | pop eax edi |
||
1513 | |||
1514 | .cont: |
||
1515 | add edi, 6 |
||
1516 | inc eax |
||
1517 | cmp eax, breakpoints_n |
||
1518 | jb @b |
||
1519 | ret |
||
1520 | |||
1521 | ;----------------------------------------------------------------------------- |
||
1522 | |||
205 | heavyiron | 1523 | show_break_info: |
3675 | GerdtR | 1524 | push edi |
1525 | test byte [edi+4], 8 |
||
1526 | jnz .dr |
||
1527 | push dword [edi] |
||
1528 | push eax |
||
1529 | mov esi, aBreakNum |
||
1530 | call put_message_nodraw |
||
1531 | jmp .cmn |
||
205 | heavyiron | 1532 | |
3675 | GerdtR | 1533 | .dr: |
1534 | push eax |
||
1535 | mov esi, aMemBreak1 |
||
1536 | call put_message_nodraw |
||
1537 | pop edi |
||
1538 | push edi |
||
1539 | mov esi, aMemBreak2 |
||
1540 | test byte [edi+5], 2 |
||
1541 | jz @f |
||
1542 | mov esi, aMemBreak3 |
||
1543 | |||
1544 | @@: |
||
1545 | call put_message_nodraw |
||
1546 | pop edi |
||
1547 | push edi |
||
1548 | mov esi, aMemBreak6 |
||
1549 | test byte [edi+5], 8 |
||
1550 | jnz @f |
||
1551 | mov esi, aMemBreak5 |
||
1552 | test byte [edi+5], 4 |
||
1553 | jnz @f |
||
1554 | mov esi, aMemBreak4 |
||
1555 | |||
1556 | @@: |
||
1557 | call put_message_nodraw |
||
1558 | pop edi |
||
1559 | push edi |
||
1560 | push dword [edi] |
||
1561 | mov esi, aMemBreak7 |
||
1562 | call put_message_nodraw |
||
1563 | |||
1564 | .cmn: |
||
1565 | pop edi |
||
1566 | test byte [edi+4], 2 |
||
1567 | jz @f |
||
1568 | push edi |
||
1569 | mov esi, aDisabled |
||
1570 | call put_message_nodraw |
||
1571 | pop edi |
||
1572 | |||
1573 | @@: |
||
1574 | test byte [edi+4], 4 |
||
1575 | jz @f |
||
1576 | mov esi, aOneShot |
||
1577 | call put_message_nodraw |
||
1578 | |||
1579 | @@: |
||
1580 | mov esi, newline |
||
1581 | jmp put_message |
||
1582 | |||
1583 | ;----------------------------------------------------------------------------- |
||
1584 | ; Add breakpoint |
||
1585 | ; in: EAX = address; BL = flags |
||
1586 | ; out: CF = 1 => error |
||
1587 | ; CF = 0 and EAX = breakpoint number |
||
1588 | |||
205 | heavyiron | 1589 | add_breakpoint: |
3675 | GerdtR | 1590 | xor ecx, ecx |
1591 | mov edi, breakpoints |
||
205 | heavyiron | 1592 | |
3675 | GerdtR | 1593 | @@: |
1594 | test byte [edi+4], 1 |
||
1595 | jz .found |
||
1596 | add edi, 6 |
||
1597 | inc ecx |
||
1598 | cmp ecx, breakpoints_n |
||
1599 | jb @b |
||
1600 | stc |
||
1601 | ret |
||
1602 | |||
1603 | .found: |
||
1604 | stosd |
||
1605 | xchg eax, ecx |
||
1606 | mov [edi], bl |
||
1607 | test bl, 2 |
||
1608 | jnz @f |
||
1609 | or byte [edi], 2 |
||
1610 | push eax |
||
1611 | call enable_breakpoint |
||
1612 | pop eax |
||
1613 | |||
1614 | @@: |
||
1615 | clc |
||
1616 | ret |
||
1617 | |||
1618 | ;----------------------------------------------------------------------------- |
||
1619 | ; Remove breakpoint |
||
1620 | |||
205 | heavyiron | 1621 | clear_breakpoint: |
3675 | GerdtR | 1622 | cmp eax, breakpoints_n |
1623 | jae .ret |
||
1624 | mov ecx, 4 |
||
1625 | inc eax |
||
205 | heavyiron | 1626 | |
3675 | GerdtR | 1627 | .1: |
1628 | cmp [drx_break-4+ecx*4], eax |
||
1629 | jnz @f |
||
1630 | and [drx_break-4+ecx*4], 0 |
||
1631 | |||
1632 | @@: |
||
1633 | loop .1 |
||
1634 | dec eax |
||
1635 | push eax |
||
1636 | add eax, eax |
||
1637 | lea edi, [breakpoints + eax + eax*2 + 4] |
||
1638 | test byte [edi], 1 |
||
1639 | pop eax |
||
1640 | jz .ret |
||
1641 | push edi |
||
1642 | call disable_breakpoint |
||
1643 | pop edi |
||
1644 | mov byte [edi], 0 |
||
1645 | |||
1646 | .ret: |
||
1647 | ret |
||
1648 | |||
1649 | ;----------------------------------------------------------------------------- |
||
1650 | ; Disable breakpoint |
||
1651 | |||
205 | heavyiron | 1652 | disable_breakpoint: |
3675 | GerdtR | 1653 | cmp eax, breakpoints_n |
1654 | jae .ret |
||
1655 | add eax, eax |
||
1656 | lea edi, [breakpoints + eax + eax*2 + 5] |
||
1657 | test byte [edi-1], 1 |
||
1658 | jz .ret |
||
1659 | test byte [edi-1], 2 |
||
1660 | jnz .ret |
||
1661 | or byte [edi-1], 2 |
||
1662 | test byte [edi-1], 8 |
||
1663 | jnz .dr |
||
1664 | push esi |
||
1665 | ;push 7 |
||
1666 | ;pop ebx |
||
1667 | ;push 69 |
||
1668 | ;pop eax |
||
1669 | ;mov ecx, [debuggee_pid] |
||
1670 | ;xor edx, edx |
||
1671 | ;inc edx |
||
1672 | ;mov esi, [edi-5] |
||
1673 | mcall 69, 7, [debuggee_pid], 1, [edi-5] |
||
1674 | pop esi |
||
205 | heavyiron | 1675 | |
3675 | GerdtR | 1676 | .ret: |
1677 | ret |
||
1678 | |||
1679 | .dr: |
||
1680 | mov dl, [edi] |
||
1681 | shr dl, 6 |
||
1682 | mov dh, 80h |
||
1683 | ;push 69 |
||
1684 | ;pop eax |
||
1685 | ;push 9 |
||
1686 | ;pop ebx |
||
1687 | ;mov ecx, [debuggee_pid] |
||
1688 | mcall 69, 9, [debuggee_pid] |
||
1689 | ret |
||
1690 | |||
1691 | ;----------------------------------------------------------------------------- |
||
1692 | ; Enable breakpoint |
||
1693 | |||
205 | heavyiron | 1694 | enable_breakpoint: |
3675 | GerdtR | 1695 | push esi |
1696 | cmp eax, breakpoints_n |
||
1697 | jae .ret |
||
1698 | add eax, eax |
||
1699 | lea edi, [breakpoints + eax + eax*2 + 5] |
||
1700 | test byte [edi-1], 1 |
||
1701 | jz .ret |
||
1702 | test byte [edi-1], 2 |
||
1703 | jz .ret |
||
1704 | and byte [edi-1], not 2 |
||
1705 | test byte [edi-1], 8 |
||
1706 | jnz .dr |
||
1707 | ;push 6 |
||
1708 | ;pop ebx |
||
1709 | ;push 69 |
||
1710 | ;pop eax |
||
1711 | ;mov esi, [edi-5] |
||
1712 | ;mov ecx, [debuggee_pid] |
||
1713 | ;xor edx, edx |
||
1714 | ;inc edx |
||
1715 | mcall 69, 6, [debuggee_pid], 1, [edi-5] |
||
1716 | dec eax |
||
1717 | jnz .err |
||
1718 | ;mov al, 69 |
||
1719 | push 0xCC |
||
1720 | mov edi, esp |
||
1721 | inc ebx |
||
1722 | mcall 69 |
||
1723 | pop eax |
||
205 | heavyiron | 1724 | |
3675 | GerdtR | 1725 | .ret: |
1726 | pop esi |
||
1727 | ret |
||
205 | heavyiron | 1728 | |
3675 | GerdtR | 1729 | .err: |
1730 | or byte [edi-1], 2 |
||
1731 | mov esi, aBreakErr |
||
1732 | call put_message |
||
1733 | pop esi |
||
1734 | ret |
||
205 | heavyiron | 1735 | |
3675 | GerdtR | 1736 | .dr: |
1737 | ;push 9 |
||
1738 | ;pop ebx |
||
1739 | ;push 69 |
||
1740 | ;pop eax |
||
1741 | mov esi, [edi-5] |
||
1742 | ;mov ecx, [debuggee_pid] |
||
1743 | mov dl, [edi] |
||
1744 | shr dl, 6 |
||
1745 | mov dh, [edi] |
||
1746 | and dh, 0xF |
||
1747 | mcall 69, 9, [debuggee_pid] |
||
1748 | test eax, eax |
||
1749 | jnz .err |
||
1750 | pop esi |
||
1751 | ret |
||
205 | heavyiron | 1752 | |
3675 | GerdtR | 1753 | ;----------------------------------------------------------------------------- |
1754 | ; Find breakpoint |
||
542 | diamond | 1755 | |
3675 | GerdtR | 1756 | find_breakpoint: |
1757 | xor ecx, ecx |
||
1758 | xchg eax, ecx |
||
1759 | mov edi, breakpoints |
||
542 | diamond | 1760 | |
3675 | GerdtR | 1761 | @@: |
1762 | test byte [edi+4], 1 |
||
1763 | jz .cont |
||
1764 | test byte [edi+4], 8 |
||
1765 | jnz .cont |
||
1766 | cmp [edi], ecx |
||
1767 | jz .found |
||
542 | diamond | 1768 | |
3675 | GerdtR | 1769 | .cont: |
1770 | add edi, 6 |
||
1771 | inc eax |
||
1772 | cmp eax, breakpoints_n |
||
1773 | jb @b |
||
1774 | or eax, -1 |
||
542 | diamond | 1775 | |
3675 | GerdtR | 1776 | .found: |
1777 | ret |
||
542 | diamond | 1778 | |
3675 | GerdtR | 1779 | ;----------------------------------------------------------------------------- |
1780 | ; |
||
542 | diamond | 1781 | |
3675 | GerdtR | 1782 | find_enabled_breakpoint: |
1783 | xor ecx, ecx |
||
1784 | xchg eax, ecx |
||
1785 | mov edi, breakpoints |
||
542 | diamond | 1786 | |
3675 | GerdtR | 1787 | @@: |
1788 | test byte [edi+4], 1 |
||
1789 | jz .cont |
||
1790 | test byte [edi+4], 2 or 8 |
||
1791 | jnz .cont |
||
1792 | cmp [edi], ecx |
||
1793 | jz .found |
||
542 | diamond | 1794 | |
3675 | GerdtR | 1795 | .cont: |
1796 | add edi, 6 |
||
1797 | inc eax |
||
1798 | cmp eax, breakpoints_n |
||
1799 | jb @b |
||
1800 | or eax, -1 |
||
205 | heavyiron | 1801 | |
3675 | GerdtR | 1802 | .found: |
1803 | ret |
||
205 | heavyiron | 1804 | |
3675 | GerdtR | 1805 | ; TODO: add find_disabled_breakpoint |
205 | heavyiron | 1806 | |
3675 | GerdtR | 1807 | ;----------------------------------------------------------------------------- |
1808 | ; Unpack executable event |
||
205 | heavyiron | 1809 | |
3675 | GerdtR | 1810 | OnUnpack: |
1811 | ; program must be loaded - checked when command was parsed |
||
1812 | ; program must be stopped |
||
1813 | mov esi, aRunningErr |
||
1814 | cmp [bSuspended], 0 |
||
1815 | jz put_message |
||
1816 | ; all breakpoints must be disabled |
||
1817 | mov edi, breakpoints |
||
205 | heavyiron | 1818 | |
3675 | GerdtR | 1819 | @@: |
1820 | test byte [edi+4], 1 |
||
1821 | jz .cont |
||
1822 | test byte [edi+4], 2 |
||
1823 | jnz .cont |
||
1824 | mov esi, aEnabledBreakErr |
||
1825 | jmp put_message |
||
205 | heavyiron | 1826 | |
3675 | GerdtR | 1827 | .cont: |
1828 | add edi, 6 |
||
1829 | cmp edi, breakpoints+breakpoints_n*6 |
||
1830 | jb @b |
||
1831 | ; ok, now do it |
||
1832 | ; set breakpoint on 0xC dword access |
||
1833 | push 9 |
||
1834 | pop ebx |
||
1835 | mov ecx, [debuggee_pid] |
||
1836 | mov dx, 1111b*256 |
||
1837 | push 0xC |
||
1838 | pop esi |
||
205 | heavyiron | 1839 | |
3675 | GerdtR | 1840 | @@: |
1841 | ;push 69 |
||
1842 | ;pop eax |
||
1843 | mcall 69 |
||
1844 | test eax, eax |
||
1845 | jz .breakok |
||
1846 | inc edx |
||
1847 | cmp dl, 4 |
||
1848 | jb @b |
||
809 | diamond | 1849 | |
3675 | GerdtR | 1850 | .breakok: |
1851 | call GoOn |
||
809 | diamond | 1852 | |
3675 | GerdtR | 1853 | ; now wait for event |
1854 | .wait: |
||
1855 | ;push 10 |
||
1856 | ;pop eax |
||
1857 | mcall 10 |
||
1858 | dec eax |
||
1859 | jz .redraw |
||
1860 | dec eax |
||
1861 | jz .key |
||
1862 | dec eax |
||
1863 | jnz .debug |
||
1864 | ; button; we have only one button, close |
||
1865 | or eax, -1 |
||
1866 | mcall |
||
205 | heavyiron | 1867 | |
3675 | GerdtR | 1868 | .redraw: |
1869 | call draw_window |
||
1870 | jmp .wait |
||
205 | heavyiron | 1871 | |
3675 | GerdtR | 1872 | .key: |
1873 | mov al, 2 |
||
1874 | mcall |
||
1875 | cmp ah, 3 ; Ctrl+C |
||
1876 | jnz .wait |
||
205 | heavyiron | 1877 | |
3675 | GerdtR | 1878 | .userbreak: |
1879 | mov esi, aInterrupted |
||
205 | heavyiron | 1880 | |
3675 | GerdtR | 1881 | .x1: |
1882 | push edx esi |
||
1883 | call put_message |
||
1884 | pop esi edx |
||
1885 | or dh, 80h |
||
1886 | ;push 69 |
||
1887 | ;pop eax |
||
1888 | ;push 9 |
||
1889 | ;pop ebx |
||
1890 | ;mov ecx, [debuggee_pid] |
||
1891 | mcall 69, 9, [debuggee_pid] |
||
1892 | cmp esi, aUnpacked |
||
1893 | jnz OnSuspend |
||
1894 | jmp AfterSuspend |
||
205 | heavyiron | 1895 | |
3675 | GerdtR | 1896 | .debug: |
1897 | cmp [dbgbuflen], 4*3 |
||
1898 | jnz .notour |
||
1899 | cmp dword [dbgbuf], 3 |
||
1900 | jnz .notour |
||
1901 | test byte [dbgbuf+8], 1 |
||
1902 | jnz .our |
||
205 | heavyiron | 1903 | |
3675 | GerdtR | 1904 | .notour: |
1905 | mov esi, aInterrupted |
||
1906 | push edx |
||
1907 | call put_message |
||
1908 | pop edx |
||
1909 | or dh, 80h |
||
1910 | ;push 69 |
||
1911 | ;pop eax |
||
1912 | ;push 9 |
||
1913 | ;pop ebx |
||
1914 | ;mov ecx, [debuggee_pid] |
||
1915 | mcall 69, 9, [debuggee_pid] |
||
1916 | jmp debugmsg |
||
205 | heavyiron | 1917 | |
3675 | GerdtR | 1918 | .our: |
1919 | and [dbgbuflen], 0 |
||
1920 | push edx |
||
1921 | call get_context |
||
1922 | push eax |
||
1923 | ;mov al, 69 |
||
1924 | ;mov bl, 6 |
||
1925 | ;mov ecx, [debuggee_pid] |
||
1926 | ;mov edi, esp |
||
1927 | ;push 4 |
||
1928 | ;pop edx |
||
1929 | ;push 0xC |
||
1930 | ;pop esi |
||
1931 | mcall 69, 6, [debuggee_pid], 4, 0xC, esp |
||
1932 | pop eax |
||
1933 | pop edx |
||
1934 | cmp eax, [_eip] |
||
1935 | jz .done |
||
1936 | call DoResume |
||
1937 | jmp .wait |
||
205 | heavyiron | 1938 | |
3675 | GerdtR | 1939 | .done: |
1940 | mov esi, aUnpacked |
||
1941 | jmp .x1 |
||
809 | diamond | 1942 | |
3675 | GerdtR | 1943 | ;----------------------------------------------------------------------------- |
1944 | ; Working with program symbols |
||
1945 | ; |
||
1946 | ; TODO: split to symbols.inc |
||
205 | heavyiron | 1947 | |
3675 | GerdtR | 1948 | include 'sort.inc' |
205 | heavyiron | 1949 | |
3675 | GerdtR | 1950 | ; compare what? Add context-relative comment and name |
1951 | compare: |
||
1952 | cmpsd |
||
1953 | jnz @f |
||
1954 | cmp esi, edi |
||
205 | heavyiron | 1955 | |
3675 | GerdtR | 1956 | @@: |
1957 | ret |
||
205 | heavyiron | 1958 | |
3675 | GerdtR | 1959 | ; purpose of this function? |
1960 | compare2: |
||
1961 | cmpsd |
||
205 | heavyiron | 1962 | |
3675 | GerdtR | 1963 | @@: |
1964 | cmpsb |
||
1965 | jnz @f |
||
1966 | cmp byte [esi-1], 0 |
||
1967 | jnz @b |
||
1968 | cmp esi, edi |
||
205 | heavyiron | 1969 | |
3675 | GerdtR | 1970 | @@: |
1971 | ret |
||
205 | heavyiron | 1972 | |
3675 | GerdtR | 1973 | free_symbols: |
1974 | mov ecx, [symbols] |
||
1975 | jecxz @f |
||
1976 | mcall 68, 13 |
||
1977 | and [symbols], 0 |
||
1978 | and [num_symbols], 0 |
||
205 | heavyiron | 1979 | |
3675 | GerdtR | 1980 | @@: |
1981 | ret |
||
1982 | ;----------------------------------------------------------------------------- |
||
1983 | ; Load symbols event |
||
205 | heavyiron | 1984 | |
3675 | GerdtR | 1985 | OnLoadSymbols.fileerr: |
1986 | test ebp, ebp |
||
1987 | jz @f |
||
1988 | mcall 68, 13, edi |
||
1989 | ret |
||
205 | heavyiron | 1990 | |
3675 | GerdtR | 1991 | @@: |
1992 | push eax |
||
1993 | mcall 68, 13, edi |
||
1994 | mov esi, aCannotLoadFile |
||
1995 | call put_message_nodraw |
||
1996 | pop eax |
||
1997 | cmp eax, 0x20 |
||
1998 | jae .unk |
||
1999 | mov esi, [load_err_msgs + eax*4] |
||
2000 | test esi, esi |
||
2001 | jnz put_message |
||
205 | heavyiron | 2002 | |
3675 | GerdtR | 2003 | .unk: |
2004 | mov esi, unk_err_msg2 |
||
2005 | jmp put_message |
||
205 | heavyiron | 2006 | |
3675 | GerdtR | 2007 | OnLoadSymbols: |
2008 | xor ebp, ebp |
||
2009 | ; load input file |
||
2010 | mov esi, [curarg] |
||
2011 | call free_symbols |
||
809 | diamond | 2012 | |
3675 | GerdtR | 2013 | .silent: |
2014 | xor edi, edi |
||
2015 | cmp [num_symbols], edi |
||
2016 | jz @f |
||
2017 | |||
2018 | call free_symbols |
||
2019 | ;ret |
||
2020 | |||
2021 | @@: |
||
2022 | mov ebx, fn70_attr_block |
||
2023 | mov [ebx+21], esi |
||
2024 | mcall 70 |
||
2025 | test eax, eax |
||
2026 | jnz .fileerr |
||
2027 | cmp dword [fileattr+36], edi |
||
2028 | jnz .memerr |
||
2029 | mov ecx, dword [fileattr+32] |
||
2030 | mcall 68, 12 |
||
2031 | test eax, eax |
||
2032 | jz .memerr |
||
2033 | mov edi, eax |
||
2034 | mov ebx, fn70_read_block |
||
2035 | mov [ebx+12], ecx |
||
2036 | mov [ebx+16], edi |
||
2037 | mov [ebx+21], esi |
||
2038 | mcall 70 |
||
2039 | test eax, eax |
||
2040 | jnz .fileerr |
||
2041 | ; calculate memory requirements |
||
2042 | lea edx, [ecx+edi-1] ; edx = EOF-1 |
||
2043 | mov esi, edi |
||
2044 | xor ecx, ecx |
||
809 | diamond | 2045 | |
3675 | GerdtR | 2046 | .calcloop: |
2047 | cmp esi, edx |
||
2048 | jae .calcdone |
||
2049 | cmp word [esi], '0x' |
||
2050 | jnz .skipline |
||
2051 | inc esi |
||
2052 | inc esi |
||
809 | diamond | 2053 | |
3675 | GerdtR | 2054 | @@: |
2055 | cmp esi, edx |
||
2056 | jae .calcdone |
||
2057 | lodsb |
||
2058 | or al, 20h |
||
2059 | sub al, '0' |
||
2060 | cmp al, 9 |
||
2061 | jbe @b |
||
2062 | sub al, 'a'-'0'-10 |
||
2063 | cmp al, 15 |
||
2064 | jbe @b |
||
2065 | dec esi |
||
205 | heavyiron | 2066 | |
3675 | GerdtR | 2067 | @@: |
2068 | cmp esi, edx |
||
2069 | ja .calcdone |
||
2070 | lodsb |
||
2071 | cmp al, 20h |
||
2072 | jz @b |
||
2073 | jb .calcloop |
||
2074 | cmp al, 9 |
||
2075 | jz @b |
||
2076 | add ecx, 12+1 |
||
2077 | inc [num_symbols] |
||
809 | diamond | 2078 | |
3675 | GerdtR | 2079 | @@: |
2080 | inc ecx |
||
2081 | cmp esi, edx |
||
2082 | ja .calcdone |
||
2083 | lodsb |
||
2084 | cmp al, 0xD |
||
2085 | jz .calcloop |
||
2086 | cmp al, 0xA |
||
2087 | jz .calcloop |
||
2088 | jmp @b |
||
205 | heavyiron | 2089 | |
3675 | GerdtR | 2090 | .skipline: |
2091 | cmp esi, edx |
||
2092 | jae .calcdone |
||
2093 | lodsb |
||
2094 | cmp al, 0xD |
||
2095 | jz .calcloop |
||
2096 | cmp al, 0xA |
||
2097 | jz .calcloop |
||
2098 | jmp .skipline |
||
542 | diamond | 2099 | |
3675 | GerdtR | 2100 | .calcdone: |
2101 | mcall 68, 12 |
||
2102 | test eax, eax |
||
2103 | jnz .memok |
||
2104 | inc ebx |
||
2105 | mov ecx, edi |
||
2106 | mov al, 68 |
||
2107 | mcall |
||
205 | heavyiron | 2108 | |
3675 | GerdtR | 2109 | .memerr: |
2110 | mov esi, aNoMemory |
||
2111 | jmp put_message |
||
205 | heavyiron | 2112 | |
3675 | GerdtR | 2113 | .memok: |
2114 | mov [symbols], eax |
||
2115 | mov ebx, eax |
||
2116 | push edi |
||
2117 | mov esi, edi |
||
2118 | mov edi, [num_symbols] |
||
2119 | lea ebp, [eax+edi*4] |
||
2120 | lea edi, [eax+edi*8] |
||
205 | heavyiron | 2121 | |
3675 | GerdtR | 2122 | ; parse input data, |
2123 | ; esi->input, edx->EOF, ebx->ptrs, edi->names |
||
2124 | .readloop: |
||
2125 | cmp esi, edx |
||
2126 | jae .readdone |
||
2127 | cmp word [esi], '0x' |
||
2128 | jnz .readline |
||
2129 | inc esi |
||
2130 | inc esi |
||
2131 | xor eax, eax |
||
2132 | xor ecx, ecx |
||
205 | heavyiron | 2133 | |
3675 | GerdtR | 2134 | @@: |
2135 | shl ecx, 4 |
||
2136 | add ecx, eax |
||
2137 | cmp esi, edx |
||
2138 | jae .readdone |
||
2139 | lodsb |
||
2140 | or al, 20h |
||
2141 | sub al, '0' |
||
2142 | cmp al, 9 |
||
2143 | jbe @b |
||
2144 | sub al, 'a'-'0'-10 |
||
2145 | cmp al, 15 |
||
2146 | jbe @b |
||
2147 | dec esi |
||
809 | diamond | 2148 | |
3675 | GerdtR | 2149 | @@: |
2150 | cmp esi, edx |
||
2151 | ja .readdone |
||
2152 | lodsb |
||
2153 | cmp al, 20h |
||
2154 | jz @b |
||
2155 | jb .readloop |
||
2156 | cmp al, 9 |
||
2157 | jz @b |
||
2158 | mov dword [ebx], edi |
||
2159 | add ebx, 4 |
||
2160 | mov dword [ebp], edi |
||
2161 | add ebp, 4 |
||
2162 | mov dword [edi], ecx |
||
2163 | add edi, 4 |
||
2164 | stosb |
||
205 | heavyiron | 2165 | |
3675 | GerdtR | 2166 | @@: |
2167 | xor eax, eax |
||
2168 | stosb |
||
2169 | cmp esi, edx |
||
2170 | ja .readdone |
||
2171 | lodsb |
||
2172 | cmp al, 0xD |
||
2173 | jz .readloop |
||
2174 | cmp al, 0xA |
||
2175 | jz .readloop |
||
2176 | mov byte [edi-1], al |
||
2177 | jmp @b |
||
205 | heavyiron | 2178 | |
3675 | GerdtR | 2179 | .readline: |
2180 | cmp esi, edx |
||
2181 | jae .readdone |
||
2182 | lodsb |
||
2183 | cmp al, 0xD |
||
2184 | jz .readloop |
||
2185 | cmp al, 0xA |
||
2186 | jz .readloop |
||
2187 | jmp .readline |
||
205 | heavyiron | 2188 | |
3675 | GerdtR | 2189 | .readdone: |
2190 | pop ecx |
||
2191 | mcall 68, 13 |
||
2192 | mov ecx, [num_symbols] |
||
2193 | mov edx, [symbols] |
||
2194 | mov ebx, compare |
||
2195 | call sort |
||
2196 | mov ecx, [num_symbols] |
||
2197 | lea edx, [edx+ecx*4] |
||
2198 | mov ebx, compare2 |
||
2199 | call sort |
||
2200 | mov esi, aSymbolsLoaded |
||
2201 | call put_message |
||
2202 | jmp draw_disasm.redraw |
||
205 | heavyiron | 2203 | |
3675 | GerdtR | 2204 | ;----------------------------------------------------------------------------- |
2205 | ; |
||
2206 | ; in: EAX = address |
||
2207 | ; out: ESI, CF |
||
205 | heavyiron | 2208 | |
3675 | GerdtR | 2209 | find_symbol: |
2210 | cmp [num_symbols], 0 |
||
2211 | jnz @f |
||
205 | heavyiron | 2212 | |
3675 | GerdtR | 2213 | .ret0: |
2214 | xor esi, esi |
||
2215 | stc |
||
2216 | ret |
||
205 | heavyiron | 2217 | |
3675 | GerdtR | 2218 | @@: |
2219 | push ebx ecx edx |
||
2220 | xor edx, edx |
||
2221 | mov esi, [symbols] |
||
2222 | mov ecx, [num_symbols] |
||
2223 | mov ebx, [esi] |
||
2224 | cmp [ebx], eax |
||
2225 | jz .donez |
||
2226 | jb @f |
||
2227 | pop edx ecx ebx |
||
2228 | jmp .ret0 |
||
809 | diamond | 2229 | |
3675 | GerdtR | 2230 | @@: |
2231 | ; invariant: symbols_addr[edx] < eax < symbols_addr[ecx] |
||
2232 | ; TODO: add meaningful label names |
||
2233 | .0: |
||
2234 | push edx |
||
205 | heavyiron | 2235 | |
3675 | GerdtR | 2236 | .1: |
2237 | add edx, ecx |
||
2238 | sar edx, 1 |
||
2239 | cmp edx, [esp] |
||
2240 | jz .done2 |
||
2241 | mov ebx, [esi+edx*4] |
||
2242 | cmp [ebx], eax |
||
2243 | jz .done |
||
2244 | ja .2 |
||
2245 | mov [esp], edx |
||
2246 | jmp .1 |
||
205 | heavyiron | 2247 | |
3675 | GerdtR | 2248 | .2: |
2249 | mov ecx, edx |
||
2250 | pop edx |
||
2251 | jmp .0 |
||
205 | heavyiron | 2252 | |
3675 | GerdtR | 2253 | .donecont: |
2254 | dec edx |
||
205 | heavyiron | 2255 | |
3675 | GerdtR | 2256 | .done: |
2257 | test edx, edx |
||
2258 | jz @f |
||
2259 | mov ebx, [esi+edx*4-4] |
||
2260 | cmp [ebx], eax |
||
2261 | jz .donecont |
||
205 | heavyiron | 2262 | |
3675 | GerdtR | 2263 | @@: |
2264 | pop ecx |
||
205 | heavyiron | 2265 | |
3675 | GerdtR | 2266 | .donez: |
2267 | mov esi, [esi+edx*4] |
||
2268 | add esi, 4 |
||
2269 | pop edx ecx ebx |
||
2270 | clc |
||
2271 | ret |
||
205 | heavyiron | 2272 | |
3675 | GerdtR | 2273 | .done2: |
2274 | lea esi, [esi+edx*4] |
||
2275 | pop ecx edx ecx ebx |
||
2276 | stc |
||
2277 | ret |
||
205 | heavyiron | 2278 | |
3675 | GerdtR | 2279 | ;----------------------------------------------------------------------------- |
2280 | ; |
||
2281 | ; in: esi->name |
||
2282 | ; out: if found: CF = 0, EAX = value |
||
2283 | ; otherwise CF = 1 |
||
2284 | find_symbol_name: |
||
2285 | cmp [num_symbols], 0 |
||
2286 | jnz @f |
||
205 | heavyiron | 2287 | |
3675 | GerdtR | 2288 | .stc_ret: |
2289 | stc |
||
2290 | ret |
||
205 | heavyiron | 2291 | |
3675 | GerdtR | 2292 | @@: |
2293 | push ebx ecx edx edi |
||
2294 | push -1 |
||
2295 | pop edx |
||
2296 | mov ebx, [symbols] |
||
2297 | mov ecx, [num_symbols] |
||
2298 | lea ebx, [ebx+ecx*4] |
||
2299 | |||
2300 | ; invariant: symbols_name[edx] < name < symbols_name[ecx] |
||
2301 | .0: |
||
2302 | push edx |
||
542 | diamond | 2303 | |
3675 | GerdtR | 2304 | .1: |
2305 | add edx, ecx |
||
2306 | sar edx, 1 |
||
2307 | cmp edx, [esp] |
||
2308 | jz .done2 |
||
2309 | call .cmp |
||
2310 | jz .done |
||
2311 | jb .2 |
||
2312 | mov [esp], edx |
||
2313 | jmp .1 |
||
542 | diamond | 2314 | |
3675 | GerdtR | 2315 | .2: |
2316 | mov ecx, edx |
||
2317 | pop edx |
||
2318 | jmp .0 |
||
542 | diamond | 2319 | |
3675 | GerdtR | 2320 | .done: |
2321 | pop ecx |
||
542 | diamond | 2322 | |
3675 | GerdtR | 2323 | .donez: |
2324 | mov eax, [ebx+edx*4] |
||
2325 | mov eax, [eax] |
||
2326 | pop edi edx ecx ebx |
||
2327 | clc |
||
2328 | ret |
||
542 | diamond | 2329 | |
3675 | GerdtR | 2330 | .done2: |
2331 | pop edx edi edx ecx ebx |
||
2332 | stc |
||
2333 | ret |
||
809 | diamond | 2334 | |
3675 | GerdtR | 2335 | .cmp: |
2336 | mov edi, [ebx+edx*4] |
||
2337 | push esi |
||
2338 | add edi, 4 |
||
809 | diamond | 2339 | |
3675 | GerdtR | 2340 | @@: |
2341 | cmpsb |
||
2342 | jnz @f |
||
2343 | cmp byte [esi-1], 0 |
||
2344 | jnz @b |
||
542 | diamond | 2345 | |
3675 | GerdtR | 2346 | @@: |
2347 | pop esi |
||
2348 | ret |
||
809 | diamond | 2349 | |
3675 | GerdtR | 2350 | ;----------------------------------------------------------------------------- |
2351 | ; Include disassembler engine |
||
2352 | |||
2353 | include 'disasm.inc' |
||
2354 | |||
205 | heavyiron | 2355 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2356 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
2357 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
2358 | |||
2359 | caption_str db 'Kolibri Debugger',0 |
||
2360 | caption_len = $ - caption_str |
||
2361 | |||
4285 | tserj | 2362 | begin_str db 'Kolibri Debugger, version 0.33',10 |
3675 | GerdtR | 2363 | db 'Hint: type "help" for help, "quit" for quit' |
2364 | newline db 10,0 |
||
2365 | prompt db '> ',0 |
||
2366 | |||
205 | heavyiron | 2367 | help_groups: |
3675 | GerdtR | 2368 | dd aControl, 0, 0, help_control_msg |
2369 | db 0 |
||
2370 | dd aData, 0, 0, help_data_msg |
||
2371 | db 0 |
||
2372 | dd aBreakpoints, 0, 0, help_breaks_msg |
||
2373 | db 0 |
||
2374 | |||
2375 | ;----------------------------------------------------------------------------- |
||
2376 | ; Commands format definitions |
||
2377 | |||
2378 | ; TODO: make it with macros |
||
2379 | |||
205 | heavyiron | 2380 | ; flags field: |
2381 | ; &1: command may be called without parameters |
||
2382 | ; &2: command may be called with parameters |
||
2383 | ; &4: command may be called without loaded program |
||
2384 | ; &8: command may be called with loaded program |
||
2385 | commands: |
||
3675 | GerdtR | 2386 | dd _aH, OnHelp, HelpSyntax, HelpHelp |
2387 | db 0Fh |
||
2388 | dd aHelp, OnHelp, HelpSyntax, HelpHelp |
||
2389 | db 0Fh |
||
2390 | dd aQuit, OnQuit, QuitSyntax, QuitHelp |
||
2391 | db 0Dh |
||
2392 | dd aLoad, OnLoad, LoadSyntax, LoadHelp |
||
2393 | db 6 |
||
2394 | dd aReload, OnReload, ReloadSyntax, ReloadHelp |
||
2395 | db 0Dh |
||
2396 | dd aTerminate, OnTerminate, TerminateSyntax, TerminateHelp |
||
2397 | db 9 |
||
2398 | dd aDetach, OnDetach, DetachSyntax, DetachHelp |
||
2399 | db 9 |
||
2400 | dd aSuspend, OnSuspend, SuspendSyntax, SuspendHelp |
||
2401 | db 9 |
||
2402 | dd aResume, OnResume, ResumeSyntax, ResumeHelp |
||
2403 | db 0Bh |
||
2404 | dd aStep, OnStep, StepSyntax, StepHelp |
||
2405 | db 0Bh |
||
2406 | dd aProceed, OnProceed, ProceedSyntax, ProceedHelp |
||
2407 | db 0Bh |
||
2408 | dd aCalc, OnCalc, CalcSyntax, CalcHelp |
||
2409 | db 0Eh |
||
2410 | dd aDump, OnDump, DumpSyntax, DumpHelp |
||
2411 | db 0Bh |
||
2412 | dd aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp |
||
2413 | db 0Bh |
||
2414 | dd aBp, OnBp, BpSyntax, BpHelp |
||
2415 | db 0Ah |
||
2416 | dd aBpm, OnBpmb, BpmSyntax, BpmHelp |
||
2417 | db 0Ah |
||
2418 | dd aBpmb, OnBpmb, BpmSyntax, BpmHelp |
||
2419 | db 0Ah |
||
2420 | dd aBpmw, OnBpmw, BpmSyntax, BpmHelp |
||
2421 | db 0Ah |
||
2422 | dd aBpmd, OnBpmd, BpmSyntax, BpmHelp |
||
2423 | db 0Ah |
||
2424 | dd aBl, OnBl, BlSyntax, BlHelp |
||
2425 | db 0Bh |
||
2426 | dd aBc, OnBc, BcSyntax, BcHelp |
||
2427 | db 0Ah |
||
2428 | dd aBd, OnBd, BdSyntax, BdHelp |
||
2429 | db 0Ah |
||
2430 | dd aBe, OnBe, BeSyntax, BeHelp |
||
2431 | db 0Ah |
||
2432 | dd aReg, OnReg, RSyntax, RHelp |
||
2433 | db 0Ah |
||
2434 | dd aUnpack, OnUnpack, UnpackSyntax, UnpackHelp |
||
2435 | db 9 |
||
2436 | dd aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp |
||
2437 | db 0Ah |
||
2438 | dd 0 |
||
205 | heavyiron | 2439 | |
3675 | GerdtR | 2440 | ;----------------------------------------------------------------------------- |
2441 | ; Help messages for commands groups |
||
2442 | |||
2443 | aHelp db 5,'help',0 |
||
2444 | _aH db 2,'h',0 |
||
2445 | HelpHelp db 'Help on specified function',10 |
||
2446 | HelpSyntax db 'Usage: h or help [group | command]',10,0 |
||
2447 | |||
2448 | help_msg db 'List of known command groups:',10 |
||
2449 | db '"help control" - display list of control commands',10 |
||
2450 | db '"help data" - display list of commands concerning data',10 |
||
2451 | db '"help breakpoints" - display list of commands concerning breakpoints',10,0 |
||
2452 | |||
2453 | ; Control commands group |
||
2454 | |||
2455 | aControl db 8,'control',0 |
||
2456 | help_control_msg db 'List of control commands:',10 |
||
2457 | db 'h = help - help',10 |
||
2458 | db 'quit - exit from debugger',10 |
||
2459 | db 'load |
||
2460 | db 'reload - reload debugging program',10 |
||
2461 | db 'load-symbols |
||
2462 | db 'terminate - terminate loaded program',10 |
||
2463 | db 'detach - detach from debugging program',10 |
||
2464 | db 'stop - suspend execution of debugging program',10 |
||
2465 | db 'g [ |
||
2466 | db 's [ |
||
2467 | db 'p [ |
||
2468 | db 'unpack - try to bypass unpacker code (heuristic)',10,0 |
||
2469 | |||
2470 | ; Data commands group |
||
2471 | |||
2472 | aData db 5,'data',0 |
||
2473 | help_data_msg db 'List of data commands:',10 |
||
2474 | db '? |
||
2475 | db 'd [ |
||
2476 | db 'u [ |
||
2477 | db 'r |
||
2478 | db 'r |
||
2479 | |||
2480 | ; Breakpoints commands group |
||
2481 | |||
205 | heavyiron | 2482 | aBreakpoints db 12,'breakpoints',0 |
3675 | GerdtR | 2483 | help_breaks_msg db 'List of breakpoints commands:',10 |
2484 | db 'bp |
||
2485 | db 'bpm[b|w|d] |
||
2486 | db 'bl [ |
||
2487 | db 'bc |
||
2488 | db 'bd |
||
2489 | db 'be |
||
205 | heavyiron | 2490 | |
3675 | GerdtR | 2491 | ;----------------------------------------------------------------------------- |
2492 | ; Individual command help messages |
||
205 | heavyiron | 2493 | |
3675 | GerdtR | 2494 | aQuit db 5,'quit',0 |
2495 | QuitHelp db 'Quit from debugger',10 |
||
2496 | QuitSyntax db 'Usage: quit',10,0 |
||
205 | heavyiron | 2497 | |
3675 | GerdtR | 2498 | aLoad db 5,'load',0 |
2499 | LoadHelp db 'Load program for debugging',10 |
||
2500 | LoadSyntax db 'Usage: load |
||
205 | heavyiron | 2501 | |
3675 | GerdtR | 2502 | aReload db 7,'reload',0 |
2503 | ReloadHelp db 'Reload debugging program (restart debug session)',10 |
||
2504 | ReloadSyntax db 'Usage: reload',10,0 |
||
2505 | |||
2506 | aTerminate db 10,'terminate',0 |
||
205 | heavyiron | 2507 | TerminateHelp db 'Terminate debugged program',10 |
2508 | TerminateSyntax db 'Usage: terminate',10,0 |
||
2509 | |||
3675 | GerdtR | 2510 | aDetach db 7,'detach',0 |
2511 | DetachHelp db 'Detach from debugged program',10 |
||
2512 | DetachSyntax db 'Usage: detach',10,0 |
||
205 | heavyiron | 2513 | |
3675 | GerdtR | 2514 | aSuspend db 5,'stop',0 |
2515 | SuspendHelp db 'Suspend execution of debugged program',10 |
||
205 | heavyiron | 2516 | SuspendSyntax db 'Usage: stop',10,0 |
2517 | |||
3675 | GerdtR | 2518 | aResume db 2,'g',0 |
2519 | ResumeHelp db 'Go (resume execution of debugged program)',10 |
||
2520 | ResumeSyntax db 'Usage: g',10 |
||
2521 | db ' or: g |
||
205 | heavyiron | 2522 | |
3675 | GerdtR | 2523 | aStep db 2,'s',0 |
2524 | StepHelp db 'Make step in debugged program',10 |
||
2525 | StepSyntax db 'Usage: s [ |
||
205 | heavyiron | 2526 | |
3675 | GerdtR | 2527 | aProceed db 2,'p',0 |
2528 | ProceedHelp db 'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10 |
||
2529 | ProceedSyntax db 'Usage: p [ |
||
205 | heavyiron | 2530 | |
3675 | GerdtR | 2531 | aDump db 2,'d',0 |
2532 | DumpHelp db 'Dump data of debugged program',10 |
||
2533 | DumpSyntax db 'Usage: d |
||
2534 | db ' or: d - continue current dump',10,0 |
||
205 | heavyiron | 2535 | |
3675 | GerdtR | 2536 | aCalc db 2,'?',0 |
2537 | CalcHelp db 'Calculate value of expression',10 |
||
2538 | CalcSyntax db 'Usage: ? |
||
205 | heavyiron | 2539 | |
3675 | GerdtR | 2540 | aUnassemble db 2,'u',0 |
205 | heavyiron | 2541 | UnassembleHelp db 'Unassemble',10 |
3675 | GerdtR | 2542 | UnassembleSyntax db 'Usage: u |
2543 | db ' or: u - continue current unassemble screen',10,0 |
||
205 | heavyiron | 2544 | |
3675 | GerdtR | 2545 | aReg db 2,'r',0 |
2546 | RHelp db 'Set register value',10 |
||
2547 | RSyntax db 'Usage: r |
||
2548 | db ' or: r |
||
205 | heavyiron | 2549 | |
3675 | GerdtR | 2550 | aBp db 3,'bp',0 |
2551 | BpHelp db 'set BreakPoint on execution',10 |
||
2552 | BpSyntax db 'Usage: bp |
||
205 | heavyiron | 2553 | |
3675 | GerdtR | 2554 | aBpm db 4,'bpm',0 |
2555 | aBpmb db 5,'bpmb',0 |
||
2556 | aBpmw db 5,'bpmw',0 |
||
2557 | aBpmd db 5,'bpmd',0 |
||
2558 | BpmHelp db 'set BreakPoint on Memory access',10 |
||
2559 | db 'Maximum 4 breakpoints of this type are allowed',10 |
||
2560 | db 'Note that for this breaks debugger is activated after access',10 |
||
2561 | BpmSyntax db 'Usage: bpmb [w] |
||
2562 | db ' bpmw [w] |
||
2563 | db ' bpmd [w] |
||
2564 | db ' bpm is synonym for bpmd',10 |
||
2565 | db '"w" means break only on writes (default is on read/write)',10,0 |
||
205 | heavyiron | 2566 | |
3675 | GerdtR | 2567 | aBl db 3,'bl',0 |
2568 | BlHelp db 'Breakpoint List',10 |
||
2569 | BlSyntax db 'Usage: bl - list all breakpoints',10 |
||
2570 | db ' bl |
||
205 | heavyiron | 2571 | |
3675 | GerdtR | 2572 | aBc db 3,'bc',0 |
2573 | BcHelp db 'Breakpoint Clear',10 |
||
2574 | BcSyntax db 'Usage: bc |
||
2575 | db 'Examples: bc 2',10 |
||
2576 | db ' bc 1 3 4 A',10,0 |
||
205 | heavyiron | 2577 | |
3675 | GerdtR | 2578 | aBd db 3,'bd',0 |
2579 | BdHelp db 'Breakpoint Disable',10 |
||
2580 | BdSyntax db 'Usage: bd |
||
2581 | db 'Examples: bd 2',10 |
||
2582 | db ' bd 1 3 4 A',10,0 |
||
205 | heavyiron | 2583 | |
3675 | GerdtR | 2584 | aBe db 3,'be',0 |
2585 | BeHelp db 'Breakpoint Enable',10 |
||
2586 | BeSyntax db 'Usage: be |
||
2587 | db 'Examples: be 2',10 |
||
2588 | db ' be 1 3 4 A',10,0 |
||
205 | heavyiron | 2589 | |
3675 | GerdtR | 2590 | aUnpack db 7,'unpack',0 |
2591 | UnpackHelp db 'Try to bypass unpacker code',10 |
||
2592 | UnpackSyntax db 'Usage: unpack',10,0 |
||
205 | heavyiron | 2593 | |
3675 | GerdtR | 2594 | aLoadSymbols db 13,'load-symbols',0 |
542 | diamond | 2595 | LoadSymbolsHelp db 'Load symbolic information for executable',10 |
2596 | LoadSymbolsSyntax db 'Usage: load-symbols |
||
2597 | |||
205 | heavyiron | 2598 | aUnknownCommand db 'Unknown command',10,0 |
2599 | |||
3675 | GerdtR | 2600 | ;----------------------------------------------------------------------------- |
2601 | ; Error messages |
||
2602 | |||
2603 | load_err_msg db 'Cannot load program. ',0 |
||
2604 | unk_err_msg db 'Unknown error code -%4X',10,0 |
||
2605 | aCannotLoadFile db 'Cannot load file. ',0 |
||
2606 | unk_err_msg2 db 'Unknown error code %4X.',10,0 |
||
205 | heavyiron | 2607 | load_err_msgs: |
3675 | GerdtR | 2608 | dd .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0 |
2609 | dd 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20 |
||
2610 | .1 db 'HD undefined.',10,0 |
||
2611 | .3 db 'Unknown FS.',10,0 |
||
2612 | .5 db 'File not found.',10,0 |
||
2613 | .6 db 'Unexpected EOF.',10,0 |
||
2614 | .9 db 'FAT table corrupted.',10,0 |
||
2615 | .A db 'Access denied.',10,0 |
||
2616 | .1E db 'No memory.',10,0 |
||
2617 | .1F db 'Not Menuet/Kolibri executable.',10,0 |
||
2618 | .20 db 'Too many processes.',10,0 |
||
2619 | load_succ_msg db 'Program loaded successfully! PID=%4X. Use "g" to run.',10,0 |
||
2620 | need_debuggee db 'No program loaded. Use "load" command.',10,0 |
||
2621 | aAlreadyLoaded db 'Program is already loaded. Use "terminate" or "detach" commands',10,0 |
||
2622 | terminated_msg db 'Program terminated.',10,0 |
||
2623 | aException db 'Debugged program caused an exception %2X. ' |
||
2624 | aSuspended db 'Suspended',10,0 |
||
2625 | aContinued db 'Continuing',10,0 |
||
2626 | aRunningErr db 'Program is running',10,0 |
||
2627 | read_mem_err db 'ERROR: cannot read process memory!!!',10,0 |
||
205 | heavyiron | 2628 | aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0 |
3675 | GerdtR | 2629 | aBreakErr db 'Cannot activate breakpoint, it will be disabled',10,0 |
2630 | aDuplicateBreakpoint db 'Duplicate breakpoint',10,0 |
||
2631 | aInvalidBreak db 'Invalid breakpoint number',10,0 |
||
2632 | OnBeErrMsg db 'There is already enabled breakpoint on this address',10,0 |
||
2633 | aBreakNum db '%2X: at %8X',0 |
||
2634 | aMemBreak1 db '%2X: on ',0 |
||
2635 | aMemBreak2 db 'read from ',0 |
||
2636 | aMemBreak3 db 'access of ',0 |
||
2637 | aMemBreak4 db 'byte',0 |
||
2638 | aMemBreak5 db 'word',0 |
||
2639 | aMemBreak6 db 'dword',0 |
||
2640 | aMemBreak7 db ' at %8X',0 |
||
2641 | aOneShot db ', one-shot',0 |
||
2642 | aDisabled db ', disabled',0 |
||
2643 | aBreakStop db 'Breakpoint #%2X',10,0 |
||
2644 | aUserBreak db 'int3 command at %8X',10,0 |
||
2645 | ;dbgmsg_str db 'Debug message for process %4X.',10,0 |
||
2646 | aInvAddr db 'Invalid address',10,0 |
||
2647 | NoPrgLoaded_str db 'No program loaded' |
||
205 | heavyiron | 2648 | NoPrgLoaded_len = $ - NoPrgLoaded_str |
3675 | GerdtR | 2649 | aRunning db 'Running' |
2650 | aPaused db 'Paused' |
||
2651 | aMain db '[ CPU ]' |
||
2652 | aSSE db '[ SSE ]' |
||
2653 | aAVX db '[ AVX ]' |
||
2654 | aMSR db '[ MSR ]' |
||
2655 | aPoint db 0x1C |
||
2656 | aMinus db '-' |
||
2657 | aColon db ':' |
||
2658 | aSpace db ' ' |
||
2659 | aQuests db '??' |
||
2660 | aDots db '...' |
||
2661 | aParseError db 'Parse error',10,0 |
||
2662 | aDivByZero db 'Division by 0',10,0 |
||
2663 | calc_string db '%8X',10,0 |
||
2664 | aNoMemory db 'No memory',10,0 |
||
2665 | aSymbolsLoaded db 'Symbols loaded',10,0 |
||
2666 | aUnaligned db 'Unaligned address',10,0 |
||
2667 | aEnabledBreakErr db 'Enabled breakpoints are not allowed',10,0 |
||
2668 | aInterrupted db 'Interrupted',10,0 |
||
2669 | aUnpacked db 'Unpacked successful!',10,0 |
||
2670 | aPacked1 db 'Program is probably packed with ',0 |
||
2671 | aPacked2 db '.',10,'Try to unpack automatically? [y/n]: ',0 |
||
2672 | aY_str db 'y',10,0 |
||
2673 | aN_str db 'n',10,0 |
||
2674 | mxp_nrv_name db 'mxp_nrv',0 |
||
2675 | mxp_name db 'mxp',0 |
||
2676 | mxp_lzo_name db 'mxp_lzo',0 |
||
2677 | mtappack_name db 'mtappack',0 |
||
2678 | flags db 'CPAZSDO' |
||
2679 | flags_bits db 0,2,4,6,7,10,11 |
||
2680 | |||
2681 | ;----------------------------------------------------------------------------- |
||
2682 | ; Registers strings |
||
2683 | |||
205 | heavyiron | 2684 | regs_strs: |
3675 | GerdtR | 2685 | db 'EAX=' |
2686 | db 'EBX=' |
||
2687 | db 'ECX=' |
||
2688 | db 'EDX=' |
||
2689 | db 'ESI=' |
||
2690 | db 'EDI=' |
||
2691 | db 'EBP=' |
||
2692 | db 'ESP=' |
||
2693 | db 'EIP=' |
||
2694 | db 'EFLAGS=' |
||
2695 | fpu_strs: |
||
2696 | db 'ST0=' |
||
2697 | db 'ST1=' |
||
2698 | db 'ST2=' |
||
2699 | db 'ST3=' |
||
2700 | db 'ST4=' |
||
2701 | db 'ST5=' |
||
2702 | db 'ST6=' |
||
2703 | db 'ST7=' |
||
2704 | mmx_strs: |
||
2705 | db 'MM0=' |
||
2706 | db 'MM1=' |
||
2707 | db 'MM2=' |
||
2708 | db 'MM3=' |
||
2709 | db 'MM4=' |
||
2710 | db 'MM5=' |
||
2711 | db 'MM6=' |
||
2712 | db 'MM7=' |
||
2713 | sse_strs: |
||
2714 | db '-XMM0-' |
||
2715 | db '-XMM1-' |
||
2716 | db '-XMM2-' |
||
2717 | db '-XMM3-' |
||
2718 | db '-XMM4-' |
||
2719 | db '-XMM5-' |
||
2720 | db '-XMM6-' |
||
2721 | db '-XMM7-' |
||
2722 | avx_strs: |
||
2723 | db '-YMM0-' |
||
2724 | db '-YMM1-' |
||
2725 | db '-YMM2-' |
||
2726 | db '-YMM3-' |
||
2727 | db '-YMM4-' |
||
2728 | db '-YMM5-' |
||
2729 | db '-YMM6-' |
||
2730 | db '-YMM7-' |
||
205 | heavyiron | 2731 | |
3675 | GerdtR | 2732 | debuggee_pid dd 0 |
2733 | bSuspended db 0 |
||
2734 | bAfterGo db 0 |
||
2735 | temp_break dd 0 |
||
2736 | reg_mode db 1 |
||
205 | heavyiron | 2737 | |
3675 | GerdtR | 2738 | include 'disasm_tbl.inc' |
205 | heavyiron | 2739 | |
2740 | reg_table: |
||
3675 | GerdtR | 2741 | db 2,'al',0 |
2742 | db 2,'cl',1 |
||
2743 | db 2,'dl',2 |
||
2744 | db 2,'bl',3 |
||
2745 | db 2,'ah',4 |
||
2746 | db 2,'ch',5 |
||
2747 | db 2,'dh',6 |
||
2748 | db 2,'bh',7 |
||
2749 | db 2,'ax',8 |
||
2750 | db 2,'cx',9 |
||
2751 | db 2,'dx',10 |
||
2752 | db 2,'bx',11 |
||
2753 | db 2,'sp',12 |
||
2754 | db 2,'bp',13 |
||
2755 | db 2,'si',14 |
||
2756 | db 2,'di',15 |
||
2757 | db 3,'eax',16 |
||
2758 | db 3,'ecx',17 |
||
2759 | db 3,'edx',18 |
||
2760 | db 3,'ebx',19 |
||
2761 | db 3,'esp',20 |
||
2762 | db 3,'ebp',21 |
||
2763 | db 3,'esi',22 |
||
2764 | db 3,'edi',23 |
||
2765 | db 3,'eip',24 |
||
2766 | db 0 |
||
205 | heavyiron | 2767 | |
542 | diamond | 2768 | IncludeIGlobals |
2769 | |||
2770 | fn70_read_block: |
||
3675 | GerdtR | 2771 | dd 0 |
2772 | dq 0 |
||
2773 | dd ? |
||
2774 | dd ? |
||
2775 | db 0 |
||
2776 | dd ? |
||
542 | diamond | 2777 | |
2778 | fn70_attr_block: |
||
3675 | GerdtR | 2779 | dd 5 |
2780 | dd 0,0,0 |
||
2781 | dd fileattr |
||
2782 | db 0 |
||
2783 | dd ? |
||
542 | diamond | 2784 | |
205 | heavyiron | 2785 | fn70_load_block: |
3675 | GerdtR | 2786 | dd 7 |
2787 | dd 1 |
||
2788 | load_params dd 0 |
||
2789 | dd 0 |
||
2790 | dd 0 |
||
205 | heavyiron | 2791 | i_end: |
2792 | loadname: |
||
3675 | GerdtR | 2793 | db 0 |
2794 | rb 255 |
||
205 | heavyiron | 2795 | |
3675 | GerdtR | 2796 | symbolsfile rb 260 |
542 | diamond | 2797 | |
205 | heavyiron | 2798 | prgname_ptr dd ? |
2799 | prgname_len dd ? |
||
2800 | |||
542 | diamond | 2801 | IncludeUGlobals |
2802 | |||
3675 | GerdtR | 2803 | dbgwnd dd ? |
205 | heavyiron | 2804 | |
3675 | GerdtR | 2805 | messages rb messages_height*messages_width |
2806 | messages_pos dd ? |
||
205 | heavyiron | 2807 | |
3675 | GerdtR | 2808 | cmdline rb cmdline_width+1 |
2809 | cmdline_len dd ? |
||
2810 | cmdline_pos dd ? |
||
2811 | curarg dd ? |
||
205 | heavyiron | 2812 | |
3675 | GerdtR | 2813 | cmdline_prev rb cmdline_width+1 |
205 | heavyiron | 2814 | |
3675 | GerdtR | 2815 | was_temp_break db ? |
205 | heavyiron | 2816 | |
3675 | GerdtR | 2817 | dbgbufsize dd ? |
2818 | dbgbuflen dd ? |
||
2819 | dbgbuf rb 256 |
||
542 | diamond | 2820 | |
3675 | GerdtR | 2821 | fileattr rb 40 |
2822 | |||
205 | heavyiron | 2823 | needzerostart: |
2824 | |||
2825 | context: |
||
2826 | |||
3675 | GerdtR | 2827 | _eip dd ? |
2828 | _eflags dd ? |
||
2829 | _eax dd ? |
||
2830 | _ecx dd ? |
||
2831 | _edx dd ? |
||
2832 | _ebx dd ? |
||
2833 | _esp dd ? |
||
2834 | _ebp dd ? |
||
2835 | _esi dd ? |
||
2836 | _edi dd ? |
||
205 | heavyiron | 2837 | oldcontext rb $-context |
2838 | |||
3675 | GerdtR | 2839 | mmx_context: |
2840 | _mm0 dq ? |
||
2841 | _mm1 dq ? |
||
2842 | _mm2 dq ? |
||
2843 | _mm3 dq ? |
||
2844 | _mm4 dq ? |
||
2845 | _mm5 dq ? |
||
2846 | _mm6 dq ? |
||
2847 | _mm7 dq ? |
||
2848 | oldmmxcontext rb $-mmx_context |
||
205 | heavyiron | 2849 | |
3675 | GerdtR | 2850 | fpu_context: |
2851 | _st0 dq ? |
||
2852 | _st1 dq ? |
||
2853 | _st2 dq ? |
||
2854 | _st3 dq ? |
||
2855 | _st4 dq ? |
||
2856 | _st5 dq ? |
||
2857 | _st6 dq ? |
||
2858 | _st7 dq ? |
||
2859 | oldfpucontext rb $-fpu_context |
||
2860 | |||
2861 | sse_context: |
||
2862 | _xmm0 dq 2 dup ? |
||
2863 | _xmm1 dq 2 dup ? |
||
2864 | _xmm2 dq 2 dup ? |
||
2865 | _xmm3 dq 2 dup ? |
||
2866 | _xmm4 dq 2 dup ? |
||
2867 | _xmm5 dq 2 dup ? |
||
2868 | _xmm6 dq 2 dup ? |
||
2869 | _xmm7 dq 2 dup ? |
||
2870 | oldssecontext rb $-sse_context |
||
2871 | |||
2872 | avx_context: |
||
2873 | _ymm0 dq 4 dup ? |
||
2874 | _ymm1 dq 4 dup ? |
||
2875 | _ymm2 dq 4 dup ? |
||
2876 | _ymm3 dq 4 dup ? |
||
2877 | _ymm4 dq 4 dup ? |
||
2878 | _ymm5 dq 4 dup ? |
||
2879 | _ymm6 dq 4 dup ? |
||
2880 | _ymm7 dq 4 dup ? |
||
2881 | oldavxcontext rb $-avx_context |
||
2882 | |||
2883 | step_num dd 0 |
||
2884 | proc_num dd 0 |
||
2885 | dumpread dd ? |
||
2886 | dumppos dd ? |
||
2887 | dumpdata rb dump_height*10h |
||
2888 | |||
205 | heavyiron | 2889 | ; breakpoint structure: |
2890 | ; dword +0: address |
||
2891 | ; byte +4: flags |
||
2892 | ; bit 0: 1 <=> breakpoint valid |
||
2893 | ; bit 1: 1 <=> breakpoint disabled |
||
2894 | ; bit 2: 1 <=> one-shot breakpoint |
||
2895 | ; bit 3: 1 <=> DRx breakpoint |
||
2896 | ; byte +5: overwritten byte |
||
2897 | ; for DRx breaks: flags + (index shl 6) |
||
2898 | breakpoints_n = 256 |
||
3675 | GerdtR | 2899 | breakpoints rb breakpoints_n*6 |
2900 | drx_break rd 4 |
||
205 | heavyiron | 2901 | |
3675 | GerdtR | 2902 | disasm_buf_size dd ? |
205 | heavyiron | 2903 | |
3675 | GerdtR | 2904 | symbols dd ? |
2905 | num_symbols dd ? |
||
542 | diamond | 2906 | |
3675 | GerdtR | 2907 | bReload db ? |
205 | heavyiron | 2908 | |
2909 | needzeroend: |
||
2910 | |||
3675 | GerdtR | 2911 | disasm_buffer rb 256 |
2912 | disasm_start_pos dd ? |
||
2913 | disasm_cur_pos dd ? |
||
2914 | disasm_cur_str dd ? |
||
2915 | disasm_string rb 256 |
||
205 | heavyiron | 2916 | |
3675 | GerdtR | 2917 | i_param rb 256 |
205 | heavyiron | 2918 | |
2919 | ; stack |
||
3675 | GerdtR | 2920 | align 400h |
2921 | rb 400h |
||
205 | heavyiron | 2922 | used_mem: |
3675 | GerdtR | 2923 | |
2924 | ; vim: ft=fasm tabstop=4=>=>=>=>>>>> |
||
2925 |