mirror of
https://github.com/QuasarApp/pe-parse.git
synced 2025-04-29 13:54:33 +00:00
commit
6d1b49b74a
@ -24,6 +24,9 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "nt-headers.h"
|
#include "nt-headers.h"
|
||||||
#include "to_string.h"
|
#include "to_string.h"
|
||||||
@ -91,6 +94,23 @@ string GetPEErrLoc() {
|
|||||||
return err_loc;
|
return err_loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool readCString(const bounded_buffer &buffer, ::uint32_t off,
|
||||||
|
string &result)
|
||||||
|
{
|
||||||
|
if (off < buffer.bufLen) {
|
||||||
|
::uint8_t *p = buffer.buf;
|
||||||
|
::uint32_t n = buffer.bufLen;
|
||||||
|
::uint8_t *b = p + off;
|
||||||
|
::uint8_t *x = std::find(b, p + n, 0);
|
||||||
|
if (x == p + n)
|
||||||
|
return false;
|
||||||
|
result.insert(result.end(), b, x);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool getSecForVA(list<section> &secs, VA v, section &sec) {
|
bool getSecForVA(list<section> &secs, VA v, section &sec) {
|
||||||
for(list<section>::iterator it = secs.begin(), e = secs.end();
|
for(list<section>::iterator it = secs.begin(), e = secs.end();
|
||||||
it != e;
|
it != e;
|
||||||
@ -723,9 +743,7 @@ parsed_pe *ParsePEFromFile(const char *filePath) {
|
|||||||
|
|
||||||
::uint32_t nameOff = nameVA - nameSec.sectionBase;
|
::uint32_t nameOff = nameVA - nameSec.sectionBase;
|
||||||
string modName;
|
string modName;
|
||||||
::uint8_t c;
|
if (readCString(*nameSec.sectionData, nameOff, modName) == false) {
|
||||||
do {
|
|
||||||
if(readByte(nameSec.sectionData, nameOff, c) == false) {
|
|
||||||
deleteBuffer(remaining);
|
deleteBuffer(remaining);
|
||||||
deleteBuffer(p->fileBuffer);
|
deleteBuffer(p->fileBuffer);
|
||||||
delete p;
|
delete p;
|
||||||
@ -733,14 +751,6 @@ parsed_pe *ParsePEFromFile(const char *filePath) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
modName.push_back(c);
|
|
||||||
nameOff++;
|
|
||||||
}while(true);
|
|
||||||
|
|
||||||
//now, get all the named export symbols
|
//now, get all the named export symbols
|
||||||
::uint32_t numNames;
|
::uint32_t numNames;
|
||||||
if(readDword( s.sectionData,
|
if(readDword( s.sectionData,
|
||||||
@ -1185,23 +1195,14 @@ parsed_pe *ParsePEFromFile(const char *filePath) {
|
|||||||
|
|
||||||
::uint32_t nameOff = name - nameSec.sectionBase;
|
::uint32_t nameOff = name - nameSec.sectionBase;
|
||||||
string modName;
|
string modName;
|
||||||
::uint8_t c;
|
if (readCString(*nameSec.sectionData, nameOff, modName) == false ) {
|
||||||
do {
|
|
||||||
if(readByte(nameSec.sectionData, nameOff, c) == false) {
|
|
||||||
deleteBuffer(remaining);
|
deleteBuffer(remaining);
|
||||||
deleteBuffer(p->fileBuffer);
|
deleteBuffer(p->fileBuffer);
|
||||||
delete p;
|
delete p;
|
||||||
PE_ERR(PEERR_READ);
|
PE_ERR(PEERR_READ);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
boost::to_upper(modName);
|
||||||
if(c == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
modName.push_back(toupper(c));
|
|
||||||
nameOff++;
|
|
||||||
}while(true);
|
|
||||||
|
|
||||||
//then, try and get all of the sub-symbols
|
//then, try and get all of the sub-symbols
|
||||||
VA lookupVA;
|
VA lookupVA;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user