I want to write a little program in C to extract the PE (Entry Point) and VA (Virtual Address) of a COFF executable. How can I do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both the fields you want are in the Optional Header (optional in that it doesn’t appear in object files — it’s required in images). The first bytes in the file are the DOS stub, but at 0x3c you’ll find the offset of the PE signature. Go there and you’ll find the PE signature (
PE\0\0). Immediately after that is the file header, which is 0x14 bytes long, and after that is the optional header.AddressOfEntryPointis 0x10 bytes into the optional header and spans four bytes, andBaseOfCodeis right after it at 0x14 (also 4 bytes).So, in short:
(PE signature offset)+0x28— this is theAddressOfEntryPoint(PE signature offset)+0x2c— this is theBaseOfCodeRemember to deal with endianness if necessary