Enumerate Library Functions

Windows specific forum
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Enumerate Library Functions

Post by nco2k »

im looking for a winapi equivalent of ExamineLibraryFunctions(), but couldnt find anything useful so far, without the need for some weird hacks or 3rd party tools. as far as i know, purebasic doesnt use any of those. so whats the big secret?

Code: Select all

step 1 - LoadLibrary_()
step 2 - ???
step 3 - Profit
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Enumerate Library Functions

Post by luis »

Do you want to get a list of the exported functions ?

ImageDirectoryEntryToData() with #IMAGE_DIRECTORY_ENTRY_EXPORT.
"Have you tried turning it off and on again ?"
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Enumerate Library Functions

Post by Shield »

Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Enumerate Library Functions

Post by nco2k »

update: actually you dont need any api for that. the required data is already stored in memory after using LoadLibrary_(). all you need is the returned handle and some memory reading. i can see the function names when playing around with the memory viewer, but how do i properly access that data? any ideas?

@luis
> Do you want to get a list of the exported functions
yea pretty much

@Shield
already saw that post and many many more. wasnt much of a help though.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Enumerate Library Functions

Post by luis »

nco2k wrote:update: actually you dont need any api for that. the required data is already stored in memory after using LoadLibrary_().
Yes, because the module (being it a dll or an exe) is loaded in memory. The returned handle is a pointer to the base address of the loaded module.
I *think* the structure in memory is the same in the file you are loading, try to verify with HEX editor, and at this point you could do the same by looking inside the file without even using LoadLibrary at all. But you can hop in memory instead if you like.
About the specifics I don't know them by memory... it's not simple stuff to do manually... I would try to google for some documentation about the PE file format concentrating myself on the IMAGE_EXPORT_DIRECTORY structure.

https://social.msdn.microsoft.com/Forum ... =vbinterop

Also depends on what you want to export.

AFAIK the options for enumerate the functions of a DLL (if that's what you want to do) are parsing the PE structure manually or by using some API like the one I've mentioned which is part of the Image Help library (ImageHlp.dll) which has been created to access the details of a PE image without the need to know its data structure record for record.
Don't know if there are others methods.

I would use the API anyway, I think it's more robust and future proof. Doing it manually it's easier to have surprises along the road unless you do really a good job.

EDIT: I wrote some test code in PB using the API discussed here, it seems to work for listing exported DLL functions, if that's what you want.
It's more easy than I imagined, I'll post it even if probably NO PB USER will be interested in it because we already have the PB commands... but when I'm curious I'm curious.

Why you don't want to use the PB commands by the way ?

Or this is for something not done in PB ?

http://www.purebasic.fr/english/viewtop ... 12&t=61712
"Have you tried turning it off and on again ?"
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Enumerate Library Functions

Post by nco2k »

cool thanks. your help is much appreciated. :D

> Why you don't want to use the PB commands by the way ?
well, knowledge is power. im somewhat trying to understand the whole pe concept and thats a pretty good exercise. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Enumerate Library Functions

Post by luis »

You're welcome
nco2k wrote: well, knowledge is power. im somewhat trying to understand the whole pe concept and thats a pretty good exercise. :)
Understood :P
"Have you tried turning it off and on again ?"
Post Reply