Skip to content

Commit 67f78a8

Browse files
tyranidtyranid
authored andcommitted
Use SYMBOL_INFO::Reserver[1] to get the machine type rather than accessing the DIA interface.
1 parent 507f1d8 commit 67f78a8

File tree

4 files changed

+3
-578
lines changed

4 files changed

+3
-578
lines changed

NtApiDotNet/NtApiDotNet.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,6 @@
530530
<Compile Include="Win32\ConsoleSession.cs" />
531531
<Compile Include="Win32\Debugger\DbgHelpCallbackActionCode.cs" />
532532
<Compile Include="Win32\Debugger\DbgHelpDebugCallbackHandler.cs" />
533-
<Compile Include="Win32\Debugger\IDiaSession.cs" />
534-
<Compile Include="Win32\Debugger\IDiaSymbol.cs" />
535533
<Compile Include="Win32\Debugger\IMAGEHLP_CBA_EVENTW.cs" />
536534
<Compile Include="Win32\Debugger\IMAGEHLP_DEFERRED_SYMBOL_LOADW.cs" />
537535
<Compile Include="Win32\Debugger\IMAGEHLP_STACK_FRAME.cs" />

NtApiDotNet/Win32/Debugger/DbgHelpSymbolResolver.cs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,6 @@ delegate bool SymGetHomeDirectoryW(
216216
[In, Out] StringBuilder dir,
217217
IntPtr size
218218
);
219-
220-
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
221-
delegate bool SymGetDiaSession(
222-
SafeKernelObjectHandle hProcess,
223-
long BaseOfDll,
224-
[MarshalAs(UnmanagedType.Interface)] out IDiaSession DiaSession
225-
);
226219

227220
private readonly SafeLoadLibraryHandle _dbghelp_lib;
228221
private readonly SymInitializeW _sym_init;
@@ -246,7 +239,6 @@ delegate bool SymGetDiaSession(
246239
private readonly SymSetContext _sym_set_context;
247240
private readonly SymEnumSymbolsW _sym_enum_symbols;
248241
private readonly SymGetHomeDirectoryW _sym_get_home_directory;
249-
private readonly SymGetDiaSession _sym_get_dia_session;
250242
private IEnumerable<SymbolLoadedModule> _loaded_modules;
251243
private readonly TextWriter _trace_writer;
252244
private readonly bool _trace_symbol_loading;
@@ -259,11 +251,6 @@ private void GetFunc<T>(ref T f) where T : Delegate
259251
{
260252
f = _dbghelp_lib.GetFunctionPointer<T>();
261253
}
262-
263-
private void GetFuncNoThrow<T>(ref T f) where T : Delegate
264-
{
265-
f = _dbghelp_lib.GetFunctionPointer<T>(false);
266-
}
267254

268255
private void GetFunc<T>(ref T f, string name) where T : Delegate
269256
{
@@ -280,29 +267,6 @@ private static string GetNameFromSymbolInfo(SafeStructureInOutBuffer<SYMBOL_INFO
280267
return buffer.Data.ReadNulTerminatedUnicodeString();
281268
}
282269

283-
private DllMachineType GetSymbolMachineType(SYMBOL_INFO sym_info)
284-
{
285-
IDiaSession session = null;
286-
IDiaSymbol symbol = null;
287-
try
288-
{
289-
if (_sym_get_dia_session == null || !_sym_get_dia_session(Handle, sym_info.ModBase, out session))
290-
return DllMachineType.UNKNOWN;
291-
292-
if (session.findSymbolByVA(sym_info.Address, sym_info.Tag, out symbol) != 0)
293-
return DllMachineType.UNKNOWN;
294-
295-
return (DllMachineType)symbol.machineType;
296-
}
297-
finally
298-
{
299-
if (symbol != null)
300-
Marshal.ReleaseComObject(symbol);
301-
if (session != null)
302-
Marshal.ReleaseComObject(session);
303-
}
304-
}
305-
306270
private static SafeStructureInOutBuffer<SYMBOL_INFO> MapSymbolInfo(IntPtr symbol_info)
307271
{
308272
int base_size = Marshal.SizeOf(typeof(SYMBOL_INFO));
@@ -744,7 +708,7 @@ private DataSymbolInformation GetSymbolInfoForAddress(IntPtr address)
744708

745709
return new DataSymbolInformation(result.Tag, result.Size, result.TypeIndex,
746710
result.Address, GetModuleForAddress(new IntPtr(result.ModBase)),
747-
GetNameFromSymbolInfo(sym_info), GetSymbolMachineType(result));
711+
GetNameFromSymbolInfo(sym_info), (DllMachineType)result.Reserved2);
748712
}
749713

750714
return null;
@@ -762,7 +726,7 @@ private DataSymbolInformation GetSymbolInfoForName(string name)
762726
var result = sym_info.Result;
763727
return new DataSymbolInformation(result.Tag, result.Size, result.TypeIndex,
764728
result.Address, GetModuleForAddress(new IntPtr(result.ModBase)),
765-
GetNameFromSymbolInfo(sym_info), GetSymbolMachineType(result));
729+
GetNameFromSymbolInfo(sym_info), (DllMachineType)result.Reserved2);
766730
}
767731
}
768732

@@ -897,7 +861,7 @@ private bool GetSymbolInfo(List<SymbolInformation> symbols, IntPtr symbol_info,
897861
var result = sym_info.Result;
898862
var symbol = new DataSymbolInformation(result.Tag, result.Size, result.TypeIndex,
899863
result.Address, GetModuleForAddress(new IntPtr(result.ModBase)),
900-
GetNameFromSymbolInfo(sym_info), GetSymbolMachineType(result));
864+
GetNameFromSymbolInfo(sym_info), (DllMachineType)result.Reserved2);
901865
symbols.Add(symbol);
902866
return true;
903867
}
@@ -1158,7 +1122,6 @@ internal DbgHelpSymbolResolver(NtProcess process, string dbghelp_path, string sy
11581122
GetFunc(ref _sym_enum_symbols);
11591123
GetFunc(ref _sym_set_context);
11601124
GetFunc(ref _sym_get_home_directory);
1161-
GetFuncNoThrow(ref _sym_get_dia_session);
11621125

11631126
_trace_writer = trace_writer ?? new TraceTextWriter();
11641127
SymOptions options = SymOptions.INCLUDE_32BIT_MODULES | SymOptions.UNDNAME | SymOptions.DEFERRED_LOADS;

NtApiDotNet/Win32/Debugger/IDiaSession.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)