-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
##Prerequisites
Before doing anything, you need to grab the Visual Studio 2015 update 1 compiler or better. No other library is required.
##Setup
To build the library itself, opening the PeParser.sln solution file and building as usual should do the trick. But you more likely want to configure a project to be able to work on the library directly. In this case, you have multiple solutions :
- the easy way involves using the template contained in the
template
folder. This way, you will directly have a correctly set project with all the configuration done.- Put the file contained in the
template
folder insideMy Documents\Visual Studio 2015\Templates\ProjectTemplates
. - Then, open visual studio, go to "New->Project", choose visual C++, and click "PeParserProjectTemplate".
- Create the project inside the
PeParser
directory. - Once the project is created, right click on the solution, and choose "Add->Existing project". Choose the "PeParser" project.
- Finaly, right click on the solution and select "Properties" (last option), select "Project dependencies", the name of your project, and tick the "PeParser" box. (optional)
- Put the file contained in the
Alternatively, you can also use the "ExampleProject", which is already well configured. Also, if you like doing things yourself you can take the hard way.
- the hard way involves doing all the configuration yourself. Useful if you want more controle over your what happen during the build. If you're not accustomed to linking libraries and doing configuration, I invite you to check our configuration guide.
##Your first application
Right after this, you should have a fully functional workspace. It's time to do something with the code, so let extract some data ! First of all, open your previously created project inside visual studio, either by double clicking on the solution file, or by opening it from the visual studio context menu. From here, you should have a file called "ExampleProject.cpp" in your source folder. Open it. If you did the easy way, you should already have a little code already typed in. You can test the code by compiling the project. Then, delete it (or comment it out), and write :
#include <PeHeaderParser.h>
int main()
{
PEHeaderParser myParser(#); // Replace the # with a string containing the path to your file.
system("pause"); // Dirty hack make the window not closing right after the program.
return 0;
}
Fine, now build it and run it. If the file name you passed to the constructor is correct, and the file is a PE file (exe or dll basically), the program should do nothing. The other way, it should throw an exception. I leave to you the exception handling, but basically, in this tutorial, the only exception that could be thrown are std::ios_base_failure
and std::out_of_range
. So, now let's try to do something with our file. I propose to find the file creation date, and wether the file is a 32 bit application or a 64 bit application. Juste after the first line of the main, type :
std::cout << "The file was created at : " << myParser.getFileCreationDate() << std::endl;
if(myParser.is32bit())
{
std::cout << "The file is a 32 bit application !" << std::endl;
}
else
{
std::cout << "The file is a 64 bit application !" << std::endl;
}
It should compile, and print desired informations upon execution.
NOTE : We make use of std::endl here only to ensure that we flush each information in case of a crash. In real code however, std::endl is considered harmful.