/// <summary> /// Initializes a new instance of the <see cref="CodeFunction" /> class. /// </summary> /// <param name="address">The function address.</param> /// <param name="process">The process.</param> public CodeFunction(ulong address, Process process = null) { Address = address; Process = process ?? Process.Current; sourceFileNameAndLine = SimpleCache.Create(ReadSourceFileNameAndLine); functionNameAndDisplacement = SimpleCache.Create(ReadFunctionNameAndDisplacement); }
/// <summary> /// Initializes a new instance of the <see cref="Module" /> class. /// </summary> /// <param name="process">The process.</param> /// <param name="address">The module address.</param> internal Module(Process process, ulong address) { Address = address; Process = process; name = SimpleCache.Create(() => { string name = Context.Debugger.GetModuleName(this); Process.UpdateModuleByNameCache(this, name); return name; }); imageName = SimpleCache.Create(() => Context.Debugger.GetModuleImageName(this)); loadedImageName = SimpleCache.Create(() => Context.Debugger.GetModuleLoadedImage(this)); symbolFileName = SimpleCache.Create(() => Context.Debugger.GetModuleSymbolFile(this)); mappedImageName = SimpleCache.Create(() => Context.Debugger.GetModuleMappedImage(this)); moduleVersion = SimpleCache.Create(() => { ModuleVersion version = new ModuleVersion(); Context.Debugger.GetModuleVersion(this, out version.Major, out version.Minor, out version.Revision, out version.Patch); return version; }); timestampAndSize = SimpleCache.Create(() => Context.Debugger.GetModuleTimestampAndSize(this)); clrModule = SimpleCache.Create(() => Process.ClrRuntimes.SelectMany(r => r.ClrRuntime.Modules).Where(m => m.ImageBase == Address).FirstOrDefault()); clrPdbReader = SimpleCache.Create(() => { try { string pdbPath = ClrModule.Runtime.DataTarget.SymbolLocator.FindPdb(ClrModule.Pdb); if (!string.IsNullOrEmpty(pdbPath)) { return new Microsoft.Diagnostics.Runtime.Utilities.Pdb.PdbReader(pdbPath); } } catch (Exception) { } return null; }); TypesByName = new DictionaryCache<string, CodeType>(GetTypeByName); TypesById = new DictionaryCache<uint, CodeType>(GetTypeById); ClrTypes = new DictionaryCache<Microsoft.Diagnostics.Runtime.ClrType, CodeType>(GetClrCodeType); GlobalVariables = new DictionaryCache<string, Variable>(GetGlobalVariable); UserTypeCastedGlobalVariables = new DictionaryCache<string, Variable>((name) => { Variable variable = Process.CastVariableToUserType(GlobalVariables[name]); if (UserTypeCastedGlobalVariables.Count == 0) { GlobalCache.VariablesUserTypeCastedFieldsByName.Add(UserTypeCastedGlobalVariables); } return variable; }); }
/// <summary> /// Gets the size of the context. /// </summary> /// <param name="process">The process.</param> internal static int GetContextSize(Process process) { switch (process.ActualProcessorType) { case ImageFileMachine.I386: return Marshal.SizeOf(typeof(CONTEXT_X86)); case ImageFileMachine.AMD64: return process.EffectiveProcessorType == ImageFileMachine.I386 ? Marshal.SizeOf(typeof(WOW64_CONTEXT)) : Marshal.SizeOf(typeof(CONTEXT_X64)); default: throw new Exception("Unknown platform " + process.ActualProcessorType); } }
/// <summary> /// Converts from native structure to managed object. /// </summary> /// <param name="process">The process.</param> /// <param name="pointer">The pointer.</param> internal static ThreadContext PtrToStructure(Process process, IntPtr pointer) { switch (process.ActualProcessorType) { case ImageFileMachine.I386: return ReadX86Structure(pointer); case ImageFileMachine.AMD64: return process.EffectiveProcessorType == ImageFileMachine.I386 ? ReadWowX64Structure(pointer) : ReadX64Structure(pointer); default: throw new Exception("Unknown platform " + process.ActualProcessorType); } }
/// <summary> /// Creates the array marshaler. /// </summary> /// <param name="process">The process.</param> /// <param name="elementsCount">The number of elements.</param> internal static MarshalArrayReader<ThreadContext> CreateArrayMarshaler(Process process, int elementsCount) { return new CustomMarshalArrayReader<ThreadContext>(elementsCount, (int)GetNativeStructureSize(process), (p) => PtrToStructure(process, p), StructureToPtr); }
/// <summary> /// Gets the size of the native structure. /// </summary> /// <param name="process">The process.</param> /// <returns></returns> private static uint GetNativeStructureSize(Process process) { switch (process.ActualProcessorType) { case ImageFileMachine.I386: return (uint)Marshal.SizeOf(typeof(CONTEXT_X86)); case ImageFileMachine.AMD64: return (uint)(process.EffectiveProcessorType == ImageFileMachine.I386 ? Marshal.SizeOf(typeof(WOW64_CONTEXT)) : Marshal.SizeOf(typeof(CONTEXT_X64))); default: throw new Exception("Unknown platform " + process.ActualProcessorType); } }