This commit is contained in:
Andrew 2013-07-25 16:52:03 -04:00
parent 83c258e202
commit faf770c598
2 changed files with 15 additions and 5 deletions

View File

@ -82,6 +82,9 @@ bounded_buffer *readFileToFileBuffer(const char *filePath) {
//split buffer inclusively from from to to by offset
bounded_buffer *splitBuffer(bounded_buffer *b, ::uint32_t from, ::uint32_t to) {
//safety checks
if(to < from || to >= b->bufLen) {
return NULL;
}
//make a new buffer
bounded_buffer *newBuff = new bounded_buffer();
@ -91,9 +94,9 @@ bounded_buffer *splitBuffer(bounded_buffer *b, ::uint32_t from, ::uint32_t to) {
}
newBuff->copy = true;
::uint8_t *curPtr = b->buf;
::uint8_t *newPtr = curPtr+from;
::uint8_t *newPtr = b->buf+from;
newBuff->buf = newPtr;
newBuff->bufLen = b->bufLen-(to-from);
return newBuff;
}

View File

@ -27,6 +27,9 @@ list<section> getSections(bounded_buffer *file) {
}
bool readNtHeader(bounded_buffer *b, nt_header_32 &header) {
if(b == NULL) {
return false;
}
return false;
}
@ -34,6 +37,10 @@ bool readNtHeader(bounded_buffer *b, nt_header_32 &header) {
bool getHeader(bounded_buffer *file) {
pe_header p;
if(file == NULL) {
return false;
}
//start by reading MZ
::uint16_t tmp = 0;
::uint32_t curOffset = 0;
@ -51,8 +58,8 @@ bool getHeader(bounded_buffer *file) {
curOffset += offset;
//now, we can read out the fields of the NT headers
nt_header_32 nthdr;
if(readNtHeader(splitBuffer(file, curOffset, file->bufLen), nthdr) == false) {
nt_header_32 nt;
if(readNtHeader(splitBuffer(file, curOffset, file->bufLen-1), nt) == false) {
return false;
}