public AModInfo() { LoadedMods = new List <string>(); SymCtx = Sym.Initalize(); uniqD = new Dictionary <ulong, AStepEvent>(); }
/// <summary> /// We use sympath environment variable /// </summary> /// <param name="cv_data"></param> /// <param name="BaseVA"></param> /// <param name="SymPath"></param> /// <returns></returns> public static bool TryLoadSymbols(long Handle, CODEVIEW_HEADER cv_data, ulong BaseVA, bool Verbose = false) { #if NETSTANDARD2_0 cv_data.PDBFullPath = $"NET_BINDING-{cv_data}"; return(true); #else var symStatus = false; if (string.IsNullOrWhiteSpace(cv_data.PdbName)) { return(symStatus); } var sym = Sym.Initalize(Handle, null, DebugHelp.SymOptions.SYMOPT_UNDNAME); if (!sym && Verbose) { Sym.Errors.Enqueue($"Can not initialize symbols for ${Handle}, error: {new Win32Exception(Marshal.GetLastWin32Error()).Message }"); } StringBuilder sbx = new StringBuilder(1024); StringBuilder sbName = new StringBuilder(cv_data.PdbName.Substring(0, cv_data.PdbName.IndexOf(".pdb") + 4)); uint three = 0; var flags = DebugHelp.SSRVOPT_GUIDPTR; symStatus = DebugHelp.SymFindFileInPathW(Handle, null, sbName, ref cv_data.aGuid, cv_data.Age, three, flags, sbx, IntPtr.Zero, IntPtr.Zero); //// try twice, just in case if (!symStatus) { symStatus = DebugHelp.SymFindFileInPathW(Handle, null, sbName, ref cv_data.aGuid, cv_data.Age, three, flags, sbx, IntPtr.Zero, IntPtr.Zero); } if (!symStatus) { if (Verbose) { Sym.Errors.Enqueue($" Symbol locate returned {symStatus}: {new Win32Exception(Marshal.GetLastWin32Error()).Message }, attempting less precise request."); } flags = DebugHelp.SSRVOPT_DWORDPTR; var refBytes = BitConverter.GetBytes(cv_data.TimeDateStamp); GCHandle pinnedArray = GCHandle.Alloc(refBytes, GCHandleType.Pinned); IntPtr pointer = pinnedArray.AddrOfPinnedObject(); symStatus = DebugHelp.SymFindFileInPathW(Handle, null, sbName, pointer, cv_data.VSize, three, flags, sbx, IntPtr.Zero, IntPtr.Zero); pinnedArray.Free(); if (!symStatus && Verbose) { Sym.Errors.Enqueue($" Find Symbols returned value: {symStatus}:[{sbx.ToString()}]"); } } if (symStatus) { var symLoaded = DebugHelp.SymLoadModuleEx(Handle, IntPtr.Zero, sbx.ToString(), null, BaseVA, cv_data.VSize, IntPtr.Zero, 0); if (symLoaded == 0 && Verbose) { Sym.Errors.Enqueue($"Symbols file located @ {sbx.ToString()} yet load Failed: [{new Win32Exception(Marshal.GetLastWin32Error()).Message }]"); } cv_data.PDBFullPath = sbx.ToString(); } return(symStatus); #endif }