Rename and retype the stub function.
| 70 | |
| 71 | // Rename and retype the stub function. |
| 72 | void IdentifyStub(BinaryView& view, const SharedCacheController& controller, uint64_t stubFuncAddr, uint64_t symbolAddr) { |
| 73 | static const char* STUB_PREFIX = "j_"; |
| 74 | // Try and apply a version of the symbol address to the target address |
| 75 | if (const auto symbol = view.GetSymbolByAddress(symbolAddr)) |
| 76 | { |
| 77 | // A symbol already exists at the source location. Add a stub symbol at `targetLocation` based on the existing symbol. |
| 78 | if (auto targetFunc = view.GetAnalysisFunction(view.GetDefaultPlatform(), stubFuncAddr)) |
| 79 | view.DefineAutoSymbol(new Symbol(FunctionSymbol, STUB_PREFIX + symbol->GetShortName(), stubFuncAddr)); |
| 80 | else |
| 81 | view.DefineAutoSymbol(new Symbol(symbol->GetType(), STUB_PREFIX + symbol->GetShortName(), stubFuncAddr)); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | // No existing symbol located, try and search through the symbols of the cache. |
| 86 | auto symbol = controller.GetSymbolAt(symbolAddr); |
| 87 | if (!symbol.has_value()) |
| 88 | return; |
| 89 | |
| 90 | // Demangle if possible, the type pulled will be used, however type library will take precedence. |
| 91 | auto [demangledName, demangledType] = symbol->DemangledName(view); |
| 92 | auto rawName = STUB_PREFIX + symbol->name; |
| 93 | auto shortName = STUB_PREFIX + demangledName; |
| 94 | |
| 95 | // Try and retrieve a type for the stub function using type libraries. |
| 96 | if (const auto targetFunc = view.GetAnalysisFunction(view.GetDefaultPlatform(), stubFuncAddr)) |
| 97 | { |
| 98 | // NOTE: The type library name is expected to be the image name currently. |
| 99 | // Try and pull the type from the associated type library (if there is one) |
| 100 | Ref<Type> selectedType = demangledType; |
| 101 | if (const auto image = controller.GetImageContaining(symbolAddr)) |
| 102 | if (auto typeLib = TypeLibraryFromName(view, image->name)) |
| 103 | selectedType = view.ImportTypeLibraryObject(typeLib, {symbol->name}); |
| 104 | |
| 105 | if (selectedType) |
| 106 | targetFunc->SetAutoType(selectedType); |
| 107 | } |
| 108 | |
| 109 | // Define the new symbol! |
| 110 | auto bnSymbol = new Symbol(symbol->type, shortName, shortName, rawName, stubFuncAddr, nullptr); |
| 111 | view.DefineAutoSymbol(bnSymbol); |
| 112 | } |
| 113 | |
| 114 | void AnalyzeStubFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, SharedCacheController& controller, bool loadImage) |
| 115 | { |
no test coverage detected