@@ -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
{
@@ -1342,10 +1349,13 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader)
1342
1349
{
1343
1350
auto start = ivars->GetStart ();
1344
1351
auto end = ivars->GetEnd ();
1345
- auto ivarSectionEntryTypeBuilder = new TypeBuilder (Type::IntegerType (8 , false ));
1352
+ // The ivar section contains entries of type `long` for for all architectures
1353
+ // except arm64, which uses `int` for the ivar offset.
1354
+ size_t ivarOffsetSize = m_data->GetDefaultArchitecture ()->GetName () == " aarch64" ? 4 : ptrSize;
1355
+ auto ivarSectionEntryTypeBuilder = new TypeBuilder (Type::IntegerType (ivarOffsetSize, false ));
1346
1356
ivarSectionEntryTypeBuilder->SetConst (true );
1347
1357
auto type = ivarSectionEntryTypeBuilder->Finalize ();
1348
- for (view_ptr_t i = start; i < end; i += ptrSize )
1358
+ for (view_ptr_t i = start; i < end; i += ivarOffsetSize )
1349
1359
{
1350
1360
m_data->DefineDataVariable (i, type);
1351
1361
}
@@ -1367,6 +1377,10 @@ ObjCProcessor::ObjCProcessor(BinaryView* data, const char* loggerName, bool skip
1367
1377
m_skipClassBaseProtocols(skipClassBaseProtocols), m_data(data)
1368
1378
{
1369
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" );
1370
1384
}
1371
1385
1372
1386
uint64_t ObjCProcessor::GetObjCRelativeMethodBaseAddress (ObjCReader* reader)
@@ -1384,11 +1398,6 @@ void ObjCProcessor::ProcessObjCData()
1384
1398
auto guard = ScopedSymbolQueue::Make ();
1385
1399
1386
1400
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
1401
m_typeNames.nsInteger = defineTypedef (m_data, {" NSInteger" }, Type::IntegerType (addrSize, true ));
1393
1402
m_typeNames.nsuInteger = defineTypedef (m_data, {" NSUInteger" }, Type::IntegerType (addrSize, false ));
1394
1403
m_typeNames.cgFloat = defineTypedef (m_data, {" CGFloat" }, Type::FloatType (addrSize));
@@ -1716,11 +1725,10 @@ void ObjCProcessor::ProcessNSConstantArrays()
1716
1725
auto guard = ScopedSymbolQueue::Make ();
1717
1726
uint64_t ptrSize = m_data->GetAddressSize ();
1718
1727
1719
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1720
1728
StructureBuilder nsConstantArrayBuilder;
1721
1729
nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1722
1730
nsConstantArrayBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1723
- nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, idType ), " objects" );
1731
+ nsConstantArrayBuilder.AddMember (Type::PointerType (ptrSize, m_types. id ), " objects" );
1724
1732
auto type = finalizeStructureBuilder (m_data, nsConstantArrayBuilder, " __NSConstantArray" );
1725
1733
m_typeNames.nsConstantArray = type.first ;
1726
1734
@@ -1737,7 +1745,7 @@ void ObjCProcessor::ProcessNSConstantArrays()
1737
1745
uint64_t count = reader->ReadPointer ();
1738
1746
auto dataLoc = ReadPointerAccountingForRelocations (reader.get ());
1739
1747
DefineObjCSymbol (
1740
- 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 );
1741
1749
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantArray ),
1742
1750
fmt::format (" nsarray_{:x}" , i), i, true );
1743
1751
}
@@ -1754,13 +1762,12 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1754
1762
auto guard = ScopedSymbolQueue::Make ();
1755
1763
uint64_t ptrSize = m_data->GetAddressSize ();
1756
1764
1757
- auto idType = Type::NamedType (m_data, m_typeNames.id );
1758
1765
StructureBuilder nsConstantDictionaryBuilder;
1759
1766
nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, Type::VoidType ()), " isa" );
1760
1767
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " options" );
1761
1768
nsConstantDictionaryBuilder.AddMember (Type::IntegerType (ptrSize, false ), " count" );
1762
- nsConstantDictionaryBuilder.AddMember (Type::PointerType (ptrSize, idType ), " keys" );
1763
- 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" );
1764
1771
auto type = finalizeStructureBuilder (m_data, nsConstantDictionaryBuilder, " __NSConstantDictionary" );
1765
1772
m_typeNames.nsConstantDictionary = type.first ;
1766
1773
@@ -1779,9 +1786,9 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
1779
1786
auto keysLoc = ReadPointerAccountingForRelocations (reader.get ());
1780
1787
auto objectsLoc = ReadPointerAccountingForRelocations (reader.get ());
1781
1788
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 );
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 );
1785
1792
DefineObjCSymbol (DataSymbol, Type::NamedType (m_data, m_typeNames.nsConstantDictionary ),
1786
1793
fmt::format (" nsdict_{:x}" , i), i, true );
1787
1794
}
0 commit comments