diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-07-01 02:43:29 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-07-01 02:43:29 +0100 |
commit | 5c6a48b2ff362a70416a6a00fda7d06e0f276f2d (patch) | |
tree | 62cf542c68d91aa6f7a4e3bfa9eddca4ab352970 /src/T2DLL/CPEFile.cpp | |
parent | c0c336500955a23e344651e5412c9d9d441ef4ee (diff) | |
download | t2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.tar.gz t2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.zip |
i am in hell
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/CPEFile.cpp | 99 |
1 files changed, 42 insertions, 57 deletions
diff --git a/src/T2DLL/CPEFile.cpp b/src/T2DLL/CPEFile.cpp index 7bb49de..46ce23b 100644 --- a/src/T2DLL/CPEFile.cpp +++ b/src/T2DLL/CPEFile.cpp @@ -1,26 +1,11 @@ +#define DONT_INCLUDE_AFXTEMPL #include "CPEFile.h" -CPEFile::CPEFile(const CPEFile& other) - : mFile(other.mFile) - , mFileHeader(other.mFileHeader) - , mSectionHeaders(other.mSectionHeaders) - , mRsrcPtr(other.mRsrcPtr) - , mRsrcIndex(other.mRsrcIndex) - , mStartPosition(other.mStartPosition) - , mLength(other.mLength) -{ -} - -CPEFile& CPEFile::operator=(const CPEFile& other) { - mFile = other.mFile; - mFileHeader = other.mFileHeader; - mSectionHeaders = other.mSectionHeaders; - mRsrcPtr = other.mRsrcPtr; - mRsrcIndex = other.mRsrcIndex; - mStartPosition = other.mStartPosition; - mLength = other.mLength; - return *this; -} +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif CPEFile::CPEFile() { mFile = NULL; @@ -46,7 +31,7 @@ CPEFile::~CPEFile() { BOOL result = false; #line 36 - mFile = DEBUG_NEW CFile; + mFile = new CFile; if (mFile->Open(filename, flags, pError)) { result = Init(); if (!result) @@ -126,26 +111,26 @@ BOOL CPEFile::EnumResourceDirectory(IMAGE_RESOURCE_DIRECTORY_ENTRY* entry, RESTR void CPEFile::GetResourceName(CString& s, IMAGE_RESOURCE_DIRECTORY_ENTRY& entry) { if (entry.Name & 0x80000000) { - unsigned short len; + unsigned short nameLen; mFile->Seek(mRsrcPtr + entry.NameOffset, CFile::begin); - mFile->Read(&len, sizeof(len)); + mFile->Read(&nameLen, sizeof(nameLen)); - char *widebuf = (char *) malloc(len * 2); - mFile->Read(widebuf, len * 2); + char *wstr = (char *) malloc(nameLen * 2); + mFile->Read(wstr, nameLen * 2); - int size = len * 2 + 1; - char *buf = (char *) malloc(size); - memset(buf, 0, size); + int bufferSize = nameLen * 2 + 1; + char *theBuf = (char *) malloc(bufferSize); + memset(theBuf, 0, bufferSize); int i; - for (i = 0; i < len; i++) { - buf[i] = widebuf[i * 2]; + for (i = 0; i < nameLen; i++) { + theBuf[i] = wstr[i * 2]; } - buf[i] = 0; + theBuf[i] = 0; - s = buf; - free(widebuf); - free(buf); + s = theBuf; + free(wstr); + free(theBuf); } else { s.Format("#%u", entry.Name); } @@ -162,55 +147,55 @@ void CPEFile::EnterDirectory(RESTRACKERWORK& child, RESTRACKERWORK& parent) { child.nextIndex = 0; } -/*virtual*/ BOOL CPEFile::Seek(const char* name) { +/*virtual*/ BOOL CPEFile::Seek(const char* inName) { #line 141 - _ASSERT(strncmp(name, "\\.rsrc", 6) == 0); + _ASSERT(strncmp(inName, "\\.rsrc", 6) == 0); - char *nameCopy = (char *) malloc(strlen(name) + 1); - strcpy(nameCopy, name); + char *name = (char *) malloc(strlen(inName) + 1); + strcpy(name, inName); - CString str; - str = (char *) NULL; - str = strtok(nameCopy, "\\"); + CString elem; + elem = (char *) NULL; + elem = strtok(name, "\\"); RESTRACKERWORK work; memset(&work, 0, sizeof(work)); - BOOL flag = false; + BOOL isOK = false; - CString str2(""); + CString resName = ""; - while ((str = strtok(NULL, "\\")) != "") { - if (flag) { + while ((elem = strtok(NULL, "\\")) != "") { + if (isOK) { RESTRACKERWORK child; EnterDirectory(child, work); work = child; } - flag = false; - while (EnumResource(str2, work) == 1) { - if (_stricmp(str2, str) == 0 || _stricmp(str2, str + "\\") == 0) { - flag = true; + isOK = false; + while (EnumResource(resName, work) == 1) { + if (_stricmp(resName, elem) == 0 || _stricmp(resName, elem + "\\") == 0) { + isOK = true; break; } } - if (!flag) + if (!isOK) return false; } - free(nameCopy); + free(name); - if (str2.Right(1) == "\\") + if (resName.Right(1) == "\\") return false; - IMAGE_RESOURCE_DATA_ENTRY dataEntry; + IMAGE_RESOURCE_DATA_ENTRY theEntryData; mFile->Seek(mRsrcPtr + work.entry.OffsetToData, CFile::begin); - mFile->Read(&dataEntry, sizeof(dataEntry)); + mFile->Read(&theEntryData, sizeof(theEntryData)); - mStartPosition = dataEntry.OffsetToData - (mSectionHeaders[mRsrcIndex].VirtualAddress - mSectionHeaders[mRsrcIndex].PointerToRawData); - mLength = dataEntry.Size; + mStartPosition = theEntryData.OffsetToData - (mSectionHeaders[mRsrcIndex].VirtualAddress - mSectionHeaders[mRsrcIndex].PointerToRawData); + mLength = theEntryData.Size; mFile->Seek(mStartPosition, CFile::begin); |