/* * get the address of Dos32Debug, and get the flat selectors, too. */ int GetDos32Debug( char __far *err ) { char buff[256]; RESULTCODES resc; USHORT dummy; PSZ start; PSZ p; HFILE inh; HFILE outh; USHORT rc; struct { ULONG dos_debug; USHORT cs; USHORT ds; USHORT ss; } data; rc = DosGetModName( ThisDLLModHandle, sizeof( buff ), buff ); if( rc ) { StrCopy( TRP_OS2_no_dll, err ); return( FALSE ); } start = buff; for( p = buff; *p != '\0'; ++p ) { switch( *p ) { case ':': case '\\': case '/': start = p + 1; break; } } p = StrCopy( LOCATOR, start ); if( DosMakePipe( &inh, &outh, sizeof( data ) ) ) { StrCopy( TRP_OS2_no_pipe, err ); return( FALSE ); } *++p = outh + '0'; *++p = '\0'; *++p = '\0'; rc = DosExecPgm( NULL, 0, EXEC_ASYNC, buff, NULL, &resc, buff ); DosClose( outh ); if( rc ) { DosClose( inh ); StrCopy( TRP_OS2_no_help, err ); return( FALSE ); } rc = DosRead( inh, &data, sizeof( data ), &dummy ); DosClose( inh ); if( rc ) { StrCopy( TRP_OS2_no_help, err ); return( FALSE ); } DebugFunc = (void __far *)data.dos_debug; FlatCS = (USHORT) data.cs; FlatDS = (USHORT) data.ds; _retaddr = MakeLocalPtrFlat( (void __far *)DoReturn ); return( TRUE ); }
static void GetObjectInfo( ULONG mte ) { HFILE hdl; ULONG new_head; USHORT type; unsigned_32 objoff; unsigned_32 numobjs; char buff[256]; if( mte == LastMTE ) { return; } memset( ObjInfo, 0, sizeof( ObjInfo ) ); DosGetModName( mte, 144, buff ); NumObjects = 0; if( !FindNewHeader( buff, &hdl, &new_head, &type ) ) { return; } if( type != EXE_LE && type != EXE_LX ) { DosClose( hdl ); return; } SeekRead( hdl, new_head+0x40, &objoff, sizeof( objoff ) ); SeekRead( hdl, new_head+0x44, &numobjs, sizeof( numobjs ) ); if( numobjs <= MAX_OBJECTS ) { SeekRead( hdl, new_head + objoff, ObjInfo, numobjs * sizeof( ObjInfo[0] ) ); NumObjects = numobjs; } LastMTE = mte; DosClose( hdl ); }
bool CausePgmToLoadThisDLL( ULONG startLinear ) { char savecode[LOAD_THIS_DLL_SIZE]; USHORT codesize; USHORT len; loadstack_t far *loadstack; void far *ptr; USHORT dll_name_len; USHORT size; char this_dll[BUFF_SIZE]; bool rc; /* * save a chunk of the program's code, and put in LoadThisDLL instead */ if( DosGetModName( ThisDLLModHandle, BUFF_SIZE, this_dll ) != 0 ) { return( FALSE ); } codesize = (char *)EndLoadThisDLL - (char *)LoadThisDLL; if( codesize > LOAD_THIS_DLL_SIZE ) return( FALSE ); ReadLinear( savecode, startLinear, codesize ); if( Buff.Cmd != DBG_N_Success ) return( FALSE ); WriteLinear( (byte far *)LoadThisDLL, startLinear, codesize ); /* * set up the stack for the routine LoadThisDLL */ dll_name_len = ( strlen( this_dll ) + 1 ) & ~1; size = sizeof( loadstack_t ) + dll_name_len; loadstack = Automagic( size ); Buff.ESP -= size; strcpy( loadstack->load_name, this_dll ); loadstack->fail_name = NULL; loadstack->fail_len = 0; ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP + offsetof( loadstack_t, load_name ) ); loadstack->mod_name[0] = FP_OFF( ptr ); loadstack->mod_name[1] = FP_SEG( ptr ); ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP + offsetof( loadstack_t, hmod ) ); loadstack->phmod[0] = FP_OFF( ptr ); loadstack->phmod[1] = FP_SEG( ptr ); len = WriteBuffer( (byte far *)loadstack, Buff.SS, Buff.ESP, size ); if( len != size ) return( FALSE ); /* * set up 16:16 CS:IP, SS:SP for execution */ ptr = MakeSegmentedPointer( startLinear ); Buff.CS = FP_SEG( ptr ); Buff.EIP = FP_OFF( ptr ); ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP ); Buff.SS = FP_SEG( ptr ); Buff.ESP = FP_OFF( ptr ); /* * execute LoadThisDLL on behalf of the program */ WriteRegs( &Buff ); DebugExecute( &Buff, DBG_C_Go, FALSE ); if( Buff.Cmd != DBG_N_Breakpoint ) { rc = FALSE; } else { rc = TRUE; } WriteLinear( savecode, startLinear, codesize ); return( rc ); }