flat assembler
Message board for the users of flat assembler.

Index > Windows > Why HeapSetInformation() always failed?

Author
Thread Post new topic Reply to topic
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 03:48
I want to using the low-fragmentation heap:

invoke GetProcessHeap
invoke HeapSetInformation, eax, 0, HeapFragValue, 4
.if ecx = 0
invoke MessageBox, dword NULL, 'HeapSetInformation error', 'error', dword MB_OK
.endif

HeapFragValue dd 2

but always failed, I have searched out some notes that said this function will not success if run in debug mode. the same codes work well using nasm in release mode, does this means fasm code default is run in debug mode?

_________________
Assembly Asker


Last edited by nazha on 12 Apr 2009, 07:43; edited 1 time in total
Post 12 Apr 2009, 03:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20630
Location: In your JS exploiting you and your system
revolution 12 Apr 2009, 04:00
Win32 API return values are in the EAX register, not ECX.
Post 12 Apr 2009, 04:00
View user's profile Send private message Visit poster's website Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 04:30
sorry, that is my typping error, eax also always zero, why?
Post 12 Apr 2009, 04:30
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 12 Apr 2009, 04:53
From SDK:
Quote:
To enable the low-fragmentation heap when running under a debugger, set the _NO_DEBUG_HEAP environment variable to 1.
Post 12 Apr 2009, 04:53
View user's profile Send private message Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 06:26
thanks, I have added _NO_DEBUG_HEAP, but still get error. do you think the fasm compiled codes are executed in debug mode in default?
Post 12 Apr 2009, 06:26
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 12 Apr 2009, 08:59
Why are you using magic numbers instead of symbolic constants?

Have you tried checking the error code from GetLastError on failure?

If your HeapFragValue is stored in your code section, try moving it to a writable data section and 4-byte align it - probably not an issue, but sometimes Windows is nazi about alignment (usually for structs, though).
Post 12 Apr 2009, 08:59
View user's profile Send private message Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 10:34
the error is "A device to attached to the system is not functioning".
actually, I do stored the HeapFragValue in writable data section.
Post 12 Apr 2009, 10:34
View user's profile Send private message Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 12 Apr 2009, 10:50
Have you checked to make sure that GetProcessHeap() is not null? Have you tried HeapCreate()?
Post 12 Apr 2009, 10:50
View user's profile Send private message Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 11:22
I have tried, got same error. It's curious that same code work well in nasm.
Post 12 Apr 2009, 11:22
View user's profile Send private message Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 12 Apr 2009, 13:28
Tomasz should know why, could you see this, could you help?
Post 12 Apr 2009, 13:28
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 12 Apr 2009, 21:53
Try this:
Code:
format pe gui 5.0    

For me, HeapSetInformation returns EAX=1 for '5.0' but 0 for '4.0'
Post 12 Apr 2009, 21:53
View user's profile Send private message Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 12 Apr 2009, 22:45
Thats weird; is that a fasm error or what?
Post 12 Apr 2009, 22:45
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 12 Apr 2009, 23:11
Oh, so newer linkers set 5.0 as subsystem?

Didn't know the PE subsystem was actually used for anything Razz. And if that's the issue, no, it's not a FASM bug.
Post 12 Apr 2009, 23:11
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 13 Apr 2009, 06:23
I think the 4.xx was for 2000 and 5.xx is XP so I've always tried to use the latter one. I haven't tested my code in a 2000 machine for a while, but it seemed to work a while back. Btw, Windows 2003 Server (32-bit) is 5.2 to my knowledge.
Post 13 Apr 2009, 06:23
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 13 Apr 2009, 07:08
2000 (SP4) is 5.0 and XP is 5.1. The SDK says HeapSetInformation needs 2000SP4 or XP. Like f0dder, I didn't realise the subsystem was used - maybe it's a recent (XP+) thing? I tested under win7 beta.
Post 13 Apr 2009, 07:08
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 13 Apr 2009, 09:53
Works for me on XP SP3+ with 4.0 SS ver.
Post 13 Apr 2009, 09:53
View user's profile Send private message Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 13 Apr 2009, 13:52
yes, work now, regardless of 4.0 or 5.0, my OS is xp sp3. my original code was: format PE GUI, no version number. thanks all.
Post 13 Apr 2009, 13:52
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.