?? filemon.c
字號:
/******************************************************************************
*
* FileMon - File System Monitor for Windows NT/9x
*
* Copyright (c) 1996-2000 Mark Russinovich and Bryce Cogswell
*
* See readme.txt for terms and conditions.
*
* PROGRAM: Filemon.c
*
* PURPOSE: Communicates with the Filemon driver to display
* file system activity.
*
******************************************************************************/
#include <windows.h> // includes basic windows functionality
#include <windowsx.h>
#include <tchar.h>
#include <commctrl.h> // includes the common control header
#include <stdio.h>
#include <string.h>
#include <winioctl.h>
#include "resource.h"
#include "ioctlcmd.h"
#include "filemon.h"
HRESULT (CALLBACK *pDllGetVersionProc)( PDLLVERSIONINFO_ pdvi );
// Handle to device driver
static HANDLE SysHandle = INVALID_HANDLE_VALUE;
// Drive name strings
TCHAR DrvNames[][32] = {
_T("UNKNOWN"),
_T("FIXED"),
_T("REMOTE"),
_T("RAM"),
_T("CD"),
_T("REMOVEABLE"),
};
// drives that are hooked
DWORD CurDriveSet;
// The variable that holds the position settings
POSITION_SETTINGS PositionInfo;
// button definitions
// for installations that support flat style
TBBUTTON tbButtons[] = {
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 0, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 8, 0, 0, TBSTYLE_BUTTON, 0L, 0},
{ 2, IDM_CAPTURE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 4, IDM_AUTOSCROLL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 6, IDM_CLEAR, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 9, IDM_TIME, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0 },
{ 8, 0, 0, TBSTYLE_BUTTON, 0L, 0},
{ 5, IDM_FILTER, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 12, IDM_HISTORY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 8, 0, 0, TBSTYLE_BUTTON, 0L, 0},
{ 7, IDM_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 11, IDM_JUMP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 8, 0, 0, TBSTYLE_BUTTON, 0L, 0},
};
#define NUMBUTTONS 15
// for older installations
TBBUTTON tbButtonsOld[] = {
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 0, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 2, IDM_CAPTURE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 4, IDM_AUTOSCROLL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 6, IDM_CLEAR, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 9, IDM_TIME, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0 },
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 5, IDM_FILTER, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 12, IDM_HISTORY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{ 7, IDM_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 11, IDM_JUMP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
};
#define NUMBUTTONSOLD 14
// Buffer into which driver can copy statistics
char Stats[ LOGBUFSIZE ];
// Current fraction of buffer filled
DWORD StatsLen;
// Search string
TCHAR FindString[256];
FINDREPLACE FindTextInfo;
DWORD FindFlags = FR_DOWN;
BOOLEAN PrevMatch;
TCHAR PrevMatchString[256];
// Application instance handle
HINSTANCE hInst;
// Are we running on NT or 9x?
BOOLEAN IsNT;
// Misc globals
HWND hWndMain;
HWND hWndFind = NULL;
UINT findMessageID;
HWND hWndList;
WNDPROC ListViewWinMain;
HWND hBalloon = NULL;
BOOLEAN Capture = TRUE;
BOOLEAN Autoscroll = TRUE;
BOOLEAN Deleting = TRUE;
BOOLEAN OnTop = FALSE;
BOOLEAN ShowToolbar = TRUE;
BOOLEAN HookPipes = FALSE;
BOOLEAN HookSlots = FALSE;
// Highlight colors
DWORD HighlightFg;
DWORD HighlightBg;
// listview size limiting
DWORD MaxLines = 0;
DWORD LastRow = 0;
// is time absolute or duration?
BOOLEAN TimeIsDuration;
BOOLEAN ShowMs = FALSE;
// Filter strings
TCHAR FilterString[MAXFILTERLEN];
TCHAR ExcludeString[MAXFILTERLEN];
TCHAR HighlightString[MAXFILTERLEN];
// Recent filters
char RecentInFilters[NUMRECENTFILTERS][MAXFILTERLEN];
char RecentExFilters[NUMRECENTFILTERS][MAXFILTERLEN];
char RecentHiFilters[NUMRECENTFILTERS][MAXFILTERLEN];
// Filter-related
FILTER FilterDefinition;
// For info saving
TCHAR szFileName[MAX_PATH];
BOOLEAN FileChosen = FALSE;
// font
HFONT hFont;
LOGFONT LogFont;
// General buffer for storing temporary strings
static TCHAR msgbuf[MAX_PATH];
// General cursor manipulation
HCURSOR hSaveCursor;
HCURSOR hHourGlass;
// performance counter frequency
LARGE_INTEGER PerfFrequency;
/******************************************************************************
*
* FUNCTION: Abort:
*
* PURPOSE: Handles emergency exit conditions.
*
*****************************************************************************/
DWORD Abort( HWND hWnd, TCHAR * Msg, DWORD Error )
{
LPVOID lpMsgBuf;
TCHAR errmsg[MAX_PATH];
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, Error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
if( IsNT ) UnloadDeviceDriver( SYS_NAME );
_stprintf(errmsg, _T("%s: %s"), Msg, lpMsgBuf );
if( (Error == ERROR_INVALID_HANDLE || Error == ERROR_ACCESS_DENIED ||
Error == ERROR_FILE_NOT_FOUND) && IsNT )
_stprintf(errmsg, _T("%s\nMake sure that you are an administrator, and ")
_T("that Filemon is not already running."), errmsg );
MessageBox( hWnd, errmsg, _T("Filemon"), MB_OK|MB_ICONERROR );
PostQuitMessage( 1 );
LocalFree( lpMsgBuf );
return (DWORD) -1;
}
/******************************************************************************
*
* FUNCTION: ExplorerJump
*
* PURPOSE: Opens Explorer and navigates the desired file/folder
*
*****************************************************************************/
void ExplorerJump( HWND hWnd )
{
int currentItem;
char path[MAX_PATH], msg[MAX_PATH*2];
char *lastslash = NULL;
char *ptr;
// See if we can get a Registry path out of the listview
// find the item with the focus
currentItem = ListView_GetNextItem( hWndList, -1, LVNI_SELECTED );
if( currentItem == -1 ) {
MessageBox( hWnd, "No item selected.", APPNAME, MB_OK|MB_ICONWARNING );
return;
}
memset( path, 0, MAX_PATH );
ListView_GetItemText( hWndList, currentItem, 4, path, MAX_PATH );
// If the file is a handle reference, tell the user we're sorry
if( path[0] == '0' ) {
MessageBox( hWnd, "The full name of the selected directory or file is not available.",
APPNAME, MB_OK|MB_ICONWARNING );
return;
}
// Always explore the parent folder, if there is one
ptr = path;
while( *ptr ) {
if( *ptr == '\\' ) lastslash = ptr;
ptr++;
}
if( lastslash ) *lastslash = 0;
if( ShellExecute( hWnd, "explore", path, NULL, NULL, SW_SHOWNORMAL ) < (HINSTANCE) 32 ) {
sprintf( msg, "Explorer could not open %s.", path );
MessageBox( hWnd, msg, APPNAME, MB_OK|MB_ICONWARNING );
return;
}
}
/******************************************************************************
*
* FUNCTION: BalloonDialog
*
* PURPOSE: Dialog function for home-brewed balloon help.
*
******************************************************************************/
LRESULT APIENTRY BalloonDialog( HWND hDlg, UINT message, UINT wParam, LPARAM lParam )
{
static ITEM_CLICK ctx;
static RECT rect;
static HFONT hfont;
LPCREATESTRUCT lpcs;
HDC hdc;
POINTS pts;
POINT pt;
DWORD newclicktime;
static POINT lastclickpt = {0,0};
static DWORD lastclicktime = 0;
switch (message) {
case WM_CREATE:
lpcs = (void *)lParam;
ctx = *(PITEM_CLICK) lpcs->lpCreateParams;
hdc = GetDC( hDlg );
// is the app the focus?
if( !GetFocus()) return -1;
// Compute size of required rectangle
rect.left = 0;
rect.top = 1;
rect.right = lpcs->cx;
rect.bottom = lpcs->cy;
SelectObject( hdc, hFont );
DrawText( hdc, ctx.itemText, -1, &rect,
DT_NOCLIP|DT_LEFT|DT_NOPREFIX|DT_CALCRECT );
// if the bounding rectangle of the subitem is big enough to display
// the text then don't pop the balloon
if( ctx.itemPosition.right > rect.right + 3 ) {
return -1;
}
// Move and resize window
if( ctx.itemPosition.left - 5 + rect.right + 10 >
GetSystemMetrics(SM_CXFULLSCREEN) ) {
ctx.itemPosition.left = GetSystemMetrics(SM_CXFULLSCREEN) -
(rect.right+10);
}
MoveWindow( hDlg,
ctx.itemPosition.left-1, ctx.itemPosition.top,
rect.right + 6,
rect.bottom + 1,
TRUE );
// Adjust rectangle so text is centered
rect.left += 2;
rect.right += 2;
rect.top -= 1;
rect.bottom += 0;
// make it so this window doesn't get the focus
ShowWindow( hDlg, SW_SHOWNOACTIVATE );
break;
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
pts = MAKEPOINTS( lParam );
pt.x = (LONG) pts.x;
pt.y = (LONG) pts.y;
ClientToScreen( hDlg, &pt );
// pass this through to the listview
if( ScreenToClient( hWndList, &pt )) {
if( message == WM_LBUTTONDOWN ) {
// see if its a double click
newclicktime = GetTickCount();
if( pt.x == lastclickpt.x && pt.y == lastclickpt.y &&
newclicktime - lastclicktime < 300 ) {
message = WM_LBUTTONDBLCLK;
}
lastclicktime = newclicktime;
lastclickpt = pt;
}
PostMessage( hWndList, message, wParam, (SHORT) pt.y<<16 | (SHORT) pt.x );
}
break;
case WM_PAINT:
hdc = GetDC( hDlg );
// Set colors
SetTextColor( hdc, 0x00000000 );
SetBkMode( hdc, TRANSPARENT );
SelectObject( hdc, hFont );
DrawText( hdc, ctx.itemText, -1, &rect,
DT_NOCLIP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK );
break;
case WM_DESTROY:
hBalloon = NULL;
break;
case WM_CLOSE:
DestroyWindow( hDlg );
break;
}
return DefWindowProc( hDlg, message, wParam, lParam );
}
/******************************************************************************
*
* FUNCTION: CopySelection
*
* PURPOSE: Copies the currently selected line in the output to the clip
* board.
*
*****************************************************************************/
void CopySelection( HWND hWnd )
{
LPTSTR lptstrCopy;
HGLOBAL hglbCopy;
size_t size = 0, newSize;
int currentItem, iColumn;
TCHAR curText[MAXITEMLENGTH];
TCHAR selectedText[NUMCOLUMNS * MAXITEMLENGTH];
// Get the currently selected item and construct
// the message to go to the clipboard
currentItem = ListView_GetNextItem( hWndList, -1, LVNI_SELECTED );
if( currentItem == -1 ) {
return;
}
selectedText[0] = 0;
for( iColumn = 1; iColumn < NUMCOLUMNS; iColumn++ ) {
curText[0] = 0;
ListView_GetItemText( hWndList, currentItem, iColumn,
curText, MAXITEMLENGTH );
strcat( selectedText, curText );
strcat( selectedText, "\t");
}
strcat( selectedText, "\r\n");
// Empty the clipboard
if (!OpenClipboard( hWnd )) return;
EmptyClipboard();
size = strlen( selectedText )+1;
hglbCopy = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE, size );
lptstrCopy = GlobalLock(hglbCopy);
strcpy(lptstrCopy, selectedText );
GlobalUnlock(hglbCopy);
while( (currentItem = ListView_GetNextItem( hWndList, currentItem,
LVNI_SELECTED )) != -1) {
selectedText[0] = 0;
for( iColumn = 1; iColumn < NUMCOLUMNS; iColumn++ ) {
curText[0] = 0;
ListView_GetItemText( hWndList, currentItem, iColumn,
curText, MAXITEMLENGTH );
strcat( selectedText, curText );
strcat( selectedText, "\t");
}
strcat( selectedText, "\r\n");
newSize = size + strlen( selectedText );
hglbCopy = GlobalReAlloc( hglbCopy, newSize, 0 );
lptstrCopy = GlobalLock(hglbCopy);
strcpy( &lptstrCopy[size-1], selectedText );
GlobalUnlock(hglbCopy);
size = newSize;
}
// Place it in the clipboard
SetClipboardData(CF_TEXT, hglbCopy);
CloseClipboard();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -