197 Commits

Author SHA1 Message Date
Jack Williams
766b183a1b Explicit use of std namespace, prefer std::vector over std::list, never use std::endl (#74) 2018-09-24 11:10:29 -04:00
William Woodruff
78869e5337
cmake: Bump minimum version to 3.7 (#78) 2018-09-21 17:29:29 -04:00
William Woodruff
697714b379
parse: Limit resource table recursion to 3 levels (#77) 2018-09-21 11:06:08 -04:00
Jack Williams
19a3bf4859 Minor pepy fixes (#73)
* Minor pepy fixes

* Fix python2

* Fix conversion

* Adjust whitespace

* Bumping pepy version
2018-09-21 10:27:40 -04:00
William Woodruff
c6acdea485
Merge pull request #76 from trailofbits/buffer-overread
buffer, parse: Fix overread on {d,q,}words
2018-09-20 16:41:00 -04:00
William Woodruff
0f740c43ab
buffer, parse: Fix overread on {d,q,}words
When read 2, 4, or 8 bytes from a bounded_buffer, we only
checked to see if the offset, not the whole span, was in bounds.

This results in an arbitrary memory read of up to 1, 3, or 7 bytes
when the offset is aligned with the very end of the buffer.
2018-09-20 10:57:22 -04:00
Jack Williams
11685390bb Fix Windows build and VS2017 compiler errors for example project (#70) 2018-09-05 19:03:59 +02:00
Jack Williams
6fa093aa42 Minor update to machine and subsytem constants (#72) 2018-09-05 15:22:05 +02:00
Jack Williams
2664eec5f6 Add machine and subsytem to-string methods (#71)
* Add machine and subsytem enums and to-string methods

* Minor fix
2018-08-31 17:44:22 +02:00
Alessandro Gario
9545944ea5 Fix symbol table parsing (#65)
The following issues were found and corrected:

1. Auxiliary symbols were not being counted; this caused
   the parser to loop above the actual number of symbols
2. When parsing auxiliary symbols, it is best to position
   the offset manually at the start of the next data
   structure (everything is padded to 18 bytes)
3. Some auxiliary symbol handlers were not correctly
   updating the file offset
4. Print a warning when skipping auxiliary symbols

This closes #65
2018-04-16 10:26:55 +02:00
Marty Plummer
b66e9dbedb Added meson build scripts.
Mostly for ease of use as a subproject to parse windows dependencies
for packaging.

Signed-off-by: Marty Plummer <ntzrmtthihu777@gmail.com>
2018-04-16 10:26:55 +02:00
Tony Theodore
64989f688a CMake improvements, MinGW compatibility, shared libs support
* mingw-w64 fixes

  - `WIN32` is user-defined, `_WIN32` is pre-defined by toolchain[1]
  - use gcc options instead of MSVC
    - `-fPIC` is redundant on mingw
    - don't error on `old-style-cast`

[1] https://msdn.microsoft.com/en-us/library/b0084kay.aspx

* add option to build shared libs

* add option to disable command line tools

* ignore more Visual Studio files

* enable shared builds on MSVC (with cmake >= 3.4)

https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/

* fix old-style-cast warning
2018-03-27 14:52:05 +02:00
Alessandro Gario
4cd4127961 Docs: Update the build instructions 2018-03-26 14:40:30 +02:00
Alessandro Gario
50ca8192e6
MSVC: Fix compilation warning caused by ::toupper (#64) 2018-03-26 13:40:48 +02:00
Alessandro Gario
752f526e2e
Fix compilation error on Ubuntu Xenial (#60)
* CMake: Remove -Wstrict-overflow (#59)
This warning has been added by mistake in a previous PR. Closes #59

* Travis: Do not build the examples
2017-12-20 00:13:03 +01:00
Alessandro Gario
b60b908fa2 Install public headers, add Arch package, build pepy under Travis and more (#57)
* CMake: Added install directives

* CMake: Added support for find_package(pe-parse)

* Fixed a compilation error on Linux

* CMake: Fix cmake module installation

* Added ArchLinux package

* Finished implementing the address converted example

* peaddrconv: Print the image base address.

* peaddrconv: Enable more warnings.

* Update travis to also build the examples

* Fix a compilation warning on Ubuntu 14.04

* Travis: Add macOS support.

* Better output for Travis, fix a compilation error on macOS.

* Travis: Do not build examples under macOS.

* Travis: Also compile the python module (pepy)

* Readme: Add a section to show how to use the library.

* Windows: Fix a compilation error, enable /analyze (see details).

The nt-headers.h include file is defining several constexpr values
using reserved (by windows.h) names.

These names (i.e.: IMAGE_FILE_MACHINE_UNKNOWN) are in fact macros
defined inside the Windows header files, and causes the preprocessor
to break definitions such as the following one:

constexpr std::uint16_t IMAGE_FILE_MACHINE_UNKNOWN = 0x0;

The fix (for now) consists in including the nt-headers.h file before
windows.h, but we should probably choose whether to use different
names or avoid defining those values (since they are inside the
system header anyway).
2017-11-25 16:01:53 -05:00
Alessandro Gario
e632a37290 Bugfix: Do not use memset on non-POD structures 2017-10-21 19:45:25 +02:00
Alessandro Gario
0d0ca1861c Squash (#56)
- CMake: Refactor, added more warnings.
- Refactor
- Added Windows support
- Added a missing include file for linux.
- Do not set CMAKE_CXX_STANDARD on Windows
- Always initialize the stat struct
- CMake: update the required version, request C++11, disable GNU extensions
- CMake: Add default switch cases, fix GCC warnings.
- Prefer assignment from an empty object when initializing
2017-10-19 12:13:35 -04:00
Marwan Burelle
4d34d91333 Adding support for python3 (#51)
* Adapt wrapper to support python3

This seems to work with either python3 and python2.

* converted test file

* Testing better get_byte implem

* Clean and working get_bytes wrapper

* Correct bytearray display method

* Documents macros for python 2/3 support

* Remove useless typedef

This is C++ code, typedefed struct is useless (and probably bad style
C++).

* Add some comments and C++ style cast.

* Replace new[] with nothrow version

* Update error message to indicate allocation failure
2017-07-22 11:25:27 -04:00
Dan Guido
27e6f70bc6 Merge pull request #49 from jkolek/master
Fixed memory leaks
2017-04-23 17:52:58 -04:00
Jozef Kolek
b85c4225ad Fixed memory leaks 2017-04-18 14:20:40 +02:00
Dan Guido
fac3826677 Merge pull request #48 from jkolek/cpp11_flags
Issue #47 - Add C++11 flags
2017-04-18 02:32:27 -04:00
Jozef Kolek
35057f6270 Issue #47 - Add C++11 flags 2017-04-17 16:32:28 +02:00
Dan Guido
7dd1b15f5e Update README.md 2017-04-12 17:54:54 -04:00
Peter Goodman
05869b0c00 Merge pull request #46 from jkolek/constexpr
Constexpr
2017-04-12 12:28:15 -04:00
Jozef Kolek
974494f622 const replaced by constexpr in nt-headers.h 2017-04-12 17:39:59 +02:00
Jozef Kolek
9f74016e0d Perform endian swap as needed 2017-04-12 00:24:03 +02:00
Peter Goodman
f2e38505fb Merge pull request #42 from jkolek/master
Fixed some memory leaks
2017-04-06 16:23:01 -04:00
Jozef Kolek
aca0344abb Fixed some memory leaks 2017-04-06 20:47:23 +02:00
Peter Goodman
9510a71648 Merge pull request #41 from jkolek/master
Added clang-format spec - issue #35
2017-03-31 11:51:56 -04:00
Jozef Kolek
cb2fd5736f Added clang-format spec - issue #35 2017-03-31 17:01:20 +02:00
Peter Goodman
e3f63e11cb Merge pull request #40 from jkolek/clang_tidy_review
Clang tidy review
2017-03-30 18:44:53 -04:00
Jozef Kolek
1183047cbb Changes made according to clang-tidy review.
* 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.
2017-03-31 00:21:20 +02:00
Dan Guido
0ed5779ba9 Don't allow failures on macOS travis builds 2017-03-30 16:43:13 -04:00
Peter Goodman
418cbfdb9a Merge pull request #39 from jkolek/master
Bugfix - parse all possible relocation blocks
2017-03-30 16:25:39 -04:00
Jozef Kolek
29106a75e0 Bugfix - parse all possible relocation blocks
PE file can contain any number of base relocation blocks, where
each of the blocks can contain any number of Type/Offset entries
beside of PageRVA and BlockSize fields. Without this fix only
first base relocation block is parsed.

Also fixes the issue #32.
2017-03-24 22:16:57 +01:00
Peter Goodman
563b4c1a62 Merge pull request #38 from jkolek/master
Fix UNIX/Windows build issue
2017-03-22 18:09:45 -04:00
Jozef Kolek
dcc79b5237 Fix UNIX/Windows build issue 2017-03-22 22:54:56 +01:00
Peter Goodman
50d54d2415 Merge pull request #34 from jkolek/master
Symbol table parsing
2017-03-21 11:26:47 -04:00
Jozef Kolek
1459fec319 lookupVA clang warning resolved
lookupVA is initialized to 0. Also, if it remains 0 after the two
ifs, then ParsePEFromFile() returns NULL, since the section
lookup at the virtual address 0 is invalid.
2017-03-17 12:46:55 +01:00
Jozef Kolek
326ca41bc6 Symbol table parsing 2017-03-16 22:18:08 +01:00
Dan Guido
6e1e2a99b5 Remove boost from README 2017-03-11 19:25:58 -05:00
Peter Goodman
cf1991b1f3 Merge pull request #31 from hobo-ru/no-boost-travis
Removed all the dependencies on Boost.
2017-03-11 15:56:14 -05:00
hobo-ru
0ddd2f6684 Fix AppleCLang build issue(s) 2017-03-11 23:10:33 +03:00
hobo-ru
f325d6da09 Instruct Travis to use modern C++ standard 2017-03-11 23:08:11 +03:00
hobo-ru
7ab4f77b86 Remove dependency on boost from .travis.yml 2017-03-09 20:05:57 +03:00
hobo-ru
465ed4ba6e Make the sources MS VC compatible (define the macro for __typeof__) 2017-03-09 19:25:20 +03:00
hobo-ru
d067641bf0 Get rid of boost at all 2017-03-09 19:11:41 +03:00
hobo-ru
1a5455e06b Get rid of boost integer types 2017-03-09 19:10:17 +03:00
hobo-ru
7f4152f310 Remove dependency on boost case conversion function(s) 2017-03-09 18:59:37 +03:00