Any ideas why this is not working ?
.586
option casemap:none
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32rt.inc
.data
LineBreak dword 00D0Ah, 0
.data?
NumberOfHeaps dword ?
hMem dword ?
PHE PROCESS_HEAP_ENTRY <>
.code
Start:
xor ebx, ebx
invoke AllocConsole
@@:
invoke GetProcessHeaps, ebx, ebx
mov NumberOfHeaps, eax
shl eax, 2
mov hMem, alloc(eax)
invoke GetProcessHeaps, NumberOfHeaps, hMem
mov eax, hMem
mov ecx, dword ptr ds:[eax]
cmp ecx, ebx
jnz @f
free hMem
jmp @b
@@:
mov esi, hMem
xor edi, edi
@@:
cmp edi, NumberOfHeaps
je @f
invoke HeapWalk, dword ptr ds:[esi+edi*4], addr PHE
print "0x"
print uhex$(PHE.lpData)
print "-0x"
mov eax, PHE.lpData
add eax, PHE.cbData
print uhex$(eax), 13, 10
add edi, 1
jmp @b
@@:
invoke StdOut, addr LineBreak
inkey
free hMem
invoke FreeConsole
invoke ExitProcess, ebx
end Start
This is the PROCESS_HEAP_ENTRY I am using since it is not already in windows.inc:
PHE_BLOCK struct
hMem HANDLE ?
dwReserved DWORD 3 dup (?)
PHE_BLOCK ends
PHE_REGION struct
dwCommittedSize DWORD ?
dwUnCommittedSize DWORD ?
lpFirstBlock LPVOID ?
lpLastBlock LPVOID ?
PHE_REGION ends
PROCESS_HEAP_ENTRY struct
lpData DWORD ?
cbData DWORD ?
cbOverhead BYTE ?
iRegionIndex BYTE ?
wFlags WORD ?
union
Block PHE_BLOCK <>
Region PHE_REGION <>
ends
PROCESS_HEAP_ENTRY ends
Somehow the cbData which should be the size of the heap keeps being 0.
Hi Slugsnack:
Try masm32rt.inc BEFORE the lib files!
include \masm32\include\masm32rt.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
Regards herge
I'm not sure what you mean by not working, because I don't know what you expect the code to do, but HeapWalk "enumerates the memory blocks in a specified heap", something like this:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
PHE_BLOCK struct
hMem HANDLE ?
dwReserved DWORD 3 dup (?)
PHE_BLOCK ends
PHE_REGION struct
dwCommittedSize DWORD ?
dwUnCommittedSize DWORD ?
lpFirstBlock LPVOID ?
lpLastBlock LPVOID ?
PHE_REGION ends
PROCESS_HEAP_ENTRY struct
lpData DWORD ?
cbData DWORD ?
cbOverhead BYTE ?
iRegionIndex BYTE ?
wFlags WORD ?
union
Block PHE_BLOCK <>
Region PHE_REGION <>
ends
PROCESS_HEAP_ENTRY ends
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
nHeaps dd 0
hbuff dd 20 dup(0)
phe PROCESS_HEAP_ENTRY <>
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
invoke GetProcessHeaps, 20, ADDR hbuff
mov nHeaps, eax
print "nHeaps "
print ustr$(nHeaps),13,10
print "hHeap ",9,"lpData ",9,"cbData",13,10
print "-----------------------------------------",13,10
xor ebx, ebx
.WHILE ebx < nHeaps
mov phe.lpData, 0
@@:
invoke HeapWalk, hbuff[ebx*4], ADDR phe
test eax, eax
jz @F
print uhex$(hbuff[ebx*4]),"h",9
print uhex$(phe.lpData),"h",9
print uhex$(phe.cbData),"h",13,10
jmp @B
@@:
inc ebx
print chr$(13,10)
.ENDW
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
sorry I was unclear, that is exactly what I meant to do. thanks =]
@ herge, does the order actually matter ? I've been putting libs before incs (don't ask me why !) since I started with masm32 and has all been working out okay so far ha
Quote from: Slugsnack on January 09, 2009, 12:43:44 AM
@ herge, does the order actually matter ? I've been putting libs before incs (don't ask me why !) since I started with masm32 and has all been working out okay so far ha
Not sure, but if this is a problem, there might be a proto or dependency problem...
Just as a safe measure... 'INCs before LIBs'
:8)