static USHORT ReadBuffer( void *dst, USHORT segv, ULONG offv, USHORT size ) { USHORT length; bool iugs; USHORT resdata; ULONG flat; BYTE *data = dst; if( segv < 4 ) { return( 0 ); } length = size; if( Pid != 0 ) { iugs = IsUnknownGDTSeg( segv ); if( !iugs ) { flat = MakeItFlatNumberOne( segv, offv ); ReadLinear( data, flat, size ); if( Buff.Cmd == DBG_N_Success ) { return( size ); } } while( length != 0 ) { if( iugs || offv > KERNEL_MEM_OFFSET ) { if( !TaskReadWord( segv, offv, &resdata ) ) { break; } } else { Buff.Cmd = DBG_C_ReadMem_D; Buff.Addr = MakeItFlatNumberOne( segv, offv ); CallDosDebug(&Buff); if( Buff.Cmd != DBG_N_Success ) { break; } resdata = Buff.Value; } *data = resdata & 0xff; data++; offv++; length--; if( length != 0 ) { *data = resdata >> 8; data++; offv++; length--; } }
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 ); }