flat assembler
Message board for the users of flat assembler.

Index > Windows > VirtualAlloc Trouble.

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 04 Jan 2012, 18:21
Hello everyone, I'm failing when trying to allocate memory twice at different address. For example:
Code:
myaddr = 0x400000
myaddr2 = 0x401000
mysize = 0x200
...
invoke VirtualAlloc,myaddr,mysize,MEM_COMMIT+MEM_RESERVE,PAGE_EXECUTE_READWRITE ;first time -> OK.
invoke VirtualAlloc,myaddr2,mysize,MEM_COMMIT+MEM_RESERVE,PAGE_EXECUTE_READWRITE ;failed, ERROR_INVALID_ADDRESS    

Why Question Sad
P.S playing with PE format.
Post 04 Jan 2012, 18:21
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 04 Jan 2012, 19:49
let the system do it for you the second call.
Post 04 Jan 2012, 19:49
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 04 Jan 2012, 20:03
typedef
What you mean ?
Post 04 Jan 2012, 20:03
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 04 Jan 2012, 20:09
Leave out the address parameter to null and the system will find the appropriate address for you
Post 04 Jan 2012, 20:09
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 04 Jan 2012, 20:31
I know that, but I need it to be allocated at that address :/ trying to write windows PE loader manually.
I did like this, but imports are not correct Sad I don't know what is happening..
Image is loaded at 50000000h, file is in buffer and when I allocated space equal to IMAGE_NT_HEADERS.OptionalHeader.SizeOfImage and copied IMAGE_DOS_HEADER, IMAGE_NT_HEADERS and all sections there, but it didn't loaded cause of import calls are wrong. Did I miss something ?
Post 04 Jan 2012, 20:31
View user's profile Send private message Reply with quote
aq83326



Joined: 25 Jun 2011
Posts: 21
aq83326 05 Jan 2012, 07:06
http://blogs.msdn.com/b/oldnewthing/archive/2003/10/08/55239.aspx

Maybe:
VirtualAlloc cannot reserve a reserved page, but the documentation doesn't say what happens if you try to do so-I'd like to know what happens too.

The allocation granularity is likely 64k, thus the first call to VirtualAlloc reserves and commits 64k rather than the single page necessary to hold 200h.

So even though the addresses are likely a page apart (4k being the usual page size) you are reserving a reserved page.

So see what happens when you try to reserve a reserved page and try just using MEM_COMMIT by itself for that second line to see what happens.
Post 05 Jan 2012, 07:06
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 05 Jan 2012, 08:55
Thanks, I'm working on it now.
Post 05 Jan 2012, 08:55
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 05 Jan 2012, 23:27
Check http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958%28v=vs.85%29.aspx , notably the allocation granularity - don't blindly assume 64k.
Post 05 Jan 2012, 23:27
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.