HeapAlloc分配的块不在任何堆段中

时间:2018-05-05 07:34:24

标签: windows debugging windbg heap-memory

以下反汇编是msvcrt!_heap_alloc函数的一部分,由msvcrt调用!malloc:

msvcrt!_heap_alloc+0xd1:
77c2c3ba 56              push    esi
77c2c3bb 6a00            push    0
77c2c3bd ff351824c677    push    dword ptr [msvcrt!_crtheap (77c62418)]
77c2c3c3 ff15f410c177    call    dword ptr [msvcrt!_imp__HeapAlloc (77c110f4)]

上面的反汇编显示msvcrt!_heap_alloc调用HeapAlloc(hHeap,dwFlags,dwBytes),hHeap设置为C运行时堆(0x1ea0000),dwFags设置为0,dwBytes设置为0x964。这从以下调试器输出中也很明显:< / p>

eax=00000001 ebx=00000000 ecx=5384f625 edx=00000964 esi=00000964 edi=0336cd5c
eip=77c2c3c3 esp=0336ccc8 ebp=0336cd00 iopl=0 nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000 efl=00000246
msvcrt!_heap_alloc+0xda:
77c2c3c3 ff15f410c177    call    dword ptr [msvcrt!_imp__HeapAlloc (77c110f4)] ds:0023:77c110f4={ntdll!RtlAllocateHeap (7c9100c4)}
0:008> r esi
esi=00000964
0:008> dd msvcrt!_crtheap
77c62418  01ea0000 00000001 00000020 00000000

在调用HeapAlloc eax后立即具有值3b8c8698,该值必须是分配的块的地址:

0:008> r eax
eax=3b8c8698

但是块不在任何堆段范围内:

0:008> !heap -a 
Index   Address  Name      Debugging options enabled
1:   00250000 
 Segment at 00250000 to 00350000 (00003000 bytes committed)
2:   00360000 
 Segment at 00360000 to 00370000 (00006000 bytes committed)
3:   00370000 
 Segment at 00370000 to 00380000 (00003000 bytes committed)
4:   01820000 
 Segment at 01820000 to 01830000 (00002000 bytes committed)
5:   01930000 
 Segment at 01930000 to 01940000 (00003000 bytes committed)
6:   01a50000 
 Segment at 01a50000 to 01a90000 (00003000 bytes committed)
7:   016d0000 
 Segment at 016d0000 to 016e0000 (00003000 bytes committed)
8:   01710000 
 Segment at 01710000 to 01720000 (00003000 bytes committed)
9:   020b0000 
 Segment at 020b0000 to 020c0000 (00003000 bytes committed)
10:   02450000 
 Segment at 02450000 to 02550000 (00003000 bytes committed)
11:   03d70000 
 Segment at 03d70000 to 03db0000 (00003000 bytes committed)
12:   047b0000 
 Segment at 047b0000 to 047f0000 (00003000 bytes committed)
13:   048f0000 
 Segment at 048f0000 to 04900000 (00003000 bytes committed)
14:   04a40000 
 Segment at 04a40000 to 04a50000 (00003000 bytes committed)
15:   053a0000 
 Segment at 053a0000 to 053b0000 (00003000 bytes committed)
16:   154b0000 
 Segment at 154b0000 to 155b0000 (00100000 bytes committed)
17:   38170000 
 Segment at 38170000 to 38180000 (00008000 bytes committed)

哪个堆是分配的块? 谢谢你的回复。

1 个答案:

答案 0 :(得分:0)

你引用的内容似乎不可行恕我直言

但是如果你确定你在正确的地方而且eax确实指向了一些分配的地址

你可以让windbg说出那个地址区正在使用!地址命令

向后反汇编以显示来电者是谁

0:000> ub . l5
malloc!_malloc_base+0x27 [minkernel\crts\ucrt\src\appcrt\heap\malloc_base.cpp @ 39]:
01230c49 7415            je      malloc!_malloc_base+0x3e (01230c60)
01230c4b 56              push    esi
01230c4c 6a00            push    0
01230c4e ff3504ab2501    push    dword ptr [malloc!__acrt_heap (0125ab04)]
01230c54 ff15b0002501    call    dword ptr [malloc!_imp__HeapAlloc (012500b0)]

反汇编以显示通话返回的地址(1230c5a)

0:000> u . l1
malloc!_malloc_base+0x38 [minkernel\crts\ucrt\src\appcrt\heap\malloc_base.cpp @ 34]:
01230c5a 85c0            test    eax,eax

确认我们在返回地址,以便eax实际上指向分配的内存
在eip注意(1230c5a)

0:000> r
eax=002cb958 ebx=7ffdd000 ecx=77545dd3 edx=002cb953 esi=00000984 edi=0012fa54
**eip=01230c5a** esp=0012fa08 ebp=0012fa0c iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
malloc!_malloc_base+0x38:
01230c5a 85c0            test    eax,eax

让我们看看这个内存区域是什么以及它属于哪个区域

0:000> !address @eax

Usage:                  Heap
Base Address:           002c0000
End Address:            002cf000
Region Size:            0000f000 (  60.000 kB)
State:                  00001000          MEM_COMMIT
Protect:                00000004          PAGE_READWRITE
Type:                   00020000          MEM_PRIVATE
Allocation Base:        002c0000
Allocation Protect:     00000004          PAGE_READWRITE
More info:              heap owning the address: !heap 0x2c0000
More info:              heap segment
More info:              heap entry containing the address: !heap -x 0x2cb958


Content source: 1 (target), length: 36a8