public SourceLocation(ReadOnlyCollection <byte> encodedLocation, DkmProcess process = null) { var buffer = encodedLocation.ToArray(); using (var stream = new MemoryStream(buffer)) using (var reader = new BinaryReader(stream)) { FileName = reader.ReadString(); bool hasFunctionName = reader.ReadBoolean(); if (hasFunctionName) { FunctionName = reader.ReadString(); } LineNumber = reader.ReadInt32(); bool hasNativeAddress = reader.ReadBoolean(); if (hasNativeAddress && process != null) { var ip = reader.ReadUInt64(); var rva = reader.ReadUInt32(); PythonDLLs dlls = process.GetPythonRuntimeInfo().DLLs; DkmNativeModuleInstance dll = null; switch (reader.ReadInt32()) { case 0: dll = dlls.Python; break; case 1: dll = dlls.DebuggerHelper; break; } if (dll != null) { NativeAddress = DkmNativeInstructionAddress.Create( process.GetNativeRuntimeInstance(), dll, rva, new DkmNativeInstructionAddress.CPUInstruction(ip)); } } else { NativeAddress = null; } } }
public ReadOnlyCollection <byte> Encode() { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { writer.Write(FileName); if (FunctionName != null) { writer.Write(true); writer.Write(FunctionName); } else { writer.Write(false); } writer.Write(LineNumber); if (NativeAddress != null) { writer.Write(true); writer.Write(NativeAddress.CPUInstructionPart.InstructionPointer); writer.Write(NativeAddress.RVA); PythonDLLs dlls = NativeAddress.Process.GetPythonRuntimeInfo().DLLs; if (NativeAddress.ModuleInstance == dlls.Python) { writer.Write(0); } else if (NativeAddress.ModuleInstance == dlls.DebuggerHelper) { writer.Write(1); } } else { writer.Write(false); } writer.Flush(); return(new ReadOnlyCollection <byte>(stream.ToArray())); } }