Example #1
0
/*
 * MakeItSegmentedNumberOne - make a (sel,offset) into a 16:16 pointer
 */
void __far * MakeItSegmentedNumberOne( USHORT seg, ULONG offset )
{
    if( !IsFlatSeg( seg ) ) return( MK_FP( seg, (USHORT) offset ) );
    return( MakeSegmentedPointer( offset ) );

} /* MakeItSegmentedNumberOne */
Example #2
0
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 );
}