248 Commits

Author SHA1 Message Date
hobo-ru
7f4152f310 Remove dependency on boost case conversion function(s) 2017-03-09 18:59:37 +03:00
artemdinaburg
a8ccfb9df3 Put all of peparse in the peparse namespace. (#26)
* Put all of peparse in the peparse namespace.
* Fixes dupicate symbol problems when using the library inside other applications, namely Python
* Closes #25
2017-03-03 14:41:14 -05:00
Peter Goodman
6d1b49b74a Merge pull request #22 from gsauthof/speedup-cstring-copy
LGTM
2016-09-08 12:18:36 -04:00
Peter Goodman
e09f4a9e52 Fixes Issue #23 2016-09-08 12:00:05 -04:00
Georg Sauthoff
094dff7d38 Speedup copying of C-strings
Also, the copy functionality is now inside an extra function,
thus easier to maintain.
2016-02-28 00:01:01 +01:00
gaasedelen
8505e15e3f Merge pull request #20 from armbues/master
Checking for NumberOfRvaAndSizes to avoid DataDirectory overflow
2016-01-20 19:50:45 -08:00
armbues
73ca478788 Checking for NumberOfRvaAndSizes to avoid DataDirectory overflow 2016-01-19 17:17:37 -08:00
armbues
65c9454e5c Checking for NumberOfRvaAndSizes to avoid DataDirectory overflow 2016-01-19 17:05:32 -08:00
doom
e203466e9c fixed some resource leaks 2015-05-12 17:07:16 -07:00
gaasedelen
0e1cedef1d Merge pull request #18 from Arbiv/Arbiv-patch-2
Added share for read, write and delete
2015-05-12 18:31:04 -04:00
gaasedelen
2262cfd50a Merge pull request #19 from Arbiv/Arbiv-patch-1-1
Fixed buffer leak
2015-05-12 18:30:43 -04:00
Arbiv
6b8aae18e0 Added share for read, write and delete
Opening the file with share enables other processes to use this file while the pe-parse object is still open
2015-05-07 13:27:20 +03:00
Arbiv
19eb5b4f4f Fixed buffer leak
Added a call to deleteBuffer in DestructParsedPE .
Without the buffer leaks.
2015-05-07 13:05:56 +03:00
Dan Guido
436457493e Merge pull request #16 from wxsBSD/issue_15
Fix crash.
2015-03-02 16:24:58 -05:00
Wesley Shields
684156c51c Fix crash.
Fixes #15.
2015-03-02 16:14:31 -05:00
Andrew Ruef
d822731466 zero-init this structure, the uninit reads will at least be predictable until someone can look at the parser logic and figure out which fields should be populated 2015-01-16 11:24:34 -08:00
Dan Guido
0dae935114 better 2015-01-16 12:33:31 -05:00
Dan Guido
df1309eb98 exclude osx/gcc from travis 2015-01-16 12:31:27 -05:00
Wesley Shields
407cf81685 Merge pull request #12 from wxsBSD/resource_strings_fix
Clear strings.
2015-01-15 20:57:06 -05:00
Wesley Shields
d708387f5e Merge pull request #13 from wxsBSD/null_ptr_deref
Address a problem with invalid sections.
2015-01-15 20:56:51 -05:00
Dan Guido
633f2d48a0 third time is a charm 2015-01-15 15:33:25 -05:00
Dan Guido
ea30300348 damn typos 2015-01-15 15:26:25 -05:00
Dan Guido
966f4e0505 try adding multi-os builds 2015-01-15 15:13:20 -05:00
Wesley Shields
6d9bb17e3f Address a problem with invalid sections.
I've noticed this in one (otherwise valid) EFI image. What happens is
the section specifies an invalid PointerToRawData, which the bounded
buffer abstraction catches and returns NULL. However, the SizeOfRawData
is still in the structure (and probably invalid too).

I saw two ways to fix this. If sectionData ends up being NULL we can set
SizeOfRawData to 0, but that would be truncating what is otherwise
specified in the file.

The other option is to teach dump-prog and pepy about this and adjust
accordingly. This involves checking for a data being a NULL pointer in
dump-prog when printing sections. In pepy it required roughly the same
check.

I went with option 2.
2015-01-04 22:20:07 -05:00
Wesley Shields
ab9775cce9 Clear strings.
This was causing a problem where resources with strings would accumulate
the strings of previous resources in the directory.

For example, here is the output of test.py on
3f0961b7942f12bc96848509c04da2b6:

Resources: (4)
[+] MD5: (191649) 33a6345b919c7c733da9d33ee4ac64eb
    Type string: BINARY
    Name string:
1.165.3106.0_TO_1.165.3138.0_MPASDLTA.VDM._P
    Lang: 0x0
    Codepage: 0x4e4
    RVA: 0x51dc
    Size: 0x2eca1
    First 10 bytes: 0x4d50535091ec0200c263
[+] MD5: (293587) e4c9b9aa65e0b236cb180fa489502700
    Type string: BINARY
    Name string: 1.165.3106.0_TO_1.165.3138.0_MPASDLTA.VDM._P1.165.3106.0_TO_1.165.3138.0_MPAVDLTA.VDM._P

The second resource has the first resources name string in it.
2015-01-02 23:16:03 -05:00
Dan Guido
c648905250 moar badges 2014-12-10 20:29:57 -05:00
Dan Guido
c4523528af setup coverity scan 2014-12-10 20:21:43 -05:00
munin
e75e0383dc small change 2014-08-08 17:55:35 -04:00
Dan Guido
da4f6e3b1b add a travis button 2014-08-08 17:44:43 -04:00
Dan Guido
a9aba1220b damn it lunix 2014-08-08 17:43:45 -04:00
Dan Guido
466dd4362d sssshhhhhhhhhhh 2014-08-08 17:41:15 -04:00
Dan Guido
03fee3620e wrong lunix 2014-08-08 17:38:34 -04:00
Dan Guido
543d0e4d6e first shot at travis 2014-08-08 17:36:27 -04:00
Andrew Ruef
f59587712e Merge pull request #9 from wxsBSD/pe32_plus_and_more
Implement PE32+ and error reporting.
2014-03-07 23:14:40 -05:00
Wesley Shields
77b72f3cc9 Implement PE32+ and error reporting.
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.
2014-03-07 13:18:24 -05:00
Dan Guido
4bc575dedf Update README.md 2014-01-22 17:26:06 -05:00
munin
30f350ff65 update readme 2014-01-17 11:15:44 -05:00
Andrew Ruef
0433de5c9e Merge pull request #8 from wxsBSD/define_cleanup
Cleanup all the macro definitions.
2014-01-17 08:14:22 -08:00
Wesley Shields
acd76dbcda Cleanup all the macro definitions.
Instead of constantly defining and redefining the macros to read values
just define them once. There are now the three main ones (READ_WORD,
READ_DWORD and READ_BYTE) along with READ_DWORD_PTR and READ_DWORD_NULL.

Each macro takes a pointer to a bounded_buffer (what to read), an offset
(where to read), a structure and member (what to read into). You should
use READ_DWORD_PTR when you have a pointer to a structure. You can
use READ_DWORD_NULL when failure to read should return NULL as all the
rest return false.

Fixes #7.
2014-01-17 00:34:58 -05:00
Andrew Ruef
ac15bf8faf Merge pull request #6 from wxsBSD/resources
Implement resource parsing.
2014-01-02 09:37:30 -08:00
Wesley Shields
4e5d6f6902 Document size and RVA changes. 2013-12-30 17:10:44 -05:00
Wesley Shields
ec5c49eaff Make resource parsing more resilient.
I have a UPX packed sample that corrupted the resource directory. These changes
allow the resources to be properly parsed.

They add an RVA and size to the resource struct. This is the address and size
of the resource as it is declared in the directory. If the address is invalid
create a zero-length buffer for the data. If the size is invalid (ie: it goes
off the end of the .rsrc section) create a zero-length buffer for the data.
Otherwise, return the actual data.

This allows consumers of the rsrc to figure out if the resource is corrupt
or not by comparing the length of the buffer to the size element. If the
size is greater than 0 but buffer is empty then it's invalid.

Also, it should never happen but just to be safe make pepy catch NULL
buffers (in pepy_data_converter) and return an empty bytearray.
2013-12-30 16:45:50 -05:00
Wesley Shields
b9d1592c50 Fix a type and expand a comment a bit. 2013-12-25 21:10:23 -05:00
Wesley Shields
8f9662cc92 Fix resource parsing so it works. ;)
I had initially written this in such a way that it would break if there
were multiple entries anywhere other than the first table. This change
now works across more complex samples that I have tested against.

While here, I did a little moving around and had to create a structure
that isn't used other than to know how far to move the offset when
parsing. This is because the struct into which I am parsing the data
keeps track of other things along the way, so it's size is incorrect.

While here, change parse_resource() to be parse_resource_table() as it
is more accurate to what it really does.
2013-12-25 21:01:55 -05:00
Wesley Shields
bc6b67fa0e Fix a bug in test.py.
When iterating through the bytearray it would cause a python crash if
the byte value was 0x78. I have a test sample where the first 8 bytes
at the entry point are 0xe8 0xa6 0x4e 0x0 0x0 0xe9 0x78 0xfe. If I don't
do this dance it crashes when trying to get the 6th (0x78) byte out
of the array.
2013-12-24 15:38:45 -05:00
Wesley Shields
913b3c16d1 Catch if PyInt_FromLong() returns NULL. 2013-12-24 14:43:09 -05:00
Wesley Shields
4a574e0e07 Remove debugging. 2013-12-24 13:34:04 -05:00
Wesley Shields
a6af4cbd18 Implement resource parsing.
While here, fix a memory leak in pepy as I was not decrementing the
reference counter on self->data in section_dealloc().
2013-12-24 12:41:59 -05:00
Dan Guido
b139ae3b39 Merge pull request #5 from wxsBSD/pepy
Pepy
2013-12-15 12:23:58 -08:00
Wesley Shields
f23cbb132f Document the data attribute on sections. 2013-12-14 22:36:56 -05:00