Jump to content
Tuts 4 You

Virtual Alloc


starzboy

Recommended Posts

hello people

i am trying to use Virtual Alloc to fork around with Files (<200 kb) and i am having problems ....

.data?

vir_address dd ?

invoke GetFileSize,hFile,0

mov FileSize,eax

invoke VirtualAlloc,NULL,FileSize,MEM_COMMIT,PAGE_READWRITE

mov vir_address,eax

invoke ReadFile,hFile,esi,ebx,addr dwBytes,0

mov edi,offset SerialBuffer

mov ecx,offset vir_address

loop1:

mov al,byte ptr ds:[esi]

mov byte ptr ds:[edi],al

....calculations .....

mov byte ptr ds:[ecx],al

inc edi

inc esi

loop1

but it fails ...

can someone explain where i am going wrong ...

but when i continue with files below 100Kb the code executes fine ...

Link to comment

from parts of code its hard to say where you have bug, use olly to debug or use that code,just change global to virtual

invoke CreateFile,o file_name,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0

mov file_handle,eax

invoke GetFileSize,file_handle,0

push eax

invoke GlobalAlloc,GMEM_FIXED,eax

mov src,eax

pop eax

invoke ReadFile,file_handle,src,eax,o buff,0

invoke CloseHandle,file_handle

Edited by human
Link to comment

nah ... i jusss posted in short wasnt at home ...

here is:

invoke CreateFile,addr szFileName1,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke GetFileSize,hFile,0
mov ebx,eax ; Store FileSize
mov FileSize,ebx
invoke GlobalAlloc,0,eax
mov esi,eaxinvoke VirtualAlloc,NULL,FileSize,MEM_COMMIT,PAGE_READWRITE
mov vir_address,eaxinvoke ReadFile,hFile,esi,ebx,addr dwBytes,0
mov edi,offset SerialBuffer
mov ecx,offset vir_address
Link to comment

hi Ted

the mistake was'nt in Allocation ... it was on the next buffer [fixed buffer] which overflowed and crashed ...

mov edi,offset SerialBuffer ... this was wrong

i was so flaming at VirtualAlloc that i forgot to see the other buffers

now all ok ..

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...