From a8ccfb9df370be8d53ce0f358a65e22004bfafa8 Mon Sep 17 00:00:00 2001 From: artemdinaburg Date: Fri, 3 Mar 2017 14:41:14 -0500 Subject: [PATCH] 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 --- dump-prog/dump.cpp | 1 + parser-library/buffer.cpp | 3 +++ parser-library/nt-headers.h | 2 ++ parser-library/parse.cpp | 3 +++ parser-library/parse.h | 3 +++ parser-library/to_string.h | 2 ++ python/pepy.cpp | 2 ++ 7 files changed, 16 insertions(+) diff --git a/dump-prog/dump.cpp b/dump-prog/dump.cpp index d91438f..4b8cf60 100644 --- a/dump-prog/dump.cpp +++ b/dump-prog/dump.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. using namespace std; using namespace boost; +using namespace peparse; int printExps(void *N, VA funcAddr, std::string &mod, std::string &func) { cout << "EXP: "; diff --git a/parser-library/buffer.cpp b/parser-library/buffer.cpp index 79c4b52..e20a0cf 100644 --- a/parser-library/buffer.cpp +++ b/parser-library/buffer.cpp @@ -38,6 +38,8 @@ THE SOFTWARE. using namespace boost; using namespace std; +namespace peparse { + extern ::uint32_t err; extern ::string err_loc; @@ -266,3 +268,4 @@ void deleteBuffer(bounded_buffer *b) { uint64_t bufLen(bounded_buffer *b) { return b->bufLen; } +} // namespace peparse diff --git a/parser-library/nt-headers.h b/parser-library/nt-headers.h index a025009..70a12a4 100644 --- a/parser-library/nt-headers.h +++ b/parser-library/nt-headers.h @@ -31,6 +31,7 @@ THE SOFTWARE. //need to pack these structure definitions //some constant definitions +namespace peparse { const boost::uint16_t MZ_MAGIC = 0x5A4D; const boost::uint32_t NT_MAGIC = 0x00004550; const boost::uint16_t NUM_DIR_ENTRIES = 16; @@ -307,5 +308,6 @@ struct reloc_block { boost::uint32_t PageRVA; boost::uint32_t BlockSize; }; +} // namespace peparse #endif diff --git a/parser-library/parse.cpp b/parser-library/parse.cpp index 3b25115..c76998a 100644 --- a/parser-library/parse.cpp +++ b/parser-library/parse.cpp @@ -34,6 +34,8 @@ THE SOFTWARE. using namespace std; using namespace boost; +namespace peparse { + struct section { string sectionName; ::uint64_t sectionBase; @@ -1489,3 +1491,4 @@ bool GetEntryPoint(parsed_pe *pe, VA &v) { return false; } +} // namespace peparse diff --git a/parser-library/parse.h b/parser-library/parse.h index b79f127..8b25a25 100644 --- a/parser-library/parse.h +++ b/parser-library/parse.h @@ -72,6 +72,8 @@ if(readDword(b, o+_offset(__typeof__(inst), member), inst.member) == false) { \ return NULL; \ } +namespace peparse { + typedef boost::uint32_t RVA; typedef boost::uint64_t VA; @@ -197,5 +199,6 @@ bool ReadByteAtVA(parsed_pe *pe, VA v, boost::uint8_t &b); //get entry point into PE bool GetEntryPoint(parsed_pe *pe, VA &v); +} // namespace peparse #endif diff --git a/parser-library/to_string.h b/parser-library/to_string.h index 1e96f01..8328bd8 100644 --- a/parser-library/to_string.h +++ b/parser-library/to_string.h @@ -2,6 +2,7 @@ #define _TO_STRING_H #include +namespace peparse { template static std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) { @@ -9,4 +10,5 @@ std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) { oss << f << t; return oss.str(); } +} #endif diff --git a/python/pepy.cpp b/python/pepy.cpp index d5781aa..52313be 100644 --- a/python/pepy.cpp +++ b/python/pepy.cpp @@ -29,6 +29,8 @@ #include #include "parse.h" +using namespace peparse; + #define PEPY_VERSION "0.2" /* These are used to across multiple objects. */