Skip to content

Commit

Permalink
Support reading python object type "Link"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Viir committed May 26, 2024
1 parent a8b3f1f commit ac4fc80
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions implement/read-memory-64-bit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -738,7 +738,12 @@ struct LocalMemoryReadingTools
.Add("bool", new Func<ulong, LocalMemoryReadingTools, object>(ReadingFromPythonType_bool))
.Add("float", new Func<ulong, LocalMemoryReadingTools, object>(ReadingFromPythonType_float))
.Add("PyColor", new Func<ulong, LocalMemoryReadingTools, object>(ReadingFromPythonType_PyColor))
.Add("Bunch", new Func<ulong, LocalMemoryReadingTools, object>(ReadingFromPythonType_Bunch));
.Add("Bunch", new Func<ulong, LocalMemoryReadingTools, object>(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<ulong, LocalMemoryReadingTools, object>(ReadingFromPythonType_Link));

static object ReadingFromPythonType_str(ulong address, LocalMemoryReadingTools memoryReadingTools)
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit ac4fc80

Please sign in to comment.