mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed loading crash with signature but no string table
This commit is contained in:
parent
503179c245
commit
50e606773e
2 changed files with 38 additions and 23 deletions
|
@ -5519,6 +5519,29 @@ bool DbgModule::CanRead(DataStream* stream, DebuggerResult* outResult)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* DbgModule::GetStringTable(DataStream* stream, int stringTablePos)
|
||||||
|
{
|
||||||
|
if (mStringTable == NULL)
|
||||||
|
{
|
||||||
|
int prevPos = stream->GetPos();
|
||||||
|
stream->SetPos(stringTablePos);
|
||||||
|
int strTableSize = 0;
|
||||||
|
stream->Read(&strTableSize, 4);
|
||||||
|
if (strTableSize != 0)
|
||||||
|
{
|
||||||
|
strTableSize -= 4;
|
||||||
|
|
||||||
|
char* strTableData = new char[strTableSize + 4];
|
||||||
|
memcpy(strTableData, &strTableSize, 4);
|
||||||
|
stream->Read(strTableData + 4, strTableSize);
|
||||||
|
mStringTable = strTableData;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->SetPos(prevPos);
|
||||||
|
}
|
||||||
|
return mStringTable;
|
||||||
|
}
|
||||||
|
|
||||||
bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
||||||
{
|
{
|
||||||
BP_ZONE("DbgModule::ReadCOFF");
|
BP_ZONE("DbgModule::ReadCOFF");
|
||||||
|
@ -5628,15 +5651,19 @@ bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
||||||
miniDumpDebugger->MapMemory((addr_target)mImageBase, (uint8*)mMappedImageFile->mData, 0x1000);
|
miniDumpDebugger->MapMemory((addr_target)mImageBase, (uint8*)mMappedImageFile->mData, 0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wantStringTable = isObjectFile;
|
||||||
|
|
||||||
stream->SetPos(sectionStartPos);
|
stream->SetPos(sectionStartPos);
|
||||||
for (int dirNum = 0; dirNum < (int) ntHdr.mFileHeader.mNumberOfSections; dirNum++)
|
for (int dirNum = 0; dirNum < (int) ntHdr.mFileHeader.mNumberOfSections; dirNum++)
|
||||||
{
|
{
|
||||||
PESectionHeader sectHdr;
|
PESectionHeader sectHdr;
|
||||||
|
|
||||||
|
char* name = sectHdr.mName;
|
||||||
stream->Read(§Hdr, sizeof(PESectionHeader));
|
stream->Read(§Hdr, sizeof(PESectionHeader));
|
||||||
if (sectHdr.mSizeOfRawData > 0)
|
if (sectHdr.mSizeOfRawData > 0)
|
||||||
sectionDataEndPos = sectHdr.mPointerToRawData + sectHdr.mSizeOfRawData;
|
sectionDataEndPos = BF_MAX(sectionDataEndPos, (int)(sectHdr.mPointerToRawData + sectHdr.mSizeOfRawData));
|
||||||
if (sectHdr.mNumberOfRelocations > 0)
|
if (sectHdr.mNumberOfRelocations > 0)
|
||||||
sectionDataEndPos = sectHdr.mPointerToRelocations + sectHdr.mNumberOfRelocations * sizeof(COFFRelocation);
|
sectionDataEndPos = BF_MAX(sectionDataEndPos, (int)(sectHdr.mPointerToRelocations + sectHdr.mNumberOfRelocations * sizeof(COFFRelocation)));
|
||||||
|
|
||||||
if (miniDumpDebugger != NULL)
|
if (miniDumpDebugger != NULL)
|
||||||
{
|
{
|
||||||
|
@ -5653,23 +5680,10 @@ bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
||||||
mSymbolData = symbolData;
|
mSymbolData = symbolData;
|
||||||
stream->Read(symbolData, ntHdr.mFileHeader.mNumberOfSymbols * 18);
|
stream->Read(symbolData, ntHdr.mFileHeader.mNumberOfSymbols * 18);
|
||||||
|
|
||||||
int curPos = stream->GetPos();
|
int curPos = stream->GetPos();
|
||||||
|
int stringTablePos = curPos;
|
||||||
int strTableSize = 0;
|
if (isObjectFile)
|
||||||
char* strTableData = NULL;
|
GetStringTable(stream, stringTablePos);
|
||||||
if (!stream->Eof())
|
|
||||||
{
|
|
||||||
stream->Read(&strTableSize, 4);
|
|
||||||
if (strTableSize != 0)
|
|
||||||
{
|
|
||||||
strTableSize -= 4;
|
|
||||||
|
|
||||||
strTableData = new char[strTableSize + 4];
|
|
||||||
memcpy(strTableData, &strTableSize, 4);
|
|
||||||
stream->Read(strTableData + 4, strTableSize);
|
|
||||||
mStringTable = strTableData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int mDebugFrameDataLen = 0;
|
int mDebugFrameDataLen = 0;
|
||||||
|
|
||||||
|
@ -5701,11 +5715,11 @@ bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
||||||
PESectionHeader& sectHdr = sectionHeaders[sectNum];
|
PESectionHeader& sectHdr = sectionHeaders[sectNum];
|
||||||
//stream->Read(§Hdr, sizeof(PESectionHeader));
|
//stream->Read(§Hdr, sizeof(PESectionHeader));
|
||||||
|
|
||||||
char* name = sectHdr.mName;
|
const char* name = sectHdr.mName;
|
||||||
if (name[0] == '/')
|
if (name[0] == '/')
|
||||||
{
|
{
|
||||||
int strIdx = atoi(name + 1);
|
int strIdx = atoi(name + 1);
|
||||||
name = &strTableData[strIdx];
|
name = &GetStringTable(stream, stringTablePos)[strIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
sectionNames[sectNum] = name;
|
sectionNames[sectNum] = name;
|
||||||
|
@ -6184,7 +6198,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
name = strTableData + symInfo->mNameOfs[1];
|
name = (char*)GetStringTable(stream, stringTablePos) + symInfo->mNameOfs[1];
|
||||||
|
|
||||||
if ((symInfo->mStorageClass == COFF_SYM_CLASS_EXTERNAL) ||
|
if ((symInfo->mStorageClass == COFF_SYM_CLASS_EXTERNAL) ||
|
||||||
(symInfo->mStorageClass == COFF_SYM_CLASS_STATIC))
|
(symInfo->mStorageClass == COFF_SYM_CLASS_STATIC))
|
||||||
|
|
|
@ -1127,7 +1127,7 @@ public:
|
||||||
const uint8** mDebugAbbrevPtrData;
|
const uint8** mDebugAbbrevPtrData;
|
||||||
Array<DbgSectionData> mExceptionDirectory;
|
Array<DbgSectionData> mExceptionDirectory;
|
||||||
const uint8* mEHFrameData;
|
const uint8* mEHFrameData;
|
||||||
const char* mStringTable;
|
const char* mStringTable;
|
||||||
const uint8* mSymbolData;
|
const uint8* mSymbolData;
|
||||||
addr_target mEHFrameAddress;
|
addr_target mEHFrameAddress;
|
||||||
addr_target mTLSAddr;
|
addr_target mTLSAddr;
|
||||||
|
@ -1225,6 +1225,7 @@ public:
|
||||||
virtual bool DbgIsStrMutable(const char* str) { return true; } // Always assume its a copy
|
virtual bool DbgIsStrMutable(const char* str) { return true; } // Always assume its a copy
|
||||||
virtual addr_target LocateSymbol(const StringImpl& name) { return 0; }
|
virtual addr_target LocateSymbol(const StringImpl& name) { return 0; }
|
||||||
virtual DbgSubprogram* FindSubprogram(DbgType* dbgType, const char* methodName);
|
virtual DbgSubprogram* FindSubprogram(DbgType* dbgType, const char* methodName);
|
||||||
|
const char* GetStringTable(DataStream* stream, int stringTablePos);
|
||||||
|
|
||||||
void Fail(const StringImpl& error);
|
void Fail(const StringImpl& error);
|
||||||
void FindTemplateStr(const char*& name, int& templateNameIdx);
|
void FindTemplateStr(const char*& name, int& templateNameIdx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue