📄 accload.c
字号:
}
if( *src == '#' ) {
src++;
pid = strtoul( src, &endsrc, 16 );
if( pid == 0 ) {
pid = -1;
}
strcpy( buff, endsrc );
} else {
while( *src ) {
if( !isdigit( *src ) ) {
break;
}
src++;
}
if( *src == 0 && src != parm ) {
pid = atoi( parm );
}
}
/*
* get program to debug. If the user has specified a pid, then
* skip directly to doing a DebugActiveProcess
*/
IsWOW = FALSE;
IsDOS = FALSE;
if( pid == 0 ) {
if( FindFilePath( parm, exe_name, ExtensionList ) != 0 ) {
ret->err = ERROR_FILE_NOT_FOUND;
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
/*
* Get type of application
*/
handle = CreateFile( ( LPTSTR ) exe_name, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, 0 );
if( handle == ( HANDLE ) - 1 ) {
ret->err = GetLastError();
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
GetFullPathName( exe_name, MAX_PATH, CurrEXEName, NULL );
/*
* get the parm list
*/
if( strchr( CurrEXEName, ' ' ) != NULL ) {
strcpy( buff, "\"" );
strcat( buff, CurrEXEName );
strcat( buff, "\"" );
} else {
strcpy( buff, CurrEXEName );
}
dst = &buff[strlen( buff )];
src = parm;
while( *src != 0 ) {
++src;
}
len = &parm[GetTotalSize() -sizeof( *acc )] - src;
for( ;; ) {
if( len == 0 ) {
break;
}
ch = *src;
if( ch == 0 ) {
ch = ' ';
}
*dst = ch;
++dst;
++src;
--len;
}
*dst = 0;
cr_flags = DEBUG_ONLY_THIS_PROCESS;
if( !GetEXEHeader( handle, &hi, &stack ) ) {
ret->err = GetLastError();
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
if( hi.sig == EXE_PE ) {
DebugeeSubsystem = hi.peh.subsystem;
if( DebugeeSubsystem == SS_WINDOWS_CHAR ) {
cr_flags |= CREATE_NEW_CONSOLE;
}
} else if( hi.sig == EXE_NE ) {
IsWOW = TRUE;
/*
* find out the pid of WOW, if it is already running.
*/
pVDMEnumProcessWOW( EnumWOWProcessFunc, ( LPARAM ) & pid );
if( pid != 0 ) {
version = LOWORD( GetVersion() );
if( LOBYTE( version ) == 3 && HIBYTE( version ) < 50 ) {
int kill = MessageBox( NULL, TRP_NT_wow_warning,
TRP_The_WATCOM_Debugger,
MB_APPLMODAL + MB_YESNO );
if( kill == IDYES ) {
DWORD axs = PROCESS_TERMINATE+STANDARD_RIGHTS_REQUIRED;
HANDLE hprocess = OpenProcess( axs, FALSE, pid );
if( hprocess != 0 && TerminateProcess( hprocess, 0 ) ) {
CloseHandle( hprocess );
pid = 0;
}
}
} else {
cr_flags |= CREATE_SEPARATE_WOW_VDM;
pid = 0; // always start a new VDM.
}
}
if( pid != 0 ) {
ret->err = GetLastError();
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
} else {
IsDOS = TRUE;
}
CloseHandle( handle );
}
/*
* start the debugee
*/
pid_started = pid;
if( *dll_name ) {
strcat( buff, LOAD_PROG_STR_DELIM );
strcat( buff, LOAD_PROG_STR_DLLNAME );
strcat( buff, dll_name );
}
if( *service_name ) {
strcat( buff, LOAD_PROG_STR_DELIM );
strcat( buff, LOAD_PROG_STR_SERVICE );
strcat( buff, service_name );
}
if( *dll_destination ) {
strcat( buff, LOAD_PROG_STR_DELIM );
strcat( buff, LOAD_PROG_STR_COPYDIR );
strcat( buff, dll_destination );
}
if( *service_parm ) {
strcat( buff, LOAD_PROG_STR_DELIM );
strcat( buff, LOAD_PROG_STR_SERVICEPARM );
strcat( buff, service_parm );
}
ret->err = StartControlThread( buff, &pid_started, cr_flags );
if( ret->err != 0 ) {
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
/*
* CREATE_PROCESS_DEBUG_EVENT will always be the first debug event.
* If it is not, then something is horribly wrong.
*/
rc = MyWaitForDebugEvent();
if( !rc || ( DebugEvent.dwDebugEventCode != CREATE_PROCESS_DEBUG_EVENT ) ||
( DebugEvent.dwProcessId != pid_started ) ) {
ret->err = GetLastError();
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
ProcessInfo.pid = DebugEvent.dwProcessId;
ProcessInfo.process_handle = DebugEvent.u.CreateProcessInfo.hProcess;
ProcessInfo.base_addr = DebugEvent.u.CreateProcessInfo.lpBaseOfImage;
AddProcess( &hi );
AddThread( DebugEvent.dwThreadId, DebugEvent.u.CreateProcessInfo.hThread,
DebugEvent.u.CreateProcessInfo.lpStartAddress );
DebugeePid = DebugEvent.dwProcessId;
DebugeeTid = DebugEvent.dwThreadId;
LastDebugEventTid = DebugEvent.dwThreadId;
#ifdef WOW
if( IsWOW ) {
ret->flags = LD_FLAG_IS_PROT;
ret->err = 0;
ret->task_id = DebugeePid;
/*
* we use our own CS and DS as the Flat CS and DS, for lack
* of anything better
*/
FlatDS = DS();
FlatCS = CS();
if( !executeUntilVDMStart() ) {
ret->err = GetLastError();
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
if( pid != NULL ) {
addAllWOWModules();
} else {
addKERNEL();
}
/*
* we save the starting CS:IP of the WOW app, since we will use
* it to force execution of code later
*/
ti = FindThread( DebugeeTid );
MyGetThreadContext( ti, &con );
WOWAppInfo.segment = ( WORD ) con.SegCs;
WOWAppInfo.offset = ( WORD ) con.Eip;
con.SegSs = con.SegDs; // Wow lies about the stack segment. Reset it
con.Esp = stack;
MySetThreadContext( ti, &con );
} else
#endif
{
DWORD base;
if( pid == 0 ) {
base = ( DWORD ) DebugEvent.u.CreateProcessInfo.lpStartAddress;
} else {
base = 0;
}
ret->flags = 0;
ret->err = 0;
ret->task_id = DebugeePid;
if( executeUntilStart( pid != 0 ) ) {
DWORD old;
/*
* make the application load our DLL, so that we can have it
* run code out of it. One small note: this will not work right
* if the app does not load our DLL at the same address the
* debugger loaded it at!!!
*/
ti = FindThread( DebugeeTid );
MyGetThreadContext( ti, &con );
old = AdjustIP( &con, 0 );
if( base != 0 ) {
SetIP( &con, base );
}
MySetThreadContext( ti, &con );
SetIP( &con, old );
MySetThreadContext( ti, &con );
}
ti = FindThread( DebugeeTid );
MyGetThreadContext( ti, &con );
#if defined( MD_x86 )
FlatCS = con.SegCs;
FlatDS = con.SegDs;
#endif
}
ret->flags |= LD_FLAG_HAVE_RUNTIME_DLLS;
if( pid != 0 ) {
ret->flags |= LD_FLAG_IS_STARTED;
}
ret->mod_handle = 0;
if( buff ) {
free( buff );
buff = NULL;
}
return( sizeof( *ret ) );
}
unsigned ReqProg_kill( void )
{
prog_kill_ret *ret;
ret = GetOutPtr( 0 );
ret->err = 0;
DelProcess( TRUE );
StopControlThread();
return( sizeof( *ret ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -