@@ -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
{
@@ -1367,6 +1374,10 @@ ObjCProcessor::ObjCProcessor(BinaryView* data, const char* loggerName, bool skip
1367
1374
m_skipClassBaseProtocols(skipClassBaseProtocols), m_data(data)
1368
1375
{
1369
1376
m_logger = m_data->CreateLogger (loggerName);
1377
+
1378
+ m_types.id = NamedType (" id" );
1379
+ m_types.sel = NamedType (" SEL" );
1380
+ m_types.BOOL = NamedType (" BOOL" );
1370
1381
}
1371
1382
1372
1383
uint64_t ObjCProcessor::GetObjCRelativeMethodBaseAddress (ObjCReader* reader)
@@ -1384,11 +1395,6 @@ void ObjCProcessor::ProcessObjCData()
1384
1395
auto guard = ScopedSymbolQueue::Make ();
1385
1396
1386
1397
auto addrSize = m_data->GetAddressSize ();
1387
-
1388
- m_typeNames.id = defineTypedef (m_data, {" id" }, Type::PointerType (addrSize, Type::VoidType ()));
1389
- m_typeNames.sel = defineTypedef (m_data, {" SEL" }, Type::PointerType (addrSize, Type::IntegerType (1 , false )));
1390
-
1391
- m_typeNames.BOOL = defineTypedef (m_data, {" BOOL" }, Type::IntegerType (1 , false ));
1392
1398
m_typeNames.nsInteger = defineTypedef (m_data, {" NSInteger" }, Type::IntegerType (addrSize, true ));
1393
1399
m_typeNames.nsuInteger = defineTypedef (m_data, {" NSUInteger" }, Type::IntegerType (addrSize, false ));
1394
1400
m_typeNames.cgFloat = defineTypedef (m_data, {" CGFloat" }, Type::FloatType (addrSize));
@@ -1716,11 +1722,10 @@ void ObjCProcessor::ProcessNSConstantArrays()
1716
1722
auto guard = ScopedSymbolQueue::Make ();
1717
1723
uint64_t ptrSize = m_data->GetAddressSize ();
1718
1724
1719
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1720
1725
StructureBuilder nsConstantArrayBuilder;
1721
1726
nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1722
1727
nsConstantArrayBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1723
- nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, idType ), " objects" );
1728
+ nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " objects" );
1724
1729
auto type = finalizeStructureBuilder (m_data, nsConstantArrayBuilder, " __NSConstantArray" );
1725
1730
m_typeNames.nsConstantArray = type.first ;
1726
1731
@@ -1737,7 +1742,7 @@ void ObjCProcessor::ProcessNSConstantArrays()
1737
1742
uint64_t count = reader->ReadPointer ();
1738
1743
auto dataLoc = ReadPointerAccountingForRelocations (reader.get ());
1739
1744
DefineObjCSymbol (
1740
- DataSymbol, Type::ArrayType (idType , count), fmt::format (" nsarray_{:x}_data" , i), dataLoc, true );
1745
+ DataSymbol, Type::ArrayType (m_types. id , count), fmt::format (" nsarray_{:x}_data" , i), dataLoc, true );
1741
1746
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantArray ),
1742
1747
fmt::format (" nsarray_{:x}" , i), i, true );
1743
1748
}
@@ -1754,13 +1759,12 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1754
1759
auto guard = ScopedSymbolQueue::Make ();
1755
1760
uint64_t ptrSize = m_data->GetAddressSize ();
1756
1761
1757
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1758
1762
StructureBuilder nsConstantDictionaryBuilder;
1759
1763
nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1760
1764
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " options" );
1761
1765
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1762
- nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, idType ), " keys" );
1763
- nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, idType ), " objects" );
1766
+ nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " keys" );
1767
+ nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " objects" );
1764
1768
auto type = finalizeStructureBuilder (m_data, nsConstantDictionaryBuilder, " __NSConstantDictionary" );
1765
1769
m_typeNames.nsConstantDictionary = type.first ;
1766
1770
@@ -1779,9 +1783,9 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1779
1783
auto keysLoc = ReadPointerAccountingForRelocations (reader.get ());
1780
1784
auto objectsLoc = ReadPointerAccountingForRelocations (reader.get ());
1781
1785
DefineObjCSymbol (
1782
- DataSymbol, Type::ArrayType (idType , count), fmt::format (" nsdict_{:x}_keys" , i), keysLoc, true );
1783
- DefineObjCSymbol (
1784
- DataSymbol, Type::ArrayType (idType, count), fmt::format ( " nsdict_{:x}_objects " , i), objectsLoc, true );
1786
+ DataSymbol, Type::ArrayType (m_types. id , count), fmt::format (" nsdict_{:x}_keys" , i), keysLoc, true );
1787
+ DefineObjCSymbol (DataSymbol, Type::ArrayType (m_types. id , count), fmt::format ( " nsdict_{:x}_objects " , i),
1788
+ objectsLoc, true );
1785
1789
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantDictionary ),
1786
1790
fmt::format (" nsdict_{:x}" , i), i, true );
1787
1791
}
0 commit comments