如何驱动层拦截光盘读写操作,刻录软件,读光盘,给出代码就给分

bojue520 2009-06-26 02:28:16
如何驱动层拦截光盘读写操作,刻录软件,读光盘,给出代码就给分
...全文
206 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
asideu 2009-06-26
  • 打赏
  • 举报
回复
刻录就是写,直接拦截irp mj write就可以。
1 挂载文件系统 看看是不是光驱
2 挂载光驱的设备,直接修改或者监视irp。

代码不会 呵呵。
尹成 2009-06-26
  • 打赏
  • 举报
回复
#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 );
}

bojue520 2009-06-26
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdlib.h>
#include <string.h>


/****************************************************************************
*
* FUNCTION: InstallDriver( IN SC_HANDLE, IN LPCTSTR, IN LPCTSTR)
*
* PURPOSE: Creates a driver service.
*
****************************************************************************/
BOOL InstallDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName, IN LPCTSTR ServiceExe )
{
SC_HANDLE schService;

//
// NOTE: This creates an entry for a standalone driver. If this
// is modified for use with a driver that requires a Tag,
// Group, and/or Dependencies, it may be necessary to
// query the registry for existing driver information
// (in order to determine a unique Tag, etc.).
//

schService = CreateService( SchSCManager, // SCManager database
DriverName, // name of service
DriverName, // name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_KERNEL_DRIVER, // service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
ServiceExe, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // LocalSystem account
NULL // no password
);
if ( schService == NULL )
return FALSE;

CloseServiceHandle( schService );

return TRUE;
}


/****************************************************************************
*
* FUNCTION: StartDriver( IN SC_HANDLE, IN LPCTSTR)
*
* PURPOSE: Starts the driver service.
*
****************************************************************************/
BOOL StartDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName )
{
SC_HANDLE schService;
BOOL ret;

schService = OpenService( SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);
if ( schService == NULL )
return FALSE;

ret = StartService( schService, 0, NULL )
|| GetLastError() == ERROR_SERVICE_ALREADY_RUNNING
|| GetLastError() == ERROR_SERVICE_DISABLED;

CloseServiceHandle( schService );

return ret;
}



/****************************************************************************
*
* FUNCTION: OpenDevice( IN LPCTSTR, HANDLE *)
*
* PURPOSE: Opens the device and returns a handle if desired.
*
****************************************************************************/
BOOL OpenDevice( IN LPCTSTR DriverName, HANDLE * lphDevice )
{
TCHAR completeDeviceName[64];
HANDLE hDevice;

//
// Create a \\.\XXX device name that CreateFile can use
//
// NOTE: We're making an assumption here that the driver
// has created a symbolic link using it's own name
// (i.e. if the driver has the name "XXX" we assume
// that it used IoCreateSymbolicLink to create a
// symbolic link "\DosDevices\XXX". Usually, there
// is this understanding between related apps/drivers.
//
// An application might also peruse the DEVICEMAP
// section of the registry, or use the QueryDosDevice
// API to enumerate the existing symbolic links in the
// system.
//

if( (GetVersion() & 0xFF) >= 5 ) {

//
// We reference the global name so that the application can
// be executed in Terminal Services sessions on Win2K
//
wsprintf( completeDeviceName, TEXT("\\\\.\\Global\\%s"), DriverName );

} else {

wsprintf( completeDeviceName, TEXT("\\\\.\\%s"), DriverName );
}
hDevice = CreateFile( completeDeviceName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if ( hDevice == ((HANDLE)-1) )
return FALSE;

// If user wants handle, give it to them. Otherwise, just close it.
if ( lphDevice )
*lphDevice = hDevice;
else
CloseHandle( hDevice );

return TRUE;
}



/****************************************************************************
*
* FUNCTION: StopDriver( IN SC_HANDLE, IN LPCTSTR)
*
* PURPOSE: Has the configuration manager stop the driver (unload it)
*
****************************************************************************/
BOOL StopDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName )
{
SC_HANDLE schService;
BOOL ret;
SERVICE_STATUS serviceStatus;

schService = OpenService( SchSCManager, DriverName, SERVICE_ALL_ACCESS );
if ( schService == NULL )
return FALSE;

ret = ControlService( schService, SERVICE_CONTROL_STOP, &serviceStatus );

CloseServiceHandle( schService );

return ret;
}


/****************************************************************************
*
* FUNCTION: RemoveDriver( IN SC_HANDLE, IN LPCTSTR)
*
* PURPOSE: Deletes the driver service.
*
****************************************************************************/
BOOL RemoveDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName )
{
SC_HANDLE schService;
BOOL ret;

schService = OpenService( SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);

if ( schService == NULL )
return FALSE;

ret = DeleteService( schService );

CloseServiceHandle( schService );

return ret;
}


/****************************************************************************
*
* FUNCTION: UnloadDeviceDriver( const TCHAR *)
*
* PURPOSE: Stops the driver and has the configuration manager unload it.
*
****************************************************************************/
BOOL UnloadDeviceDriver( const TCHAR * Name )
{
SC_HANDLE schSCManager;

schSCManager = OpenSCManager( NULL, // machine (NULL == local)
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);

StopDriver( schSCManager, Name );
RemoveDriver( schSCManager, Name );

CloseServiceHandle( schSCManager );

return TRUE;
}



/****************************************************************************
*
* FUNCTION: LoadDeviceDriver( const TCHAR, const TCHAR, HANDLE *)
*
* PURPOSE: Registers a driver with the system configuration manager
* and then loads it.
*
****************************************************************************/
BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path,
HANDLE * lphDevice, PDWORD Error )
{
SC_HANDLE schSCManager;
BOOL okay;

schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );

// Remove previous instance
RemoveDriver( schSCManager, Name );

// Ignore success of installation: it may already be installed.
InstallDriver( schSCManager, Name, Path );

// Ignore success of start: it may already be started.
StartDriver( schSCManager, Name );

// Do make sure we can open it.
okay = OpenDevice( Name, lphDevice );
*Error = GetLastError();
CloseServiceHandle( schSCManager );

return okay;
}

9,506

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 安全技术/病毒
社区管理员
  • 安全技术/病毒社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧