📄 regmon.c
字号:
case IDM_FIND:
// search the listview
if( !hWndFind ) {
PrevMatch = FALSE;
PopFindDialog( hWnd );
} else if( PrevMatch ) {
// treat this like a find-next
SetCapture(hWndFind);
hSaveCursor = SetCursor(hHourGlass);
EnableWindow( hWndFind, FALSE );
if (FindInListview( hWnd, &FindTextInfo ) ) {
Autoscroll = FALSE;
CheckMenuItem( GetMenu(hWnd), IDM_AUTOSCROLL,
MF_BYCOMMAND|MF_UNCHECKED );
SendMessage( hWndToolbar, TB_CHANGEBITMAP, IDM_AUTOSCROLL, 3 );
}
EnableWindow( hWndFind, TRUE );
SetCursor( hSaveCursor );
ReleaseCapture();
}
return 0;
case IDM_CAPTURE:
// Read statistics from driver
Capture = !Capture;
CheckMenuItem( GetMenu(hWnd), IDM_CAPTURE,
MF_BYCOMMAND|(Capture?MF_CHECKED:MF_UNCHECKED) );
// Have driver turn on hooks
if ( ! DeviceIoControl( SysHandle, Capture ? REGMON_hook :
REGMON_unhook,
NULL, 0, NULL, 0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return TRUE;
}
SendMessage( hWndToolbar, TB_CHANGEBITMAP, IDM_CAPTURE, (Capture?2:1) );
InvalidateRect( hWndToolbar, NULL, TRUE );
return FALSE;
case IDM_AUTOSCROLL:
Autoscroll = !Autoscroll;
CheckMenuItem( GetMenu(hWnd), IDM_AUTOSCROLL,
MF_BYCOMMAND|(Autoscroll?MF_CHECKED:MF_UNCHECKED) );
SendMessage( hWndToolbar, TB_CHANGEBITMAP, IDM_AUTOSCROLL, (Autoscroll?4:3) );
InvalidateRect( hWndToolbar, NULL, TRUE );
return FALSE;
case IDM_BOOTLOG:
BootLog = !BootLog;
CheckMenuItem( GetMenu(hWnd), IDM_BOOTLOG,
MF_BYCOMMAND|(BootLog?MF_CHECKED:MF_UNCHECKED) );
if( BootLog ) {
sprintf( msgbuf,
_T("Regmon has been configured to log Registry activity to %s during the next boot"),
logFile );
MessageBox( hWnd, msgbuf, _T("Regmon"), MB_OK|MB_ICONINFORMATION);
}
BootLogMenuUsed = TRUE;
return FALSE;
case IDM_EXIT:
// Close ourself
SendMessage( hWnd, WM_CLOSE, 0, 0 );
return FALSE;
case IDM_FILTER:
DialogBox( hInst, _T("Filter"), hWnd, (DLGPROC) FilterProc );
return FALSE;
case IDM_ONTOP:
OnTop = !OnTop;
if( OnTop ) SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE );
else SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE );
CheckMenuItem( GetMenu(hWnd), IDM_ONTOP,
MF_BYCOMMAND|(OnTop?MF_CHECKED:MF_UNCHECKED) );
return 0;
case IDM_JUMP:
// open the specified key in Regedit, if we can
RegeditJump( hWnd );
return FALSE;
case IDM_ABOUT:
// Show the names of the authors
DialogBox( hInst, _T("AboutBox"), hWnd, (DLGPROC)About );
return FALSE;
case IDM_SAVE:
SaveFile( hWnd, hWndList, FALSE );
return FALSE;
case IDM_SAVEAS:
SaveFile( hWnd, hWndList, TRUE );
return FALSE;
default:
// Default behavior
return DefWindowProc( hWnd, message, wParam, lParam );
}
break;
case WM_TIMER:
// Time to query the device driver for more data
if ( Capture ) {
// don't process for more than a second without pausing
startTime = GetTickCount();
for (;;) {
// Have driver fill Stats buffer with information
if ( ! DeviceIoControl( SysHandle, REGMON_getstats,
NULL, 0, &Stats, sizeof Stats,
&StatsLen, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return TRUE;
}
if ( StatsLen == 0 )
break;
// Update statistics windows
UpdateStatistics( hWnd, hWndList, FALSE );
if( GetTickCount() - startTime > 1000 ) break;
}
}
// delete balloon if necessary
if( hBalloon ) {
GetCursorPos( &hitPoint );
GetWindowRect( hWndList, &listRect );
if( hitPoint.x < listRect.left ||
hitPoint.x > listRect.right ||
hitPoint.y < listRect.top ||
hitPoint.y > listRect.bottom ) {
DestroyWindow( hBalloon );
}
}
return FALSE;
case WM_SIZE:
// Move or resize the List
MoveWindow( hWndToolbar, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE );
MoveWindow( hWndList, 0, TOOLBARHEIGHT, LOWORD(lParam), HIWORD(lParam)-TOOLBARHEIGHT, TRUE );
if( hBalloon ) DestroyWindow( hBalloon );
return FALSE;
case WM_MOVE:
case WM_MOUSEMOVE:
if( hBalloon ) DestroyWindow( hBalloon );
return FALSE;
case WM_CLOSE:
// Have driver unhook if necessary
if( Capture ) {
if ( ! DeviceIoControl( SysHandle, REGMON_unhook,
NULL, 0, NULL, 0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return TRUE;
}
}
KillTimer( hWnd, 1 );
CloseHandle( SysHandle );
#if _DEBUG
if ( IsNT && !UnloadDeviceDriver( SYS_NAME ) ) {
wsprintf( msgbuf, _T("Error unloading \"%s\""), SYS_NAME );
MessageBox( hWnd, msgbuf, _T("Regmon"), MB_OK );
}
#endif
// Make sure the user knows boot logging will take place
if( IsNT ) {
if( !BootLogMenuUsed && BootLog ) {
sprintf( msgbuf,
_T("Regmon is configured to log Registry activity to %s during the next boot"),
logFile );
MessageBox( hWnd, msgbuf, _T("Regmon"), MB_ICONINFORMATION);
}
// if boot logging isn't enabled, delete the driver from
// the drivers directory
if( !BootLog ) {
if( RegCreateKey( HKEY_LOCAL_MACHINE, DriverRegistryKey, &hDriverKey ) ==
ERROR_SUCCESS ) {
driverStart = SERVICE_DEMAND_START;
RegSetValueEx( hDriverKey, _T("Start"), 0, REG_DWORD,
(PBYTE) &driverStart, sizeof(driverStart));
RegDeleteValue( hDriverKey, _T("Group"));
RegDeleteValue( hDriverKey, _T("Tag"));
DeleteFile( driverPath );
}
} else {
// boot logging on - configure the regmon service key.
if( RegCreateKey( HKEY_LOCAL_MACHINE, DriverRegistryKey, &hDriverKey ) ==
ERROR_SUCCESS ) {
// the driver is already in the winnt\system32\drivers directory
driverStart = SERVICE_BOOT_START;
RegDeleteValue( hDriverKey, _T("DeleteFlag" ));
RegSetValueEx( hDriverKey, _T("Start"), 0, REG_DWORD,
(PBYTE) &driverStart, sizeof(driverStart));
RegSetValueEx( hDriverKey, "Group", 0, REG_SZ, group, sizeof( group ));
tag = 1;
RegSetValueEx( hDriverKey, "Tag", 0, REG_DWORD,
(PBYTE) &tag, sizeof(tag));
RegSetValueEx( hDriverKey, "Type", 0, REG_DWORD,
(PBYTE) &tag, sizeof(tag));
sprintf( Path, _T("System32\\Drivers\\%s"),
SYS_FILE );
RegSetValueEx( hDriverKey, _T("ImagePath"), 0, REG_EXPAND_SZ,
Path, strlen(Path));
RegCloseKey( hDriverKey );
} else {
Abort( hWnd, _T("Regmon could not configure boot logging"));
}
}
if( hDriverKey != INVALID_HANDLE_VALUE ) RegCloseKey( hDriverKey );
}
Save_Position_Settings( hWnd );
return DefWindowProc( hWnd, message, wParam, lParam );
case WM_SETFOCUS:
SetFocus( hWndList );
break;
case WM_DESTROY:
PostQuitMessage(0);
return FALSE;
case WM_PAINT:
if( !IsNT && Deleting ) {
hDC = BeginPaint( hWnd, &Paint );
EndPaint( hWnd, &Paint );
return TRUE;
}
return DefWindowProc( hWnd, message, wParam, lParam );
default:
// is it a find-string message?
if (message == findMessageID ){
// get a pointer to the find structure
findMessageInfo = (LPFINDREPLACE)lParam;
// If the FR_DIALOGTERM flag is set, invalidate the find window handle
if( findMessageInfo->Flags & FR_DIALOGTERM) {
hWndFind = NULL;
PrevMatch = FALSE;
FindFlags = FindTextInfo.Flags & (FR_DOWN|FR_MATCHCASE|FR_WHOLEWORD);
return 0;
}
// if the FR_FINDNEXT flag is set, go do the search
if( findMessageInfo->Flags & FR_FINDNEXT ) {
SetCapture(hWndFind);
hSaveCursor = SetCursor(hHourGlass);
EnableWindow( hWndFind, FALSE );
if( FindInListview( hWnd, findMessageInfo ) ) {
Autoscroll = FALSE;
CheckMenuItem( GetMenu(hWnd), IDM_AUTOSCROLL,
MF_BYCOMMAND|MF_UNCHECKED );
SendMessage( hWndToolbar, TB_CHANGEBITMAP, IDM_AUTOSCROLL, 3 );
}
EnableWindow( hWndFind, TRUE );
ReleaseCapture();
return 0;
}
return 0;
}
// Default behavior
return DefWindowProc( hWnd, message, wParam, lParam );
}
return FALSE;
}
/****************************************************************************
*
* FUNCTION: InitApplication(HANDLE)
*
* PURPOSE: Initializes window data and registers window class
*
****************************************************************************/
BOOL InitApplication( HANDLE hInstance )
{
WNDCLASS wc;
// Fill in window class structure with parameters that describe the
// main (statistics) window.
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, _T("ICON") );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)(COLOR_INACTIVEBORDER + 1); // Default color
wc.lpszMenuName = _T("LISTMENU");
wc.lpszClassName = _T("RegmonClass");
if ( ! RegisterClass( &wc ) )
return FALSE;
wc.lpszMenuName = NULL;
wc.lpfnWndProc = (WNDPROC) BalloonDialog;
wc.hbrBackground = CreateSolidBrush( 0x00E0FFFF );
wc.lpszClassName = "BALLOON";
RegisterClass( &wc );
return TRUE;
}
/****************************************************************************
*
* FUNCTION: InitInstance(HANDLE, int)
*
* PURPOSE: Saves instance handle and creates main window
*
****************************************************************************/
HWND InitInstance( HANDLE hInstance, int nCmdShow )
{
// get the window position settings from the registry
Get_Position_Settings();
hInst = hInstance;
hWndMain = CreateWindow( _T("RegmonClass"), _T("Registry Monitor"),
WS_OVERLAPPEDWINDOW,
PositionInfo.left, PositionInfo.top,
PositionInfo.width, PositionInfo.height,
NULL, NULL, hInstance, NULL );
// if window could not be created, return "failure"
if ( ! hWndMain )
return NULL;
// make the window visible; update its client area; and return "success"
ShowWindow( hWndMain, nCmdShow );
UpdateWindow( hWndMain );
// maximize it if necessary
if( PositionInfo.maximized ) {
ShowWindow( hWndMain, SW_SHOWMAXIMIZED );
}
if( OnTop ) {
SetWindowPos( hWndMain, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE );
CheckMenuItem( GetMenu(hWndMain), IDM_ONTOP,
MF_BYCOMMAND|(OnTop?MF_CHECKED:MF_UNCHECKED) );
}
return hWndMain;
}
/****************************************************************************
*
* FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
*
* PURPOSE: calls initialization function, processes message loop
*
****************************************************************************/
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
DWORD NTVersion;
if ( ! InitApplication( hInstance ) )
return FALSE;
// get NT version
NTVersion = GetVersion();
if( NTVersion >= 0x80000000 ) {
IsNT = FALSE;
} else {
IsNT = TRUE;
}
// initializations that apply to a specific instance
if ( (hWnd = InitInstance( hInstance, nCmdShow )) == NULL )
return FALSE;
// load accelerators
hAccel = LoadAccelerators( hInstance, _T("ACCELERATORS"));
// register for the find window message
findMessageID = RegisterWindowMessage( FINDMSGSTRING );
// acquire and dispatch messages until a WM_QUIT message is received.
while ( GetMessage( &msg, NULL, 0, 0 ) ) {
if( !TranslateAccelerator( hWnd, hAccel, &msg ) &&
(!hWndFind || !IsWindow(hWndFind) || !IsDialogMessage( hWndFind, &msg ))) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return msg.wParam;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -