/* * codeLoad - handle the loading of a new DLL/EXE */ static void codeLoad( HANDLE handle, DWORD base, char *name, samp_block_kinds kind ) { seg_offset ovl; int i; pe_object obj; WORD seg; DWORD offset; DWORD bytes; pe_header peh; name = name; ovl.offset = 0; ovl.segment = 0; WriteCodeLoad( ovl, name, kind ); if( !getPEHeader( handle, &peh ) ) { return; } for( i = 0; i < peh.num_objects; i++ ) { ReadFile( handle, &obj, sizeof( obj ), &bytes, NULL ); if( obj.flags & (PE_OBJ_CODE | PE_OBJ_EXECUTABLE) ) { seg = FP_SEG( codeLoad ); } else { seg = FP_SEG( &seg ); } offset = (DWORD) base + obj.rva; WriteAddrMap( i + 1, seg, offset ); } } /* codeLoad */
static void CodeLoad( char *name, u_long addr, samp_block_kinds kind ) { seg_offset ovl; ovl.offset = 0; ovl.segment = 0; WriteCodeLoad( ovl, name, kind ); /* fake the address map - no segments here */ WriteAddrMap( 1, FlatSeg, addr ); }
void CodeLoad( struct LoadDefinitionStructure *loaded, samp_block_kinds kind ) { seg_offset ovl_tbl; char buff[256]; ovl_tbl.segment = 0; ovl_tbl.offset = 0; memcpy( buff, loaded->LDFileName + 1, loaded->LDFileName[0] ); buff[loaded->LDFileName[0]] = '\0'; WriteCodeLoad( ovl_tbl, buff, kind ); WriteAddrMap( 1, GetCS(), loaded->LDCodeImageOffset ); }
static void CodeLoad( TRACEBUF FAR_PTR *buff, USHORT mte, const char *name, samp_block_kinds kind ) { seg_offset ovl; int i; ovl.offset = 0; ovl.segment = 0; WriteCodeLoad( ovl, name, kind ); buff->mte = mte; for( i = 1;; ++i ) { buff->cmd = PT_CMD_SEG_TO_SEL; buff->value = i; if( DosPTrace( buff ) != 0 ) break; if( buff->cmd != PT_RET_SUCCESS ) break; WriteAddrMap( i, buff->value, 0 ); } }
/* * codeLoad - handle the loading of a new DLL/EXE */ static void codeLoad( HANDLE handle, DWORD base, const char *name, samp_block_kinds kind ) { seg_offset ovl; int i; pe_object obj; DWORD offset; DWORD bytes; pe_header peh; ovl.offset = 0; ovl.segment = 0; WriteCodeLoad( ovl, name, kind ); if( !getPEHeader( handle, &peh ) ) { return; } for( i = 0; i < peh.num_objects; i++ ) { ReadFile( handle, &obj, sizeof( obj ), &bytes, NULL ); offset = (DWORD)base + obj.rva; WriteAddrMap( i + 1, SEGMENT, offset ); } } /* codeLoad */
void StartProg( char *cmd, char *prog, char *full_args, char *dos_args ) { seg_offset where; int error_num; char buff[BSIZE]; Fptr32 fp; short initial_cs; int len; cmd = cmd; SampleIndex = 0; CurrTick = 0L; D32HookTimer( TimerMult ); /* ask for timer - before D32DebugInit!! */ D32DebugBreakOp(&Break); /* Get the 1 byte break op */ error_num = D32DebugInit( &Proc ); if( error_num == 0 ) { strcpy( buff, full_args ); error_num = D32DebugLoad( prog, buff, &Proc ); } if( error_num != 0 ) { Output( MsgArray[MSG_SAMPLE_2-ERR_FIRST_MESSAGE] ); Output( prog ); Output( "\r\n" ); MsgFini(); exit(1); } where.offset = 0; where.segment = 0; WriteCodeLoad( where, ExeName, SAMP_MAIN_LOAD ); fp.sel = 1; fp.off = 0; D32Relocate(&fp); WriteAddrMap( 1, fp.sel, fp.off ); initial_cs = Proc.cs; for( ;; ) { D32DebugRun( &Proc ); if( SampleIndex > Margin && Proc.cs == initial_cs ) { StopAndSave(); } if( Proc.int_id == 8 ) { ++InsiderTime; RecordSample( Proc.eip, Proc.cs ); --InsiderTime; } else if( Proc.int_id == 3 && (Proc.edx & 0xffff) != 0 ) { len = 0; /* this is a mark */ where.segment = Proc.edx & 0xffff; where.offset = Proc.eax; for( ;; ) { if( !D32AddressCheck( where.segment, where.offset, 1, NULL ) ) break; D32DebugRead( where.offset, where.segment, 0, &buff[len], 1 ); if( len == BSIZE ) break; if( buff[len] == '\0' ) break; len++; where.offset++; } buff[len] = '\0'; where.segment = Proc.cs; where.offset = Proc.eip; WriteMark( buff, where ); Proc.eip++; } else if( Proc.int_id == 3 ) { /* remember common storage */ CommonAddr.segment = Proc.ecx & 0xffff; /* area ... */ CommonAddr.offset = Proc.ebx; Proc.eip++; } else { break; } } D32UnHookTimer(); if( Proc.int_id != 0x21 ) { Output( MsgArray[MSG_SAMPLE_1-ERR_FIRST_MESSAGE] ); Output( MsgArray[Exceptions[Proc.int_id]+MSG_EXCEPT_0-ERR_FIRST_MESSAGE] ); Output( "\r\n" ); } D32DebugTerm(); report(); }
/* * newModule - handle a new module */ static void newModule( HANDLE hmod, char *name, samp_block_kinds kind ) { GLOBALENTRY ge; os2_exe_header ne; dos_exe_header de; seg_offset ovl; int i; LPVOID ptr; WORD sel; int handle; int numsegs; WORD win32ds; WORD win32cs; DWORD win32initialeip; int rc; ovl.offset = 0; ovl.segment = 0; rc = CheckIsModuleWin32App( hmod, &win32ds, &win32cs, &win32initialeip ); if( rc ) { if( win32ds != 0 ) { WriteCodeLoad( ovl, name, kind ); WriteAddrMap( 1, win32cs, win32initialeip ); WriteAddrMap( 2, win32ds, 0 ); } else if( kind == SAMP_MAIN_LOAD ) { FlagWin32AppAsDebugged( hmod ); WaitForInt3 = GetCurrentTask(); } else if( WaitForInt1 == 0 ) { FlagWin32AppAsDebugged( hmod ); WaitForInt1 = hmod; } return; } WriteCodeLoad( ovl, name, kind ); handle = open( name,O_BINARY | O_RDONLY ); if( handle >= 0 ) { read( handle, &de, sizeof( de ) ); if( de.signature == DOS_SIGNATURE ) { lseek( handle, ( de.file_size - 1L ) * 512L + (long)de.mod_size, SEEK_SET ); } else { lseek( handle, 0, SEEK_SET ); } read( handle, &ne, sizeof( ne ) ); if( ne.signature == OS2_SIGNATURE_WORD ) { numsegs = ne.segments; if( numsegs > 8192 ) { // must not really be a valid OS2 sig. numsegs = -1; } } else { numsegs = -1; } close( handle ); } for( i = 1; i < 8192; i++ ) { if( !MyGlobalEntryModule( &ge, hmod, i ) ) { if( numsegs > 0 ) { sel = horkyFindSegment( hmod, i ); if( sel == 0 ) { continue; } } else { continue; } } else { if( ge.hBlock != NULL ) { ptr = GlobalLock( ge.hBlock ); GlobalUnlock( ge.hBlock ); sel = FP_SEG( ptr ); if( sel == NULL ) { sel = (WORD)ge.hBlock + 1; } } else { continue; } } WriteAddrMap( i, sel, 0 ); numsegs--; if( numsegs == 0 ) { break; } } } /* newModule */