mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-07-22 21:17:14 +00:00
Implement xex imports
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "xex.h"
|
||||
#include "image.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
Image Xex2LoadImage(const uint8_t* data)
|
||||
{
|
||||
@@ -79,5 +80,35 @@ Image Xex2LoadImage(const uint8_t* data)
|
||||
section.Misc.VirtualSize, flags, image.data.get() + section.VirtualAddress);
|
||||
}
|
||||
|
||||
auto* imports = Xex2FindOptionalHeader<XEX_IMPORT_HEADER>(header, XEX_HEADER_IMPORT_LIBRARIES);
|
||||
if (imports != nullptr)
|
||||
{
|
||||
std::vector<std::string_view> stringTable;
|
||||
auto* pStrTable = reinterpret_cast<const char*>(imports + 1);
|
||||
|
||||
for (size_t i = 0; i < imports->NumImports; i++)
|
||||
{
|
||||
stringTable.emplace_back(pStrTable);
|
||||
pStrTable += strlen(pStrTable) + 1;
|
||||
}
|
||||
|
||||
auto* library = (XEX_IMPORT_LIBRARY*)(((char*)imports) + sizeof(XEX_IMPORT_HEADER) + imports->SizeOfStringTable);
|
||||
for (size_t i = 0; i < stringTable.size(); i++)
|
||||
{
|
||||
auto* descriptors = (XEX_IMPORT_DESCRIPTOR*)(library + 1);
|
||||
for (size_t im = 0; im < library->NumberOfImports; im++)
|
||||
{
|
||||
auto originalThunk = (XEX_THUNK_DATA*)image.Find(descriptors[im].FirstThunk);
|
||||
auto thunkType = originalThunk->Function >> 24;
|
||||
|
||||
if (thunkType == 1)
|
||||
{
|
||||
uint32_t thunk[4] = { 0x00000060, 0x00000060, 0x00000060, 0x2000804E };
|
||||
memcpy(originalThunk, thunk, sizeof(thunk));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user