Add GetExports and GetImports to the module scripting API.
This commit is contained in:
parent
4273fce56e
commit
72d76bb9bc
|
@ -179,4 +179,61 @@ SCRIPT_EXPORT bool Script::Module::GetList(ListOf(ModuleInfo) list)
|
|||
modScriptList.push_back(scriptMod);
|
||||
});
|
||||
return BridgeList<ModuleInfo>::CopyData(list, modScriptList);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::GetExports(const ModuleInfo* mod, ListOf(ModuleExport) list)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
||||
if(mod == nullptr)
|
||||
return false;
|
||||
|
||||
MODINFO* modInfo = ModInfoFromAddr(mod->base);
|
||||
if(modInfo == nullptr)
|
||||
return false;
|
||||
|
||||
std::vector<ModuleExport> modExportList;
|
||||
modExportList.reserve(modInfo->exports.size());
|
||||
|
||||
for(auto & modExport : modInfo->exports)
|
||||
{
|
||||
ModuleExport entry;
|
||||
entry.ordinal = modExport.ordinal;
|
||||
entry.rva = modExport.rva;
|
||||
entry.va = modExport.rva + modInfo->base;
|
||||
entry.forwarded = modExport.forwarded;
|
||||
strncpy_s(entry.forwardName, modExport.forwardName.c_str(), _TRUNCATE);
|
||||
strncpy_s(entry.name, modExport.name.c_str(), _TRUNCATE);
|
||||
strncpy_s(entry.undecoratedName, modExport.undecoratedName.c_str(), _TRUNCATE);
|
||||
modExportList.push_back(entry);
|
||||
}
|
||||
return BridgeList<ModuleExport>::CopyData(list, modExportList);
|
||||
}
|
||||
|
||||
|
||||
SCRIPT_EXPORT bool Script::Module::GetImports(const ModuleInfo* mod, ListOf(ModuleImport) list)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
||||
if(mod == nullptr)
|
||||
return false;
|
||||
|
||||
MODINFO* modInfo = ModInfoFromAddr(mod->base);
|
||||
if(modInfo == nullptr)
|
||||
return false;
|
||||
|
||||
std::vector<ModuleImport> modImportList;
|
||||
modImportList.reserve(modInfo->imports.size());
|
||||
|
||||
for(auto & modImport : modInfo->imports)
|
||||
{
|
||||
ModuleImport entry;
|
||||
entry.ordinal = modImport.ordinal;
|
||||
entry.iatRva = modImport.iatRva;
|
||||
entry.iatVa = modImport.iatRva + modInfo->base;
|
||||
strncpy_s(entry.name, modImport.name.c_str(), _TRUNCATE);
|
||||
strncpy_s(entry.undecoratedName, modImport.undecoratedName.c_str(), _TRUNCATE);
|
||||
modImportList.push_back(entry);
|
||||
}
|
||||
return BridgeList<ModuleImport>::CopyData(list, modImportList);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,26 @@ namespace Script
|
|||
char name[MAX_SECTION_SIZE * 5];
|
||||
};
|
||||
|
||||
struct ModuleExport
|
||||
{
|
||||
duint ordinal;
|
||||
duint rva;
|
||||
duint va;
|
||||
bool forwarded;
|
||||
char forwardName[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
char undecoratedName[MAX_STRING_SIZE];
|
||||
};
|
||||
|
||||
struct ModuleImport
|
||||
{
|
||||
duint iatRva;
|
||||
duint iatVa;
|
||||
duint ordinal; //equal to -1 if imported by name
|
||||
char name[MAX_STRING_SIZE];
|
||||
char undecoratedName[MAX_STRING_SIZE];
|
||||
};
|
||||
|
||||
SCRIPT_EXPORT bool InfoFromAddr(duint addr, ModuleInfo* info);
|
||||
SCRIPT_EXPORT bool InfoFromName(const char* name, ModuleInfo* info);
|
||||
SCRIPT_EXPORT duint BaseFromAddr(duint addr);
|
||||
|
@ -50,7 +70,9 @@ namespace Script
|
|||
SCRIPT_EXPORT bool GetMainModulePath(char* path); //path[MAX_PATH]
|
||||
SCRIPT_EXPORT bool GetMainModuleSectionList(ListOf(ModuleSectionInfo) list); //caller has the responsibility to free the list
|
||||
SCRIPT_EXPORT bool GetList(ListOf(ModuleInfo) list); //caller has the responsibility to free the list
|
||||
SCRIPT_EXPORT bool GetExports(const ModuleInfo* mod, ListOf(ModuleExport) list); //caller has the responsibility to free the list
|
||||
SCRIPT_EXPORT bool GetImports(const ModuleInfo* mod, ListOf(ModuleImport) list); //caller has the responsibility to free the list
|
||||
}; //Module
|
||||
}; //Script
|
||||
|
||||
#endif //_SCRIPTAPI_MODULE_H
|
||||
#endif //_SCRIPTAPI_MODULE_H
|
||||
|
|
Loading…
Reference in New Issue