@@ -71,30 +71,36 @@ void ApplySymbol(Ref<BinaryView> view, Ref<TypeLibrary> typeLib, Ref<Symbol> sym
7171 auto symbolAddress = symbol->GetAddress ();
7272 auto symbolName = symbol->GetFullName ();
7373
74- if (symbol->GetType () == FunctionSymbol)
75- {
76- Ref<Platform> targetPlatform = view->GetDefaultPlatform ();
77- func = view->AddFunctionForAnalysis (targetPlatform, symbolAddress, true );
78- }
74+ // Sometimes the symbol will be duplicated, so lets not do this work again.
75+ if (view->GetSymbolByAddress (symbolAddress))
76+ return ;
7977
78+ // Define the symbol!
79+ view->DefineAutoSymbol (symbol);
80+
81+ // Try and pull a type to apply at the symbol location.
82+ Ref<Type> type = nullptr ;
8083 if (typeLib)
84+ type = view->ImportTypeLibraryObject (typeLib, {symbolName});
85+
86+ if (symbol->GetType () == FunctionSymbol)
8187 {
82- auto type = view->ImportTypeLibraryObject (typeLib, {symbolName} );
83- // TODO: This is still auto
84- if ( type)
85- view->DefineAutoSymbolAndVariableOrFunction (view-> GetDefaultPlatform (), symbol, type );
86- else
87- view->DefineAutoSymbol (symbol );
88+ Ref<Platform> targetPlatform = view->GetDefaultPlatform ( );
89+ // Make sure to check for already added function from the function table.
90+ // Unless we have retrieved a type here we don't need to make a new function.
91+ func = view->GetAnalysisFunction (targetPlatform, symbolAddress );
92+ if (!func || type)
93+ func = view->AddFunctionForAnalysis (targetPlatform, symbolAddress, false , type );
8894 }
8995 else
9096 {
91- view->DefineAutoSymbol (symbol);
97+ // Other symbol types can just use this, they don't need to worry about linear sweep removing them.
98+ view->DefineAutoSymbolAndVariableOrFunction (view->GetDefaultPlatform (), symbol, type);
9299 }
93100
94- if (!func)
95- func = view->GetAnalysisFunction (view->GetDefaultPlatform (), symbolAddress);
96101 if (func)
97102 {
103+ // objective c type adjustment stuff.
98104 if (symbolName == " _objc_msgSend" )
99105 {
100106 func->SetHasVariableArguments (false );
0 commit comments