From 5c97202d8ecef0d324688a041b54c302785aaa0c Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 1 Aug 2020 05:23:44 +0200 Subject: [PATCH] C++: Significant iteration of scaffolding output (see commit description) Generate pre-compiled headers for IL2CPP types and functions Resolved naming conflicts with functions and macros from windows.h IL2CPP app functions and TypeInfos were incorrectly placed in global namespace instead of 'app' Added /MP compiler option (multi-processor compilation) Split source files into folders Move GetBaseAddress() into helpers.cpp Add NewConsole() to helpers.cpp Move init_il2cpp() from IL2CPP declarations header to own source file Refactor some header files for consistency and duplicate elimination --- Il2CppInspector.CLI/Program.cs | 2 +- .../Outputs/CppScaffolding.cs | 42 ++- .../Properties/Resources.Designer.cs | 174 ++++++--- .../Properties/Resources.resx | 350 +++++++++++------- Il2CppTests/TestRunner.cs | 5 +- Il2CppTests/update-expected-results.ps1 | 4 +- 6 files changed, 377 insertions(+), 200 deletions(-) diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index 4727494..2e23441 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -258,7 +258,7 @@ namespace Il2CppInspector.CLI // IDA Python script output using (new Benchmark("Generate IDAPython script")) { - new IDAPythonScript(appModel).WriteScriptToFile(options.PythonOutFile, options.CppOutPath + Path.DirectorySeparatorChar + "il2cpp-types.h"); + new IDAPythonScript(appModel).WriteScriptToFile(options.PythonOutFile, Path.Combine(options.CppOutPath, "appdata/il2cpp-types.h")); } // C++ output diff --git a/Il2CppInspector.Common/Outputs/CppScaffolding.cs b/Il2CppInspector.Common/Outputs/CppScaffolding.cs index fdda516..825a408 100644 --- a/Il2CppInspector.Common/Outputs/CppScaffolding.cs +++ b/Il2CppInspector.Common/Outputs/CppScaffolding.cs @@ -80,17 +80,24 @@ typedef size_t uintptr_t; writer.Close(); } - public void Write(string outputPath) { + public void Write(string projectPath) { // Ensure output directory exists and is not a file // A System.IOException will be thrown if it's a file' - Directory.CreateDirectory(outputPath); + var srcUserPath = Path.Combine(projectPath, "user"); + var srcFxPath = Path.Combine(projectPath, "framework"); + var srcDataPath = Path.Combine(projectPath, "appdata"); + + Directory.CreateDirectory(projectPath); + Directory.CreateDirectory(srcUserPath); + Directory.CreateDirectory(srcFxPath); + Directory.CreateDirectory(srcDataPath); // Write type definitions to il2cpp-types.h - WriteTypes(Path.Combine(outputPath, "il2cpp-types.h")); + WriteTypes(Path.Combine(srcDataPath, "il2cpp-types.h")); // Write selected Unity API function file to il2cpp-api-functions.h // (this is a copy of the header file from an actual Unity install) - var il2cppApiFile = Path.Combine(outputPath, "il2cpp-api-functions.h"); + var il2cppApiFile = Path.Combine(srcDataPath, "il2cpp-api-functions.h"); var apiHeaderText = model.UnityHeaders.GetAPIHeaderText(); using var fsApi = new FileStream(il2cppApiFile, FileMode.Create); @@ -110,7 +117,7 @@ typedef size_t uintptr_t; writer.Close(); // Write API function pointers to il2cpp-function-ptr.h - var il2cppFnPtrFile = Path.Combine(outputPath, "il2cpp-function-ptr.h"); + var il2cppFnPtrFile = Path.Combine(srcDataPath, "il2cpp-function-ptr.h"); using var fs2 = new FileStream(il2cppFnPtrFile, FileMode.Create); writer = new StreamWriter(fs2, Encoding.ASCII); @@ -130,7 +137,7 @@ typedef size_t uintptr_t; writer.Close(); // Write application type definition addresses to il2cpp-type-ptr.h - var il2cppTypeInfoFile = Path.Combine(outputPath, "il2cpp-type-ptr.h"); + var il2cppTypeInfoFile = Path.Combine(srcDataPath, "il2cpp-type-ptr.h"); using var fs3 = new FileStream(il2cppTypeInfoFile, FileMode.Create); writer = new StreamWriter(fs3, Encoding.ASCII); @@ -145,7 +152,7 @@ typedef size_t uintptr_t; writer.Close(); // Write method pointers and signatures to il2cpp-functions.h - var methodFile = Path.Combine(outputPath, "il2cpp-functions.h"); + var methodFile = Path.Combine(srcDataPath, "il2cpp-functions.h"); using var fs4 = new FileStream(methodFile, FileMode.Create); writer = new StreamWriter(fs4, Encoding.ASCII); @@ -165,19 +172,24 @@ typedef size_t uintptr_t; writer.Close(); // Write boilerplate code - File.WriteAllText(Path.Combine(outputPath, "il2cpp-init.h"), Resources.Cpp_IL2CPPInitH); - File.WriteAllText(Path.Combine(outputPath, "helpers.h"), Resources.Cpp_HelpersH); - File.WriteAllText(Path.Combine(outputPath, "dllmain.h"), Resources.Cpp_DLLMainH); - File.WriteAllText(Path.Combine(outputPath, "main.cpp"), Resources.Cpp_MainCpp); - File.WriteAllText(Path.Combine(outputPath, "helpers.cpp"), Resources.Cpp_HelpersCpp); - File.WriteAllText(Path.Combine(outputPath, "dllmain.cpp"), Resources.Cpp_DLLMainCpp); + File.WriteAllText(Path.Combine(srcFxPath, "dllmain.cpp"), Resources.Cpp_DLLMainCpp); + File.WriteAllText(Path.Combine(srcFxPath, "helpers.cpp"), Resources.Cpp_HelpersCpp); + File.WriteAllText(Path.Combine(srcFxPath, "helpers.h"), Resources.Cpp_HelpersH); + File.WriteAllText(Path.Combine(srcFxPath, "il2cpp-appdata.h"), Resources.Cpp_Il2CppAppDataH); + File.WriteAllText(Path.Combine(srcFxPath, "il2cpp-init.cpp"), Resources.Cpp_Il2CppInitCpp); + File.WriteAllText(Path.Combine(srcFxPath, "il2cpp-init.h"), Resources.Cpp_Il2CppInitH); + File.WriteAllText(Path.Combine(srcFxPath, "pch-il2cpp.cpp"), Resources.Cpp_PCHIl2Cpp); + File.WriteAllText(Path.Combine(srcFxPath, "pch-il2cpp.h"), Resources.Cpp_PCHIl2CppH); + + File.WriteAllText(Path.Combine(srcUserPath, "main.cpp"), Resources.Cpp_MainCpp); + File.WriteAllText(Path.Combine(srcUserPath, "main.h"), Resources.Cpp_MainH); // Write Visual Studio project and solution files var projectGuid = Guid.NewGuid(); var projectName = "IL2CppDLL"; var projectFile = projectName + ".vcxproj"; - File.WriteAllText(Path.Combine(outputPath, projectFile), + File.WriteAllText(Path.Combine(projectPath, projectFile), Resources.CppProjTemplate.Replace("%PROJECTGUID%", projectGuid.ToString())); var solutionGuid = Guid.NewGuid(); @@ -189,7 +201,7 @@ typedef size_t uintptr_t; .Replace("%PROJECTFILE%", projectFile) .Replace("%SOLUTIONGUID%", solutionGuid.ToString()); - File.WriteAllText(Path.Combine(outputPath, solutionFile), sln); + File.WriteAllText(Path.Combine(projectPath, solutionFile), sln); } private void writeHeader() { diff --git a/Il2CppInspector.Common/Properties/Resources.Designer.cs b/Il2CppInspector.Common/Properties/Resources.Designer.cs index 5d351eb..c0a46e2 100644 --- a/Il2CppInspector.Common/Properties/Resources.Designer.cs +++ b/Il2CppInspector.Common/Properties/Resources.Designer.cs @@ -62,10 +62,12 @@ namespace Il2CppInspector.Properties { /// /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty + ///// DLL entry point /// ///#define WIN32_LEAN_AND_MEAN - ///#include "windows.h" - ///#include "dllmain.h" + ///#include <windows.h> + ///#include "il2cpp-init.h" + ///#include "main.h" /// ///// DLL entry point ///BOOL APIENTRY DllMain( HMODULE hModule, @@ -77,7 +79,7 @@ namespace Il2CppInspector.Properties { /// { /// case DLL_PROCESS_ATTACH: /// init_il2cpp(); - /// CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Run, NULL, [rest of string was truncated]";. + /// CreateThread(NULL, 0, (LPTHREAD_S [rest of string was truncated]";. /// internal static string Cpp_DLLMainCpp { get { @@ -87,35 +89,24 @@ namespace Il2CppInspector.Properties { /// /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty - /// - ///// Entry point declaration for custom injected code - ///void Run(); - /// - ///// IL2CPP initializer - ///void init_il2cpp();. - /// - internal static string Cpp_DLLMainH { - get { - return ResourceManager.GetString("Cpp-DLLMainH", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty - ///// Logging functions + ///// Helper functions /// ///#define WIN32_LEAN_AND_MEAN - ///#define WIN32_EXTRA_LEAN ///#include <windows.h> + ///#include <string> ///#include "helpers.h" /// - ///// Write some text to the log file - ///void LogWrite(std::string text) - ///{ - /// HANDLE hfile = CreateFileW(LOG_FILE, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + ///// Log file location + ///extern const LPCWSTR LOG_FILE; /// - /// if (hfile == INVALID_HANDLE_VALUE) - /// MessageBox(0, L"Could not open log file", 0, [rest of string was truncated]";. + ///// Helper function to get the module base address + ///uintptr_t GetBaseAddress() { + /// return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll"); + ///} + /// + ///// Helper function to append text to a file + ///void LogWrite(std::string text) { + /// HANDLE hfile = CreateFileW(LOG [rest of string was truncated]";. /// internal static string Cpp_HelpersCpp { get { @@ -125,22 +116,24 @@ namespace Il2CppInspector.Properties { /// /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty - ///// Logging functions + ///// Helper functions /// ///#pragma once + /// ///#include <string> ///#include <sstream> - ///#include <iomanip> /// - ///extern const LPCWSTR LOG_FILE; + ///// Helper function to get the module base address + ///uintptr_t GetBaseAddress(); /// ///// Helper function to append text to a file ///void LogWrite(std::string text); /// + ///// Helper function to open a new console window and redirect stdout there + ///void NewConsole(); + /// ///// Helper function to convert a pointer to hex - ///template<typename T> std::string to_hex_string(T i) { - /// std::stringstream stream; - /// stream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << [rest of string was truncated]";. + ///template<typename T> std::string to_hex_string(T [rest of string was truncated]";. /// internal static string Cpp_HelpersH { get { @@ -150,7 +143,7 @@ namespace Il2CppInspector.Properties { /// /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty - ///// IL2CPP application initializer + ///// IL2CPP application data /// ///#pragma once /// @@ -163,18 +156,65 @@ namespace Il2CppInspector.Properties { ///#include "il2cpp-function-ptr.h" /// ///// IL2CPP APIs + ///#define DO_API(r, n, p) extern r (*n) p + ///#include "il2cpp-api-functions.h" + ///#undef DO_API + /// + ///// Application-specific functions + ///#define DO_APP_FUNC(a, r, n, p) extern r (*n) p + ///namespace app { + /// #include "il2cpp-functions.h" + ///} [rest of string was truncated]";. + /// + internal static string Cpp_Il2CppAppDataH { + get { + return ResourceManager.GetString("Cpp-Il2CppAppDataH", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty + ///// IL2CPP application initializer + /// + ///#include "pch-il2cpp.h" + /// + ///#include "il2cpp-appdata.h" + ///#include "il2cpp-init.h" + ///#include "helpers.h" + /// + ///// IL2CPP APIs ///#define DO_API(r, n, p) r (*n) p ///#include "il2cpp-api-functions.h" ///#undef DO_API /// ///// Application-specific functions ///#define DO_APP_FUNC(a, r, n, p) r (*n) p + ///namespace app { ///#include "il2cpp-functions.h" - ///#und [rest of string was truncated]";. + ///} + ///#undef DO_APP_FUNC + /// + ///// TypeInfo pointers + ///#define DO_TYPEDEF(a, n [rest of string was truncated]";. /// - internal static string Cpp_IL2CPPInitH { + internal static string Cpp_Il2CppInitCpp { get { - return ResourceManager.GetString("Cpp-IL2CPPInitH", resourceCulture); + return ResourceManager.GetString("Cpp-Il2CppInitCpp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty + ///// IL2CPP application initializer + /// + ///#pragma once + /// + ///// IL2CPP application initializer + ///void init_il2cpp();. + /// + internal static string Cpp_Il2CppInitH { + get { + return ResourceManager.GetString("Cpp_Il2CppInitH", resourceCulture); } } @@ -182,7 +222,12 @@ namespace Il2CppInspector.Properties { /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty ///// Custom injected code entry point /// - ///#include "il2cpp-init.h" + ///#include "pch-il2cpp.h" + /// + ///#define WIN32_LEAN_AND_MEAN + ///#include <Windows.h> + ///#include <iostream> + ///#include "il2cpp-appdata.h" ///#include "helpers.h" /// ///using namespace app; @@ -190,13 +235,10 @@ namespace Il2CppInspector.Properties { ///// Set the name of your log file here ///extern const LPCWSTR LOG_FILE = L"il2cpp-log.txt"; /// - ///// Injected code entry point + ///// Custom injected code entry point ///void Run() ///{ - /// LogWrite("Startup"); - /// - /// // Place your custom code here - ///}. + /// // If you would like to write to a log file, specify the name above and u [rest of string was truncated]";. /// internal static string Cpp_MainCpp { get { @@ -204,6 +246,52 @@ namespace Il2CppInspector.Properties { } } + /// + /// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty + ///// Custom injected code entry point + /// + ///#pragma once + /// + ///// Custom injected code entry point + ///void Run();. + /// + internal static string Cpp_MainH { + get { + return ResourceManager.GetString("Cpp-MainH", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to // pch.cpp: source file corresponding to the pre-compiled header + /// + ///#include "pch-il2cpp.h" + /// + ///// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.. + /// + internal static string Cpp_PCHIl2Cpp { + get { + return ResourceManager.GetString("Cpp-PCHIl2Cpp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to // pch.h: This is a precompiled header file. + ///// Files listed below are compiled only once, improving build performance for future builds. + ///// This also affects IntelliSense performance, including code completion and many code browsing features. + ///// However, files listed here are ALL re-compiled if any one of them is updated between builds. + ///// Do not add files here that you will be updating frequently as this negates the performance advantage. + /// + ///#ifndef PCH_IL2CPP_H + ///#define PCH_IL2CPP_H + /// + ///// add headers [rest of string was truncated]";. + /// + internal static string Cpp_PCHIl2CppH { + get { + return ResourceManager.GetString("Cpp-PCHIl2CppH", resourceCulture); + } + } + /// /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?> ///<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> @@ -238,7 +326,7 @@ namespace Il2CppInspector.Properties { /// Release|x64 = Release|x64 /// Release|x86 = Release|x86 /// EndGlobalSection - /// GlobalSection(ProjectConfig [rest of string was truncated]";. + /// GlobalSection(ProjectConfigurationPlatfo [rest of string was truncated]";. /// internal static string CppSlnTemplate { get { diff --git a/Il2CppInspector.Common/Properties/Resources.resx b/Il2CppInspector.Common/Properties/Resources.resx index 03f94b2..f8110fd 100644 --- a/Il2CppInspector.Common/Properties/Resources.resx +++ b/Il2CppInspector.Common/Properties/Resources.resx @@ -119,10 +119,12 @@ // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty +// DLL entry point #define WIN32_LEAN_AND_MEAN -#include "windows.h" -#include "dllmain.h" +#include <windows.h> +#include "il2cpp-init.h" +#include "main.h" // DLL entry point BOOL APIENTRY DllMain( HMODULE hModule, @@ -143,53 +145,61 @@ BOOL APIENTRY DllMain( HMODULE hModule, } return TRUE; } - - - // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty - -// Entry point declaration for custom injected code -void Run(); - -// IL2CPP initializer -void init_il2cpp(); // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty -// Logging functions +// Helper functions #define WIN32_LEAN_AND_MEAN -#define WIN32_EXTRA_LEAN #include <windows.h> +#include <string> #include "helpers.h" -// Write some text to the log file -void LogWrite(std::string text) -{ +// Log file location +extern const LPCWSTR LOG_FILE; + +// Helper function to get the module base address +uintptr_t GetBaseAddress() { + return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll"); +} + +// Helper function to append text to a file +void LogWrite(std::string text) { HANDLE hfile = CreateFileW(LOG_FILE, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hfile == INVALID_HANDLE_VALUE) - MessageBox(0, L"Could not open log file", 0, 0); + MessageBoxW(0, L"Could not open log file", 0, 0); DWORD written; WriteFile(hfile, text.c_str(), (DWORD) text.length(), &written, NULL); WriteFile(hfile, "\r\n", 2, &written, NULL); CloseHandle(hfile); +} + +// Helper function to open a new console window and redirect stdout there +void NewConsole() { + AllocConsole(); + freopen_s((FILE**) stdout, "CONOUT$", "w", stdout); } // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty -// Logging functions +// Helper functions #pragma once + #include <string> #include <sstream> -#include <iomanip> -extern const LPCWSTR LOG_FILE; +// Helper function to get the module base address +uintptr_t GetBaseAddress(); // Helper function to append text to a file void LogWrite(std::string text); +// Helper function to open a new console window and redirect stdout there +void NewConsole(); + // Helper function to convert a pointer to hex template<typename T> std::string to_hex_string(T i) { std::stringstream stream; @@ -197,111 +207,25 @@ template<typename T> std::string to_hex_string(T i) { return stream.str(); } - + // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty // IL2CPP application initializer #pragma once -#include <cstdint> - -// Application-specific types -#include "il2cpp-types.h" - -// IL2CPP API function pointers -#include "il2cpp-function-ptr.h" - -// IL2CPP APIs -#define DO_API(r, n, p) r (*n) p -#include "il2cpp-api-functions.h" -#undef DO_API - -// Application-specific functions -#define DO_APP_FUNC(a, r, n, p) r (*n) p -#include "il2cpp-functions.h" -#undef DO_APP_FUNC - -// TypeInfo pointers -#define DO_TYPEDEF(a, n) n ## __Class* n ## __TypeInfo -#include "il2cpp-type-ptr.h" -#undef DO_TYPEDEF - -// Try not to include any Windows symbosl that might cause a naming conflict -#define WIN32_LEAN_AND_MEAN -#define WIN32_EXTRA_LEAN -#define NOIME -#define NOWINRES -#define NOGDICAPMASKS -#define NOVIRTUALKEYCODES -#define NOWINMESSAGES -#define NOWINSTYLES -#define NOSYSMETRICS -#define NOMENUS -#define NOICONS -#define NOKEYSTATES -#define NOSYSCOMMANDS -#define NORASTEROPS -#define NOSHOWWINDOW -#define OEMRESOURCE -#define NOATOM -#define NOCLIPBOARD -#define NOCOLOR -#define NOCTLMGR -#define NODRAWTEXT -#define NOGDI -#define NOUSER -#define NOMB -#define NOMEMMGR -#define NOMETAFILE -#define NOMINMAX -#define NOMSG -#define NOOPENFILE -#define NOSCROLL -#define NOSERVICE -#define NOSOUND -#define NOTEXTMETRIC -#define NOWH -#define NOWINOFFSETS -#define NOCOMM -#define NOKANJI -#define NOHELP -#define NOPROFILER -#define NODEFERWINDOWPOS -#define NOMCX -#define NOIME -#define NOPROXYSTUB -#define NOIMAGE -#define NO -#define NOTAPE -#define ANSI_ONLY -#include "windows.h" - -// Initialize everything -void init_il2cpp() { - // Get base address of IL2CPP module - uintptr_t baseAddress = (uintptr_t) GetModuleHandleW(L"GameAssembly.dll"); - - // Define IL2CPP API function addresses - #define DO_API(r, n, p) n = (r (*) p)(baseAddress + n ## _ptr) - #include "il2cpp-api-functions.h" - #undef DO_API - - // Define function addresses - #define DO_APP_FUNC(a, r, n, p) n = (r (*) p)(baseAddress + a) - #include "il2cpp-functions.h" - #undef DO_APP_FUNC - - // Define TypeInfo variables - #define DO_TYPEDEF(a, n) n ## __TypeInfo = *(n ## __Class**) (baseAddress + a); - #include "il2cpp-type-ptr.h" - #undef DO_TYPEDEF -} +// IL2CPP application initializer +void init_il2cpp(); // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty // Custom injected code entry point -#include "il2cpp-init.h" +#include "pch-il2cpp.h" + +#define WIN32_LEAN_AND_MEAN +#include <Windows.h> +#include <iostream> +#include "il2cpp-appdata.h" #include "helpers.h" using namespace app; @@ -309,10 +233,14 @@ using namespace app; // Set the name of your log file here extern const LPCWSTR LOG_FILE = L"il2cpp-log.txt"; -// Injected code entry point +// Custom injected code entry point void Run() { - LogWrite("Startup"); + // If you would like to write to a log file, specify the name above and use LogWrite() + // LogWrite("Startup"); + + // If you would like to output to a new console window, use NewConsole() to open one and redirect stdout + // NewConsole(); // Place your custom code here } @@ -338,10 +266,44 @@ void Run() <Platform>x64</Platform> </ProjectConfiguration> </ItemGroup> + <ItemGroup> + <ClCompile Include="framework\dllmain.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> + </ClCompile> + <ClCompile Include="framework\helpers.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader> + </ClCompile> + <ClCompile Include="framework\il2cpp-init.cpp" /> + <ClCompile Include="framework\pch-il2cpp.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="user\main.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="appdata\il2cpp-api-functions.h" /> + <ClInclude Include="appdata\il2cpp-function-ptr.h" /> + <ClInclude Include="appdata\il2cpp-functions.h" /> + <ClInclude Include="appdata\il2cpp-type-ptr.h" /> + <ClInclude Include="appdata\il2cpp-types.h" /> + <ClInclude Include="framework\helpers.h" /> + <ClInclude Include="framework\il2cpp-appdata.h" /> + <ClInclude Include="framework\il2cpp-init.h" /> + <ClInclude Include="framework\pch-il2cpp.h" /> + <ClInclude Include="user\main.h" /> + </ItemGroup> <PropertyGroup Label="Globals"> <!--<VCProjectVersion>16.0</VCProjectVersion>--> <Keyword>Win32Proj</Keyword> - <ProjectGuid>{%PROJECTGUID%}</ProjectGuid> + <ProjectGuid>{%PROJECTGUID}</ProjectGuid> <RootNamespace>Il2CppDLL</RootNamespace> <!--<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>--> </PropertyGroup> @@ -408,7 +370,10 @@ void Run() <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>WIN32;_DEBUG;IL2CPPDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> - <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch-il2cpp.h</PrecompiledHeaderFile> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <AdditionalIncludeDirectories>$(ProjectDir)appdata;$(ProjectDir)framework;$(ProjectDir)user</AdditionalIncludeDirectories> </ClCompile> <Link> <SubSystem>Windows</SubSystem> @@ -424,7 +389,10 @@ void Run() <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>WIN32;NDEBUG;IL2CPPDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> - <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch-il2cpp.h</PrecompiledHeaderFile> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <AdditionalIncludeDirectories>$(ProjectDir)appdata;$(ProjectDir)framework;$(ProjectDir)user</AdditionalIncludeDirectories> </ClCompile> <Link> <SubSystem>Windows</SubSystem> @@ -440,7 +408,10 @@ void Run() <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>_DEBUG;IL2CPPDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> - <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch-il2cpp.h</PrecompiledHeaderFile> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <AdditionalIncludeDirectories>$(ProjectDir)appdata;$(ProjectDir)framework;$(ProjectDir)user</AdditionalIncludeDirectories> </ClCompile> <Link> <SubSystem>Windows</SubSystem> @@ -456,7 +427,10 @@ void Run() <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>NDEBUG;IL2CPPDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> - <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch-il2cpp.h</PrecompiledHeaderFile> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <AdditionalIncludeDirectories>$(ProjectDir)appdata;$(ProjectDir)framework;$(ProjectDir)user</AdditionalIncludeDirectories> </ClCompile> <Link> <SubSystem>Windows</SubSystem> @@ -466,21 +440,6 @@ void Run() <EnableUAC>false</EnableUAC> </Link> </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="dllmain.cpp" /> - <ClCompile Include="helpers.cpp" /> - <ClCompile Include="main.cpp" /> - </ItemGroup> - <ItemGroup> - <ClInclude Include="dllmain.h" /> - <ClInclude Include="helpers.h" /> - <ClInclude Include="il2cpp-api-functions.h" /> - <ClInclude Include="il2cpp-init.h" /> - <ClInclude Include="il2cpp-function-ptr.h" /> - <ClInclude Include="il2cpp-functions.h" /> - <ClInclude Include="il2cpp-type-ptr.h" /> - <ClInclude Include="il2cpp-types.h" /> - </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> @@ -1172,4 +1131,121 @@ Global EndGlobal + + // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty +// IL2CPP application data + +#pragma once + +#include <cstdint> + +// Application-specific types +#include "il2cpp-types.h" + +// IL2CPP API function pointers +#include "il2cpp-function-ptr.h" + +// IL2CPP APIs +#define DO_API(r, n, p) extern r (*n) p +#include "il2cpp-api-functions.h" +#undef DO_API + +// Application-specific functions +#define DO_APP_FUNC(a, r, n, p) extern r (*n) p +namespace app { + #include "il2cpp-functions.h" +} +#undef DO_APP_FUNC + +// TypeInfo pointers +#define DO_TYPEDEF(a, n) extern n ## __Class* n ## __TypeInfo +namespace app { + #include "il2cpp-type-ptr.h" +} +#undef DO_TYPEDEF + + + // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty +// IL2CPP application initializer + +#include "pch-il2cpp.h" + +#include "il2cpp-appdata.h" +#include "il2cpp-init.h" +#include "helpers.h" + +// IL2CPP APIs +#define DO_API(r, n, p) r (*n) p +#include "il2cpp-api-functions.h" +#undef DO_API + +// Application-specific functions +#define DO_APP_FUNC(a, r, n, p) r (*n) p +namespace app { +#include "il2cpp-functions.h" +} +#undef DO_APP_FUNC + +// TypeInfo pointers +#define DO_TYPEDEF(a, n) n ## __Class* n ## __TypeInfo +namespace app { +#include "il2cpp-type-ptr.h" +} +#undef DO_TYPEDEF + +// IL2CPP application initializer +void init_il2cpp() +{ + // Get base address of IL2CPP module + uintptr_t baseAddress = GetBaseAddress(); + + using namespace app; + + // Define IL2CPP API function addresses + #define DO_API(r, n, p) n = (r (*) p)(baseAddress + n ## _ptr) + #include "il2cpp-api-functions.h" + #undef DO_API + + // Define function addresses + #define DO_APP_FUNC(a, r, n, p) n = (r (*) p)(baseAddress + a) + #include "il2cpp-functions.h" + #undef DO_APP_FUNC + + // Define TypeInfo variables + #define DO_TYPEDEF(a, n) n ## __TypeInfo = *(n ## __Class**) (baseAddress + a); + #include "il2cpp-type-ptr.h" + #undef DO_TYPEDEF +} + + + // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty +// Custom injected code entry point + +#pragma once + +// Custom injected code entry point +void Run(); + + + // pch.cpp: source file corresponding to the pre-compiled header + +#include "pch-il2cpp.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. + + + // pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_IL2CPP_H +#define PCH_IL2CPP_H + +// add headers that you want to pre-compile here +#include "il2cpp-appdata.h" + +#endif //PCH_IL2CPP_H + \ No newline at end of file diff --git a/Il2CppTests/TestRunner.cs b/Il2CppTests/TestRunner.cs index 827c95b..1401e71 100644 --- a/Il2CppTests/TestRunner.cs +++ b/Il2CppTests/TestRunner.cs @@ -55,7 +55,8 @@ namespace Il2CppInspector }.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs"); new IDAPythonScript(appModel) - .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py", testPath + $@"\test-cpp-result{nameSuffix}\il2cpp-types.h"); + .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py", + testPath + $@"\test-cpp-result{nameSuffix}\appdata\il2cpp-types.h"); new CppScaffolding(appModel) .Write(testPath + $@"\test-cpp-result{nameSuffix}"); @@ -66,7 +67,7 @@ namespace Il2CppInspector var suffix = (i > 0 ? "-" + i : ""); compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs"); - compareFiles(testPath, suffix + ".h", $@"test-cpp-result{suffix}\il2cpp-types.h"); + compareFiles(testPath, suffix + ".h", $@"test-cpp-result{suffix}\appdata\il2cpp-types.h"); compareFiles(testPath, suffix + ".py", $"test-ida-result{suffix}.py"); } } diff --git a/Il2CppTests/update-expected-results.ps1 b/Il2CppTests/update-expected-results.ps1 index 5fea1e1..97d3dcc 100644 --- a/Il2CppTests/update-expected-results.ps1 +++ b/Il2CppTests/update-expected-results.ps1 @@ -10,8 +10,8 @@ $bin = (gci "$PSScriptRoot/TestBinaries/*/*" -Filter test-result.cs) $bin2 = (gci "$PSScriptRoot/TestBinaries/*/*" -Filter test-result-1.cs) $py = (gci "$PSScriptRoot/TestBinaries/*/*" -Filter test-ida-result.py) $py2 = (gci "$PSScriptRoot/TestBinaries/*/*" -Filter test-ida-result-1.py) -$cpp = (gci "$PSScriptRoot/TestBinaries/*/test-cpp-result/*" -Filter il2cpp-types.h) -$cpp2 = (gci "$PSScriptRoot/TestBinaries/*/test-cpp-result-1/*" -Filter il2cpp-types.h) +$cpp = (gci "$PSScriptRoot/TestBinaries/*/test-cpp-result/appdata/*" -Filter il2cpp-types.h) +$cpp2 = (gci "$PSScriptRoot/TestBinaries/*/test-cpp-result-1/appdata/*" -Filter il2cpp-types.h) # Get path to expected test results $results = "$PSScriptRoot/TestExpectedResults"