diff --git a/Il2CppInspector.Common/Cpp/CppApplicationModel.cs b/Il2CppInspector.Common/Cpp/CppApplicationModel.cs new file mode 100644 index 0000000..93de803 --- /dev/null +++ b/Il2CppInspector.Common/Cpp/CppApplicationModel.cs @@ -0,0 +1,59 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using System.Collections.Generic; +using System.Linq; +using Il2CppInspector.Cpp.UnityHeaders; +using Il2CppInspector.Reflection; + +namespace Il2CppInspector.Cpp +{ + // Class that represents a composite IL/C++ type + public class CppModelType + { + // The corresponding C++ type definition which represents an instance of the object + // If a .NET type, this is derived from Il2CppObject, otherwise it can be any type + // If the underlying .NET type is a struct (value type), this will return the boxed version + public CppType CppType { get; internal set; } + + // For an underlying .NET type which is a struct (value type), the unboxed type, otherwise null + public CppType CppValueType { get; internal set; } + + // The type in the model this object represents (for .NET types, otherwise null) + public TypeInfo ILType { get; internal set; } + + // The VA of the Il2CppClass object which defines this type (for .NET types, otherwise zero) + public uint VirtualAddress { get; internal set; } + } + + // Class that represents the entire structure of the IL2CPP binary realized as C++ types and code, + // correlated with .NET types where applicable. Primarily designed to enable automated static analysis of disassembly code. + public class CppApplicationModel + { + public CppCompiler.Type Compiler { get; } + public UnityVersion UnityVersion { get; } + public CppTypes Types { get; } + public Il2CppModel ILModel { get; } + public List Exports { get; } + public int WordSize => ILModel.Package.BinaryImage.Bits; + + public CppApplicationModel(Il2CppModel model, UnityVersion unityVersion, CppCompiler.Type compiler = CppCompiler.Type.BinaryFormat) { + // Set key properties + Compiler = compiler == CppCompiler.Type.BinaryFormat ? CppCompiler.GuessFromImage(model.Package.BinaryImage) : compiler; + UnityVersion = unityVersion; + ILModel = model; + + // Start creation of type model by parsing all of the Unity IL2CPP headers + Types = CppTypes.FromUnityVersion(unityVersion, WordSize); + + // TODO: Process every type in the binary + var decl = new CppDeclarationGenerator(ILModel, UnityVersion); + + // Add addresses of IL2CPP API function exports + Exports = model.Package.Binary.Image.GetExports().ToList(); + } + } +} diff --git a/Il2CppInspector.Common/Cpp/CppCompiler.cs b/Il2CppInspector.Common/Cpp/CppCompiler.cs index 15331a8..cd79797 100644 --- a/Il2CppInspector.Common/Cpp/CppCompiler.cs +++ b/Il2CppInspector.Common/Cpp/CppCompiler.cs @@ -1,6 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ namespace Il2CppInspector.Cpp { diff --git a/Il2CppInspector.Common/Cpp/CppDeclarationGenerator.cs b/Il2CppInspector.Common/Cpp/CppDeclarationGenerator.cs index 32fc653..5e699d1 100644 --- a/Il2CppInspector.Common/Cpp/CppDeclarationGenerator.cs +++ b/Il2CppInspector.Common/Cpp/CppDeclarationGenerator.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty Copyright 2020 Robert Xiao - https://robertxiao.ca All rights reserved. diff --git a/Il2CppInspector.Common/Cpp/CppNamespace.cs b/Il2CppInspector.Common/Cpp/CppNamespace.cs index 436cb92..9a0cbe3 100644 --- a/Il2CppInspector.Common/Cpp/CppNamespace.cs +++ b/Il2CppInspector.Common/Cpp/CppNamespace.cs @@ -1,5 +1,5 @@ /* - Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty Copyright 2020 Robert Xiao - https://robertxiao.ca All rights reserved. diff --git a/Il2CppInspector.Common/FileFormatReaders/Export.cs b/Il2CppInspector.Common/FileFormatReaders/Export.cs index 8cbcc5c..0bc853c 100644 --- a/Il2CppInspector.Common/FileFormatReaders/Export.cs +++ b/Il2CppInspector.Common/FileFormatReaders/Export.cs @@ -6,6 +6,7 @@ namespace Il2CppInspector { + // A code file function export public class Export { public int Ordinal;