4
0
mirror of https://github.com/QuasarApp/pe-parse.git synced 2025-05-07 00:59:34 +00:00

Don't store parsed values in python objects.

Convert the PyObject pointers used inside pepy_parsed into their corresponding
native types and use those. Teach the members array to return them accordingly.

While here might as well add support for signature and machine values.

Also, convert test.py to have shorter output by not using pprint.
This commit is contained in:
Wesley Shields 2013-11-29 14:28:39 -05:00
parent b816e1cbf9
commit 860fbff4e4
2 changed files with 16 additions and 8 deletions

@ -39,7 +39,9 @@ typedef struct {
typedef struct {
PyObject_HEAD
PyObject *timedatestamp;
uint32_t signature;
uint32_t machine;
uint32_t timedatestamp;
parsed_pe *pe;
} pepy_parsed;
@ -70,13 +72,14 @@ static int pepy_parsed_init(pepy_parsed *self, PyObject *args, PyObject *kwds) {
Py_DECREF(py_str);
self->timedatestamp = PyInt_FromLong(self->pe->peHeader.nt.FileHeader.TimeDateStamp);
self->signature = self->pe->peHeader.nt.Signature;
self->machine = self->pe->peHeader.nt.FileHeader.Machine;
self->timedatestamp = self->pe->peHeader.nt.FileHeader.TimeDateStamp;
return 0;
}
static void pepy_parsed_dealloc(pepy_parsed *self) {
DestructParsedPE(self->pe);
Py_XDECREF(self->timedatestamp);
self->ob_type->tp_free((PyObject *) self);
}
@ -176,8 +179,12 @@ static PyObject *pepy_parsed_get_sections(PyObject *self, PyObject *args) {
}
static PyMemberDef pepy_parsed_members[] = {
{ (char *) "timedatestamp", T_OBJECT, offsetof(pepy_parsed, timedatestamp),
READONLY, (char *) "PE Timestamp" },
{ (char *) "signature", T_UINT, offsetof(pepy_parsed, signature), READONLY,
(char *) "Signature" },
{ (char *) "machine", T_UINT, offsetof(pepy_parsed, machine), READONLY,
(char *) "Machine" },
{ (char *) "timedatestamp", T_UINT, offsetof(pepy_parsed, timedatestamp),
READONLY, (char *) "Timestamp" },
{ NULL }
};

@ -4,12 +4,13 @@ import sys
import time
import pepy
from pprint import pprint
p = pepy.parse(sys.argv[1])
ep = p.get_entry_point()
byts = p.get_bytes(ep, 8)
print "Signature: %s" % hex(p.signature)
print "Machine: %s" % hex(p.machine)
print "Timedatestamp: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(p.timedatestamp))
print "Bytes at 0x%x: %s" % (ep, byts)
print "Sections:"
for sect in p.get_sections():
pprint(sect)
print(sect)