Explicit use of std namespace, prefer std::vector over std::list, never use std::endl (#74)

This commit is contained in:
Jack Williams 2018-09-24 08:10:29 -07:00 committed by William Woodruff
parent 78869e5337
commit 766b183a1b
5 changed files with 201 additions and 191 deletions

View File

@ -28,7 +28,6 @@ THE SOFTWARE.
#include <parser-library/parse.h> #include <parser-library/parse.h>
using namespace std;
using namespace peparse; using namespace peparse;
int printExps(void *N, VA funcAddr, std::string &mod, std::string &func) { int printExps(void *N, VA funcAddr, std::string &mod, std::string &func) {
@ -41,19 +40,22 @@ int printExps(void *N, VA funcAddr, std::string &mod, std::string &func) {
std::cout << "!"; std::cout << "!";
std::cout << func; std::cout << func;
std::cout << ": 0x"; std::cout << ": 0x";
std::cout << to_string<decltype(address)>(address, hex); std::cout << to_string<decltype(address)>(address, std::hex);
std::cout << endl; std::cout << "\n";
return 0; return 0;
} }
int printImports(void *N, VA impAddr, string &modName, string &symName) { int printImports(void *N,
VA impAddr,
const std::string &modName,
const std::string &symName) {
static_cast<void>(N); static_cast<void>(N);
auto address = static_cast<std::uint32_t>(impAddr); auto address = static_cast<std::uint32_t>(impAddr);
std::cout << "0x" << to_string<decltype(address)>(address, hex); std::cout << "0x" << to_string<decltype(address)>(address, std::hex);
std::cout << " " << modName << "!" << symName; std::cout << " " << modName << "!" << symName;
std::cout << endl; std::cout << "\n";
return 0; return 0;
} }
@ -91,7 +93,7 @@ int printRelocs(void *N, VA relocAddr, reloc_type type) {
break; break;
} }
std::cout << " VA: 0x" << to_string<VA>(relocAddr, hex) << endl; std::cout << " VA: 0x" << to_string<VA>(relocAddr, std::hex) << "\n";
return 0; return 0;
} }
@ -105,8 +107,9 @@ int printSymbols(void *N,
uint8_t &numberOfAuxSymbols) { uint8_t &numberOfAuxSymbols) {
static_cast<void>(N); static_cast<void>(N);
std::cout << "Symbol Name: " << strName << endl; std::cout << "Symbol Name: " << strName << "\n";
std::cout << "Symbol Value: 0x" << to_string<uint32_t>(value, hex) << endl; std::cout << "Symbol Value: 0x"
<< to_string<std::uint32_t>(value, std::hex) << "\n";
std::cout << "Symbol Section Number: "; std::cout << "Symbol Section Number: ";
switch (sectionNumber) { switch (sectionNumber) {
@ -123,7 +126,7 @@ int printSymbols(void *N,
std::cout << sectionNumber; std::cout << sectionNumber;
break; break;
} }
std::cout << endl; std::cout << "\n";
std::cout << "Symbol Type: "; std::cout << "Symbol Type: ";
switch (type) { switch (type) {
@ -179,7 +182,7 @@ int printSymbols(void *N,
std::cout << "UNKNOWN"; std::cout << "UNKNOWN";
break; break;
} }
std::cout << endl; std::cout << "\n";
std::cout << "Symbol Storage Class: "; std::cout << "Symbol Storage Class: ";
switch (storageClass) { switch (storageClass) {
@ -217,10 +220,10 @@ int printSymbols(void *N,
std::cout << "UNKNOWN"; std::cout << "UNKNOWN";
break; break;
} }
std::cout << endl; std::cout << "\n";
std::cout << "Symbol Number of Aux Symbols: " std::cout << "Symbol Number of Aux Symbols: "
<< static_cast<uint32_t>(numberOfAuxSymbols) << endl; << static_cast<std::uint32_t>(numberOfAuxSymbols) << "\n";
return 0; return 0;
} }
@ -229,37 +232,43 @@ int printRsrc(void *N, resource r) {
static_cast<void>(N); static_cast<void>(N);
if (r.type_str.length()) if (r.type_str.length())
std::cout << "Type (string): " << r.type_str << endl; std::cout << "Type (string): " << r.type_str << "\n";
else else
std::cout << "Type: 0x" << to_string<uint32_t>(r.type, hex) << endl; std::cout << "Type: 0x"
<< to_string<std::uint32_t>(r.type, std::hex) << "\n";
if (r.name_str.length()) if (r.name_str.length())
std::cout << "Name (string): " << r.name_str << endl; std::cout << "Name (string): " << r.name_str << "\n";
else else
std::cout << "Name: 0x" << to_string<uint32_t>(r.name, hex) << endl; std::cout << "Name: 0x"
<< to_string<std::uint32_t>(r.name, std::hex) << "\n";
if (r.lang_str.length()) if (r.lang_str.length())
std::cout << "Lang (string): " << r.lang_str << endl; std::cout << "Lang (string): " << r.lang_str << "\n";
else else
std::cout << "Lang: 0x" << to_string<uint32_t>(r.lang, hex) << endl; std::cout << "Lang: 0x"
std::cout << "Codepage: 0x" << to_string<uint32_t>(r.codepage, hex) << endl; << to_string<std::uint32_t>(r.lang, std::hex) << "\n";
std::cout << "RVA: " << to_string<uint32_t>(r.RVA, dec) << endl; std::cout << "Codepage: 0x"
std::cout << "Size: " << to_string<uint32_t>(r.size, dec) << endl; << to_string<std::uint32_t>(r.codepage, std::hex) << "\n";
std::cout << "RVA: " << to_string<std::uint32_t>(r.RVA, std::dec) << "\n";
std::cout << "Size: " << to_string<std::uint32_t>(r.size, std::dec) << "\n";
return 0; return 0;
} }
int printSecs(void *N, int printSecs(void *N,
VA secBase, VA secBase,
string &secName, std::string &secName,
image_section_header s, image_section_header s,
bounded_buffer *data) { bounded_buffer *data) {
static_cast<void>(N); static_cast<void>(N);
static_cast<void>(s); static_cast<void>(s);
std::cout << "Sec Name: " << secName << endl; std::cout << "Sec Name: " << secName << "\n";
std::cout << "Sec Base: 0x" << to_string<uint64_t>(secBase, hex) << endl; std::cout << "Sec Base: 0x"
<< to_string<std::uint64_t>(secBase, std::hex) << "\n";
if (data) if (data)
std::cout << "Sec Size: " << to_string<uint64_t>(data->bufLen, dec) << endl; std::cout << "Sec Size: "
<< to_string<std::uint64_t>(data->bufLen, std::dec) << "\n";
else else
std::cout << "Sec Size: 0" << endl; std::cout << "Sec Size: 0" << "\n";
return 0; return 0;
} }
@ -267,12 +276,12 @@ int printSecs(void *N,
std::cout << "" #x << ": 0x"; \ std::cout << "" #x << ": 0x"; \
std::cout << to_string<std::uint32_t>( \ std::cout << to_string<std::uint32_t>( \
static_cast<std::uint32_t>(p->peHeader.nt.x), std::hex) \ static_cast<std::uint32_t>(p->peHeader.nt.x), std::hex) \
<< endl; << "\n";
#define DUMP_DEC_FIELD(x) \ #define DUMP_DEC_FIELD(x) \
std::cout << "" #x << ": "; \ std::cout << "" #x << ": "; \
std::cout << to_string<uint32_t>( \ std::cout << to_string<std::uint32_t>( \
static_cast<std::uint32_t>(p->peHeader.nt.x), std::dec) \ static_cast<std::uint32_t>(p->peHeader.nt.x), std::dec) \
<< endl; << "\n";
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc != 2 || (argc == 2 && std::strcmp(argv[1], "--help") == 0)) { if (argc != 2 || (argc == 2 && std::strcmp(argv[1], "--help") == 0)) {
@ -352,15 +361,15 @@ int main(int argc, char *argv[]) {
#undef DUMP_FIELD #undef DUMP_FIELD
#undef DUMP_DEC_FIELD #undef DUMP_DEC_FIELD
std::cout << "Imports: " << endl; std::cout << "Imports: " << "\n";
IterImpVAString(p, printImports, NULL); IterImpVAString(p, printImports, NULL);
std::cout << "Relocations: " << endl; std::cout << "Relocations: " << "\n";
IterRelocs(p, printRelocs, NULL); IterRelocs(p, printRelocs, NULL);
std::cout << "Symbols (symbol table): " << endl; std::cout << "Symbols (symbol table): " << "\n";
IterSymbols(p, printSymbols, NULL); IterSymbols(p, printSymbols, NULL);
std::cout << "Sections: " << endl; std::cout << "Sections: " << "\n";
IterSec(p, printSecs, NULL); IterSec(p, printSecs, NULL);
std::cout << "Exports: " << endl; std::cout << "Exports: " << "\n";
IterExpVA(p, printExps, NULL); IterExpVA(p, printExps, NULL);
// read the first 8 bytes from the entry point and print them // read the first 8 bytes from the entry point and print them
@ -368,24 +377,24 @@ int main(int argc, char *argv[]) {
if (GetEntryPoint(p, entryPoint)) { if (GetEntryPoint(p, entryPoint)) {
std::cout << "First 8 bytes from entry point (0x"; std::cout << "First 8 bytes from entry point (0x";
std::cout << to_string<VA>(entryPoint, hex); std::cout << to_string<VA>(entryPoint, std::hex);
std::cout << "):" << endl; std::cout << "):" << "\n";
for (std::size_t i = 0; i < 8; i++) { for (std::size_t i = 0; i < 8; i++) {
::uint8_t b; std::uint8_t b;
ReadByteAtVA(p, i + entryPoint, b); ReadByteAtVA(p, i + entryPoint, b);
std::cout << " 0x" << to_string<uint32_t>(b, hex); std::cout << " 0x" << to_string<std::uint32_t>(b, std::hex);
} }
std::cout << endl; std::cout << "\n";
} }
std::cout << "Resources: " << endl; std::cout << "Resources: " << "\n";
IterRsrc(p, printRsrc, NULL); IterRsrc(p, printRsrc, NULL);
DestructParsedPE(p); DestructParsedPE(p);
} else { } else {
std::cout << "Error: " << GetPEErr() << " (" << GetPEErrString() << ")" std::cout << "Error: " << GetPEErr() << " (" << GetPEErrString() << ")"
<< endl; << "\n";
std::cout << "Location: " << GetPEErrLoc() << endl; std::cout << "Location: " << GetPEErrLoc() << "\n";
} }
return 0; return 0;

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#define _offset(t, f) \ #define _offset(t, f) \
static_cast<std::uint32_t>( \ static_cast<std::uint32_t>( \
reinterpret_cast<ptrdiff_t>(&static_cast<t *>(nullptr)->f)) reinterpret_cast<std::ptrdiff_t>(&static_cast<t *>(nullptr)->f))
// need to pack these structure definitions // need to pack these structure definitions

View File

@ -181,7 +181,7 @@ typedef int (*iterRsrc)(void *, resource);
void IterRsrc(parsed_pe *pe, iterRsrc cb, void *cbd); void IterRsrc(parsed_pe *pe, iterRsrc cb, void *cbd);
// iterate over the imports by RVA and string // iterate over the imports by RVA and string
typedef int (*iterVAStr)(void *, VA, std::string &, std::string &); typedef int (*iterVAStr)(void *, VA, const std::string &, const std::string &);
void IterImpVAString(parsed_pe *pe, iterVAStr cb, void *cbd); void IterImpVAString(parsed_pe *pe, iterVAStr cb, void *cbd);
// iterate over relocations in the PE file // iterate over relocations in the PE file

View File

@ -25,19 +25,17 @@ THE SOFTWARE.
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <list> #include <vector>
#include <stdexcept> #include <stdexcept>
#include <parser-library/nt-headers.h> #include <parser-library/nt-headers.h>
#include <parser-library/parse.h> #include <parser-library/parse.h>
#include <parser-library/to_string.h> #include <parser-library/to_string.h>
using namespace std;
namespace peparse { namespace peparse {
struct section { struct section {
string sectionName; std::string sectionName;
std::uint64_t sectionBase; std::uint64_t sectionBase;
bounded_buffer *sectionData; bounded_buffer *sectionData;
image_section_header sec; image_section_header sec;
@ -45,14 +43,14 @@ struct section {
struct importent { struct importent {
VA addr; VA addr;
string symbolName; std::string symbolName;
string moduleName; std::string moduleName;
}; };
struct exportent { struct exportent {
VA addr; VA addr;
string symbolName; std::string symbolName;
string moduleName; std::string moduleName;
}; };
struct reloc { struct reloc {
@ -64,64 +62,64 @@ struct reloc {
#define SYMBOL_TYPE_HI(x) (x.type >> 8) #define SYMBOL_TYPE_HI(x) (x.type >> 8)
union symbol_name { union symbol_name {
uint8_t shortName[NT_SHORT_NAME_LEN]; std::uint8_t shortName[NT_SHORT_NAME_LEN];
uint32_t zeroes; std::uint32_t zeroes;
uint64_t data; std::uint64_t data;
}; };
struct aux_symbol_f1 { struct aux_symbol_f1 {
uint32_t tagIndex; std::uint32_t tagIndex;
uint32_t totalSize; std::uint32_t totalSize;
uint32_t pointerToLineNumber; std::uint32_t pointerToLineNumber;
uint32_t pointerToNextFunction; std::uint32_t pointerToNextFunction;
}; };
struct aux_symbol_f2 { struct aux_symbol_f2 {
uint16_t lineNumber; std::uint16_t lineNumber;
uint32_t pointerToNextFunction; std::uint32_t pointerToNextFunction;
}; };
struct aux_symbol_f3 { struct aux_symbol_f3 {
uint32_t tagIndex; std::uint32_t tagIndex;
uint32_t characteristics; std::uint32_t characteristics;
}; };
struct aux_symbol_f4 { struct aux_symbol_f4 {
uint8_t filename[SYMTAB_RECORD_LEN]; std::uint8_t filename[SYMTAB_RECORD_LEN];
string strFilename; std::string strFilename;
}; };
struct aux_symbol_f5 { struct aux_symbol_f5 {
uint32_t length; std::uint32_t length;
uint16_t numberOfRelocations; std::uint16_t numberOfRelocations;
uint16_t numberOfLineNumbers; std::uint16_t numberOfLineNumbers;
uint32_t checkSum; std::uint32_t checkSum;
uint16_t number; std::uint16_t number;
uint8_t selection; std::uint8_t selection;
}; };
struct symbol { struct symbol {
string strName; std::string strName;
symbol_name name; symbol_name name;
uint32_t value; std::uint32_t value;
int16_t sectionNumber; std::int16_t sectionNumber;
uint16_t type; std::uint16_t type;
uint8_t storageClass; std::uint8_t storageClass;
uint8_t numberOfAuxSymbols; std::uint8_t numberOfAuxSymbols;
list<aux_symbol_f1> aux_symbols_f1; std::vector<aux_symbol_f1> aux_symbols_f1;
list<aux_symbol_f2> aux_symbols_f2; std::vector<aux_symbol_f2> aux_symbols_f2;
list<aux_symbol_f3> aux_symbols_f3; std::vector<aux_symbol_f3> aux_symbols_f3;
list<aux_symbol_f4> aux_symbols_f4; std::vector<aux_symbol_f4> aux_symbols_f4;
list<aux_symbol_f5> aux_symbols_f5; std::vector<aux_symbol_f5> aux_symbols_f5;
}; };
struct parsed_pe_internal { struct parsed_pe_internal {
list<section> secs; std::vector<section> secs;
list<resource> rsrcs; std::vector<resource> rsrcs;
list<importent> imports; std::vector<importent> imports;
list<reloc> relocs; std::vector<reloc> relocs;
list<exportent> exports; std::vector<exportent> exports;
list<symbol> symbols; std::vector<symbol> symbols;
}; };
std::uint32_t err = 0; std::uint32_t err = 0;
@ -144,11 +142,11 @@ std::uint32_t GetPEErr() {
return err; return err;
} }
string GetPEErrString() { std::string GetPEErrString() {
return pe_err_str[err]; return pe_err_str[err];
} }
string GetPEErrLoc() { std::string GetPEErrLoc() {
return err_loc; return err_loc;
} }
@ -214,7 +212,7 @@ const char *GetSymbolTableStorageClassName(std::uint8_t id) {
} }
static bool static bool
readCString(const bounded_buffer &buffer, std::uint32_t off, string &result) { readCString(const bounded_buffer &buffer, std::uint32_t off, std::string &result) {
if (off < buffer.bufLen) { if (off < buffer.bufLen) {
std::uint8_t *p = buffer.buf; std::uint8_t *p = buffer.buf;
std::uint32_t n = buffer.bufLen; std::uint32_t n = buffer.bufLen;
@ -231,10 +229,10 @@ readCString(const bounded_buffer &buffer, std::uint32_t off, string &result) {
return false; return false;
} }
bool getSecForVA(list<section> &secs, VA v, section &sec) { bool getSecForVA(const std::vector<section> &secs, VA v, section &sec) {
for (section s : secs) { for (section s : secs) {
::uint64_t low = s.sectionBase; std::uint64_t low = s.sectionBase;
::uint64_t high = low + s.sec.Misc.VirtualSize; std::uint64_t high = low + s.sec.Misc.VirtualSize;
if (v >= low && v < high) { if (v >= low && v < high) {
sec = s; sec = s;
@ -257,7 +255,7 @@ void IterRsrc(parsed_pe *pe, iterRsrc cb, void *cbd) {
return; return;
} }
bool parse_resource_id(bounded_buffer *data, std::uint32_t id, string &result) { bool parse_resource_id(bounded_buffer *data, std::uint32_t id, std::string &result) {
std::uint8_t c; std::uint8_t c;
std::uint16_t len; std::uint16_t len;
@ -279,7 +277,7 @@ bool parse_resource_table(bounded_buffer *sectionData,
std::uint32_t virtaddr, std::uint32_t virtaddr,
std::uint32_t depth, std::uint32_t depth,
resource_dir_entry *dirent, resource_dir_entry *dirent,
list<resource> &rsrcs) { std::vector<resource> &rsrcs) {
resource_dir_table rdt; resource_dir_table rdt;
if (sectionData == nullptr) { if (sectionData == nullptr) {
@ -492,8 +490,8 @@ bool parse_resource_table(bounded_buffer *sectionData,
bool getResources(bounded_buffer *b, bool getResources(bounded_buffer *b,
bounded_buffer *fileBegin, bounded_buffer *fileBegin,
list<section> secs, const std::vector<section> secs,
list<resource> &rsrcs) { std::vector<resource> &rsrcs) {
static_cast<void>(fileBegin); static_cast<void>(fileBegin);
if (b == nullptr) if (b == nullptr)
@ -518,17 +516,17 @@ bool getResources(bounded_buffer *b,
bool getSections(bounded_buffer *b, bool getSections(bounded_buffer *b,
bounded_buffer *fileBegin, bounded_buffer *fileBegin,
nt_header_32 &nthdr, nt_header_32 &nthdr,
list<section> &secs) { std::vector<section> &secs) {
if (b == nullptr) { if (b == nullptr) {
return false; return false;
} }
// get each of the sections... // get each of the sections...
for (::uint32_t i = 0; i < nthdr.FileHeader.NumberOfSections; i++) { for (std::uint32_t i = 0; i < nthdr.FileHeader.NumberOfSections; i++) {
image_section_header curSec; image_section_header curSec;
::uint32_t o = i * sizeof(image_section_header); std::uint32_t o = i * sizeof(image_section_header);
for (::uint32_t k = 0; k < NT_SHORT_NAME_LEN; k++) { for (std::uint32_t k = 0; k < NT_SHORT_NAME_LEN; k++) {
if (!readByte(b, o + k, curSec.Name[k])) { if (!readByte(b, o + k, curSec.Name[k])) {
return false; return false;
} }
@ -547,8 +545,8 @@ bool getSections(bounded_buffer *b,
// now we have the section header information, so fill in a section // now we have the section header information, so fill in a section
// object appropriately // object appropriately
section thisSec; section thisSec;
for (::uint32_t charIndex = 0; charIndex < NT_SHORT_NAME_LEN; charIndex++) { for (std::uint32_t charIndex = 0; charIndex < NT_SHORT_NAME_LEN; charIndex++) {
::uint8_t c = curSec.Name[charIndex]; std::uint8_t c = curSec.Name[charIndex];
if (c == 0) { if (c == 0) {
break; break;
} }
@ -567,8 +565,8 @@ bool getSections(bounded_buffer *b,
} }
thisSec.sec = curSec; thisSec.sec = curSec;
::uint32_t lowOff = curSec.PointerToRawData; std::uint32_t lowOff = curSec.PointerToRawData;
::uint32_t highOff = lowOff + curSec.SizeOfRawData; std::uint32_t highOff = lowOff + curSec.SizeOfRawData;
thisSec.sectionData = splitBuffer(fileBegin, lowOff, highOff); thisSec.sectionData = splitBuffer(fileBegin, lowOff, highOff);
secs.push_back(thisSec); secs.push_back(thisSec);
@ -614,10 +612,10 @@ bool readOptionalHeader(bounded_buffer *b, optional_header_32 &header) {
header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES; header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES;
} }
for (::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) { for (std::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) {
::uint32_t c = (i * sizeof(data_directory)); std::uint32_t c = (i * sizeof(data_directory));
c += _offset(optional_header_32, DataDirectory[0]); c += _offset(optional_header_32, DataDirectory[0]);
::uint32_t o; std::uint32_t o;
o = c + _offset(data_directory, VirtualAddress); o = c + _offset(data_directory, VirtualAddress);
if (!readDword(b, o, header.DataDirectory[i].VirtualAddress)) { if (!readDword(b, o, header.DataDirectory[i].VirtualAddress)) {
@ -669,10 +667,10 @@ bool readOptionalHeader64(bounded_buffer *b, optional_header_64 &header) {
header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES; header.NumberOfRvaAndSizes = NUM_DIR_ENTRIES;
} }
for (::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) { for (std::uint32_t i = 0; i < header.NumberOfRvaAndSizes; i++) {
::uint32_t c = (i * sizeof(data_directory)); std::uint32_t c = (i * sizeof(data_directory));
c += _offset(optional_header_64, DataDirectory[0]); c += _offset(optional_header_64, DataDirectory[0]);
::uint32_t o; std::uint32_t o;
o = c + _offset(data_directory, VirtualAddress); o = c + _offset(data_directory, VirtualAddress);
if (!readDword(b, o, header.DataDirectory[i].VirtualAddress)) { if (!readDword(b, o, header.DataDirectory[i].VirtualAddress)) {
@ -705,8 +703,8 @@ bool readNtHeader(bounded_buffer *b, nt_header_32 &header) {
return false; return false;
} }
::uint32_t pe_magic; std::uint32_t pe_magic;
::uint32_t curOffset = 0; std::uint32_t curOffset = 0;
if (!readDword(b, curOffset, pe_magic) || pe_magic != NT_MAGIC) { if (!readDword(b, curOffset, pe_magic) || pe_magic != NT_MAGIC) {
PE_ERR(PEERR_READ); PE_ERR(PEERR_READ);
return false; return false;
@ -803,8 +801,8 @@ bool getHeader(bounded_buffer *file, pe_header &p, bounded_buffer *&rem) {
} }
// start by reading MZ // start by reading MZ
::uint16_t tmp = 0; std::uint16_t tmp = 0;
::uint32_t curOffset = 0; std::uint32_t curOffset = 0;
if (!readWord(file, curOffset, tmp)) { if (!readWord(file, curOffset, tmp)) {
PE_ERR(PEERR_READ); PE_ERR(PEERR_READ);
return false; return false;
@ -815,7 +813,7 @@ bool getHeader(bounded_buffer *file, pe_header &p, bounded_buffer *&rem) {
} }
// read the offset to the NT headers // read the offset to the NT headers
::uint32_t offset; std::uint32_t offset;
if (!readDword(file, _offset(dos_header, e_lfanew), offset)) { if (!readDword(file, _offset(dos_header, e_lfanew), offset)) {
PE_ERR(PEERR_READ); PE_ERR(PEERR_READ);
return false; return false;
@ -837,15 +835,15 @@ bool getHeader(bounded_buffer *file, pe_header &p, bounded_buffer *&rem) {
* Need to determine if this is a PE32 or PE32+ binary and use the * Need to determine if this is a PE32 or PE32+ binary and use the
# correct size. # correct size.
*/ */
::uint32_t rem_size; std::uint32_t rem_size;
if (p.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) { if (p.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) {
// signature + file_header + optional_header_32 // signature + file_header + optional_header_32
rem_size = rem_size =
sizeof(::uint32_t) + sizeof(file_header) + sizeof(optional_header_32); sizeof(std::uint32_t) + sizeof(file_header) + sizeof(optional_header_32);
} else if (p.nt.OptionalMagic == NT_OPTIONAL_64_MAGIC) { } else if (p.nt.OptionalMagic == NT_OPTIONAL_64_MAGIC) {
// signature + file_header + optional_header_64 // signature + file_header + optional_header_64
rem_size = rem_size =
sizeof(::uint32_t) + sizeof(file_header) + sizeof(optional_header_64); sizeof(std::uint32_t) + sizeof(file_header) + sizeof(optional_header_64);
} else { } else {
PE_ERR(PEERR_MAGIC); PE_ERR(PEERR_MAGIC);
deleteBuffer(ntBuf); deleteBuffer(ntBuf);
@ -910,7 +908,7 @@ bool getExports(parsed_pe *p) {
} }
auto nameOff = static_cast<std::uint32_t>(nameVA - nameSec.sectionBase); auto nameOff = static_cast<std::uint32_t>(nameVA - nameSec.sectionBase);
string modName; std::string modName;
if (!readCString(*nameSec.sectionData, nameOff, modName)) { if (!readCString(*nameSec.sectionData, nameOff, modName)) {
return false; return false;
} }
@ -925,7 +923,7 @@ bool getExports(parsed_pe *p) {
if (numNames > 0) { if (numNames > 0) {
// get the names section // get the names section
::uint32_t namesRVA; std::uint32_t namesRVA;
if (!readDword(s.sectionData, if (!readDword(s.sectionData,
rvaofft + _offset(export_dir_table, NamePointerRVA), rvaofft + _offset(export_dir_table, NamePointerRVA),
namesRVA)) { namesRVA)) {
@ -950,7 +948,7 @@ bool getExports(parsed_pe *p) {
static_cast<std::uint32_t>(namesVA - namesSec.sectionBase); static_cast<std::uint32_t>(namesVA - namesSec.sectionBase);
// get the EAT section // get the EAT section
::uint32_t eatRVA; std::uint32_t eatRVA;
if (!readDword(s.sectionData, if (!readDword(s.sectionData,
rvaofft + _offset(export_dir_table, ExportAddressTableRVA), rvaofft + _offset(export_dir_table, ExportAddressTableRVA),
eatRVA)) { eatRVA)) {
@ -974,7 +972,7 @@ bool getExports(parsed_pe *p) {
auto eatOff = static_cast<std::uint32_t>(eatVA - eatSec.sectionBase); auto eatOff = static_cast<std::uint32_t>(eatVA - eatSec.sectionBase);
// get the ordinal base // get the ordinal base
::uint32_t ordinalBase; std::uint32_t ordinalBase;
if (!readDword(s.sectionData, if (!readDword(s.sectionData,
rvaofft + _offset(export_dir_table, OrdinalBase), rvaofft + _offset(export_dir_table, OrdinalBase),
ordinalBase)) { ordinalBase)) {
@ -1008,10 +1006,10 @@ bool getExports(parsed_pe *p) {
auto ordinalOff = static_cast<std::uint32_t>(ordinalTableVA - auto ordinalOff = static_cast<std::uint32_t>(ordinalTableVA -
ordinalTableSec.sectionBase); ordinalTableSec.sectionBase);
for (::uint32_t i = 0; i < numNames; i++) { for (std::uint32_t i = 0; i < numNames; i++) {
::uint32_t curNameRVA; std::uint32_t curNameRVA;
if (!readDword(namesSec.sectionData, if (!readDword(namesSec.sectionData,
namesOff + (i * sizeof(::uint32_t)), namesOff + (i * sizeof(std::uint32_t)),
curNameRVA)) { curNameRVA)) {
return false; return false;
} }
@ -1033,7 +1031,7 @@ bool getExports(parsed_pe *p) {
auto curNameOff = auto curNameOff =
static_cast<std::uint32_t>(curNameVA - curNameSec.sectionBase); static_cast<std::uint32_t>(curNameVA - curNameSec.sectionBase);
string symName; std::string symName;
std::uint8_t d; std::uint8_t d;
do { do {
@ -1050,17 +1048,17 @@ bool getExports(parsed_pe *p) {
} while (true); } while (true);
// now, for this i, look it up in the ExportOrdinalTable // now, for this i, look it up in the ExportOrdinalTable
::uint16_t ordinal; std::uint16_t ordinal;
if (!readWord(ordinalTableSec.sectionData, if (!readWord(ordinalTableSec.sectionData,
ordinalOff + (i * sizeof(uint16_t)), ordinalOff + (i * sizeof(std::uint16_t)),
ordinal)) { ordinal)) {
return false; return false;
} }
//::uint32_t eatIdx = ordinal - ordinalBase; //::uint32_t eatIdx = ordinal - ordinalBase;
::uint32_t eatIdx = (ordinal * sizeof(uint32_t)); std::uint32_t eatIdx = (ordinal * sizeof(std::uint32_t));
::uint32_t symRVA; std::uint32_t symRVA;
if (!readDword(eatSec.sectionData, eatOff + eatIdx, symRVA)) { if (!readDword(eatSec.sectionData, eatOff + eatIdx, symRVA)) {
return false; return false;
} }
@ -1149,9 +1147,9 @@ bool getRelocations(parsed_pe *p) {
// Iterate over all of the block Type/Offset entries // Iterate over all of the block Type/Offset entries
while (entryCount != 0) { while (entryCount != 0) {
::uint16_t entry; std::uint16_t entry;
::uint8_t type; std::uint8_t type;
::uint16_t offset; std::uint16_t offset;
if (!readWord(d.sectionData, rvaofft, entry)) { if (!readWord(d.sectionData, rvaofft, entry)) {
return false; return false;
@ -1181,7 +1179,7 @@ bool getRelocations(parsed_pe *p) {
p->internal->relocs.push_back(r); p->internal->relocs.push_back(r);
entryCount--; entryCount--;
rvaofft += sizeof(::uint16_t); rvaofft += sizeof(std::uint16_t);
} }
} }
} }
@ -1254,7 +1252,7 @@ bool getImports(parsed_pe *p) {
} }
auto nameOff = static_cast<std::uint32_t>(name - nameSec.sectionBase); auto nameOff = static_cast<std::uint32_t>(name - nameSec.sectionBase);
string modName; std::string modName;
if (!readCString(*nameSec.sectionData, nameOff, modName)) { if (!readCString(*nameSec.sectionData, nameOff, modName)) {
return false; return false;
} }
@ -1303,13 +1301,13 @@ bool getImports(parsed_pe *p) {
auto lookupOff = auto lookupOff =
static_cast<std::uint32_t>(lookupVA - lookupSec.sectionBase); static_cast<std::uint32_t>(lookupVA - lookupSec.sectionBase);
::uint32_t offInTable = 0; std::uint32_t offInTable = 0;
do { do {
VA valVA = 0; VA valVA = 0;
::uint8_t ord = 0; std::uint8_t ord = 0;
::uint16_t oval = 0; std::uint16_t oval = 0;
::uint32_t val32 = 0; std::uint32_t val32 = 0;
::uint64_t val64 = 0; std::uint64_t val64 = 0;
if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) { if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) {
if (!readDword(lookupSec.sectionData, lookupOff, val32)) { if (!readDword(lookupSec.sectionData, lookupOff, val32)) {
return false; return false;
@ -1336,7 +1334,7 @@ bool getImports(parsed_pe *p) {
if (ord == 0) { if (ord == 0) {
// import by name // import by name
string symName; std::string symName;
section symNameSec; section symNameSec;
if (!getSecForVA(p->internal->secs, valVA, symNameSec)) { if (!getSecForVA(p->internal->secs, valVA, symNameSec)) {
@ -1345,7 +1343,7 @@ bool getImports(parsed_pe *p) {
std::uint32_t nameOffset = std::uint32_t nameOffset =
static_cast<std::uint32_t>(valVA - symNameSec.sectionBase) + static_cast<std::uint32_t>(valVA - symNameSec.sectionBase) +
sizeof(::uint16_t); sizeof(std::uint16_t);
do { do {
std::uint8_t chr; std::uint8_t chr;
if (!readByte(symNameSec.sectionData, nameOffset, chr)) { if (!readByte(symNameSec.sectionData, nameOffset, chr)) {
@ -1377,8 +1375,8 @@ bool getImports(parsed_pe *p) {
ent.moduleName = modName; ent.moduleName = modName;
p->internal->imports.push_back(ent); p->internal->imports.push_back(ent);
} else { } else {
string symName = std::string symName =
"ORDINAL_" + modName + "_" + to_string<uint32_t>(oval, dec); "ORDINAL_" + modName + "_" + to_string<std::uint32_t>(oval, std::dec);
importent ent; importent ent;
@ -1399,11 +1397,11 @@ bool getImports(parsed_pe *p) {
} }
if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) { if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_32_MAGIC) {
lookupOff += sizeof(::uint32_t); lookupOff += sizeof(std::uint32_t);
offInTable += sizeof(::uint32_t); offInTable += sizeof(std::uint32_t);
} else if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_64_MAGIC) { } else if (p->peHeader.nt.OptionalMagic == NT_OPTIONAL_64_MAGIC) {
lookupOff += sizeof(::uint64_t); lookupOff += sizeof(std::uint64_t);
offInTable += sizeof(::uint64_t); offInTable += sizeof(std::uint64_t);
} else { } else {
return false; return false;
} }
@ -1421,13 +1419,13 @@ bool getSymbolTable(parsed_pe *p) {
return true; return true;
} }
uint32_t strTableOffset = std::uint32_t strTableOffset =
p->peHeader.nt.FileHeader.PointerToSymbolTable + p->peHeader.nt.FileHeader.PointerToSymbolTable +
(p->peHeader.nt.FileHeader.NumberOfSymbols * SYMTAB_RECORD_LEN); (p->peHeader.nt.FileHeader.NumberOfSymbols * SYMTAB_RECORD_LEN);
uint32_t offset = p->peHeader.nt.FileHeader.PointerToSymbolTable; std::uint32_t offset = p->peHeader.nt.FileHeader.PointerToSymbolTable;
for (uint32_t i = 0; i < p->peHeader.nt.FileHeader.NumberOfSymbols; i++) { for (std::uint32_t i = 0; i < p->peHeader.nt.FileHeader.NumberOfSymbols; i++) {
symbol sym; symbol sym;
// Read name // Read name
@ -1452,16 +1450,16 @@ bool getSymbolTable(parsed_pe *p) {
break; break;
} }
sym.strName.push_back(static_cast<char>(ch)); sym.strName.push_back(static_cast<char>(ch));
strOffset += sizeof(uint8_t); strOffset += sizeof(std::uint8_t);
} }
} else { } else {
for (uint8_t n = 0; n < NT_SHORT_NAME_LEN && sym.name.shortName[n] != 0; for (std::uint8_t n = 0; n < NT_SHORT_NAME_LEN && sym.name.shortName[n] != 0;
n++) { n++) {
sym.strName.push_back(static_cast<char>(sym.name.shortName[n])); sym.strName.push_back(static_cast<char>(sym.name.shortName[n]));
} }
} }
offset += sizeof(uint64_t); offset += sizeof(std::uint64_t);
// Read value // Read value
if (!readDword(p->fileBuffer, offset, sym.value)) { if (!readDword(p->fileBuffer, offset, sym.value)) {
@ -1469,7 +1467,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read section number // Read section number
uint16_t secNum; uint16_t secNum;
@ -1477,9 +1475,9 @@ bool getSymbolTable(parsed_pe *p) {
PE_ERR(PEERR_MAGIC); PE_ERR(PEERR_MAGIC);
return false; return false;
} }
sym.sectionNumber = static_cast<int16_t>(secNum); sym.sectionNumber = static_cast<std::int16_t>(secNum);
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Read type // Read type
if (!readWord(p->fileBuffer, offset, sym.type)) { if (!readWord(p->fileBuffer, offset, sym.type)) {
@ -1487,7 +1485,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Read storage class // Read storage class
if (!readByte(p->fileBuffer, offset, sym.storageClass)) { if (!readByte(p->fileBuffer, offset, sym.storageClass)) {
@ -1495,7 +1493,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint8_t); offset += sizeof(std::uint8_t);
// Read number of auxiliary symbols // Read number of auxiliary symbols
if (!readByte(p->fileBuffer, offset, sym.numberOfAuxSymbols)) { if (!readByte(p->fileBuffer, offset, sym.numberOfAuxSymbols)) {
@ -1504,7 +1502,7 @@ bool getSymbolTable(parsed_pe *p) {
} }
// Set offset to next symbol // Set offset to next symbol
offset += sizeof(uint8_t); offset += sizeof(std::uint8_t);
// Save the symbol // Save the symbol
p->internal->symbols.push_back(sym); p->internal->symbols.push_back(sym);
@ -1524,7 +1522,7 @@ bool getSymbolTable(parsed_pe *p) {
SYMBOL_TYPE_HI(sym) == 0x20 && sym.sectionNumber > 0) { SYMBOL_TYPE_HI(sym) == 0x20 && sym.sectionNumber > 0) {
// Auxiliary Format 1: Function Definitions // Auxiliary Format 1: Function Definitions
for (uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) { for (std::uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) {
aux_symbol_f1 asym; aux_symbol_f1 asym;
// Read tag index // Read tag index
@ -1533,7 +1531,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read total size // Read total size
if (!readDword(p->fileBuffer, offset, asym.totalSize)) { if (!readDword(p->fileBuffer, offset, asym.totalSize)) {
@ -1541,7 +1539,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read pointer to line number // Read pointer to line number
if (!readDword(p->fileBuffer, offset, asym.pointerToLineNumber)) { if (!readDword(p->fileBuffer, offset, asym.pointerToLineNumber)) {
@ -1549,7 +1547,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read pointer to next function // Read pointer to next function
if (!readDword(p->fileBuffer, offset, asym.pointerToNextFunction)) { if (!readDword(p->fileBuffer, offset, asym.pointerToNextFunction)) {
@ -1558,7 +1556,7 @@ bool getSymbolTable(parsed_pe *p) {
} }
// Skip the processed 4 bytes + unused 2 bytes // Skip the processed 4 bytes + unused 2 bytes
offset += sizeof(uint8_t) * 6; offset += sizeof(std::uint8_t) * 6;
// Save the record // Save the record
sym.aux_symbols_f1.push_back(asym); sym.aux_symbols_f1.push_back(asym);
@ -1567,10 +1565,10 @@ bool getSymbolTable(parsed_pe *p) {
} else if (sym.storageClass == IMAGE_SYM_CLASS_FUNCTION) { } else if (sym.storageClass == IMAGE_SYM_CLASS_FUNCTION) {
// Auxiliary Format 2: .bf and .ef Symbols // Auxiliary Format 2: .bf and .ef Symbols
for (uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) { for (std::uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) {
aux_symbol_f2 asym; aux_symbol_f2 asym;
// Skip unused 4 bytes // Skip unused 4 bytes
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read line number // Read line number
if (!readWord(p->fileBuffer, offset, asym.lineNumber)) { if (!readWord(p->fileBuffer, offset, asym.lineNumber)) {
@ -1578,10 +1576,10 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Skip unused 6 bytes // Skip unused 6 bytes
offset += sizeof(uint8_t) * 6; offset += sizeof(std::uint8_t) * 6;
// Read pointer to next function // Read pointer to next function
if (!readDword(p->fileBuffer, offset, asym.pointerToNextFunction)) { if (!readDword(p->fileBuffer, offset, asym.pointerToNextFunction)) {
@ -1590,7 +1588,7 @@ bool getSymbolTable(parsed_pe *p) {
} }
// Skip the processed 4 bytes + unused 2 bytes // Skip the processed 4 bytes + unused 2 bytes
offset += sizeof(uint8_t) * 6; offset += sizeof(std::uint8_t) * 6;
// Save the record // Save the record
sym.aux_symbols_f2.push_back(asym); sym.aux_symbols_f2.push_back(asym);
@ -1600,7 +1598,7 @@ bool getSymbolTable(parsed_pe *p) {
sym.sectionNumber == IMAGE_SYM_UNDEFINED && sym.value == 0) { sym.sectionNumber == IMAGE_SYM_UNDEFINED && sym.value == 0) {
// Auxiliary Format 3: Weak Externals // Auxiliary Format 3: Weak Externals
for (uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) { for (std::uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) {
aux_symbol_f3 asym; aux_symbol_f3 asym;
// Read line number // Read line number
@ -1616,7 +1614,7 @@ bool getSymbolTable(parsed_pe *p) {
} }
// Skip unused 10 bytes // Skip unused 10 bytes
offset += sizeof(uint8_t) * 10; offset += sizeof(std::uint8_t) * 10;
// Save the record // Save the record
sym.aux_symbols_f3.push_back(asym); sym.aux_symbols_f3.push_back(asym);
@ -1625,13 +1623,13 @@ bool getSymbolTable(parsed_pe *p) {
} else if (sym.storageClass == IMAGE_SYM_CLASS_FILE) { } else if (sym.storageClass == IMAGE_SYM_CLASS_FILE) {
// Auxiliary Format 4: Files // Auxiliary Format 4: Files
for (uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) { for (std::uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) {
aux_symbol_f4 asym; aux_symbol_f4 asym;
// Read filename // Read filename
bool terminatorFound = false; bool terminatorFound = false;
for (uint16_t j = 0; j < SYMTAB_RECORD_LEN; j++) { for (std::uint16_t j = 0; j < SYMTAB_RECORD_LEN; j++) {
// Save the raw field // Save the raw field
if (!readByte(p->fileBuffer, offset, asym.filename[j])) { if (!readByte(p->fileBuffer, offset, asym.filename[j])) {
PE_ERR(PEERR_MAGIC); PE_ERR(PEERR_MAGIC);
@ -1656,7 +1654,7 @@ bool getSymbolTable(parsed_pe *p) {
} else if (sym.storageClass == IMAGE_SYM_CLASS_STATIC) { } else if (sym.storageClass == IMAGE_SYM_CLASS_STATIC) {
// Auxiliary Format 5: Section Definitions // Auxiliary Format 5: Section Definitions
for (uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) { for (std::uint8_t n = 0; n < sym.numberOfAuxSymbols; n++) {
aux_symbol_f5 asym; aux_symbol_f5 asym;
// Read length // Read length
@ -1665,7 +1663,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read number of relocations // Read number of relocations
if (!readWord(p->fileBuffer, offset, asym.numberOfRelocations)) { if (!readWord(p->fileBuffer, offset, asym.numberOfRelocations)) {
@ -1673,7 +1671,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Read number of line numbers // Read number of line numbers
if (!readWord(p->fileBuffer, offset, asym.numberOfLineNumbers)) { if (!readWord(p->fileBuffer, offset, asym.numberOfLineNumbers)) {
@ -1681,7 +1679,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Read checksum // Read checksum
if (!readDword(p->fileBuffer, offset, asym.checkSum)) { if (!readDword(p->fileBuffer, offset, asym.checkSum)) {
@ -1689,7 +1687,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint32_t); offset += sizeof(std::uint32_t);
// Read number // Read number
if (!readWord(p->fileBuffer, offset, asym.number)) { if (!readWord(p->fileBuffer, offset, asym.number)) {
@ -1697,7 +1695,7 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint16_t); offset += sizeof(std::uint16_t);
// Read selection // Read selection
if (!readByte(p->fileBuffer, offset, asym.selection)) { if (!readByte(p->fileBuffer, offset, asym.selection)) {
@ -1705,10 +1703,10 @@ bool getSymbolTable(parsed_pe *p) {
return false; return false;
} }
offset += sizeof(uint8_t); offset += sizeof(std::uint8_t);
// Skip unused 3 bytes // Skip unused 3 bytes
offset += sizeof(uint8_t) * 3; offset += sizeof(std::uint8_t) * 3;
// Save the record // Save the record
sym.aux_symbols_f5.push_back(asym); sym.aux_symbols_f5.push_back(asym);
@ -1866,7 +1864,7 @@ void DestructParsedPE(parsed_pe *p) {
// iterate over the imports by VA and string // iterate over the imports by VA and string
void IterImpVAString(parsed_pe *pe, iterVAStr cb, void *cbd) { void IterImpVAString(parsed_pe *pe, iterVAStr cb, void *cbd) {
list<importent> &l = pe->internal->imports; std::vector<importent> &l = pe->internal->imports;
for (importent i : l) { for (importent i : l) {
if (cb(cbd, i.addr, i.moduleName, i.symbolName) != 0) { if (cb(cbd, i.addr, i.moduleName, i.symbolName) != 0) {
@ -1879,7 +1877,7 @@ void IterImpVAString(parsed_pe *pe, iterVAStr cb, void *cbd) {
// iterate over relocations in the PE file // iterate over relocations in the PE file
void IterRelocs(parsed_pe *pe, iterReloc cb, void *cbd) { void IterRelocs(parsed_pe *pe, iterReloc cb, void *cbd) {
list<reloc> &l = pe->internal->relocs; std::vector<reloc> &l = pe->internal->relocs;
for (reloc r : l) { for (reloc r : l) {
if (cb(cbd, r.shiftedAddr, r.type) != 0) { if (cb(cbd, r.shiftedAddr, r.type) != 0) {
@ -1892,7 +1890,7 @@ void IterRelocs(parsed_pe *pe, iterReloc cb, void *cbd) {
// Iterate over symbols (symbol table) in the PE file // Iterate over symbols (symbol table) in the PE file
void IterSymbols(parsed_pe *pe, iterSymbol cb, void *cbd) { void IterSymbols(parsed_pe *pe, iterSymbol cb, void *cbd) {
list<symbol> &l = pe->internal->symbols; std::vector<symbol> &l = pe->internal->symbols;
for (symbol s : l) { for (symbol s : l) {
if (cb(cbd, if (cb(cbd,
@ -1911,7 +1909,7 @@ void IterSymbols(parsed_pe *pe, iterSymbol cb, void *cbd) {
// iterate over the exports by VA // iterate over the exports by VA
void IterExpVA(parsed_pe *pe, iterExp cb, void *cbd) { void IterExpVA(parsed_pe *pe, iterExp cb, void *cbd) {
list<exportent> &l = pe->internal->exports; std::vector<exportent> &l = pe->internal->exports;
for (exportent i : l) { for (exportent i : l) {
if (cb(cbd, i.addr, i.moduleName, i.symbolName) != 0) { if (cb(cbd, i.addr, i.moduleName, i.symbolName) != 0) {
@ -1935,7 +1933,7 @@ void IterSec(parsed_pe *pe, iterSec cb, void *cbd) {
return; return;
} }
bool ReadByteAtVA(parsed_pe *pe, VA v, ::uint8_t &b) { bool ReadByteAtVA(parsed_pe *pe, VA v, std::uint8_t &b) {
// find this VA in a section // find this VA in a section
section s; section s;

View File

@ -945,7 +945,10 @@ static PyObject *pepy_parsed_get_resources(PyObject *self, PyObject *args) {
return ret; return ret;
} }
int import_callback(void *cbd, VA addr, std::string &name, std::string &sym) { int import_callback(void *cbd,
VA addr,
const std::string &name,
const std::string &sym) {
PyObject *imp; PyObject *imp;
PyObject *tuple; PyObject *tuple;
PyObject *list = (PyObject *) cbd; PyObject *list = (PyObject *) cbd;