diff --git a/Il2CppInspector.Common/Cpp/UnityHeaders/UnityHeaders.cs b/Il2CppInspector.Common/Cpp/UnityHeaders/UnityHeaders.cs index f0045bf..98fbbbc 100644 --- a/Il2CppInspector.Common/Cpp/UnityHeaders/UnityHeaders.cs +++ b/Il2CppInspector.Common/Cpp/UnityHeaders/UnityHeaders.cs @@ -5,13 +5,14 @@ All rights reserved. */ +using Il2CppInspector.Next; +using Spectre.Console; using System; -using System.Linq; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using System.Linq; using System.Text.RegularExpressions; -using Il2CppInspector.Next; using VersionedSerialization; namespace Il2CppInspector.Cpp.UnityHeaders @@ -140,7 +141,7 @@ namespace Il2CppInspector.Cpp.UnityHeaders // No il2cpp exports? Just return the earliest version from the header range // The API version may be incorrect but should be a subset of the real API and won't cause C++ compile errors if (!exports.Any()) { - Console.WriteLine("No IL2CPP API exports found in binary - IL2CPP APIs will be unavailable in C++ project"); + AnsiConsole.WriteLine("No IL2CPP API exports found in binary - IL2CPP APIs will be unavailable in C++ project"); return typeHeaders.Select(t => new UnityHeaders(t, apis.Last(a => a.VersionRange.Intersect(t.VersionRange) != null))).ToList(); @@ -161,7 +162,7 @@ namespace Il2CppInspector.Cpp.UnityHeaders if (apiMatches.Any()) { // Intersect all API ranges with all header ranges to produce final list of possible ranges - Console.WriteLine("IL2CPP API discovery was successful"); + AnsiConsole.WriteLine("IL2CPP API discovery was successful"); return typeHeaders.SelectMany( t => apiMatches.Where(a => t.VersionRange.Intersect(a.VersionRange) != null) @@ -170,7 +171,7 @@ namespace Il2CppInspector.Cpp.UnityHeaders // None of the possible API versions match the binary // Select the oldest API version from the group - C++ project compilation will fail - Console.WriteLine("No exact match for IL2CPP APIs found in binary - IL2CPP API availability in C++ project will be partial"); + AnsiConsole.WriteLine("No exact match for IL2CPP APIs found in binary - IL2CPP API availability in C++ project will be partial"); return typeHeaders.Select(t => new UnityHeaders(t, apis.Last(a => a.VersionRange.Intersect(t.VersionRange) != null))).ToList(); diff --git a/Il2CppInspector.Common/FileFormatStreams/AABReader.cs b/Il2CppInspector.Common/FileFormatStreams/AABReader.cs index de85280..a69a15d 100644 --- a/Il2CppInspector.Common/FileFormatStreams/AABReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/AABReader.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using Spectre.Console; using System; using System.Collections.Generic; using System.IO; @@ -51,7 +52,7 @@ namespace Il2CppInspector public override IFileFormatStream this[uint index] { get { - Console.WriteLine($"Extracting binary from {binaryFiles[index].FullName}"); + AnsiConsole.WriteLine($"Extracting binary from {binaryFiles[index].FullName}"); IFileFormatStream loaded = null; // ZipArchiveEntry does not support seeking so we have to close and re-open for each possible load format diff --git a/Il2CppInspector.Common/FileFormatStreams/APKReader.cs b/Il2CppInspector.Common/FileFormatStreams/APKReader.cs index e970bed..1ad5e35 100644 --- a/Il2CppInspector.Common/FileFormatStreams/APKReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/APKReader.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using Spectre.Console; using System; using System.Collections.Generic; using System.IO; @@ -51,7 +52,7 @@ namespace Il2CppInspector public override IFileFormatStream this[uint index] { get { - Console.WriteLine($"Extracting binary from {binaryFiles[index].FullName}"); + AnsiConsole.WriteLine($"Extracting binary from {binaryFiles[index].FullName}"); IFileFormatStream loaded = null; // ZipArchiveEntry does not support seeking so we have to close and re-open for each possible load format diff --git a/Il2CppInspector.Common/FileFormatStreams/ElfReader.cs b/Il2CppInspector.Common/FileFormatStreams/ElfReader.cs index 02eabbc..8badedc 100644 --- a/Il2CppInspector.Common/FileFormatStreams/ElfReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/ElfReader.cs @@ -5,6 +5,7 @@ All rights reserved. */ +using Spectre.Console; using System; using System.Collections.Generic; using System.Linq; @@ -160,7 +161,7 @@ namespace Il2CppInspector } catch (Exception ex) { - Console.WriteLine($"Got exception {ex} while parsing SHT - reverting to PHT"); + AnsiConsole.WriteLine($"Got exception {ex} while parsing SHT - reverting to PHT"); preferPHT = true; SHT = []; } @@ -170,12 +171,12 @@ namespace Il2CppInspector // These can happen as a result of conversions from other formats to ELF, // or if the SHT has been deliberately stripped if (!SHT.Any()) { - Console.WriteLine("ELF binary has no SHT - reverting to PHT"); + AnsiConsole.WriteLine("ELF binary has no SHT - reverting to PHT"); preferPHT = true; } else if (SHT.All(s => conv.ULong(s.sh_addr) == 0ul)) { - Console.WriteLine("ELF binary SHT is all-zero - reverting to PHT"); + AnsiConsole.WriteLine("ELF binary SHT is all-zero - reverting to PHT"); preferPHT = true; } @@ -192,7 +193,7 @@ namespace Il2CppInspector // If the first file offset of the first PHT is zero, assume a dumped image if (PHT.Any(t => conv.ULong(t.p_vaddr) == 0ul)) { - Console.WriteLine("ELF binary appears to be a dumped memory image"); + AnsiConsole.WriteLine("ELF binary appears to be a dumped memory image"); isMemoryImage = true; } preferPHT = true; @@ -202,7 +203,7 @@ namespace Il2CppInspector else { var shtOverlap = shtShouldBeOrdered.Aggregate((x, y) => x <= y? y : ulong.MaxValue) == ulong.MaxValue; if (shtOverlap) { - Console.WriteLine("ELF binary SHT contains invalid ranges - reverting to PHT"); + AnsiConsole.WriteLine("ELF binary SHT contains invalid ranges - reverting to PHT"); preferPHT = true; } } @@ -361,7 +362,7 @@ namespace Il2CppInspector WriteWord(result.newValue); } } - Console.WriteLine($"Processed {rels.Count} relocations"); + AnsiConsole.WriteLine($"Processed {rels.Count} relocations"); // Build symbol and export tables processSymbols(); diff --git a/Il2CppInspector.Common/FileFormatStreams/MachOReader.cs b/Il2CppInspector.Common/FileFormatStreams/MachOReader.cs index 409dd0d..8285302 100644 --- a/Il2CppInspector.Common/FileFormatStreams/MachOReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/MachOReader.cs @@ -4,12 +4,13 @@ All rights reserved. */ +using NoisyCowStudios.Bin2Object; +using Spectre.Console; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using NoisyCowStudios.Bin2Object; namespace Il2CppInspector { @@ -194,7 +195,7 @@ namespace Il2CppInspector // TODO: Implement Mach-O relocations if (rels.Any()) { - Console.WriteLine("Mach-O file contains relocations (feature not yet implemented)"); + AnsiConsole.WriteLine("Mach-O file contains relocations (feature not yet implemented)"); break; } } @@ -288,7 +289,7 @@ namespace Il2CppInspector : SymbolType.Unknown; if (type == SymbolType.Unknown) { - Console.WriteLine($"Unknown symbol type: {((int) ntype):x2} {value:x16} {name}"); + AnsiConsole.WriteLine($"Unknown symbol type: {((int) ntype):x2} {value:x16} {name}"); } // Ignore duplicates @@ -301,13 +302,13 @@ namespace Il2CppInspector var chainedFixupsHeader = ReadVersionedObject(info.Offset); if (chainedFixupsHeader.FixupsVersion != 0) { - Console.WriteLine($"Unsupported chained fixups version: {chainedFixupsHeader.FixupsVersion}"); + AnsiConsole.WriteLine($"Unsupported chained fixups version: {chainedFixupsHeader.FixupsVersion}"); return; } if (chainedFixupsHeader.ImportsFormat != 1 /* DYLD_CHAINED_IMPORT */) { - Console.WriteLine($"Unsupported chained fixups import format: {chainedFixupsHeader.ImportsFormat}"); + AnsiConsole.WriteLine($"Unsupported chained fixups import format: {chainedFixupsHeader.ImportsFormat}"); return; } diff --git a/Il2CppInspector.Common/FileFormatStreams/PEReader.cs b/Il2CppInspector.Common/FileFormatStreams/PEReader.cs index 13b77ff..7139fd6 100644 --- a/Il2CppInspector.Common/FileFormatStreams/PEReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/PEReader.cs @@ -4,13 +4,14 @@ All rights reserved. */ +using NoisyCowStudios.Bin2Object; +using Spectre.Console; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; -using NoisyCowStudios.Bin2Object; namespace Il2CppInspector { @@ -102,7 +103,7 @@ namespace Il2CppInspector // Unpacking must be done starting here, one byte after the end of the headers // Packed or previously packed with Themida? This is purely for information if (sections.FirstOrDefault(x => x.Name == ".themida") is PESection _) - Console.WriteLine("Themida protection detected"); + AnsiConsole.WriteLine("Themida protection detected"); // Packed with anything (including Themida)? mightBePacked = sections.FirstOrDefault(x => x.Name == ".rdata") is null; diff --git a/Il2CppInspector.Common/FileFormatStreams/ProcessMapReader.cs b/Il2CppInspector.Common/FileFormatStreams/ProcessMapReader.cs index db30fe9..24ac35e 100644 --- a/Il2CppInspector.Common/FileFormatStreams/ProcessMapReader.cs +++ b/Il2CppInspector.Common/FileFormatStreams/ProcessMapReader.cs @@ -4,11 +4,12 @@ All rights reserved. */ +using NoisyCowStudios.Bin2Object; +using Spectre.Console; using System; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using NoisyCowStudios.Bin2Object; namespace Il2CppInspector { @@ -100,7 +101,7 @@ namespace Il2CppInspector // Get the entire remaining chunk, or to the end of the file if it doesn't contain the end of the chunk var length = (uint) Math.Min(chunk.Memory.End - memoryNext, source.Length); - Console.WriteLine($"Writing {length:x8} bytes from {Path.GetFileName(file.Name)} +{fileStart:x8} ({memoryNext:x8}) to target {il2cpp.Position:x8}"); + AnsiConsole.WriteLine($"Writing {length:x8} bytes from {Path.GetFileName(file.Name)} +{fileStart:x8} ({memoryNext:x8}) to target {il2cpp.Position:x8}"); // Can't use Stream.CopyTo as it doesn't support length parameter var buffer = new byte[length]; diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index 42503c9..cb65d57 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -6,12 +6,13 @@ */ using Il2CppInspector.Next; +using Il2CppInspector.Next.BinaryMetadata; +using Il2CppInspector.Next.Metadata; +using Spectre.Console; using System.Collections.Immutable; using System.Diagnostics; using System.Reflection; using System.Text.RegularExpressions; -using Il2CppInspector.Next.BinaryMetadata; -using Il2CppInspector.Next.Metadata; using VersionedSerialization; namespace Il2CppInspector @@ -191,7 +192,7 @@ namespace Il2CppInspector var symbols = Image.GetSymbolTable(); if (symbols.Any()) { - Console.WriteLine($"Symbol table(s) found with {symbols.Count} entries"); + AnsiConsole.WriteLine($"Symbol table(s) found with {symbols.Count} entries"); symbols.TryGetValue("g_CodeRegistration", out var code); symbols.TryGetValue("g_MetadataRegistration", out var metadata); @@ -202,13 +203,13 @@ namespace Il2CppInspector symbols.TryGetValue("_g_MetadataRegistration", out metadata); if (code != null && metadata != null) { - Console.WriteLine("Required structures acquired from symbol lookup"); + AnsiConsole.WriteLine("Required structures acquired from symbol lookup"); return (code.VirtualAddress, metadata.VirtualAddress); } else { - Console.WriteLine("No matches in symbol table"); + AnsiConsole.WriteLine("No matches in symbol table"); } } else if (symbols != null) { - Console.WriteLine("No symbol table present in binary file"); + AnsiConsole.WriteLine("No symbol table present in binary file"); } else { Console.WriteLine("Symbol table search not implemented for this binary format"); } @@ -227,12 +228,12 @@ namespace Il2CppInspector var (code, metadata) = ConsiderCode(Image, loc); if (code != 0) { RegistrationFunctionPointer = loc + Image.GlobalOffset; - Console.WriteLine("Required structures acquired from code heuristics. Initialization function: 0x{0:X16}", RegistrationFunctionPointer); + AnsiConsole.WriteLine("Required structures acquired from code heuristics. Initialization function: 0x{0:X16}", RegistrationFunctionPointer); return (code, metadata); } } - Console.WriteLine("No matches via code heuristics"); + AnsiConsole.WriteLine("No matches via code heuristics"); return null; } @@ -244,11 +245,11 @@ namespace Il2CppInspector var (codePtr, metadataPtr) = ImageScan(Metadata); if (codePtr == 0) { - Console.WriteLine("No matches via data heuristics"); + AnsiConsole.WriteLine("No matches via data heuristics"); return null; } - Console.WriteLine("Required structures acquired from data heuristics"); + AnsiConsole.WriteLine("Required structures acquired from data heuristics"); return (codePtr, metadataPtr); } @@ -274,8 +275,8 @@ namespace Il2CppInspector var pointerSize = Image.Bits == 32 ? 4u : 8u; - Console.WriteLine("CodeRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? codeRegistration & 0xffff_ffff : codeRegistration, Image.MapVATR(codeRegistration)); - Console.WriteLine("MetadataRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? metadataRegistration & 0xffff_ffff : metadataRegistration, Image.MapVATR(metadataRegistration)); + AnsiConsole.WriteLine("CodeRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? codeRegistration & 0xffff_ffff : codeRegistration, Image.MapVATR(codeRegistration)); + AnsiConsole.WriteLine("MetadataRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? metadataRegistration & 0xffff_ffff : metadataRegistration, Image.MapVATR(metadataRegistration)); // Root structures from which we find everything else CodeRegistration = Image.ReadMappedVersionedObject(codeRegistration); diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs index 9ee970f..24e52eb 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs @@ -5,8 +5,11 @@ */ using Il2CppInspector.Next; +using Il2CppInspector.Next.BinaryMetadata; +using Il2CppInspector.Next.Metadata; using Il2CppInspector.Utils; using NoisyCowStudios.Bin2Object; +using Spectre.Console; using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -14,8 +17,6 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Text; -using Il2CppInspector.Next.BinaryMetadata; -using Il2CppInspector.Next.Metadata; using VersionedSerialization; namespace Il2CppInspector @@ -410,7 +411,7 @@ namespace Il2CppInspector if (metadataFile != null) { // Extract the metadata file to memory if (!silent) - Console.WriteLine($"Extracting metadata from (archive){Path.DirectorySeparatorChar}{metadataFile.FullName}"); + AnsiConsole.WriteLine($"Extracting metadata from (archive){Path.DirectorySeparatorChar}{metadataFile.FullName}"); metadataMemoryStream = new MemoryStream(); using var metadataStream = metadataFile.Open(); @@ -428,7 +429,7 @@ namespace Il2CppInspector // IPAs will only have one binary (which may or may not be a UB covering multiple architectures) if (ipaBinaryFolder != null) { if (!silent) - Console.WriteLine($"Extracting binary from {zipStreams.First()}{Path.DirectorySeparatorChar}{binaryFiles.First().FullName}"); + AnsiConsole.WriteLine($"Extracting binary from {zipStreams.First()}{Path.DirectorySeparatorChar}{binaryFiles.First().FullName}"); // Extract the binary file or package to memory binaryMemoryStream = new MemoryStream(); @@ -531,7 +532,7 @@ namespace Il2CppInspector return null; } - Console.WriteLine("Detected metadata version " + metadata.Version); + AnsiConsole.WriteLine("Detected metadata version " + metadata.Version); // Load the il2cpp code file (try all available file formats) IFileFormatStream stream; @@ -559,16 +560,16 @@ namespace Il2CppInspector var processors = new List(); foreach (var image in stream.Images) { - Console.WriteLine("Container format: " + image.Format); - Console.WriteLine("Container endianness: " + ((BinaryObjectStream) image).Endianness); - Console.WriteLine("Architecture word size: {0}-bit", image.Bits); - Console.WriteLine("Instruction set: " + image.Arch); - Console.WriteLine("Global offset: 0x{0:X16}", image.GlobalOffset); + AnsiConsole.WriteLine("Container format: " + image.Format); + AnsiConsole.WriteLine("Container endianness: " + ((BinaryObjectStream) image).Endianness); + AnsiConsole.WriteLine("Architecture word size: {0}-bit", image.Bits); + AnsiConsole.WriteLine("Instruction set: " + image.Arch); + AnsiConsole.WriteLine("Global offset: 0x{0:X16}", image.GlobalOffset); // Architecture-agnostic load attempt try { if (Il2CppBinary.Load(image, metadata, statusCallback) is Il2CppBinary binary) { - Console.WriteLine("IL2CPP binary version " + image.Version); + AnsiConsole.WriteLine("IL2CPP binary version " + image.Version); processors.Add(new Il2CppInspector(binary, metadata)); } diff --git a/Il2CppInspector.Common/Il2CppInspector.csproj b/Il2CppInspector.Common/Il2CppInspector.csproj index 23462ef..073a79c 100644 --- a/Il2CppInspector.Common/Il2CppInspector.csproj +++ b/Il2CppInspector.Common/Il2CppInspector.csproj @@ -42,6 +42,7 @@ + diff --git a/Il2CppInspector.Common/Model/AppModel.cs b/Il2CppInspector.Common/Model/AppModel.cs index d7127e7..b4e0cb0 100644 --- a/Il2CppInspector.Common/Model/AppModel.cs +++ b/Il2CppInspector.Common/Model/AppModel.cs @@ -14,6 +14,7 @@ using Il2CppInspector.Cpp; using Il2CppInspector.Cpp.UnityHeaders; using Il2CppInspector.Next; using Il2CppInspector.Reflection; +using Spectre.Console; namespace Il2CppInspector.Model { @@ -152,12 +153,12 @@ namespace Il2CppInspector.Model UnityHeaders = unityVersion != null ? UnityHeaders.GetHeadersForVersion(unityVersion) : UnityHeaders.GuessHeadersForBinary(TypeModel.Package.Binary).Last(); UnityVersion = unityVersion ?? UnityHeaders.VersionRange.Min; - Console.WriteLine($"Selected Unity version(s) {UnityHeaders.VersionRange} (types: {UnityHeaders.TypeHeaderResource.VersionRange}, APIs: {UnityHeaders.APIHeaderResource.VersionRange})"); + AnsiConsole.WriteLine($"Selected Unity version(s) {UnityHeaders.VersionRange} (types: {UnityHeaders.TypeHeaderResource.VersionRange}, APIs: {UnityHeaders.APIHeaderResource.VersionRange})"); // Check for matching metadata and binary versions if (UnityHeaders.MetadataVersion != Image.Version) { - Console.WriteLine($"Warning: selected version {UnityVersion} (metadata version {UnityHeaders.MetadataVersion})" + - $" does not match metadata version {Image.Version}."); + AnsiConsole.WriteLine($"Warning: selected version {UnityVersion} (metadata version {UnityHeaders.MetadataVersion})" + + $" does not match metadata version {Image.Version}."); } // Initialize declaration generator to process every type in the binary diff --git a/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs b/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs index 991be6c..d7e53de 100644 --- a/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs +++ b/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs @@ -4,6 +4,11 @@ All rights reserved. */ +using Il2CppInspector.PluginAPI; +// This is the ONLY line to update when the API version changes +using Il2CppInspector.PluginAPI.V100; +using McMaster.NETCore.Plugins; +using Spectre.Console; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -12,11 +17,6 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using McMaster.NETCore.Plugins; -using Il2CppInspector.PluginAPI; - -// This is the ONLY line to update when the API version changes -using Il2CppInspector.PluginAPI.V100; namespace Il2CppInspector { diff --git a/Il2CppInspector.Common/Utils/BlobReader.cs b/Il2CppInspector.Common/Utils/BlobReader.cs index 0d6705c..882a1b9 100644 --- a/Il2CppInspector.Common/Utils/BlobReader.cs +++ b/Il2CppInspector.Common/Utils/BlobReader.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using Il2CppInspector.Next; using Il2CppInspector.Next.BinaryMetadata; using Il2CppInspector.Next.Metadata; +using Spectre.Console; namespace Il2CppInspector.Utils; @@ -122,7 +123,7 @@ public static class BlobReader } catch (InvalidDataException) { - Console.WriteLine($"Found invalid compressed int at metadata address 0x{address:x8}. Reading as normal int."); + AnsiConsole.WriteLine($"Found invalid compressed int at metadata address 0x{address:x8}. Reading as normal int."); return blob.ReadInt32(address); } } @@ -142,7 +143,7 @@ public static class BlobReader } catch (InvalidDataException) { - Console.WriteLine($"Found invalid compressed uint at metadata address 0x{address:x8}. Reading as normal uint."); + AnsiConsole.WriteLine($"Found invalid compressed uint at metadata address 0x{address:x8}. Reading as normal uint."); return blob.ReadUInt32(address); } }