Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get Program section address

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ulysse31
Master Cheater
Reputation: 2

Joined: 19 Mar 2015
Posts: 324
Location: Paris

PostPosted: Sat Jun 18, 2016 1:40 pm    Post subject: Get Program section address Reply with quote

After looking around it seems like the only way the get a section address is to manually make my program browse through the PE header, while that's doable I wanted confirmation here that there is no API that will get me closer to section's addresses than getmodulehandle ?
Back to top
View user's profile Send private message
zm0d
Master Cheater
Reputation: 7

Joined: 06 Nov 2013
Posts: 423

PostPosted: Sun Jun 19, 2016 5:01 am    Post subject: Reply with quote

IMAGE_NT_HEADERS structure:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680336(v=vs.85).aspx

IMAGE_FILE_HEADER structure:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx

IMAGE_OPTIONAL_HEADER structure:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339(v=vs.85).aspx

That should help you with PE headers.

Wink
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Jun 19, 2016 1:22 pm    Post subject: Reply with quote

There is no API to obtain section information, you have to walk the PE header manually. But that is very simple to do with the structures provided within Microsofts headers. (As zm0d linked to.)

The file will start with the IMAGE_DOS_HEADER. From there within the IMAGE_DOS_HEADER structure is a value e_lfanew which points to the IMAGE_NT_HEADERS within the file.

The file may have a DOS stub as well which will sit just after the dos header and can be validated via: e_lfanew - sizeof(IMAGE_DOS_HEADER)
If the size is bigger than 0, then there is a DOS stub. Otherwise its just the NT headers following directly.

The NT header holds the information for the sections within its FileHeader sub-structure. The OptionalHeader holds the file aligment and other important data needed to ensure you are reading the proper size of data and such.

There are a ton of examples and code around the web showing how to do all this which you should be able to find no problem via Google.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ulysse31
Master Cheater
Reputation: 2

Joined: 19 Mar 2015
Posts: 324
Location: Paris

PostPosted: Sun Jun 19, 2016 5:45 pm    Post subject: Reply with quote

Yeah thanks, I actually know the PE header section by heart (i thought it was a good idea to spend few days learning it back when I started unpacking tuts Twisted Evil ), I just wanted to be sure I wasn't wasting time by coding the functions.
Thanks for the links also cause I probably would have forgotten to use the given structures as I was focused for the APIs
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites