From 9c172c351977eb2b4ad867b91b9083b6fdb236f2 Mon Sep 17 00:00:00 2001 From: ComeInRage Date: Wed, 18 Oct 2023 00:32:52 +0300 Subject: [PATCH] Add support for root-address flag when reading from saved sample --- implement/read-memory-64-bit/Program.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/implement/read-memory-64-bit/Program.cs b/implement/read-memory-64-bit/Program.cs index fb53357..8919aaa 100644 --- a/implement/read-memory-64-bit/Program.cs +++ b/implement/read-memory-64-bit/Program.cs @@ -124,6 +124,22 @@ static int Main(string[] args) return (memoryReader, uiRootCandidatesAddresses); } + (IMemoryReader, IImmutableList) GetMemoryReaderAndWithSpecifiedRootFromProcessSampleFile(byte[] processSampleFile, ulong rootAddress) + { + var processSampleId = Pine.CommonConversion.StringBase16FromByteArray( + Pine.CommonConversion.HashSHA256(processSampleFile)); + + Console.WriteLine($"Reading from process sample {processSampleId}."); + + var processSampleUnpacked = ProcessSample.ProcessSampleFromZipArchive(processSampleFile); + + var memoryReader = new MemoryReaderFromProcessSample(processSampleUnpacked.memoryRegions); + + Console.WriteLine($"Reading UIRoot from specified address: {rootAddress}"); + + return (memoryReader, ImmutableList.Empty.Add(rootAddress)); + } + (IMemoryReader, IImmutableList) GetMemoryReaderAndRootAddresses() { if (processId.HasValue) @@ -141,6 +157,11 @@ static int Main(string[] args) throw new Exception("Where should I read from?"); } + if (0 < rootAddressArgument?.Length) + { + return GetMemoryReaderAndWithSpecifiedRootFromProcessSampleFile(System.IO.File.ReadAllBytes(sourceFileArgument), ParseULong(rootAddressArgument)); + } + return GetMemoryReaderAndRootAddressesFromProcessSampleFile(System.IO.File.ReadAllBytes(sourceFileArgument)); }