This commit is contained in:
Zhentar 2019-01-24 23:26:10 -06:00 коммит произвёл Dan Thompson
Родитель 13ff6d3e67
Коммит 37f65c91c6
7 изменённых файлов: 121 добавлений и 107 удалений

Просмотреть файл

@ -1,13 +1,16 @@
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\zhent\Source\Repos\DbgShell codebase based on best match to current usage at 11/8/2018
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]
[*]
#Core editorconfig formatting - indentation
#use soft tabs (spaces) for indentation
indent_style = space
#resharper alignment options
align_multiline_parameter = true
align_multiline_argument = true
[*.cs]
#Formatting - indentation options
#indent switch case contents.
@ -58,6 +61,17 @@ csharp_space_between_square_brackets = true
csharp_space_within_type_parameter_angles = true
csharp_space_within_type_argument_angles = true
csharp_space_within_sizeof_parentheses = true
csharp_space_within_typeof_parentheses = true
csharp_space_within_checked_parentheses = true
csharp_space_within_single_line_array_initializer_braces = true
csharp_blank_lines_after_block_statements = 0
csharp_blank_lines_around_field = 0
csharp_place_simple_anonymousmethod_on_single_line = false
csharp_anonymous_method_declaration_braces = next_line_shifted_2
#Formatting - wrapping options
#leave code block on single line

Просмотреть файл

@ -5051,22 +5051,22 @@ int WDebugDataSpaces::ReadVirtualDirect(
generic <typename TValue>
where TValue : value class
int WDebugDataSpaces::ReadVirtualValue(
[In] UInt64 Offset,
[Out] TValue% value)
[In] UInt64 Offset,
[Out] TValue% value)
{
ULONG BytesRead;
pin_ptr<TValue> pval = &value;
int hr = m_pNative->ReadVirtual( Offset,
pval,
sizeof(TValue),
&BytesRead);
//Since we are reading a single discrete value, treat under-read as failure
if (hr == S_OK && BytesRead < sizeof(TValue))
{
return HRESULT_FROM_WIN32(ERROR_READ_FAULT);
}
return hr;
ULONG BytesRead;
pin_ptr<TValue> pval = &value;
int hr = m_pNative->ReadVirtual( Offset,
pval,
sizeof(TValue),
&BytesRead);
//Since we are reading a single discrete value, treat under-read as failure
if (hr == S_OK && BytesRead < sizeof(TValue))
{
return HRESULT_FROM_WIN32(ERROR_READ_FAULT);
}
return hr;
}
// Note that not all bytes may be written!

Просмотреть файл

@ -2767,14 +2767,14 @@ namespace DbgEngWrapper
[In] ULONG BytesRequested,
[In] BYTE* buffer,
[Out] ULONG% BytesRead);
// This is a convenience wrapper for ReadVirtual for reading a single discrete value
// without needing an extra byte array or copies
generic <typename TValue>
where TValue : value class // should be `unmanaged` but that's not a choice we have
int ReadVirtualValue(
[In] UInt64 Offset,
[Out] TValue% value);
// This is a convenience wrapper for ReadVirtual for reading a single discrete value
// without needing an extra byte array or copies
generic <typename TValue>
where TValue : value class // should be `unmanaged` but that's not a choice we have
int ReadVirtualValue(
[In] UInt64 Offset,
[Out] TValue% value);
// Note that not all bytes may be written!
int WriteVirtual(

Просмотреть файл

@ -234,15 +234,15 @@ namespace MS.Dbg
SetLastError = true,
CharSet = CharSet.Unicode,
EntryPoint = "SymLoadModuleExW" )]
internal static unsafe extern ulong SymLoadModuleEx( IntPtr hProcess,
IntPtr hFile,
string ImageName,
string ModuleName,
ulong BaseOfDll,
uint DllSize,
/*MODLOAD_DATA*/ IntPtr Data,
uint Flags );
internal static extern ulong SymLoadModuleEx( IntPtr hProcess,
IntPtr hFile,
string ImageName,
string ModuleName,
ulong BaseOfDll,
uint DllSize,
/*MODLOAD_DATA*/ IntPtr Data,
uint Flags );
} // end partial class NativeMethods
@ -3720,15 +3720,16 @@ namespace MS.Dbg
}
} // end SymFromInlineContext_naked()
public static int SymLoadModule( WDebugClient debugClient, ulong moduleBaseAddress)
public static int SymLoadModule( WDebugClient debugClient, ulong moduleBaseAddress )
{
IntPtr hProc = _GetHProcForDebugClient( debugClient );
if( 0 == NativeMethods.SymLoadModuleEx( hProc, default, null, null, moduleBaseAddress, 0, default, 0 ))
{ //0 means no new module was loaded... but you don't know if that's because it was already loaded without checking the last error.
if( 0 == NativeMethods.SymLoadModuleEx( hProc, default, null, null, moduleBaseAddress, 0, default, 0 ) )
{
// 0 means no new module was loaded... but you don't know if that's because it was already loaded without checking the last error.
var err = Marshal.GetLastWin32Error();
if( err != 0 )
{
return (err | unchecked((int) 0x80070000));
return (err | unchecked( (int) 0x80070000 ));
}
}
return 0;

Просмотреть файл

@ -2098,20 +2098,20 @@ namespace MS.Dbg
public DbgModuleInfo GetNtdllModuleNative()
{
return ExecuteOnDbgEngThread( () =>
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntnsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntnsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
} // end GetNativeNtDllModule()
// Retrieves the ntdll module associated with the current effective machine type
public DbgModuleInfo GetNtdllModuleEffective()
{
return ExecuteOnDbgEngThread( () =>
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
} // end GetNativeNtDllModule()
// Retrieves the 32 bit ntdll module, whether it is a pure 32 bit process or WoW64
@ -2119,33 +2119,33 @@ namespace MS.Dbg
public DbgModuleInfo GetNtdllModule32()
{
return ExecuteOnDbgEngThread( () =>
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntwsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
{
CheckHr( m_debugSymbols.GetSymbolModuleWide( "${$ntwsym}!", out var modBase ) );
return GetModuleByAddress( modBase );
} );
} // end Get32bitNtDllModule()
public ulong GetCurrentThreadTebAddressEffective()
{
return Debugger.ExecuteOnDbgEngThread( () =>
{
CheckHr( m_debugSystemObjects.GetCurrentThreadTeb( out var nativeTebAddress ) );
CheckHr( m_debugControl.GetActualProcessorType( out IMAGE_FILE_MACHINE actualType ) );
CheckHr( m_debugControl.GetEffectiveProcessorType( out IMAGE_FILE_MACHINE effectiveType ) );
if(actualType != effectiveType)
{
var tebType = Debugger.GetModuleTypeByName( GetNtdllModuleNative(), "_TEB" );
var wowtebOffset = 8192u; //It's been that for 15 years now, so seems like a safe enough default
if(tebType is DbgUdtTypeInfo udtType && udtType.Members.HasItemNamed( "WowTebOffset" ))
CheckHr( m_debugSystemObjects.GetCurrentThreadTeb( out var nativeTebAddress ) );
CheckHr( m_debugControl.GetActualProcessorType( out IMAGE_FILE_MACHINE actualType ) );
CheckHr( m_debugControl.GetEffectiveProcessorType( out IMAGE_FILE_MACHINE effectiveType ) );
if( actualType != effectiveType )
{
var wowtebOffsetOffset = udtType.FindMemberOffset( "WowTebOffset" );
wowtebOffset = ReadMemAs< uint >( nativeTebAddress + wowtebOffsetOffset );
var tebType = Debugger.GetModuleTypeByName( GetNtdllModuleNative(), "_TEB" );
var wowtebOffset = 8192u; // It's been that for 15 years now, so seems like a safe enough default
if( tebType is DbgUdtTypeInfo udtType && udtType.Members.HasItemNamed( "WowTebOffset" ) )
{
var wowtebOffsetOffset = udtType.FindMemberOffset( "WowTebOffset" );
wowtebOffset = ReadMemAs< uint >( nativeTebAddress + wowtebOffsetOffset );
}
return nativeTebAddress + wowtebOffset;
}
return nativeTebAddress + wowtebOffset;
}
return nativeTebAddress;
} );
return nativeTebAddress;
} );
} // end GetCurrentThreadTebAddress32()
public DbgSymbol GetCurrentThreadTebEffective( CancellationToken token = default )
@ -2154,28 +2154,28 @@ namespace MS.Dbg
"_TEB",
$"Thread_0x{m_cachedContext.ThreadIndexOrAddress}_TEB32",
token );
} // end GetCurrentThreadTeb32()
} // end GetCurrentThreadTeb32()
internal DbgSymbol _CreateNtdllSymbolForAddress( ulong address, string type, string symbolName, CancellationToken token = default )
{
return Debugger.ExecuteOnDbgEngThread( () =>
{
try
{
var module = GetNtdllModuleEffective();
var tebType = GetModuleTypeByName( module, type, token );
var tebSym = CreateSymbolForAddressAndType( address, tebType, symbolName );
return tebSym;
}
catch( DbgProviderException dpe )
{
throw new DbgProviderException( $"Could not create symbol for {type}. Are you missing the PDB for ntdll?",
"NoTebSymbol",
System.Management.Automation.ErrorCategory.ObjectNotFound,
dpe,
this );
}
} );
try
{
var module = GetNtdllModuleEffective();
var tebType = GetModuleTypeByName( module, type, token );
var tebSym = CreateSymbolForAddressAndType( address, tebType, symbolName );
return tebSym;
}
catch( DbgProviderException dpe )
{
throw new DbgProviderException( $"Could not create symbol for {type}. Are you missing the PDB for ntdll?",
"NoTebSymbol",
System.Management.Automation.ErrorCategory.ObjectNotFound,
dpe,
this );
}
} );
} // end _CreateNtdllSymbolForAddress
public byte[] ReadMem( ulong address, uint lengthDesired )
@ -3497,7 +3497,7 @@ namespace MS.Dbg
Util.Assert( 0 == Util.Strcmp_OI( "*", modName ) );
pattern = "*!" + pattern;
}
else if ( "nt" == modName )
else if( "nt" == modName )
{
var ntdllModule = GetNtdllModuleNative();
modName = ntdllModule.Name;
@ -3654,29 +3654,28 @@ namespace MS.Dbg
return GetModuleTypeByName( mod, bareSym, cancelToken );
} // end GetSingleTypeByName()
public DbgNamedTypeInfo GetModuleTypeByName( DbgModuleInfo module,
public DbgNamedTypeInfo GetModuleTypeByName( DbgModuleInfo module,
string typeName,
CancellationToken cancelToken = default)
CancellationToken cancelToken = default )
{
_EnsureSymbolsLoaded( module, cancelToken );
return ExecuteOnDbgEngThread( () =>
{
SymbolInfo symInfo = DbgHelp.TryGetTypeFromName( m_debugClient,
module.BaseAddress,
typeName );
if( null != symInfo )
{
return DbgNamedTypeInfo.GetNamedTypeInfo( this,
symInfo.ModBase,
symInfo.TypeIndex,
symInfo.Tag,
GetCurrentTarget() );
}
SymbolInfo symInfo = DbgHelp.TryGetTypeFromName( m_debugClient,
module.BaseAddress,
typeName );
return null;
} );
if( null != symInfo )
{
return DbgNamedTypeInfo.GetNamedTypeInfo( this,
symInfo.ModBase,
symInfo.TypeIndex,
symInfo.Tag,
GetCurrentTarget() );
}
return null;
} );
} // end GetModuleTypeByName()
public IEnumerable<DbgNamedTypeInfo> GetTypeInfoByName( string pattern )

Просмотреть файл

@ -274,7 +274,7 @@ namespace MS.Dbg
public void DiscardCachedModuleInfo()
{
RefreshModuleInfo(); //Need to tell modules to dump their cache for anyone holding onto a reference
RefreshModuleInfo(); // Need to tell modules to dump their cache for anyone holding onto a reference
m_modules = null;
m_unloadedModules = null;
} // end DiscardCachedModuleInfo()

Просмотреть файл

@ -564,11 +564,11 @@ namespace MS.Dbg
{
if( (0 != (int) (Flags & (DEBUG_CSS.LOADS | DEBUG_CSS.UNLOADS))) )
{
//If we load symbols using DbgEng's Reload command, it will send
//us back an Argument of 0, and we'll be forced to throw away everything.
//But in at least some other cases it faithfully passes along the
//base address - we still don't know which target it is for, but it is
//at least for no more than one module.
// If we load symbols using DbgEng's Reload command, it will send
// us back an Argument of 0, and we'll be forced to throw away everything.
// But in at least some other cases it faithfully passes along the
// base address - we still don't know which target it is for, but it is
// at least for no more than one module.
m_debugger.DiscardCachedModuleInfo( Argument );
// TODO: BUGBUG: To do this right requires knowing the current