📄 ddlxioct.cpp
字号:
//******************************************************************************
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//******************************************************************************
/*++
Module Name:
ddlxioct.cpp
Abstract:
implemenation of ddlx interface:
1)make the test dll a driver and will be loaded in device.exe space
2)using message queue to pass kato debug message to tux and print out through tux.exe
--*/
// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
#include "TestMain.h"
#include "ddlxioct.h"
#include <msgqueue.h>
// ----------------------------------------------------------------------------
// Command line support
// ----------------------------------------------------------------------------
TCHAR glpCommandLines[10][256] = { 0 };
//CRITICAL_SECTION gcsCritSect;
typedef struct _EX_STRUCT
{
DWORD dwOpenData;
DWORD dwNotOpenData;
}
EX_STRUCT, *LPEX_STRUCT;
// ----------------------------------------------------------------------------
// Function Prototypes
// ----------------------------------------------------------------------------
BOOL ProcessShellCommand( DWORD dwOpenData, // handle identifying the open context of the device
UINT uMsg, // shell message
PBYTE pBufIn, // input buffer
DWORD dwLenIn, // input buffer length
PBYTE pBufOut, // output buffer
DWORD dwLenOut, // output buffer length
PDWORD pdwActualOut); // actual output length
BOOL ProcessTestCommand( DWORD dwOpenData, // handle identifying the open context of the device
UINT uMsg, // test message
PBYTE pBufIn, // input buffer
DWORD dwLenIn, // input buffer length
PBYTE pBufOut, // output buffer
DWORD dwLenOut, // output buffer length
PDWORD pdwActualOut); // actual output length
void DumpFunctionTableEntry ( LPFUNCTION_TABLE_ENTRY );
LPCTSTR ShellCmdToString( UINT );
LPCTSTR TestCmdToString( UINT );
SHELLPROCAPI ShellProc(UINT, SPPARAM);
// ----------------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------------
static const LPTSTR cszThisFile = TEXT("DRVIOCTL.CPP");
static const LPTSTR cszThisTest = TEXT("Generic Device Driver Loader Client");
static int g_iTblSize;
/*// ----------------------------------------------------------------------------
// Debug zone support
// ----------------------------------------------------------------------------
#define DDLXDEBUGZONE(n) (dpPrivCurSettings.ulZoneMask&(0x00000001<<n))
//
// These zones are shared between ddlxdll and ddlxioct, so don't change one
// without changing the other.
//
#define ZONE_ERROR DDLXDEBUGZONE(0)
#define ZONE_WARNING DDLXDEBUGZONE(1)
#define ZONE_FUNCTION DDLXDEBUGZONE(2)
#define ZONE_INIT DDLXDEBUGZONE(3)
#define ZONE_VERBOSE DDLXDEBUGZONE(4)
#define ZONE_IOCTL DDLXDEBUGZONE(5)
#define DBG_ERROR 1
#define DBG_WARNING 2
#define DBG_FUNCTION 4
#define DBG_INIT 8
#define DBG_VERBOSE 16
#define DBG_IOCTL 32
DBGPARAM dpPrivCurSettings =
{
TEXT("DDLX IOCTL"),
{
TEXT("Errors"),TEXT("Warnings"),TEXT("Functions"),TEXT("Initialization"),
TEXT("Verbose"),TEXT("Ioctl"),TEXT("Undefined"),TEXT("Undefined"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined")
},
DBG_ERROR | DBG_INIT|DBG_VERBOSE | 0xFFFFFFFF
};
*/
// ----------------------------------------------------------------------------
//
// Note: All required entry points are represented, but not all are fully
// implemented.
//
// ----------------------------------------------------------------------------
CRITICAL_SECTION * pcsCritSect=NULL;
BOOL
WINAPI DdlxDLLEntry(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
pcsCritSect = new CRITICAL_SECTION;
if (pcsCritSect)
InitializeCriticalSection( pcsCritSect );
break;
case DLL_PROCESS_DETACH:
if (pcsCritSect) {
DeleteCriticalSection( pcsCritSect );
delete pcsCritSect;
pcsCritSect=NULL;
};
default:
break;
};
return TRUE;
};
// ----------------------------------------------------------------------------
// gen_Init()
// ----------------------------------------------------------------------------
DWORD gen_Init (DWORD Index)
{
static int i = 1;
// InitializeCriticalSection( & gcsCritSect );
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Init called...\r\n"),
cszThisFile));
return i++;
}
// ----------------------------------------------------------------------------
// gen_Deinit()
// ----------------------------------------------------------------------------
BOOL gen_Deinit(DWORD dwData)
{
// DeleteCriticalSection( & gcsCritSect );
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Deinit called...\r\n"),
cszThisFile));
return TRUE;
}
// ----------------------------------------------------------------------------
// gen_Open()
// ----------------------------------------------------------------------------
DWORD gen_Open (DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Open called...\r\n"),
cszThisFile));
if (pcsCritSect)
EnterCriticalSection( pcsCritSect );
int i;
for( i = 1; i < 10; i++ )
{
if( glpCommandLines[i][0] == 0 )
{
// This is the first available slot. Take it and mark the entry as
// being in use.
memset( glpCommandLines[i], 0, 256 );
glpCommandLines[i][0] = 1;
break;
}
}
if (pcsCritSect)
LeaveCriticalSection( pcsCritSect );
return i;
}
// ----------------------------------------------------------------------------
// gen_Close()
// ----------------------------------------------------------------------------
BOOL gen_Close (DWORD dwData)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Close called...\r\n"),
cszThisFile));
if(g_pKato){
g_pKato->Stop();
delete g_pKato;
}
if (pcsCritSect)
EnterCriticalSection( pcsCritSect );
// Mark our 'slot' as being available again.
glpCommandLines[dwData][0] = 0;
if (pcsCritSect)
LeaveCriticalSection( pcsCritSect );
return TRUE;
}
// ----------------------------------------------------------------------------
// gen_Read()
// ----------------------------------------------------------------------------
DWORD gen_Read (DWORD dwData, LPVOID pBuf, DWORD Len)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Read called...\r\n"),
cszThisFile));
return 0;
}
// ----------------------------------------------------------------------------
// gen_Write()
// ----------------------------------------------------------------------------
DWORD gen_Write (DWORD dwData, LPCVOID pBuf, DWORD Len)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Write called...\r\n"),
cszThisFile));
return 0;
}
// ----------------------------------------------------------------------------
// gen_Seek()
// ----------------------------------------------------------------------------
DWORD gen_Seek (DWORD dwData, long pos, DWORD type)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_Seek called...\r\n"),
cszThisFile));
return 0;
}
// ----------------------------------------------------------------------------
// gen_PowerUp()
// ----------------------------------------------------------------------------
void gen_PowerUp(DWORD dwData)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_PowerUp called...\r\n"),
cszThisFile));
return;
}
// ----------------------------------------------------------------------------
// gen_PowerDown()
// ----------------------------------------------------------------------------
void gen_PowerDown(DWORD dwData)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("%s: gen_PowerDown called...\r\n"),
cszThisFile));
return;
}
// ----------------------------------------------------------------------------
// gen_IOControl()
// ----------------------------------------------------------------------------
BOOL
gen_IOControl( DWORD dwOpenData, // handle identifying the open context of the device
DWORD dwCode, // command code and uMsg
PBYTE pBufIn, // input buffer
DWORD dwLenIn, // input buffer length
PBYTE pBufOut, // output buffer
DWORD dwLenOut, // output buffer length
PDWORD pdwActualOut) { // actual output length
BOOL fRet = FALSE;
// Extract the i/o control code and message from dwCode
UINT uCmd = LOWORD(dwCode);
UINT uMsg = HIWORD(dwCode);
switch( uCmd )
{
case DRV_IOCTL_CMD_SHELL:
DEBUGMSG(ZONE_IOCTL, (TEXT("DRV_IOCTL_CMD_SHELL: uMsg=%s\r\n"),
ShellCmdToString( uMsg )));
fRet = ProcessShellCommand( dwOpenData, uMsg, pBufIn, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
break;
case DRV_IOCTL_CMD_TEST:
NKDbgPrintfW(TEXT("DRV_IOCTL_CMD_TEST: uMsg=%s\r\n"),
TestCmdToString( uMsg ));
DEBUGMSG(ZONE_IOCTL, (TEXT("DRV_IOCTL_CMD_TEST: uMsg=%s\r\n"),
TestCmdToString( uMsg )));
fRet = ProcessTestCommand( dwOpenData, uMsg, pBufIn, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
break;
case DRV_IOCTL_CMD_PING:
DEBUGMSG(ZONE_IOCTL, (TEXT("DRV_IOCTL_CMD_PING called\r\n")));
g_pKato = NULL;
g_pKato = new DDLXKato_Talk(TRUE);
if(g_pKato == NULL)
return FALSE;
if(g_pKato->Init() == FALSE){
NKDbgPrintfW(_T("Debug output message won't be able to redirect to a file!"));
}
fRet = TRUE;
break;
case DRV_IOCTL_CMD_DEBUG:
DEBUGMSG(ZONE_IOCTL, (TEXT("DRV_IOCTL_CMD_DEBUG called\r\n")));
// Not going to return the value of the current ddlxioct debug zone
// mask, since it should be the same as the mask in ddlx.
//dpPrivCurSettings.ulZoneMask = dwLenIn;
fRet = TRUE;
break;
default:
DEBUGMSG(ZONE_IOCTL, (TEXT("IOControl UNKNOWN, FAILED.\r\n")));
break;
}
return fRet;
}
// ----------------------------------------------------------------------------
// ProcessShellCommand
// ----------------------------------------------------------------------------
BOOL
ProcessShellCommand( DWORD dwOpenData, // handle identifying the open context of the device
UINT uMsg, // shell message
PBYTE pBufIn, // input buffer
DWORD dwLenIn, // input buffer length
PBYTE pBufOut, // output buffer
DWORD dwLenOut, // output buffer length
PDWORD pdwActualOut) // actual output length
{
static SPS_REGISTER spsRegister;
DWORD dwRet = SPR_HANDLED;
BOOL fRet = TRUE;
switch (uMsg)
{
case SPM_LOAD_DLL:
// Originally used for setting Unicode flag, but not really useful
// at this point.
SPS_LOAD_DLL spsLoadDll;
dwRet = ShellProc( SPM_LOAD_DLL, (DWORD) &spsLoadDll );
break;
case SPM_UNLOAD_DLL:
dwRet = ShellProc( SPM_UNLOAD_DLL, NULL );
break;
case SPM_SHELL_INFO:
static SPL_SHELL_INFO IoctlShellInfo;
//
// Copy the command line to our (ddlxioct) table containing command lines.
//
if( ((LPSPI_SHELL_INFO)pBufIn)->tDllCmdLine &&
((LPSPI_SHELL_INFO)pBufIn)->tDllCmdLine[0] )
{
_tcscpy( (glpCommandLines[dwOpenData])+1, ((LPSPI_SHELL_INFO)pBufIn)->tDllCmdLine );
DEBUGMSG(ZONE_VERBOSE, (TEXT("Command line: %s\r\n"), glpCommandLines[dwOpenData]+1));
}
else
{
DEBUGMSG(ZONE_VERBOSE, (TEXT("No command line.\r\n")));
}
if( !pBufIn )
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("IOControl, SHELLPROC, SPM_SHELL_INFO pBufIn==NULL\r\n")));
break;
}
IoctlShellInfo.PassedShellInfo = *((LPSPI_SHELL_INFO)pBufIn);
IoctlShellInfo.LocalShellInfo.hInstance = NULL;
IoctlShellInfo.LocalShellInfo.hWnd = NULL;
IoctlShellInfo.LocalShellInfo.hLib = NULL;
IoctlShellInfo.LocalShellInfo.hevmTerminate = NULL;
IoctlShellInfo.LocalShellInfo.fUsingServer = IoctlShellInfo.PassedShellInfo.fUsingServer;
IoctlShellInfo.LocalShellInfo.szDllCmdLine = IoctlShellInfo.PassedShellInfo.tDllCmdLine;
//Modified to take the command line parameters.
dwRet = ShellProc( SPM_SHELL_INFO, (DWORD) &IoctlShellInfo.LocalShellInfo );
break;
case SPM_REGISTER:
LPFUNCTION_TABLE_ENTRY lpFTEFrom;
LPFUNCTION_TABLE_ENTRY lpFTETo;
LPCTSTR lpDescFrom;
LPTSTR lpDescTo;
int ndx;
dwRet = ShellProc( SPM_REGISTER, (DWORD)&spsRegister );
if ( !pBufIn )
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("ERROR: gen_IOControl, SHELLPROC, SPM_REGISTER pBufIn==NULL\r\n")));
break;
}
// First, copy the function table over from device.exe space to ddlx.exe
// space. (LPFUNCTION_TABLE_ENTRY)pBufIn points to the 16K function table
// in the tux.exe memory space.
lpFTEFrom = spsRegister.lpFunctionTable;
lpFTETo = (LPFUNCTION_TABLE_ENTRY)pBufIn;
g_iTblSize = 0;
do
{
DumpFunctionTableEntry( lpFTEFrom );
*lpFTETo = *lpFTEFrom;
lpFTETo++;
g_iTblSize++;
}
while( (lpFTEFrom++)->lpDescription && ((PBYTE)lpFTETo < (PBYTE)pBufIn + dwLenIn));
// Then, walk along and copy and fix function description strings
lpDescTo = (LPTSTR) lpFTETo;
lpFTETo = (LPFUNCTION_TABLE_ENTRY)pBufIn;
for( ndx=0; ndx < g_iTblSize; ndx++ ) {
lpDescFrom = spsRegister.lpFunctionTable[ndx].lpDescription;
if( !lpDescFrom )
{
break;
}
lpFTETo[ndx].lpDescription = lpDescTo;
do
{
*lpDescTo = *lpDescFrom;
lpDescTo++;
}
while ( *lpDescFrom++ && ((PBYTE)lpFTETo < (PBYTE)pBufIn + dwLenIn));
DumpFunctionTableEntry( & lpFTETo[ndx] );
}
break;
case SPM_START_SCRIPT:
dwRet = ShellProc( SPM_START_SCRIPT, NULL );
break;
case SPM_STOP_SCRIPT:
dwRet = ShellProc( SPM_STOP_SCRIPT, NULL );
break;
case SPM_BEGIN_GROUP:
dwRet = ShellProc( SPM_BEGIN_GROUP, NULL );
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -