flat assembler
Message board for the users of flat assembler.

Index > Windows > Getting handles without GetModuleHandle...

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 21 Jun 2007, 09:27
I noticed in my programs that putting "handle:" at the top of the program works for almost all scenarios i need for handles. But apparently it seems that for those cases it just needs a unique ID. My theory was that handles are mearly pointers to the program itself. That would ensure the program got a unique ID and one could just add the pointer to the program to all the pointers in the program file and it would be easy. Welp, i never did printf the handle method i used till now. It turns out that the variable gets the value of 0. So, i came up with a way to check if i'm right (beause if you declare it after the format part, it adds 4kb to it). But i'm assuming that if we all ran it on our computers it would ensure that it works, because it could just end up being one wacky coincidence on my computer.

Code:
use32
format PE GUI 4.0

handlecalcvar:

handle = handlecalcvar-4096

entry main
include '%fasminc%\win32ax.inc'
section '.code' readable writeable executable
good du "Please post that it worked.", 10, "Kohlrak found how to get a handle without calling GetModuleHandle.", 0
bad du "Please post that it didn't work.", 0
main:
invoke  GetModuleHandle, 0
        cmp eax, handle
        jne DARN
invoke  MessageBox, HWND_DESKTOP, good, 0, MB_OK
        jmp YAY
DARN:
invoke  MessageBox, HWND_DESKTOP, bad, 0, MB_OK
YAY:
invoke  ExitProcess, 0

section '.idata' readable writeable import

library kernel, 'kernel32.dll',\
        user, 'user32.dll'

import kernel, GetModuleHandle, 'GetModuleHandleA',\
               ExitProcess, 'ExitProcess'

import user, MessageBox, 'MessageBoxW'          


I know, no error checking, but personally i think that since this is a restricted test, if anything goes wrong you can fix it.

I hope this works. That way, i'm not only right about something for once, but I will also have a way to get away from the GetModuleHandle and perhaps some other goodies will follow, as well.
Post 21 Jun 2007, 09:27
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 23 Jun 2007, 06:22
Yep, it works here with Win98SE.
Post 23 Jun 2007, 06:22
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 23 Jun 2007, 06:45
Thank you.
Post 23 Jun 2007, 06:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
handyman



Joined: 04 Jun 2007
Posts: 40
Location: USA - KS
handyman 23 Jun 2007, 12:39
It works here with my Win98SE.
Post 23 Jun 2007, 12:39
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 23 Jun 2007, 12:40
Coooooool... Thank you.
Post 23 Jun 2007, 12:40
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger 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.