📄 hwlist.c
字号:
}
if( hl->info.ge.wcPageLock ) {
strcat( lock, "P1" );
}
if( hl->info.ge.wType == GT_CODE ) {
sprintf( type,"%s(%d)", gbl_types[GT_CODE], hl->info.ge.wData );
} else if( hl->info.ge.wType == GT_RESOURCE ) {
sprintf( type,"%s(%s)", gbl_types[GT_RESOURCE],
(hl->info.ge.wData < (sizeof( res_types ) /sizeof( char *))) ?
res_types[ hl->info.ge.wData ]: GetRCString( STR_LOWER_UNKNOWN ) );
} else {
strcpy( type,gbl_types[hl->info.ge.wType] );
}
sprintf( line,"%s%4s %08lx %8ld %-8s %c %-5s %c %-21s",
hl->is_added ? "*" : " ",
handle,
hl->info.ge.dwAddress,
hl->info.ge.dwBlockSize,
hl->szModule,
hl->flag,
lock,
(hl->info.ge.wHeapPresent ? 'Y':' '),
type
);
}
return( TRUE );
} /* FormatHeapListItem */
/*
* SaveGlobalListState - save the top item and selected item in the
* list box so we can restore them later
*/
static BOOL SaveGlobalListState( HWND boxhwnd, GlobStateStruct *state ) {
LRESULT top, sel;
if( HeapList == NULL ) return( FALSE );
top = SendMessage( boxhwnd, LB_GETTOPINDEX, 0, 0L );
sel = SendMessage( boxhwnd, LB_GETCURSEL, 0, 0L );
if( sel != LB_ERR && sel < HeapListSize ) {
state->sel = *HeapList[sel];
state->sel_valid = TRUE;
} else {
state->sel_valid = FALSE;
}
if( top >= HeapListSize ) top = 0;
state->top = *HeapList[top];
return( TRUE );
}
/*
* ReDisplayHeapList - dump heap list into list box
*/
void ReDisplayHeapList( HWND boxhwnd, GlobStateStruct *state ) {
WORD topselector;
WORD curselector;
unsigned i;
if( state == NULL ) {
SendMessage( boxhwnd, LB_SETTOPINDEX, 0, 0 );
SendMessage( boxhwnd, LB_SETCURSEL, -1, 0 );
}
SetBoxCnt( boxhwnd, HeapListSize );
if( state != NULL ) {
if( state->top.is_dpmi ) {
curselector = state->sel.info.mem.sel;
topselector = state->top.info.mem.sel;
for( i=0; i < HeapListSize; i++ ) {
if( HeapList[i]->info.mem.sel == topselector ) {
SendMessage( boxhwnd, LB_SETTOPINDEX, i, 0 );
}
if( state->sel_valid
&& HeapList[i]->info.mem.sel == curselector ) {
SendMessage( boxhwnd, LB_SETCURSEL, i, 0 );
}
}
} else {
curselector = (WORD)state->sel.info.ge.hBlock;
topselector = (WORD)state->top.info.ge.hBlock;
for( i=0; i < HeapListSize; i++ ) {
if( (WORD)HeapList[i]->info.ge.hBlock == topselector
&& HeapList[i]->info.ge.dwAddress
== state->top.info.ge.dwAddress ) {
SendMessage( boxhwnd, LB_SETTOPINDEX, i, 0 );
}
if( state->sel_valid
&& (WORD)HeapList[i]->info.ge.hBlock == curselector
&& HeapList[i]->info.ge.dwAddress
== state->sel.info.ge.dwAddress ) {
SendMessage( boxhwnd, LB_SETCURSEL, i, 0 );
}
}
}
}
}
/*
* FreeHeapList - release old heap list
*/
void FreeHeapList( void )
{
int i;
if( HeapListSize != 0 ) {
for( i=0;i<HeapListSize;i++ ) {
MemFree( HeapList[i] );
}
MemFree( HeapList );
HeapList = NULL;
HeapListSize = 0;
}
} /* FreeHeapList */
/*
* AddToHeapList - add a new item to the heap list
*/
static BOOL AddToHeapList( heap_list *hl )
{
void *ptr;
ptr = MemReAlloc( HeapList,
sizeof( heap_list * ) * (HeapListSize + 1) );
if( ptr == NULL ) {
return( FALSE );
} else {
HeapList = ptr;
}
HeapList[ HeapListSize ] = MemAlloc( sizeof( heap_list ) );
if( HeapList[ HeapListSize ] == NULL ) return( FALSE );
*HeapList[ HeapListSize ] = *hl;
HeapListSize++;
return( TRUE );
} /* AddToHeapList */
/*
* AddAllSelectors - add all DPMI selectors starting at given one
*/
static BOOL AddAllSelectors( WORD sel )
{
heap_list hl;
BOOL ret;
hl.is_dpmi = TRUE;
hl.is_added = FALSE;
while( 1 ) {
if( IsValidSelector( sel ) ) {
hl.info.mem.sel = sel;
GetADescriptor( sel, &hl.info.mem.desc );
ret = AddToHeapList( &hl );
if( !ret ) return( FALSE );
}
if( sel + 0x08 < sel ) break;
sel += 0x08;
}
return( TRUE );
} /* AddAllSelectors */
static char GetMemFlag( heap_list *hl ) {
if( (WORD)hl->info.ge.hBlock % 2 ) return( 'F' );
if( hl->info.ge.wType == GT_CODE || hl->info.ge.wType == GT_RESOURCE ) {
if( hl->info.ge.wcLock == 0 && hl->info.ge.wcPageLock == 0 ) {
return( 'D' );
}
}
return( ' ' );
} /* GetMemFlag */
/*
* FindModuleName - find the name of the owner of a piece of memory.
* modhdl may be a task id or a module id so we try both
*/
void FindModuleName( char *buf, HANDLE modhdl ) {
MODULEENTRY me;
TASKENTRY te;
if( MyModuleFindHandle( &me, modhdl ) ) {
strcpy( buf, me.szModule );
buf[MAX_MODULE_NAME]=0;
} else if( MyTaskFindHandle( &te, modhdl ) ) {
strcpy( buf, te.szModule );
buf[MAX_MODULE_NAME]=0;
} else {
buf[0] = '\0';
}
}
/*
* InitHeapList - build a heap list
*/
void InitHeapList( HWND boxhwnd, BOOL keeppos )
{
GlobStateStruct state;
int htype;
HCURSOR hourglass;
HCURSOR oldcursor;
WORD pos;
BOOL ret;
hourglass = LoadCursor( NULL, IDC_WAIT );
SetCapture( boxhwnd );
oldcursor= SetCursor( hourglass );
if( keeppos ) {
keeppos = SaveGlobalListState( boxhwnd, &state );
}
FreeHeapList();
switch( HeapType ) {
case HEAPMENU_DISPLAY_ENTIRE:
htype = GLOBAL_ALL;
break;
case HEAPMENU_DISPLAY_LRU:
htype = GLOBAL_LRU;
break;
case HEAPMENU_DISPLAY_FREE:
htype = GLOBAL_FREE;
break;
}
if( HeapType != HEAPMENU_DISPLAY_DPMI ) {
heap_list hl;
ListingDPMI = FALSE;
hl.is_dpmi = FALSE;
hl.is_added = FALSE;
pos = 0;
MyGlobalFirst( &hl.info.ge, htype );
do {
hl.szModule[0] = 0;
hl.lru_pos = pos;
if( hl.info.ge.hOwner != NULL ) {
FindModuleName( hl.szModule, hl.info.ge.hOwner );
}
hl.flag = GetMemFlag( &hl );
ret = AddToHeapList( &hl );
if( !ret ) break;
pos ++;
} while( MyGlobalNext( &hl.info.ge, htype ) );
} else {
ListingDPMI = TRUE;
ret = AddAllSelectors( 7 );
if( ret ) {
ret = AddAllSelectors( 0 );
}
}
if( !ret ) {
ErrorBox( HeapWalkMainWindow, STR_CANT_CONSTRUCT_GBL_LIST,
MB_OK | MB_ICONINFORMATION );
SendMessage( boxhwnd, LB_RESETCONTENT, 0, 0L );
} else {
SortHeapList();
ReDisplayHeapList( boxhwnd, keeppos ? &state:NULL );
}
SetCursor( oldcursor );
ReleaseCapture();
} /* InitHeapList */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -