60 lines
1.7 KiB
C
Raw Normal View History

2013-07-24 17:32:23 -04:00
/* DO WHATEVER YOU WANT */
#ifndef _PARSE_H
#define _PARSE_H
#include <string>
#include <boost/cstdint.hpp>
typedef boost::uint32_t RVA;
2013-07-24 17:57:58 -04:00
typedef struct _bounded_buffer {
2013-07-24 18:43:02 -04:00
boost::uint8_t *buf;
2013-07-24 17:57:58 -04:00
boost::uint32_t bufLen;
2013-07-24 19:15:53 -04:00
bool copy;
2013-07-24 17:57:58 -04:00
} bounded_buffer;
bool readByte(bounded_buffer *b, boost::uint32_t offset, boost::uint8_t &out);
bool readWord(bounded_buffer *b, boost::uint32_t offset, boost::uint16_t &out);
bool readDword(bounded_buffer *b, boost::uint32_t offset, boost::uint32_t &out);
2013-07-24 18:32:56 -04:00
bounded_buffer *readFileToFileBuffer(const char *filePath);
2013-07-25 15:19:00 -04:00
bounded_buffer *splitBuffer(bounded_buffer *b, boost::uint32_t from, boost::uint32_t to);
void deleteBuffer(bounded_buffer *b);
2013-07-24 18:32:56 -04:00
2013-07-24 18:52:38 -04:00
struct parsed_pe_internal;
2013-07-24 19:15:53 -04:00
typedef struct _pe_header {
RVA entryPoint;
bounded_buffer headerData;
} pe_header;
2013-07-24 17:32:23 -04:00
typedef struct _parsed_pe {
2013-07-24 18:52:38 -04:00
bounded_buffer *fileBuffer;
parsed_pe_internal *internal;
2013-07-24 19:15:53 -04:00
pe_header peHeader;
2013-07-24 17:32:23 -04:00
} parsed_pe;
//get a PE parse context from a file
parsed_pe *ParsePEFromFile(const char *filePath);
2013-07-24 17:35:25 -04:00
//destruct a PE context
2013-07-24 17:32:23 -04:00
void DestructParsedPE(parsed_pe *pe);
2013-07-24 17:35:25 -04:00
//iterate over the imports by RVA and string
typedef void (*iterRVAStr)(void *, RVA, std::string &);
void IterImpRVAString(parsed_pe *pe, iterRVAStr cb, void *cbd);
//iterate over relocations in the PE file
typedef void (*iterReloc)(void *, RVA);
void IterRelocs(parsed_pe *pe, iterReloc cb, void *cbd);
//iterate over the exports by RVA
typedef void (*iterRVA)(void *, RVA);
void IterExpRVA(parsed_pe *pe, iterRVA cb, void *cbd);
2013-07-24 17:57:58 -04:00
//iterate over sections
typedef void (*iterSec)(void *, RVA secBase, std::string &, bounded_buffer *b);
void IterSec(parsed_pe *pe, iterSec cb, void *cbd);
2013-07-24 17:32:23 -04:00
#endif