📄 pkfuncs.h
字号:
#define GetCurrentProcessIndex() GetProcessIndexFromID(GetCurrentProcess())
DWORD SetLowestScheduledPriority(DWORD maxprio);
BOOL IsPrimaryThread(void);
LPBYTE CreateLocaleView(BOOL bFirst);
DWORD SetProcPermissions(DWORD);
DWORD GetCurrentPermissions(void);
void SetTimeZoneBias(DWORD dwBias, DWORD dwDaylightBias);
void SetCleanRebootFlag(void);
HANDLE CreateCrit(LPCRITICAL_SECTION lpcs);
void PowerOffSystem(void);
BOOL SetDbgZone(DWORD dwProcid, LPVOID lpvMod, LPVOID baseptr, DWORD zone, LPDBGPARAM lpdbgTgt);
VOID TurnOnProfiling(HANDLE hThread);
VOID WINAPI TurnOffProfiling(HANDLE hThread);
void NKTerminateThread(DWORD dwExitCode);
LPCWSTR GetProcName(void);
void CloseAllHandles(void);
BOOL SetHandleOwner(HANDLE h, HANDLE hProc);
HINSTANCE LoadDriver(LPCTSTR lpszFile);
HANDLE LoadIntChainHandler(LPCTSTR lpszFileName, LPCTSTR lpszFunctionName, BYTE bIRQ);
BOOL FreeIntChainHandler(HANDLE hInstance);
HANDLE LoadKernelLibrary(LPCWSTR lpszFileName);
BOOL InterruptInitialize(DWORD idInt, HANDLE hEvent, LPVOID pvData, DWORD cbData);
void InterruptMask (DWORD idInt, BOOL fDisable);
void InterruptDone(DWORD idInt);
void InterruptDisable(DWORD idInt);
DWORD SetKMode(DWORD);
BOOL SetPowerOffHandler(FARPROC pfn);
BOOL SetGwesPowerHandler(FARPROC pfn);
BOOL ConnectDebugger(LPVOID pInit);
BOOL ConnectHdstub(LPVOID pInit);
BOOL ConnectOsAxsT0(LPVOID pInit);
BOOL ConnectOsAxsT1(LPVOID pInit);
__int64 CeGetRandomSeed(void);
BOOL SetHardwareWatch(LPVOID vAddr, DWORD flags);
BOOL RegisterAPISet(HANDLE hASet, DWORD dwSetID);
HANDLE CreateAPIHandle(HANDLE hASet, LPVOID pvData);
LPVOID VerifyAPIHandle(HANDLE hASet, HANDLE h);
void PPSHRestart(void);
BOOL AddEventAccess(HANDLE hEvent);
// valid flags for PageOutModule
#define PAGE_OUT_PROCESS_ONLY 0 // page out process/module only
#define PAGE_OUT_DLL_USED_ONLY_BY_THISPROC 1 // (ignored if hModule is a DLL) page out process
// together with dependent modules used only by the process
#define PAGE_OUT_ALL_DEPENDENT_DLL 2 // (ignored if hModule is a DLL) page out process
// together with all dependent modules. USE WITH CARE.
BOOL PageOutModule (HANDLE hModule, DWORD dwFlags);
// set/get event data
DWORD GetEventData(HANDLE hEvent);
BOOL SetEventData(HANDLE hEvent, DWORD dwData);
// check if a named event is signaled.
BOOL IsNamedEventSignaled (LPCWSTR pszName, DWORD dwFlags);
void DebugNotify(DWORD dwFlags, DWORD data);
//THSNAP *THCreateSnapshot(DWORD dwFlags, DWORD dwProcID);
//LPBYTE THGrow(THSNAP *pSnap, DWORD dwSize);
BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
void CompactAllHeaps (void);
//
// ACL related functions
//
// the super token - access to everything
#define TOKEN_SYSTEM ((HANDLE) 0x2)
// flags for CeCreateToken
#define TF_OWNED_BY_KERNEL 1 // the token is owned by kernel - should only used by filesys or the handle
// created will not be freed on process exit
HANDLE CeCreateToken (LPVOID pTok, DWORD dwFlags);
BOOL CeRevertToSelf (void);
BOOL CeAccessCheck (LPVOID pSecDesc, HANDLE hTok, DWORD dwAccess);
BOOL CePrivilegeCheck (HANDLE hTok, LPDWORD pPrivs, int nPrivs);
BOOL CeImpersonateToken (HANDLE hTok);
HANDLE CeCreateTokenFromAccount (LPCWSTR pszAccountName);
BOOL CeImpersonateCurrentProcess (void);
BOOL CeDuplicateToken (HANDLE hTok, DWORD dwFlags, PHANDLE phRet);
//
// Standard privileges
//
#define CEPRI_IMPERSONATE 0x00000001 // Impersonate
#define CEPRI_NETWORK 0x00000002 // use network APIs
#define CEPRI_REALTIME 0x00000004 // real-time APIs
#define CEPRI_READ_SYSTEM_FILE 0x00000008 // read system file
#define CEPRI_WRITE_SYSTEM_FILE 0x00000010 // update system file
#define CEPRI_RADIO_STACK 0x00000020 // access to radio stack
#define CEPRI_STANDARD_ALL 0x3fffffff // all standard privileges
//
// Extended privileges
//
#define CEPRI_EX_WRITE_ADB 0x80000001 // update account DB APIs
#define CEPRI_EX_NET_ADMIN 0x80000002 // network admin APIs
#define CEPRI_EX_READ_CREDENTIAL 0x80000003 // read credentials
#define CEPRI_EX_CREDENTIAL_ADMIN 0x80000004 // credential manager
#define CEPRI_EX_DRM_CONTENT 0x80000005 // access DRM content
// yet to determine, but might be needed
#define CEPRI_EX_DRM_ADMIN 0x80000006 // access to DRM core/engine
#define CEPRI_EX_PROTECTED_WINDOW 0x80000007 // access to protected windows
//////////////////////////////////////////////////////////////////////////////////
// cache information structure, used with IOCTL_KLIB_GETCACHE_INFO
typedef struct _CacheInfo {
DWORD dwL1Flags; // flags for L1 cache, see below
DWORD dwL1ICacheSize; // total size in bytes
DWORD dwL1ICacheLineSize; // line size in bytes
DWORD dwL1ICacheNumWays; // number of ways, 1 for direct mapped
DWORD dwL1DCacheSize; // total size in bytes
DWORD dwL1DCacheLineSize; // line size in bytes
DWORD dwL1DCacheNumWays; // number of ways, 1 for direct mapped
DWORD dwL2Flags; // flags for L2 cache, see below
DWORD dwL2ICacheSize; // total size in bytes, 0 means no L2 ICache
DWORD dwL2ICacheLineSize; // line size in bytes
DWORD dwL2ICacheNumWays; // number of ways, 1 for direct mapped
DWORD dwL2DCacheSize; // total size in bytes, 0 means no L2 DCache
DWORD dwL2DCacheLineSize; // line size in bytes
DWORD dwL2DCacheNumWays; // number of ways, 1 for direct mapped
} CacheInfo, *PCacheInfo;
// cache info flags (applied to both L1 and L2
#define CF_UNIFIED 0x01 // I and D caches unified, use ICache info fields
#define CF_WRITETHROUGH 0x02 // writeback if not set
#define CF_COHERENT 0x04 // no cache flush operations necessary
//
// CeGetCacheInfo: Get cache information
// Parameters:
// cbSize: must be sizeof(CacheInfo)
// pCacheInfo: pointer to CachInfo struct to receive the cache infomation
// Return Value:
// TRUE if success, FALSE if failed (if OEM didn't implement the function
//
_inline BOOL CeGetCacheInfo (DWORD cbSize, PCacheInfo pCacheInfo)
{
return KernelIoControl (IOCTL_HAL_GET_CACHE_INFO, 0, 0, pCacheInfo, cbSize, 0);
}
// CeLog status flags
// Since the CeLog zones are stored in the same UserKData DWORD as these status
// flags, they must be chosen so as not to collide with CeLog zones.
#define CELOGSTATUS_ENABLED_GENERAL CELZONE_RESERVED1
#define CELOGSTATUS_ENABLED_PROFILE CELZONE_RESERVED2
#define CELOGSTATUS_ENABLED_ANY (CELOGSTATUS_ENABLED_GENERAL | CELOGSTATUS_ENABLED_PROFILE)
// Is CeLog loaded with this status.
#define IsCeLogStatus(Status) ((UserKInfo[KINX_CELOGSTATUS] & (Status)) != 0)
// Is CeLog loaded with this status and one of these zones enabled.
#define IsCeLogEnabled(Status, ZoneCE) (IsCeLogStatus(Status) && ((UserKInfo[KINX_CELOGSTATUS] & (ZoneCE)) != 0))
// Is CeLog loaded with general status and one of these zones enabled.
#define IsCeLogZoneEnabled(ZoneCE) (IsCeLogEnabled(CELOGSTATUS_ENABLED_GENERAL, (ZoneCE)))
// Function pointers and data provided by the kernel for CeLog to use.
// Queried with IOCTL_CELOG_IMPORT.
typedef struct _CeLogImportTable {
DWORD dwVersion; // Version of this structure, set to 4
FARPROC pCreateEventW;
FARPROC pEventModify;
FARPROC pCreateFileMappingW;
FARPROC pMapViewOfFile;
FARPROC pUnmapViewOfFile;
FARPROC pCloseHandle;
FARPROC pLockPages;
FARPROC pUnlockPages;
FARPROC pVirtualAlloc;
FARPROC pVirtualFree;
FARPROC pMapPtrToProcess;
FARPROC pQueryPerformanceCounter;
FARPROC pQueryPerformanceFrequency;
FARPROC pNKDbgPrintfW;
FARPROC pCeLogReSync;
FARPROC pGetLastError;
FARPROC pSetLastError;
FARPROC pGetThreadCallStack;
FARPROC pInSysCall; // Pointer to InSysCall wrapper function
DWORD *pdwCeLogTLBMiss; // Pointer to TLB miss count
DWORD dwCeLogLargeBuf; // OEM-changeable large buffer size
DWORD dwCeLogSmallBuf; // OEM-changeable small buffer size
DWORD dwDefaultThreadQuantum; // The scheduler's default thread quantum
} CeLogImportTable;
// Function pointers and data provided by CeLog for the kernel to use.
// Registered with IOCTL_CELOG_REGISTER.
typedef struct _CeLogExportTable {
DWORD dwVersion; // Version of this structure, set to 2
PFNVOID pfnCeLogData; // Receives CeLogData calls (REQUIRED)
PFNVOID pfnCeLogInterrupt; // Receives CeLogInterrupt calls (OPTIONAL)
PFNVOID pfnCeLogSetZones; // Receives CeLogSetZones calls (OPTIONAL)
FARPROC pfnCeLogQueryZones; // Receives CeLogGetZones calls, minus last param (OPTIONAL)
DWORD dwCeLogTimerFrequency; // Less than or equal to QueryPerformanceFrequency(), 0 if not used
} CeLogExportTable;
// Used with IOCTL_KLIB_CHANGEMAPFLUSHING
typedef struct _MapFlushInfo {
LPCVOID lpBaseAddress;
DWORD dwFlags;
} MapFlushInfo;
#define FILEMAP_NORMAL 0 // Default
#define FILEMAP_NOBACKGROUNDFLUSH 1 // Turn off background flushing
//
// KernelLibIoControl definitions
//
// Predefined Kernel Module numbers
#define KMOD_INVALID 0
#define KMOD_CORE 1
#define KMOD_DBG 2 // Debugger specific extensions
#define KMOD_CELOG 3
#define KMOD_VERIFIER 4
#define KMOD_OAL 5 // Pass through to OEMIoControl
#define KMOD_MAX 5
// Kernel reserves the control code from 0-255
#define IOCTL_KLIB_ALLOCSHAREMEM 0
#define IOCTL_KLIB_FREESHAREMEM 1
#define IOCTL_KLIB_GETROMCHAIN 2
#define IOCTL_KLIB_GETCOMPRESSIONINFO 3
#define IOCTL_KLIB_CHANGEMAPFLUSHING 4 // Change flush settings for mapped view of a file
#define IOCTL_KLIB_GETALARMRESOLUTION 5 // Retrieves NKAlarmResolutionMSec from the kernel
#define IOCTL_KLIB_ISKDPRESENT 6 // Returns TRUE if KD is pressent FALSE otherwise
#define IOCTL_KLIB_SETROMDLLBASE 7 // called from filesys only, for loading externel MODULE to slot1
#define IOCTL_KLIB_GETPROCMEMINFO 8 // get per-process id and r/w memory usage
#define IOCTL_KLIB_GETCALLSTACK 9 // get callstack of of current thread with context information
#define IOCTL_KLIB_JITGETCALLSTACK 10 // get the last call stack of the thread that have an un-handled exception
#define IOCTL_KLIB_SETIGNORENOFAULT 11 // enable/disable no-fault so that one can choose to break into debugger on threads with nofault set
#define IOCTL_KLIB_SETMEMORYATTR 12 // CeSetMemoryAttributes
#define IOCTL_KLIB_GETWATSONSIZE 13 // get the size of Dr. Watson dump area
#define IOCTL_KLIB_WRITEWATSON 14 // Write data to Dr. Watson dump area
#define IOCTL_KLIB_READWATSON 15 // read data from Dr. Watson dump area
#define IOCTL_KLIB_FLUSHWATSON 16 // Flush data to Dr. Watson dump area, if using persistent storage
#define IOCTL_KLIB_CLEARWATSON 17 // Clear the Dr. Watson dump area
#define IOCTL_KLIB_SETJITDBGRPATH 18 // Change the path of JIT debugger
#define IOCTL_KLIB_WDOGAPI 19 // watchdog timer APIs
#define IOCTL_KLIB_SETDBGLIST 20 // set the debug module list to force ROM module to be loaded form FRD
#define IOCTL_KLIB_INTERRUPTDONE 21 // same as calling InterruptDone. Accessible from installable ISR from direct function all.
#define IOCTL_KLIB_USER 256 // where OEM defined IOCTL starts.
// Debugger IOCTLs are separate from the rest of the kernel
#define IOCTL_DBG_INIT 0
#define IOCTL_DBG_HDSTUB_INIT 1
#define IOCTL_DBG_OSAXST0_INIT 2
#define IOCTL_DBG_OSAXST1_INIT 3
// CeLog IOCTLs are separate from the rest of the kernel
#define IOCTL_CELOG_IMPORT 0
#define IOCTL_CELOG_REGISTER 1
#define IOCTL_CELOG_GETDESKTOPZONE 2
#define IOCTL_CELOG_DEREGISTER 3
#define IOCTL_CELOG_REPORTZONECHANGE 4
#define IOCTL_CELOG_IMPORT_PRIVATE 5
// Verifier IOCTLs are separate from the rest of the kernel
#define IOCTL_VERIFIER_IMPORT 0
#define IOCTL_VERIFIER_REGISTER 1
BOOL KernelLibIoControl(HANDLE hLib, DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
// Interface from OAL (inside kernel)
LPVOID NKCreateStaticMapping(DWORD dwPhysBase, DWORD dwSize);
BOOL NKDeleteStaticMapping (LPVOID pVirtAddr, DWORD dwSize);
// Interface from user-mode applications (kernel trap)
LPVOID CreateStaticMapping(DWORD dwPhysBase, DWORD dwSize);
BOOL DeleteStaticMapping (LPVOID pVirtAddr, DWORD dwSize);
#ifdef ARM
PFNVOID NKSetDataAbortHandler(PFNVOID pfnDataAbortHandler);
#endif
LPVOID MapCallerPtr (LPVOID ptr, DWORD dwLen);
LPVOID MapPtrToProcWithSize (LPVOID ptr, DWORD dwLen, HANDLE hProc);
// allocating shared memory for ISR/IST memory sharing
_inline BOOL KLibAllocShareMem (DWORD nPages, BOOL fNoCache, LPVOID *pVa, LPVOID *pPa)
{
return KernelLibIoControl ((HANDLE) KMOD_CORE, IOCTL_KLIB_ALLOCSHAREMEM,
pVa, nPages, pPa, fNoCache, NULL);
}
_inline BOOL KLibFreeShareMem (DWORD nPages, LPVOID pVa, LPVOID pPa)
{
return KernelLibIoControl ((HANDLE) KMOD_CORE, IOCTL_KLIB_FREESHAREMEM,
pVa, nPages, pPa, 0, NULL);
}
_inline LPVOID KLibGetROMChain (void)
{
return (LPVOID) KernelLibIoControl ((HANDLE) KMOD_CORE, IOCTL_KLIB_GETROMCHAIN, 0, 0, 0, 0, 0);
}
_inline void KLibSetIgnoreNoFault (BOOL fIgnore)
{
KernelLibIoControl ((HANDLE) KMOD_CORE, IOCTL_KLIB_SETIGNORENOFAULT, 0, fIgnore, 0, 0, 0);
}
//
// Use KLibIoControl to implement CeSetMemoryAttributes
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -