Rev 444 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 444 | Rev 459 | ||
---|---|---|---|
Line 120... | Line 120... | ||
120 | ; ecx=sizeof(CONTEXT) |
120 | ; ecx=sizeof(CONTEXT) |
121 | ; edx->CONTEXT |
121 | ; edx->CONTEXT |
122 | ; destroys eax,ecx,edx,esi,edi |
122 | ; destroys eax,ecx,edx,esi,edi |
123 | cmp ecx, 28h |
123 | cmp ecx, 28h |
124 | jnz .ret |
124 | jnz .ret |
125 | ; add edx, std_application_base_address |
- | |
126 | push ebx |
125 | push ebx |
127 | mov ebx, edx |
126 | mov ebx, edx |
128 | call check_region |
127 | call check_region |
129 | pop ebx |
128 | pop ebx |
130 | dec eax |
129 | dec eax |
131 | jnz .ret |
130 | jnz .ret |
132 | call get_debuggee_slot |
131 | call get_debuggee_slot |
133 | jc .ret |
132 | jc .ret |
134 | ; imul eax, tss_step/32 |
133 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
135 | ; add eax, tss_data |
134 | lea esi, [eax+RING0_STACK_SIZE] |
136 | mov edi, edx |
135 | mov edi, edx |
137 | ; cmp [eax+TSS._cs], app_code |
- | |
138 | ; jnz .ring0 |
- | |
139 | ; lea esi, [eax+TSS._eip] |
- | |
140 | ; shr ecx, 2 |
- | |
141 | ; rep movsd |
- | |
142 | ; jmp .ret |
- | |
143 | .ring0: |
136 | .ring0: |
144 | ; note that following code assumes that all interrupt/exception handlers |
137 | ; note that following code assumes that all interrupt/exception handlers |
145 | ; saves ring-3 context by pushad in this order |
138 | ; saves ring-3 context by pushad in this order |
146 | mov esi, [tss._esp0] |
- | |
147 | ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad |
139 | ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad |
148 | sub esi, 8+12+20h |
140 | sub esi, 8+12+20h |
149 | lodsd ;edi |
141 | lodsd ;edi |
150 | mov [edi+24h], eax |
142 | mov [edi+24h], eax |
151 | lodsd ;esi |
143 | lodsd ;esi |
Line 159... | Line 151... | ||
159 | mov [edi+10h], eax |
151 | mov [edi+10h], eax |
160 | lodsd ;ecx |
152 | lodsd ;ecx |
161 | mov [edi+0Ch], eax |
153 | mov [edi+0Ch], eax |
162 | lodsd ;eax |
154 | lodsd ;eax |
163 | mov [edi+8], eax |
155 | mov [edi+8], eax |
164 | ;;; add esi, 8 ;ds es |
- | |
165 | lodsd ;eip |
156 | lodsd ;eip |
166 | mov [edi], eax |
157 | mov [edi], eax |
167 | lodsd ;cs |
158 | lodsd ;cs |
168 | lodsd ;eflags |
159 | lodsd ;eflags |
169 | mov [edi+4], eax |
160 | mov [edi+4], eax |
Line 179... | Line 170... | ||
179 | ; ecx=sizeof(CONTEXT) |
170 | ; ecx=sizeof(CONTEXT) |
180 | ; edx->CONTEXT |
171 | ; edx->CONTEXT |
181 | ; destroys eax,ecx,edx,esi,edi |
172 | ; destroys eax,ecx,edx,esi,edi |
182 | cmp ecx, 28h |
173 | cmp ecx, 28h |
183 | jnz .ret |
174 | jnz .ret |
184 | ; add edx, std_application_base_address |
- | |
185 | push ebx |
175 | push ebx |
186 | mov ebx, edx |
176 | mov ebx, edx |
187 | call check_region |
177 | call check_region |
188 | pop ebx |
178 | pop ebx |
189 | dec eax |
179 | dec eax |
190 | jnz .ret |
180 | jnz .ret |
191 | call get_debuggee_slot |
181 | call get_debuggee_slot |
192 | jc .stiret |
182 | jc .stiret |
193 | ; imul eax, tss_step/32 |
183 | mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
194 | ; add eax, tss_data |
184 | lea edi, [eax+RING0_STACK_SIZE] |
195 | mov esi, edx |
185 | mov esi, edx |
196 | ; cmp [eax+TSS._cs], app_code |
- | |
197 | ; jnz .ring0 |
- | |
198 | ; lea edi, [eax+TSS._eip] |
- | |
199 | ; shr ecx, 2 |
- | |
200 | ; rep movsd |
- | |
201 | ; jmp .stiret |
- | |
202 | .ring0: |
186 | .ring0: |
203 | mov edi, [tss._esp0] |
- | |
204 | sub edi, 8+12+20h |
187 | sub edi, 8+12+20h |
205 | mov eax, [esi+24h] ;edi |
188 | mov eax, [esi+24h] ;edi |
206 | stosd |
189 | stosd |
207 | mov eax, [esi+20h] ;esi |
190 | mov eax, [esi+20h] ;esi |
208 | stosd |
191 | stosd |
Line 215... | Line 198... | ||
215 | stosd |
198 | stosd |
216 | mov eax, [esi+0Ch] ;ecx |
199 | mov eax, [esi+0Ch] ;ecx |
217 | stosd |
200 | stosd |
218 | mov eax, [esi+8] ;eax |
201 | mov eax, [esi+8] ;eax |
219 | stosd |
202 | stosd |
220 | ;;; add edi, 8 ;ds es |
- | |
221 | mov eax, [esi] ;eip |
203 | mov eax, [esi] ;eip |
222 | stosd |
204 | stosd |
223 | scasd |
205 | scasd |
224 | mov eax, [esi+4] ;eflags |
206 | mov eax, [esi+4] ;eflags |
225 | stosd |
207 | stosd |
Line 235... | Line 217... | ||
235 | jc .errret |
217 | jc .errret |
236 | mov ebp, eax |
218 | mov ebp, eax |
237 | lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
219 | lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
238 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
220 | ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
239 | ; [eax+10]=dr7 |
221 | ; [eax+10]=dr7 |
240 | ; add edx, std_application_base_address |
222 | cmp edx, OS_BASE |
241 | jc .errret |
223 | jae .errret |
242 | cmp cl, 3 |
224 | cmp cl, 3 |
243 | ja .errret |
225 | ja .errret |
244 | mov ebx, dr7 |
226 | mov ebx, dr7 |
245 | shr ebx, cl |
227 | shr ebx, cl |
246 | shr ebx, cl |
228 | shr ebx, cl |
Line 255... | Line 237... | ||
255 | btr dword [eax+10h], ecx ; clear L bit |
237 | btr dword [eax+10h], ecx ; clear L bit |
256 | test byte [eax+10h], 55h |
238 | test byte [eax+10h], 55h |
257 | jnz .okret |
239 | jnz .okret |
258 | ; imul eax, ebp, tss_step/32 |
240 | ; imul eax, ebp, tss_step/32 |
259 | ; and byte [eax + tss_data + TSS._trap], not 1 |
241 | ; and byte [eax + tss_data + TSS._trap], not 1 |
- | 242 | and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1 |
|
260 | .okret: |
243 | .okret: |
261 | and dword [esp+36], 0 |
244 | and dword [esp+36], 0 |
262 | sti |
245 | sti |
263 | ret |
246 | ret |
264 | .errret: |
247 | .errret: |
Line 297... | Line 280... | ||
297 | not edx |
280 | not edx |
298 | and [eax+10h+2], dx |
281 | and [eax+10h+2], dx |
299 | or [eax+10h+2], bx ; set R/W and LEN fields |
282 | or [eax+10h+2], bx ; set R/W and LEN fields |
300 | ; imul eax, ebp, tss_step/32 |
283 | ; imul eax, ebp, tss_step/32 |
301 | ; or byte [eax + tss_data + TSS._trap], 1 |
284 | ; or byte [eax + tss_data + TSS._trap], 1 |
- | 285 | or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1 |
|
302 | jmp .okret |
286 | jmp .okret |
Line 303... | Line 287... | ||
303 | 287 | ||
304 | debug_read_process_memory: |
288 | debug_read_process_memory: |
305 | ; in: |
289 | ; in: |
306 | ; ebx=pid |
290 | ; ebx=pid |
307 | ; ecx=length |
291 | ; ecx=length |
308 | ; esi->buffer in debugger |
292 | ; esi->buffer in debugger |
309 | ; edx=address in debuggee |
293 | ; edx=address in debuggee |
310 | ; out: [esp+36]=sizeof(read) |
294 | ; out: [esp+36]=sizeof(read) |
311 | ; destroys all |
- | |
312 | ; add esi, std_application_base_address |
295 | ; destroys all |
313 | push ebx |
296 | push ebx |
314 | mov ebx, esi |
297 | mov ebx, esi |
315 | call check_region |
298 | call check_region |
316 | pop ebx |
299 | pop ebx |
Line 334... | Line 317... | ||
334 | ; ecx=length |
317 | ; ecx=length |
335 | ; esi->buffer in debugger |
318 | ; esi->buffer in debugger |
336 | ; edx=address in debuggee |
319 | ; edx=address in debuggee |
337 | ; out: [esp+36]=sizeof(write) |
320 | ; out: [esp+36]=sizeof(write) |
338 | ; destroys all |
321 | ; destroys all |
339 | ; add esi, std_application_base_address |
- | |
340 | push ebx |
322 | push ebx |
341 | mov ebx, esi |
323 | mov ebx, esi |
342 | call check_region |
324 | call check_region |
343 | pop ebx |
325 | pop ebx |
344 | dec eax |
326 | dec eax |
Line 431... | Line 413... | ||
431 | cld |
413 | cld |
432 | mov ax, app_data ;os_data |
414 | mov ax, app_data ;os_data |
433 | mov ds, ax |
415 | mov ds, ax |
434 | mov es, ax |
416 | mov es, ax |
435 | mov eax, dr6 |
417 | mov eax, dr6 |
436 | test ax, ax |
- | |
437 | jns @f |
- | |
438 | ; this is exception from task switch |
- | |
439 | ; set DRx registers for task and continue |
- | |
440 | mov eax, [CURRENT_TASK] |
- | |
441 | shl eax, 8 |
- | |
442 | add eax, SLOT_BASE+APPDATA.dbg_regs |
- | |
443 | mov ecx, [eax+0] |
- | |
444 | mov dr0, ecx |
- | |
445 | mov ecx, [eax+4] |
- | |
446 | mov dr1, ecx |
- | |
447 | mov ecx, [eax+8] |
- | |
448 | mov dr2, ecx |
- | |
449 | mov ecx, [eax+0Ch] |
- | |
450 | mov dr3, ecx |
- | |
451 | xor ecx, ecx |
- | |
452 | mov dr6, ecx |
- | |
453 | mov ecx, [eax+10h] |
- | |
454 | mov dr7, ecx |
- | |
455 | restore_ring3_context |
- | |
456 | iretd |
- | |
457 | @@: |
- | |
458 | push eax |
418 | push eax |
459 | xor eax, eax |
419 | xor eax, eax |
460 | mov dr6, eax |
420 | mov dr6, eax |
461 | ; test if debugging |
421 | ; test if debugging |
462 | cli |
422 | cli |