diff --git a/Cpp2IL.Core/Analysis/Actions/x86/Il2CppStringToConstantAction.cs b/Cpp2IL.Core/Analysis/Actions/x86/Il2CppStringToConstantAction.cs index c30c8ddf..a210e718 100644 --- a/Cpp2IL.Core/Analysis/Actions/x86/Il2CppStringToConstantAction.cs +++ b/Cpp2IL.Core/Analysis/Actions/x86/Il2CppStringToConstantAction.cs @@ -22,7 +22,7 @@ public Il2CppStringToConstantAction(MethodAnalysis context, Instruc _destReg = Utils.GetRegisterNameNew(instruction.Op0Register); } - _constantMade = context.MakeConstant(typeof(Il2CppString), new Il2CppString(_detectedString, instruction.MemoryDisplacement64), reg: _destReg); + _constantMade = context.MakeConstant(typeof(Il2CppString), new Il2CppString(_detectedString, instruction.Op0Kind.IsImmediate() ? instruction.Immediate32 : instruction.MemoryDisplacement64), reg: _destReg); if (instruction.Mnemonic == Mnemonic.Push) { diff --git a/Cpp2IL.Core/Analysis/ResultModels/Il2CppString.cs b/Cpp2IL.Core/Analysis/ResultModels/Il2CppString.cs index 3ba8fadf..66c54507 100644 --- a/Cpp2IL.Core/Analysis/ResultModels/Il2CppString.cs +++ b/Cpp2IL.Core/Analysis/ResultModels/Il2CppString.cs @@ -1,4 +1,7 @@ -namespace Cpp2IL.Core.Analysis.ResultModels +using System; +using LibCpp2IL; + +namespace Cpp2IL.Core.Analysis.ResultModels { public class Il2CppString { @@ -8,6 +11,10 @@ public class Il2CppString public Il2CppString(string containedString, ulong addr) { ContainedString = containedString; + + if (!LibCpp2IlMain.Binary!.TryMapVirtualAddressToRaw(addr, out _)) + throw new Exception($"Invalid il2cpp string creation - 0x{addr:X} cannot be mapped to the binary."); + Address = addr; } diff --git a/Cpp2IL.Core/AttributeRestorer.cs b/Cpp2IL.Core/AttributeRestorer.cs index aaec4bc9..1b3fc579 100644 --- a/Cpp2IL.Core/AttributeRestorer.cs +++ b/Cpp2IL.Core/AttributeRestorer.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Cpp2IL.Core.Analysis; using Cpp2IL.Core.Analysis.Actions.Base; @@ -487,6 +488,9 @@ private static object AllocateArray(AllocatedArray array) var arrayType = Type.GetType(typeForArrayToCreateNow.FullName) ?? throw new Exception($"Could not resolve array type {array.ArrayType.ElementType.FullName}"); var arr = Array.CreateInstance(arrayType, array.Size); + if (array.KnownValuesAtOffsets.Count != array.Size) + throw new Exception($"Failed to populate known array - only have {array.KnownValuesAtOffsets.Count} known values for an array of length {array.Size}."); + foreach (var (index, value) in array.KnownValuesAtOffsets) { try diff --git a/Cpp2IL.Core/Cpp2IlApi.cs b/Cpp2IL.Core/Cpp2IlApi.cs index c697df5c..4d02bbac 100644 --- a/Cpp2IL.Core/Cpp2IlApi.cs +++ b/Cpp2IL.Core/Cpp2IlApi.cs @@ -289,14 +289,18 @@ public static void SaveAssemblies(string toWhere, List assem if (reference != null) assembly.MainModule.AssemblyReferences.Remove(reference); +#if !DEBUG try { +#endif assembly.Write(dllPath); +#if !DEBUG } catch (Exception e) { throw new DllSaveException(dllPath, e); } +#endif } } diff --git a/Cpp2IL/Program.cs b/Cpp2IL/Program.cs index 6d01f493..1bf4d087 100644 --- a/Cpp2IL/Program.cs +++ b/Cpp2IL/Program.cs @@ -61,7 +61,7 @@ private static void ResolvePathsFromCommandLine(string gamePath, string? inputEx //APK //Metadata: assets/bin/Data/Managed/Metadata //Binary: lib/(armeabi-v7a)|(arm64-v8a)/libil2cpp.so - + Logger.InfoNewline($"Attempting to extract required files from APK {gamePath}"); using var stream = File.OpenRead(gamePath); @@ -100,7 +100,7 @@ private static void ResolvePathsFromCommandLine(string gamePath, string? inputEx ggmStream.Read(ggmBytes, 0, 0x40); args.UnityVersion = Cpp2IlApi.GetVersionFromGlobalGameManagers(ggmBytes); - + Logger.InfoNewline($"Determined game's unity version to be {string.Join(".", args.UnityVersion)}"); args.Valid = true; @@ -176,11 +176,14 @@ public static int Main(string[] args) Logger.InfoNewline("Running on " + Environment.OSVersion.Platform); +#if !DEBUG try { +#endif var runtimeArgs = GetRuntimeOptionsFromCommandLine(args); return MainWithArgs(runtimeArgs); +#if !DEBUG } catch (DllSaveException e) { @@ -203,6 +206,7 @@ public static int Main(string[] args) Logger.ErrorNewline($"Execution Failed: {e.Message}"); return -1; } +#endif } public static int MainWithArgs(Cpp2IlRuntimeArgs runtimeArgs)