📄 accrun.c
字号:
{
DWORD bytes;
DWORD addr;
DWORD opcode;
CONTEXT con;
con.ContextFlags = CONTEXT_CONTROL;
MyGetThreadContext( FindThread( DebugeeTid ), &con );
addr = AdjustIP( &con, 0 );
ReadProcessMemory( ProcessInfo.process_handle, ( LPVOID )addr,
( LPVOID )&opcode, sizeof( opcode ), ( LPDWORD )&bytes );
opcode &= 0xfc000000;
if( opcode == ( 0x1a << 26 ) || opcode >= ( 0x30 << 26 ) ) {
returnCode = COND_WATCH;
goto done;
}
}
#endif
setTBit( T_ON_NEXT );
}
MyContinueDebugEvent( continue_how );
continue_how = DBG_CONTINUE;
rc = MyWaitForDebugEvent();
LastDebugEventTid = DebugEvent.dwThreadId;
if( IsWin32s && !rc ) {
returnCode = COND_LIBRARIES;
goto done;
}
switch( DebugEvent.dwDebugEventCode ) {
case EXCEPTION_DEBUG_EVENT:
code = DebugEvent.u.Exception.ExceptionRecord.ExceptionCode;
switch( code ) {
#ifdef WOW
case STATUS_VDM_EVENT:
subcode = W1( DebugEvent.u.Exception.ExceptionRecord );
switch( subcode ) {
case DBG_TASKSTOP:
DebugeeTid = DebugEvent.dwThreadId;
getImageNote( &imgnote );
RemoveModuleFromLibList( imgnote.Module, imgnote.FileName );
if( !stricmp( imgnote.FileName, CurrEXEName ) ) {
DebugeeEnded = TRUE;
returnCode = COND_TERMINATE;
goto done;
}
break;
case DBG_DLLSTOP:
getImageNote( &imgnote );
RemoveModuleFromLibList( imgnote.Module, imgnote.FileName );
break;
case DBG_DLLSTART:
getImageNote( &imgnote );
AddLib( TRUE, &imgnote );
if( !IsWOW && stop_on_module_load ) {
returnCode = 0;
goto done;
}
break;
case DBG_TASKSTART:
DebugeeTid = DebugEvent.dwThreadId;
ti = FindThread( DebugeeTid );
ti->is_wow = TRUE;
getImageNote( &imgnote );
/*
* check and see if we have the 16-bit app that we
* started is the one that has finally started
*/
if( !stricmp( imgnote.FileName, CurrEXEName ) &&
( state & STATE_WAIT_FOR_VDM_START ) ) {
WOWAppInfo.tid = DebugeeTid;
WOWAppInfo.htask = imgnote.hTask;
WOWAppInfo.hmodule = imgnote.hModule;
strcpy( WOWAppInfo.modname, imgnote.Module );
returnCode = COND_VDM_START;
goto done;
} else {
AddLib( TRUE, &imgnote );
}
break;
case DBG_SINGLESTEP:
DebugeeTid = DebugEvent.dwThreadId;
returnCode = handleInt1( state );
goto done;
case DBG_BREAK:
DebugeeTid = DebugEvent.dwThreadId;
returnCode = handleInt3( state );
goto done;
case DBG_GPFAULT:
DebugeeTid = DebugEvent.dwThreadId;
LastExceptionCode = STATUS_ACCESS_VIOLATION;
returnCode = COND_EXCEPTION;
goto done;
case DBG_ATTACH:
/* Sent to let debugger know 16-bit environment is set up.
* Only a notification, provides no further data. Must be
* handled so that debugger doesn't get confused.
*/
DebugeeTid = DebugEvent.dwThreadId;
ti = FindThread( DebugeeTid );
ti->is_dos = TRUE;
break;
case DBG_INIT:
// I have no idea how to handle this!
break;
default:
DebugeeTid = DebugEvent.dwThreadId;
LastExceptionCode = STATUS_ACCESS_VIOLATION;
returnCode = COND_EXCEPTION;
goto done;
}
break;
#endif
case DBG_CONTROL_C:
/*
* this never seems to happen ever never ever never
*/
DebugeeTid = DebugEvent.dwThreadId;
continue_how = DBG_EXCEPTION_NOT_HANDLED;
break;
case STATUS_SINGLE_STEP:
DebugeeTid = DebugEvent.dwThreadId;
cond = handleInt1( state );
if( cond != 0 ) {
returnCode = cond;
goto done;
}
break;
case STATUS_BREAKPOINT:
DebugeeTid = DebugEvent.dwThreadId;
if( state & STATE_WAIT_FOR_VDM_START ) {
break;
}
cond = handleInt3( state );
if( cond != 0 ) {
returnCode = cond;
goto done;
}
break;
default:
/*
* we stop on the second notification of the exception to
* give the user's exception handlers a chance to run
*/
DebugeeTid = DebugEvent.dwThreadId;
if( DebugEvent.u.Exception.dwFirstChance &&
!( state & STATE_EXPECTING_FAULT ) ) {
char buff[20];
void *a;
new = LocalAlloc( LMEM_FIXED, 80 );
new->next = NULL;
strcpy( new->msg, "First chance exception: 0x" );
ultoa( code, buff, 16 );
strcat( new->msg, buff );
strcat( new->msg, " at 0x" );
a = DebugEvent.u.Exception.ExceptionRecord.ExceptionAddress;
ultoa( (DWORD)a, buff, 16 );
strcat( new->msg, buff );
owner = &DebugString;
for( ;; ) {
if( *owner == NULL )
break;
owner = &( *owner )->next;
}
*owner = new;
continue_how = DBG_EXCEPTION_NOT_HANDLED;
/*
* Carl Young 8-Jun-2004
* Ensure we clear the trap flag so we don't single step
* the exception handler...
*/
setTBit( T_OFF );
} else {
LastExceptionCode = code;
returnCode = COND_EXCEPTION;
goto done;
}
break;
}
break;
case CREATE_THREAD_DEBUG_EVENT:
DebugeeTid = DebugEvent.dwThreadId;
if( tsc != NULL ) {
*tsc = TRUE;
}
AddThread( DebugEvent.dwThreadId, DebugEvent.u.CreateThread.hThread,
DebugEvent.u.CreateThread.lpStartAddress );
break;
case EXIT_THREAD_DEBUG_EVENT:
DebugeeTid = DebugEvent.dwThreadId;
ClearDebugRegs();
if( tsc != NULL ) {
*tsc = TRUE;
}
DeadThread( DebugEvent.dwThreadId );
break;
case CREATE_PROCESS_DEBUG_EVENT: // shouldn't ever get
DebugeeTid = DebugEvent.dwThreadId;
break;
case EXIT_PROCESS_DEBUG_EVENT:
DebugeeTid = DebugEvent.dwThreadId;
ClearDebugRegs();
DebugeeEnded = TRUE;
DelProcess( FALSE );
MyContinueDebugEvent( DBG_CONTINUE );
returnCode = COND_TERMINATE;
goto done;
case LOAD_DLL_DEBUG_EVENT:
AddLib( FALSE, NULL );
if( !IsWOW && stop_on_module_load ) {
returnCode = COND_LIBRARIES;
goto done;
}
break;
case UNLOAD_DLL_DEBUG_EVENT:
DelLib();
if( !IsWOW && stop_on_module_load ) {
returnCode = COND_LIBRARIES;
goto done;
}
break;
case OUTPUT_DEBUG_STRING_EVENT:
if( state & ( STATE_IGNORE_DEBUG_OUT | STATE_WAIT_FOR_VDM_START ) )
{
break;
}
len = DebugEvent.u.DebugString.nDebugStringLength;
p = LocalAlloc( LMEM_FIXED, len + 1 );
ReadMem( FlatDS,
( DWORD )DebugEvent.u.DebugString.lpDebugStringData, p, len );
p[len] = '\0';
#define GOOFY_NT_MESSAGE "LDR: LdrpMapDll Relocating:"
if( !strncmp( p, GOOFY_NT_MESSAGE, sizeof( GOOFY_NT_MESSAGE ) - 1 )
) {
LocalFree( p );
break;
}
q = p;
for( ;; ) {
if( q[0] == '\0' || q[0] == '\r' ) {
new = LocalAlloc( LMEM_FIXED, sizeof( *new ) + q - p + 1 );
new->next = NULL;
memcpy( new->msg, p, q - p );
new->msg[q - p] = '\0';
owner = &DebugString;
for( ;; ) {
if( *owner == NULL ) {
break;
}
owner = &( *owner )->next;
}
*owner = new;
if( q[0] == '\0' ) {
break;
}
++q;
if( q[0] == '\n' ) {
++q;
}
p = q;
} else {
++q;
}
}
LocalFree( p );
returnCode = 0;
goto done;
default:
break;
}
}
done:
;
if( DebugString != NULL ) {
returnCode += COND_MESSAGE + ( BreakOnKernelMessage ? COND_STOP : 0 );
}
return( returnCode );
}
/*
* runProg - run threads
*/
static unsigned runProg( bool single_step )
{
DWORD state;
CONTEXT con;
BOOL thread_state_changed;
thread_info *ti;
prog_go_ret *ret;
ret = GetOutPtr( 0 );
if( DebugeeEnded || DebugeePid == NULL ) {
ret->conditions = COND_TERMINATE;
return( sizeof( *ret ) );
}
state = 0;
if( single_step ) {
/*
This works on an Alpha (and other machines without a t-bit
because the MAD will simulate all control transfer instructions.
We only need to deal with straight line code.
*/
setTBit( T_ON_NEXT );
} else {
setTBit( T_OFF );
if( WPCount != 0 ) {
state |= STATE_WATCH;
#if defined( MD_x86 )
if( SetDebugRegs() ) {
state |= STATE_WATCH_386;
}
#endif
}
}
SetConsoleCtrlHandler( consoleHandler, TRUE );
ret->conditions = DebugExecute( state, &thread_state_changed, TRUE );
SetConsoleCtrlHandler( consoleHandler, FALSE );
if( state & STATE_WATCH_386 ) {
ClearDebugRegs();
} else if( state & STATE_WATCH ) {
setTBit( T_OFF );
}
if( single_step ) {
setTBit( T_OFF );
}
ti = FindThread( DebugeeTid );
MyGetThreadContext( ti, &con );
#if defined( MD_x86 )
ret->program_counter.offset = con.Eip;
ret->stack_pointer.offset = con.Esp;
ret->program_counter.segment = con.SegCs;
ret->stack_pointer.segment = con.SegSs;
#elif defined( MD_axp )
ret->program_counter.offset = ( ( unsigned_64 * ) & con.Fir )->u._32[0];
ret->stack_pointer.offset = ( ( unsigned_64 * ) & con.IntSp )->u._32[0];
ret->program_counter.segment = 0;
ret->stack_pointer.segment = 0;
#elif defined( MD_ppc )
ret->program_counter.offset = con.Iar;
ret->stack_pointer.offset = con.Gpr2;
ret->program_counter.segment = 0;
ret->stack_pointer.segment = 0;
#else
#error runProg not configured
#endif
if( ModuleTop > CurrentModule ) {
ret->conditions |= COND_LIBRARIES;
}
ret->conditions |= COND_CONFIG | COND_THREAD;
return( sizeof( *ret ) );
}
unsigned ReqProg_go( void )
{
return( runProg( FALSE ) );
}
unsigned ReqProg_step( void )
{
return( runProg( TRUE ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -