/* * horkyFindSegment: * * runs and tries to find a segment. It does this by finding the module * entry in the global heap for this task. The module entry is a lot like * an NE header, except that instead of segment numbers, it has the selector * values themselves. We pass the module entry to accessSegment, who looks * up the selector and causes it to load. * * The reason: load on call segments are not identified by toolhelp, * so mapaddrs for those segments would fail without this putrid code. * As well, the segments themselves are not always loaded (loadoncall * segments), so if you were to look at the memory there, you would see * nothing. * * Special note: this only works for the task that you are debugging. * Windows knows what the current task is, and when you access a not present * segment, it tries to load the segment based on the current task. Thus, * you cannot try to have the debugee fault in a segment belonging to some * other task. Why DLL's work at all (since they are not a "task") is beyond * me. */ static BOOL horkyFindSegment( int module, WORD segment ) { static GLOBALENTRY ge; static HMODULE lastmodid; HMODULE modid; modid = moduleIDs[ module ]; if( !moduleIsDLL[ module ] ) { return( FALSE ); } if( lastmodid == modid ) { accessSegment( ge.hBlock, segment ); return( TRUE ); } lastmodid = modid; ge.dwSize = sizeof( ge ); if( !GlobalFirst( &ge, GLOBAL_ALL ) ) { lastmodid = NULL; return( FALSE ); } do { if( ge.hOwner == modid && ge.wType == GT_MODULE ) { accessSegment( ge.hBlock, segment ); return( TRUE ); } ge.dwSize = sizeof( ge ); } while( GlobalNext( &ge, GLOBAL_ALL ) ); lastmodid = NULL; return( FALSE ); } /* horkyFindSegment */
/* * horkyFindSegment - runs and tries to find a segment. load on call * segments are not identified by toolhelp, * so mapaddrs for those segments would fail with * out this putrid code. */ static WORD horkyFindSegment( HMODULE modid, WORD segment ) { static GLOBALENTRY ge; static HMODULE lastmodid; if( lastmodid == modid ) { return( accessSegment( ge.hBlock, segment ) ); } lastmodid = modid; ge.dwSize = sizeof( ge ); if( !MyGlobalFirst( &ge, GLOBAL_ALL ) ) { lastmodid = NULL; return( 0 ); } do { if( ge.hOwner == modid && ge.wType == GT_MODULE ) { return( accessSegment( ge.hBlock, segment ) ); } ge.dwSize = sizeof( ge ); } while( MyGlobalNext( &ge, GLOBAL_ALL ) ); lastmodid = NULL; return( 0 ); } /* horkyFindSegment */