@@ -106,6 +106,13 @@ namespace {
106
106
return component;
107
107
}
108
108
109
+ Ref<Type> NamedType (const std::string& name)
110
+ {
111
+ NamedTypeReferenceBuilder builder;
112
+ builder.SetName (QualifiedName (name));
113
+ return Type::NamedType (builder.Finalize ());
114
+ }
115
+
109
116
} // namespace
110
117
111
118
Ref<Metadata> ObjCProcessor::SerializeMethod (uint64_t loc, const Method& method)
@@ -320,12 +327,12 @@ std::vector<QualifiedNameOrType> ObjCProcessor::ParseEncodedType(const std::stri
320
327
nameOrType.type = Type::PointerType (m_data->GetAddressSize (), Type::IntegerType (1 , true ));
321
328
break ;
322
329
case ' @' :
323
- qualifiedName = " id " ;
330
+ nameOrType. type = m_types. id ;
324
331
// There can be a type after this, like @"NSString", that overrides this
325
332
// The handler for " will catch it and drop this "id" entry.
326
333
break ;
327
334
case ' :' :
328
- qualifiedName = " SEL " ;
335
+ nameOrType. type = m_types. sel ;
329
336
break ;
330
337
case ' #' :
331
338
qualifiedName = " objc_class_t" ;
@@ -1214,11 +1221,11 @@ bool ObjCProcessor::ApplyMethodType(Class& cls, Method& method, bool isInstanceM
1214
1221
1215
1222
params.push_back ({" self" ,
1216
1223
cls.associatedName .IsEmpty () ?
1217
- Type::NamedType (m_data, { " id " }) :
1224
+ m_types. id :
1218
1225
Type::PointerType (m_data->GetAddressSize (), Type::NamedType (m_data, cls.associatedName )),
1219
1226
true , BinaryNinja::Variable ()});
1220
1227
1221
- params.push_back ({" sel" , Type::NamedType (m_data, { " SEL " }) , true , BinaryNinja::Variable ()});
1228
+ params.push_back ({" sel" , m_types. sel , true , BinaryNinja::Variable ()});
1222
1229
1223
1230
for (size_t i = 3 ; i < typeTokens.size (); i++)
1224
1231
{
@@ -1370,6 +1377,10 @@ ObjCProcessor::ObjCProcessor(BinaryView* data, const char* loggerName, bool skip
1370
1377
m_skipClassBaseProtocols(skipClassBaseProtocols), m_data(data)
1371
1378
{
1372
1379
m_logger = m_data->CreateLogger (loggerName);
1380
+
1381
+ m_types.id = NamedType (" id" );
1382
+ m_types.sel = NamedType (" SEL" );
1383
+ m_types.BOOL = NamedType (" BOOL" );
1373
1384
}
1374
1385
1375
1386
uint64_t ObjCProcessor::GetObjCRelativeMethodBaseAddress (ObjCReader* reader)
@@ -1387,11 +1398,6 @@ void ObjCProcessor::ProcessObjCData()
1387
1398
auto guard = ScopedSymbolQueue::Make ();
1388
1399
1389
1400
auto addrSize = m_data->GetAddressSize ();
1390
-
1391
- m_typeNames.id = defineTypedef (m_data, {" id" }, Type::PointerType (addrSize, Type::VoidType ()));
1392
- m_typeNames.sel = defineTypedef (m_data, {" SEL" }, Type::PointerType (addrSize, Type::IntegerType (1 , false )));
1393
-
1394
- m_typeNames.BOOL = defineTypedef (m_data, {" BOOL" }, Type::IntegerType (1 , false ));
1395
1401
m_typeNames.nsInteger = defineTypedef (m_data, {" NSInteger" }, Type::IntegerType (addrSize, true ));
1396
1402
m_typeNames.nsuInteger = defineTypedef (m_data, {" NSUInteger" }, Type::IntegerType (addrSize, false ));
1397
1403
m_typeNames.cgFloat = defineTypedef (m_data, {" CGFloat" }, Type::FloatType (addrSize));
@@ -1719,11 +1725,10 @@ void ObjCProcessor::ProcessNSConstantArrays()
1719
1725
auto guard = ScopedSymbolQueue::Make ();
1720
1726
uint64_t ptrSize = m_data->GetAddressSize ();
1721
1727
1722
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1723
1728
StructureBuilder nsConstantArrayBuilder;
1724
1729
nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1725
1730
nsConstantArrayBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1726
- nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, idType ), " objects" );
1731
+ nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " objects" );
1727
1732
auto type = finalizeStructureBuilder (m_data, nsConstantArrayBuilder, " __NSConstantArray" );
1728
1733
m_typeNames.nsConstantArray = type.first ;
1729
1734
@@ -1740,7 +1745,7 @@ void ObjCProcessor::ProcessNSConstantArrays()
1740
1745
uint64_t count = reader->ReadPointer ();
1741
1746
auto dataLoc = ReadPointerAccountingForRelocations (reader.get ());
1742
1747
DefineObjCSymbol (
1743
- DataSymbol, Type::ArrayType (idType , count), fmt::format (" nsarray_{:x}_data" , i), dataLoc, true );
1748
+ DataSymbol, Type::ArrayType (m_types. id , count), fmt::format (" nsarray_{:x}_data" , i), dataLoc, true );
1744
1749
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantArray ),
1745
1750
fmt::format (" nsarray_{:x}" , i), i, true );
1746
1751
}
@@ -1757,13 +1762,12 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1757
1762
auto guard = ScopedSymbolQueue::Make ();
1758
1763
uint64_t ptrSize = m_data->GetAddressSize ();
1759
1764
1760
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1761
1765
StructureBuilder nsConstantDictionaryBuilder;
1762
1766
nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1763
1767
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " options" );
1764
1768
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1765
- nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, idType ), " keys" );
1766
- nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, idType ), " objects" );
1769
+ nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " keys" );
1770
+ nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " objects" );
1767
1771
auto type = finalizeStructureBuilder (m_data, nsConstantDictionaryBuilder, " __NSConstantDictionary" );
1768
1772
m_typeNames.nsConstantDictionary = type.first ;
1769
1773
@@ -1782,9 +1786,9 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1782
1786
auto keysLoc = ReadPointerAccountingForRelocations (reader.get ());
1783
1787
auto objectsLoc = ReadPointerAccountingForRelocations (reader.get ());
1784
1788
DefineObjCSymbol (
1785
- DataSymbol, Type::ArrayType (idType , count), fmt::format (" nsdict_{:x}_keys" , i), keysLoc, true );
1786
- DefineObjCSymbol (
1787
- DataSymbol, Type::ArrayType (idType, count), fmt::format ( " nsdict_{:x}_objects " , i), objectsLoc, true );
1789
+ DataSymbol, Type::ArrayType (m_types. id , count), fmt::format (" nsdict_{:x}_keys" , i), keysLoc, true );
1790
+ DefineObjCSymbol (DataSymbol, Type::ArrayType (m_types. id , count), fmt::format ( " nsdict_{:x}_objects " , i),
1791
+ objectsLoc, true );
1788
1792
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantDictionary ),
1789
1793
fmt::format (" nsdict_{:x}" , i), i, true );
1790
1794
}
0 commit comments