* NULL is replaced by nullptr
* Added parameter std::nothrow to operator new so in case of
failure it returns nullptr instead of throwing exception
std::bad_alloc. This is important due to check that follows
the statement. Example:
parsed_pe *p = new(std::nothrow) parsed_pe();
if (p == nullptr) {
...
}
* Using range-based for loops.
* Removed redundant boolean literals.
Example: if (readWord(...) == false) => if (!readWord(...))
* Resolved implicit casts.
Example: if (!ch) => if (ch == 0u)
* Created functions getImports, getExports, getRelocations from
parts of ParsePEFromFile to make it smaller and more readable.
* Using reinterpret_cast instead of C-style cast to convert
between unrelated types.
* Added braces around statements to improve readability.
* Put all of peparse in the peparse namespace.
* Fixes dupicate symbol problems when using the library inside other applications, namely Python
* Closes#25
Teach the parser to properly handle PE32+ binaries.
The major differences are:
- Fields in the OptionalHeader which are not relative are now 64 bits.
- Base addresses should all be 64 bits.
- The BaseOfData field is not available on PE32+
There is now a 16 bit field tacked on to the end of nt_header_32 called
OptionalMagic. This is a duplicate of the Magic field in optional_header_32
and optional_header_64, but is stored in nt_header_32 to make it easier
to determine which optional header is being used.
I also added support for better error reporting. Now when something fails
to parse you can use a couple of functions to find out what happened and
where it happened:
- GetPEErr(): Return the error as an integer.
- GetPEErrString(): Return the error as a string.
- GetPEErrLoc(): Return the function and line number of the error.
Made some changes to pepy to account for these changes. The interface
into pepy is identical. Only externally visible changes are that
pepy.parse() will now return the error string and location when parsing
fails and the baseofdata attribute will throw an exception if the binary
is PE32+.
to_string.h is now included from parse.h, so remove it from dump.cpp.
While here do a bunch of cleanups to make printing consistent. Use '0x'
where appropriate and ensure exceptions are punctuated correctly.