private void WritePointer(IndentedTextWriter writer, PointerNode node) { writer.Write("Ptr["); // Pointer to class or to aliased basic type if (node.InnerNode is ClassInstanceNode ptrInstanceNode) { var className = ptrInstanceNode.InnerNode.Name; // Pointer to basic type (Class with name of basic type) if (nodeTypeToTypeDefinationMap.ContainsValue(className)) { writer.Write($"{pygamehackExt.BasicTypePrefix}{className}"); } // Pointer to class else { writer.Write(className); } } // Pointer to basic type var simpleTypePtr = GetSimpleType(node); if (simpleTypePtr != null) { writer.Write(simpleTypePtr); } // Closing bracket writer.Write("]"); }
private static bool GuessPointerNode(IntPtr address, IProcessReader process, out BaseNode node) { Contract.Requires(process != null); node = null; if (address.IsNull()) { return(false); } var section = process.GetSectionToPointer(address); if (section == null) { return(false); } if (section.Category == SectionCategory.CODE) // If the section contains code, it should be a function pointer. { node = new FunctionPtrNode(); return(true); } if (section.Category == SectionCategory.DATA || section.Category == SectionCategory.HEAP) // If the section contains data, it is at least a pointer to a class or something. { // Check if it is a vtable. Check if the first 3 values are pointers to a code section. var possibleVmt = process.ReadRemoteObject <ThreePointersData>(address); if (process.GetSectionToPointer(possibleVmt.Pointer1)?.Category == SectionCategory.CODE && process.GetSectionToPointer(possibleVmt.Pointer2)?.Category == SectionCategory.CODE && process.GetSectionToPointer(possibleVmt.Pointer3)?.Category == SectionCategory.CODE) { node = new VirtualMethodTableNode(); return(true); } // Check if it is a string. var data = process.ReadRemoteMemory(address, IntPtr.Size * 2); if (data.Take(IntPtr.Size).InterpretAsSingleByteCharacter().IsLikelyPrintableData()) { node = new Utf8TextPtrNode(); return(true); } if (data.InterpretAsDoubleByteCharacter().IsLikelyPrintableData()) { node = new Utf16TextPtrNode(); return(true); } // Now it could be a pointer to something else but we can't tell. :( node = new PointerNode(); return(true); } return(false); }
/// <summary> /// Transforms the given node into some other node if necessary. /// </summary> /// <param name="node">The node to transform.</param> /// <returns>The transformed node.</returns> private static BaseNode TransformNode(BaseNode node) { var custom = GetCustomCodeGeneratorForNode(node); if (custom != null) { return(custom.TransformNode(node)); } BaseNode GetCharacterNodeForEncoding(Encoding encoding) { if (encoding.IsSameCodePage(Encoding.Unicode)) { return(new Utf16CharacterNode()); } if (encoding.IsSameCodePage(Encoding.UTF32)) { return(new Utf32CharacterNode()); } return(new Utf8CharacterNode()); } if (node is BaseTextNode textNode) { var arrayNode = new ArrayNode { Count = textNode.Length }; arrayNode.CopyFromNode(node); arrayNode.ChangeInnerNode(GetCharacterNodeForEncoding(textNode.Encoding)); return(arrayNode); } if (node is BaseTextPtrNode textPtrNode) { var pointerNode = new PointerNode(); pointerNode.CopyFromNode(node); pointerNode.ChangeInnerNode(GetCharacterNodeForEncoding(textPtrNode.Encoding)); return(pointerNode); } if (node is BitFieldNode bitFieldNode) { var underlayingNode = bitFieldNode.GetUnderlayingNode(); underlayingNode.CopyFromNode(node); return(underlayingNode); } if (node is BaseHexNode hexNode) { var arrayNode = new ArrayNode { Count = hexNode.MemorySize }; arrayNode.CopyFromNode(node); arrayNode.ChangeInnerNode(new Utf8CharacterNode()); return(arrayNode); } return(node); }
public BaseNode GetEquivalentNode(ClassNode classNode) { var classInstanceNode = new ClassInstanceNode(); classInstanceNode.ChangeInnerNode(classNode); var pointerNode = new PointerNode(); pointerNode.ChangeInnerNode(classInstanceNode); pointerNode.CopyFromNode(this); return(pointerNode); }
public override BaseNode GetEquivalentNode(int count, ClassNode classNode) { var classInstanceNode = new ClassInstanceNode(); classInstanceNode.ChangeInnerNode(classNode); var pointerNode = new PointerNode(); pointerNode.ChangeInnerNode(classInstanceNode); var arrayNode = new ArrayNode { Count = count }; arrayNode.ChangeInnerNode(pointerNode); arrayNode.CopyFromNode(this); return(arrayNode); }
public virtual T VisitPointer(PointerNode pointer) { throw new NotImplementedException(); }
public string VisitPointer(PointerNode pointer) { throw new NotImplementedException(); }
public AddressNode VisitPointer(PointerNode pointer) { throw new System.NotImplementedException(); }