From ac4fc8034cd42e422965432ad500fc67d21ce4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Sun, 26 May 2024 19:21:58 +0000 Subject: [PATCH] Support reading python object type "Link" Today we discovered the old way of reading 'Current Solar System' did not work anymore. It turned out that the '_setText' property of the label now references an object of type 'Link', which in turn contained a reference to a dictionary. That dictionary contains the properties of interest, three strings with keys '_alt', '_text', and '_url'. The '_text' property contained the current solar system name string as shown to the user. --- implement/read-memory-64-bit/Program.cs | 52 ++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/implement/read-memory-64-bit/Program.cs b/implement/read-memory-64-bit/Program.cs index 34b89af..1864189 100644 --- a/implement/read-memory-64-bit/Program.cs +++ b/implement/read-memory-64-bit/Program.cs @@ -10,7 +10,7 @@ namespace read_memory_64_bit; class Program { - static string AppVersionId => "2024-05-25"; + static string AppVersionId => "2024-05-26"; static int Main(string[] args) { @@ -738,7 +738,12 @@ struct LocalMemoryReadingTools .Add("bool", new Func(ReadingFromPythonType_bool)) .Add("float", new Func(ReadingFromPythonType_float)) .Add("PyColor", new Func(ReadingFromPythonType_PyColor)) - .Add("Bunch", new Func(ReadingFromPythonType_Bunch)); + .Add("Bunch", new Func(ReadingFromPythonType_Bunch)) + /* + * 2024-05-26 observed dict entry with key "_setText" pointing to a python object of type "Link". + * The client used that instance of "Link" to display "Current Solar System" label in the location info panel. + * */ + .Add("Link", new Func(ReadingFromPythonType_Link)); static object ReadingFromPythonType_str(ulong address, LocalMemoryReadingTools memoryReadingTools) { @@ -876,6 +881,49 @@ static object ReadingFromPythonType_Bunch(ulong address, LocalMemoryReadingTools ); } + static object ReadingFromPythonType_Link(ulong address, LocalMemoryReadingTools memoryReadingTools) + { + var pythonObjectTypeName = memoryReadingTools.GetPythonTypeNameFromPythonObjectAddress(address); + + var linkMemory = memoryReadingTools.memoryReader.ReadBytes(address, 0x40); + + if (linkMemory is null) + return null; + + var linkMemoryAsLongMemory = TransformMemoryContent.AsULongMemory(linkMemory.Value); + + /* + * 2024-05-26 observed a reference to a dictionary object at offset 6 * 4 bytes. + * */ + + var firstDictReference = + linkMemoryAsLongMemory + .ToArray() + .Where(reference => + { + var referencedObjectTypeName = memoryReadingTools.GetPythonTypeNameFromPythonObjectAddress(reference); + + return referencedObjectTypeName is "dict"; + }) + .FirstOrDefault(); + + if (firstDictReference is 0) + return null; + + var dictEntries = + memoryReadingTools.getDictionaryEntriesWithStringKeys(firstDictReference) + ?.ToImmutableDictionary( + keySelector: dictEntry => dictEntry.Key, + elementSelector: dictEntry => memoryReadingTools.GetDictEntryValueRepresentation(dictEntry.Value)); + + return new UITreeNode( + pythonObjectAddress: address, + pythonObjectTypeName: pythonObjectTypeName, + dictEntriesOfInterest: dictEntries, + otherDictEntriesKeys: null, + children: null); + } + class MemoryReadingCache {