📄 kdriver.c
字号:
return (BOOL) ROMChain;
case IOCTL_KLIB_GETCOMPRESSIONINFO:
if (lpInBuf || nInBufSize || !lpOutBuf || (nOutBufSize != sizeof(BOOL))) {
KSetLastError(pCurThread, ERROR_INVALID_PARAMETER);
return FALSE;
}
*((BOOL*)lpOutBuf) = g_fCompressionSupported;
return TRUE;
case IOCTL_KLIB_CHANGEMAPFLUSHING: {
MapFlushInfo *pInfo;
if (!lpInBuf || (nInBufSize != sizeof(MapFlushInfo))
|| !lpOutBuf || (nOutBufSize != sizeof(BOOL))) {
KSetLastError(pCurThread, ERROR_INVALID_PARAMETER);
return FALSE;
}
pInfo = (MapFlushInfo*) lpInBuf;
*((BOOL*)lpOutBuf) = ChangeMapFlushing(pInfo->lpBaseAddress, pInfo->dwFlags);
return TRUE;
}
case IOCTL_KLIB_GETALARMRESOLUTION: {
extern DWORD dwNKAlarmResolutionMSec;
if (lpInBuf || nInBufSize || !lpOutBuf || (nOutBufSize != sizeof(DWORD))) {
KSetLastError(pCurThread, ERROR_INVALID_PARAMETER);
return FALSE;
}
*((DWORD*)lpOutBuf) = dwNKAlarmResolutionMSec;
return TRUE;
}
case IOCTL_KLIB_ISKDPRESENT: {
if (!lpOutBuf || (nOutBufSize != sizeof(DWORD))) {
KSetLastError(pCurThread, ERROR_INVALID_PARAMETER);
return FALSE;
}
*((DWORD*)lpOutBuf) = (g_pKdInit != NULL);
return TRUE;
}
case IOCTL_KLIB_SETROMDLLBASE:
return SetROMDllBase (nInBufSize, (PROMINFO) lpInBuf);
case IOCTL_KLIB_GETPROCMEMINFO:
// nInBufSize: process id
// nOutBufSize: sizeof (PROCVMINFO)
// lpOutBuf: pointer to PROCVMINFO structure
if ((sizeof (PROCVMINFO) != nOutBufSize) // size mis-match
|| !lpOutBuf // output NULL
|| (nInBufSize < 1) // valid process 1-31
|| (nInBufSize >= MAX_PROCESSES)) {
KSetLastError(pCurThread, ERROR_INVALID_PARAMETER);
return FALSE;
}
return GetVMInfo (nInBufSize, (PPROCVMINFO) lpOutBuf);
case IOCTL_KLIB_GETCALLSTACK:
//
// nInBufSize: specify flag and skip (dwFlags = LOWORD(nInBufSize), dwSkip = HIWORD(nInBufSize))
// lpInBuf: pointer to context (pCtx)
// nOutBufSize: specify max # of frames (dwMaxFrames)
// lpOutBuf: pointer to buffer to receive callstack frames (lpFrames)
//
return NKGetThreadCallStack (pCurThread, nOutBufSize, lpOutBuf, LOWORD(nInBufSize), HIWORD(nInBufSize), (PCONTEXT) lpInBuf);
case IOCTL_KLIB_JITGETCALLSTACK:
// nOutBufSize: max # of frames
// lpOutBuf: pointer to buffer to receive the callstack
return JITGetCallStack (NULL, nOutBufSize, (CallSnapshot *) lpOutBuf);
case IOCTL_KLIB_SETIGNORENOFAULT:
// nInBufSize: (BOOL) fDisableNoFault
fDisableNoFault = nInBufSize;
return TRUE;
case IOCTL_KLIB_SETMEMORYATTR:
// CeSetMemoryAttributes:
// lpInBuf: pVirtualAddr
// lpOutBuf: pShiftedPhysAddr
// nInBufSize: cbSize
// nOutBufSize: dwFlags
return NKSetMemoryAttributes (lpInBuf, lpOutBuf, nInBufSize, nOutBufSize);
case IOCTL_KLIB_GETWATSONSIZE:
// get the size of Dr. Watson dump area
return dwNKDrWatsonSize;
case IOCTL_KLIB_WRITEWATSON:
// Write data to Dr. Watson dump area
// lpInbuf: Data to be Written
// nInBufSize: Size of the data
// nOutBufSize: offset from which to be written (irregular usage)
return pfnNKDrWatsonWrite (nOutBufSize, lpInBuf, nInBufSize);
case IOCTL_KLIB_READWATSON:
// read data from Dr. Watson dump area
// nInBufSize: offset from which to be read (irregular usage)
// lpOutBuf: pointer to a buffer of size at least nOutBufSize to receive Dr.Watson Dump
// nOutBufSize: size of buffer pointed by lpOutBuf
return pfnNKDrWatsonRead (nInBufSize, lpOutBuf, nOutBufSize);
case IOCTL_KLIB_FLUSHWATSON:
// Flush data to Dr. Watson dump area, if using persistent storage
return pfnNKDrWatsonFlush ();
case IOCTL_KLIB_CLEARWATSON:
// Clear the Dr. Watson dump area
return pfnNKDrWatsonClear ();
case IOCTL_KLIB_SETJITDBGRPATH:
// change the path of JIT debugger
return SC_SetJITDebuggerPath ((LPCWSTR) lpInBuf);
case IOCTL_KLIB_WDOGAPI:
// watchdog support
// lpInBuf: pointer to WDAPIStruct struct
// nInBufSize: sizeof (WDAPIStruct)
// nOutBufSize: apiCode (irregular usage)
if (sizeof (WDAPIStruct) == nInBufSize) {
return WatchDogAPI (nOutBufSize, (PCWDAPIStruct) lpInBuf);
}
return FALSE;
case IOCTL_KLIB_SETDBGLIST:
// update debug module list
// lpInBuf: the list of modules in multi-sz format
// nInBufSize: size, in BYTE, of the list
return SetDbgList ((LPCWSTR) lpInBuf, nInBufSize/sizeof(WCHAR));
case IOCTL_KLIB_INTERRUPTDONE:
// call InterruptDone.
// nInBufSize: the sysintr value
if ((nInBufSize >= SYSINTR_DEVICES) && (nInBufSize < SYSINTR_MAXIMUM))
OEMInterruptDone (nInBufSize);
return TRUE;
default:
return FALSE;
}
return TRUE;
}
BOOL KernelLibIoControl_Dbg(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
)
{
switch (dwIoControlCode) {
case IOCTL_DBG_INIT:
if (sizeof(g_pKdInit) == nInBufSize)
{
memcpy((VOID*)&g_pKdInit, lpInBuf, sizeof(g_pKdInit));
}
break;
case IOCTL_DBG_HDSTUB_INIT:
if (sizeof (g_pHdInit) == nInBufSize)
memcpy (&g_pHdInit, lpInBuf, sizeof (g_pHdInit));
break;
case IOCTL_DBG_OSAXST0_INIT:
if (sizeof (g_pOsAxsT0Init) == nInBufSize)
memcpy (&g_pOsAxsT0Init, lpInBuf, sizeof (g_pOsAxsT0Init));
break;
case IOCTL_DBG_OSAXST1_INIT:
if (sizeof (g_pOsAxsT0Init) == nInBufSize)
memcpy (&g_pOsAxsT1Init, lpInBuf, sizeof (g_pOsAxsT1Init));
break;
default:
return FALSE;
}
return TRUE;
}
BOOL KernelLibIoControl_CeLog(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
);
BOOL KernelLibIoControl_Verifier(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
);
//------------------------------------------------------------------------------
//
// Entry to KernelLibIoControl from kernel mode code (trust already verified).
// User mode code will call into the SC_KernelLibIoControl via trap so that
// trust can be verified.
//
//------------------------------------------------------------------------------
BOOL NKKernelLibIoControl(
HANDLE hLib,
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
)
{
PKERNELMOD pKMod = (PKERNELMOD) hLib;
switch ((DWORD) hLib) {
case KMOD_OAL:
return OEMIoControl(dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
case KMOD_CORE:
return KernelLibIoControl_Core(dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
case KMOD_DBG:
return KernelLibIoControl_Dbg(dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
case KMOD_CELOG:
return KernelLibIoControl_CeLog(dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
case KMOD_VERIFIER:
return KernelLibIoControl_Verifier(dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
default:
if (!pKMod
|| (((DWORD) pKMod > KMOD_MAX) && (!IsValidModule(pKMod) || !IsValidModule (pKMod->pMod)))) {
KSetLastError(pCurThread,ERROR_INVALID_HANDLE);
return FALSE;
}
}
return pKMod->pfnIoctl? pKMod->pfnIoctl(pKMod->dwInstData, dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned) : FALSE;
}
//------------------------------------------------------------------------------
//
// Entry to KernelLibIoControl from user mode code. Installable ISRs will
// call into the NKKernelLibIoControl since they run in kernel context and
// the trust check can't follow pCurProc.
//
//------------------------------------------------------------------------------
BOOL SC_KernelLibIoControl(
HANDLE hLib,
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned
)
{
TRUSTED_API (L"SC_KernelLibIoControl", FALSE);
return NKKernelLibIoControl(hLib, dwIoControlCode, lpInBuf, nInBufSize, lpOutBuf, nOutBufSize, lpBytesReturned);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -