Page 1 of 1

Enumerate Library Functions

Posted: Sat Feb 21, 2015 7:45 am
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

Re: Enumerate Library Functions

Posted: Sat Feb 21, 2015 11:34 am
by luis
Do you want to get a list of the exported functions ?

ImageDirectoryEntryToData() with #IMAGE_DIRECTORY_ENTRY_EXPORT.

Re: Enumerate Library Functions

Posted: Sat Feb 21, 2015 11:37 am
by Shield

Re: Enumerate Library Functions

Posted: Sat Feb 21, 2015 1:56 pm
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

Re: Enumerate Library Functions

Posted: Sat Feb 21, 2015 7:44 pm
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

Re: Enumerate Library Functions

Posted: Sun Feb 22, 2015 10:37 am
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

Re: Enumerate Library Functions

Posted: Sun Feb 22, 2015 12:37 pm
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