/// <summary> /// returns the Root of the UITree. /// </summary> /// <param name="MemoryReader"></param> /// <returns></returns> static public UITreeNode UIRoot( IPythonMemoryReader MemoryReader) { var CandidateAddresses = PyTypeObject.EnumeratePossibleAddressesOfInstancesOfPythonTypeFilteredByObType(MemoryReader, "UIRoot"); var CandidatesWithChildrenCount = new List <KeyValuePair <UITreeNode, int> >(); foreach (var CandidateAddress in CandidateAddresses) { var Candidate = new UITreeNode(CandidateAddress, MemoryReader); int CandidateChildrenCount = 0; { var CandidateChildren = Candidate.EnumerateChildrenTransitive(MemoryReader); if (null != CandidateChildren) { CandidateChildrenCount = CandidateChildren.Count(); } } CandidatesWithChildrenCount.Add(new KeyValuePair <UITreeNode, int>(Candidate, CandidateChildrenCount)); } // return the candidate the most children nodes where found in. return (CandidatesWithChildrenCount .OrderByDescending((CandidateWithChildrenCount) => CandidateWithChildrenCount.Value) .FirstOrDefault() .Key); }
public PyTypeObject LoadType(IPythonMemoryReader MemoryReader) { if (ob_type.HasValue) { TypeObject = MemoryReader.TypeFromAddress(ob_type.Value); } return(TypeObject); }
PyTypeObject IPythonMemoryReader.TypeFromAddress(uint TypeObjectAddress) { PyTypeObject TypeObject; if (CacheTypeObject.TryGetValue(TypeObjectAddress, out TypeObject)) { return(TypeObject); } TypeObject = new PyTypeObject(TypeObjectAddress, MemoryReader); CacheTypeObject[TypeObjectAddress] = TypeObject; return(TypeObject); }
/// <summary> /// enumerates the subset of Addresses that satisfy this condition: /// +interpreted as the Address of a Python Type Object, the tp_name of this Object Equals <paramref name="tp_name"/> /// </summary> /// <param name="TypeObjectAddresses"></param> /// <param name="MemoryReader"></param> /// <param name="tp_name"></param> /// <returns></returns> static public IEnumerable <PyTypeObject> TypeObjectAddressesFilterByTpName( IEnumerable <UInt32> TypeObjectAddresses, IMemoryReader MemoryReader, string tp_name) { if (null == TypeObjectAddresses || null == MemoryReader) { yield break; } foreach (var CandidateTypeAddress in TypeObjectAddresses) { var PyType = new PyTypeObject(CandidateTypeAddress, MemoryReader); if (!string.Equals(PyType.tp_name_Val, tp_name)) { continue; } yield return(PyType); } }
/// <summary> /// the enumerated set contains all addresses of Python Objects of the type with the given <paramref name="tp_name"/>. /// /// the addresses are only filtered for appropriate ob_type. /// </summary> /// <param name="MemoryReader"></param> /// <param name="tp_name"></param> /// <returns></returns> static public IEnumerable <UInt32> EnumeratePossibleAddressesOfInstancesOfPythonTypeFilteredByObType( IMemoryReader MemoryReader, string tp_name) { var CandidatesTypeObjectType = PyTypeObject.FindCandidatesTypeObjectTypeAddress(MemoryReader); var TypeObjectType = PyTypeObject.TypeObjectAddressesFilterByTpName(CandidatesTypeObjectType, MemoryReader, "type").FirstOrDefault(); if (null == TypeObjectType) { yield break; } // finds candidate Addresses for Objects of type "type" with only requiring them to have a appropriate value for ob_type. var TypeCandidateAddressesPlus4 = MemoryReader.AddressesHoldingValue32Aligned32((UInt32)TypeObjectType.BaseAddress, 0, Int32.MaxValue) .ToArray(); var TypeCandidateAddresses = TypeCandidateAddressesPlus4 .Select((Address) => (UInt32)(Address - 4)) .ToArray(); var TypeObjectsWithProperName = PyTypeObject.TypeObjectAddressesFilterByTpName(TypeCandidateAddresses, MemoryReader, tp_name) .ToArray(); foreach (var TypeObject in TypeObjectsWithProperName) { // finds candidate Addresses for Objects of type tp_name with only requiring them to have a appropriate value for ob_type. foreach (var CandidateForObjectOfTypeAddressPlus4 in MemoryReader.AddressesHoldingValue32Aligned32((UInt32)TypeObject.BaseAddress, 0, Int32.MaxValue)) { yield return((UInt32)(CandidateForObjectOfTypeAddressPlus4 - 4)); } } }