Just skip modules if imports fail instead of crashing the console on purpose

This commit is contained in:
Maschell 2021-01-01 02:07:02 +01:00
parent fddf436554
commit f48a375a34
3 changed files with 21 additions and 7 deletions

View File

@ -42,10 +42,10 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
uint32_t functionAddress = 0;
for (uint32_t i = 0; i < MAXIMUM_MODULES; i++) {
if (rplName.compare(gModuleData->module_data[i].module_export_name) == 0) {
if (rplName == gModuleData->module_data[i].module_export_name) {
export_data_t *exportEntries = gModuleData->module_data[i].export_entries;
for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) {
if (functionName.compare(exportEntries[j].name) == 0) {
if (functionName == exportEntries[j].name) {
functionAddress = (uint32_t) exportEntries[j].address;
}
}
@ -54,11 +54,17 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
if (functionAddress == 0) {
int32_t isData = curReloc.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = 0;
OSDynLoad_Module rplHandle = nullptr;
if (moduleCache.count(rplName) == 0) {
if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) {
OSDynLoad_Error err = OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle);
if(err != OS_DYNLOAD_OK || rplHandle == nullptr) {
DEBUG_FUNCTION_LINE("%s is not yet loaded\n", rplName.c_str());
// only acquire if not already loaded.
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
err = OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
if(err != OS_DYNLOAD_OK){
DEBUG_FUNCTION_LINE("Failed to acquire %s\n", rplName.c_str());
//return false;
}
}
moduleCache[rplName] = rplHandle;
}
@ -81,17 +87,20 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
return true;
}
bool ResolveRelocations(const std::vector<ModuleData> &loadedModules) {
bool ResolveRelocations(std::vector<ModuleData> &loadedModules) {
bool wasSuccessful = true;
for (auto const &curModule : loadedModules) {
for (auto &curModule : loadedModules) {
DEBUG_FUNCTION_LINE("Let's do the relocations for %s\n", curModule.getExportName().c_str());
if (wasSuccessful) {
std::vector<RelocationData> relocData = curModule.getRelocationDataList();
if (!doRelocation(relocData, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH)) {
DEBUG_FUNCTION_LINE("FAIL\n");
wasSuccessful = false;
curModule.relocationsDone = false;
}
curModule.relocationsDone = true;
}
if (curModule.getBSSAddr() != 0) {
// DEBUG_FUNCTION_LINE("memset .bss %08X (%d)\n", curModule.getBSSAddr(), curModule.getBSSSize());

View File

@ -19,6 +19,10 @@ void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
void CallHook(const ModuleData &module, wums_hook_type_t type) {
if(!module.relocationsDone){
DEBUG_FUNCTION_LINE("Hook not called because the relocations failed\n");
return;
}
for (auto &curHook : module.getHookDataList()) {
auto func_ptr = (uint32_t) curHook.getTarget();
if (func_ptr == 0) {

View File

@ -147,6 +147,7 @@ public:
this->initBeforeRelocationDoneHook = value;
}
bool relocationsDone = false;
private:
std::vector<RelocationData> relocation_data_list;
std::vector<ExportData> export_data_list;