📄 pm.c
字号:
(void)findData; return PM_FILE_INVALID;}/****************************************************************************REMARKS:Function to find the next file matching a search criteria in a directory.****************************************************************************/ibool PMAPI PM_findNextFile( void *handle, PM_findData *findData){ // TODO: This function should find the next file in directory enumeration // search given the search criteria defined in the call to // PM_findFirstFile. The data should be converted and returned // in the findData standard form. (void)handle; (void)findData; return false;}/****************************************************************************REMARKS:Function to close the find process****************************************************************************/void PMAPI PM_findClose( void *handle){ // TODO: This function should close the find process. This may do // nothing for some OS'es. (void)handle;}/****************************************************************************REMARKS:Function to determine if a drive is a valid drive or not. Under Unix thisfunction will return false for anything except a value of 3 (consideredthe root drive, and equivalent to C: for non-Unix systems). The drivenumbering is: 1 - Drive A: 2 - Drive B: 3 - Drive C: etc****************************************************************************/ibool PMAPI PM_driveValid( char drive){ // Not supported in NT drivers (void)drive; return false;}/****************************************************************************REMARKS:Function to get the current working directory for the specififed drive.Under Unix this will always return the current working directory regardlessof what the value of 'drive' is.****************************************************************************/void PMAPI PM_getdcwd( int drive, char *dir, int len){ // Not supported in NT drivers (void)drive; (void)dir; (void)len;}/****************************************************************************PARAMETERS:base - The starting physical base address of the regionsize - The size in bytes of the regiontype - Type to place into the MTRR registerRETURNS:Error code describing the result.REMARKS:Function to enable write combining for the specified region of memory.****************************************************************************/int PMAPI PM_enableWriteCombine( ulong base, ulong size, uint type){ return MTRR_enableWriteCombine(base,size,type);}/****************************************************************************REMARKS:Function to change the file attributes for a specific file.****************************************************************************/void PMAPI PM_setFileAttr( const char *filename, uint attrib){ NTSTATUS status; ACCESS_MASK DesiredAccess = GENERIC_READ | GENERIC_WRITE; OBJECT_ATTRIBUTES ObjectAttributes; ULONG ShareAccess = FILE_SHARE_READ; ULONG CreateDisposition = FILE_OPEN; HANDLE FileHandle = NULL; UNICODE_STRING *uniFile = NULL; IO_STATUS_BLOCK IoStatusBlock; FILE_BASIC_INFORMATION FileBasic; char kernelFilename[PM_MAX_PATH+5]; ULONG FileAttributes = 0; // Convert file attribute flags if (attrib & PM_FILE_READONLY) FileAttributes |= FILE_ATTRIBUTE_READONLY; if (attrib & PM_FILE_ARCHIVE) FileAttributes |= FILE_ATTRIBUTE_ARCHIVE; if (attrib & PM_FILE_HIDDEN) FileAttributes |= FILE_ATTRIBUTE_HIDDEN; if (attrib & PM_FILE_SYSTEM) FileAttributes |= FILE_ATTRIBUTE_SYSTEM; // Add prefix for addressing the file system. "\??\" is short for "\DosDevices\" strcpy(kernelFilename, "\\??\\"); strcat(kernelFilename, filename); // Convert filename string to ansi string if ((uniFile = _PM_CStringToUnicodeString(kernelFilename)) == NULL) goto Exit; // Must open a file to query it's attributes InitializeObjectAttributes (&ObjectAttributes, uniFile, OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwCreateFile( &FileHandle, DesiredAccess | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, NULL, //AllocationSize OPTIONAL, FILE_ATTRIBUTE_NORMAL, ShareAccess, CreateDisposition, FILE_RANDOM_ACCESS, //CreateOptions, NULL, //EaBuffer OPTIONAL, 0 //EaLength (required if EaBuffer) ); if (!NT_SUCCESS (status)) goto Exit; // Query timestamps status = ZwQueryInformationFile(FileHandle, &IoStatusBlock, &FileBasic, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation ); if (!NT_SUCCESS (status)) goto Exit; // Change the four bits we change FileBasic.FileAttributes &= ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); FileBasic.FileAttributes |= FileAttributes; // Set timestamps ZwSetInformationFile( FileHandle, &IoStatusBlock, &FileBasic, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation );Exit: if (FileHandle) ZwClose(FileHandle); if (uniFile) _PM_FreeUnicodeString(uniFile); return;}/****************************************************************************REMARKS:Function to get the file attributes for a specific file.****************************************************************************/uint PMAPI PM_getFileAttr( const char *filename){ NTSTATUS status; ACCESS_MASK DesiredAccess = GENERIC_READ | GENERIC_WRITE; OBJECT_ATTRIBUTES ObjectAttributes; ULONG ShareAccess = FILE_SHARE_READ; ULONG CreateDisposition = FILE_OPEN; HANDLE FileHandle = NULL; UNICODE_STRING *uniFile = NULL; IO_STATUS_BLOCK IoStatusBlock; FILE_BASIC_INFORMATION FileBasic; char kernelFilename[PM_MAX_PATH+5]; ULONG FileAttributes = 0; uint retval = 0; // Add prefix for addressing the file system. "\??\" is short for "\DosDevices\" strcpy(kernelFilename, "\\??\\"); strcat(kernelFilename, filename); // Convert filename string to ansi string if ((uniFile = _PM_CStringToUnicodeString(kernelFilename)) == NULL) goto Exit; // Must open a file to query it's attributes InitializeObjectAttributes (&ObjectAttributes, uniFile, OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwCreateFile( &FileHandle, DesiredAccess | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, NULL, //AllocationSize OPTIONAL, FILE_ATTRIBUTE_NORMAL, ShareAccess, CreateDisposition, FILE_RANDOM_ACCESS, //CreateOptions, NULL, //EaBuffer OPTIONAL, 0 //EaLength (required if EaBuffer) ); if (!NT_SUCCESS (status)) goto Exit; // Query timestamps status = ZwQueryInformationFile(FileHandle, &IoStatusBlock, &FileBasic, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation ); if (!NT_SUCCESS (status)) goto Exit; // Translate the file attributes if (FileBasic.FileAttributes & FILE_ATTRIBUTE_READONLY) retval |= PM_FILE_READONLY; if (FileBasic.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) retval |= PM_FILE_ARCHIVE; if (FileBasic.FileAttributes & FILE_ATTRIBUTE_HIDDEN) retval |= PM_FILE_HIDDEN; if (FileBasic.FileAttributes & FILE_ATTRIBUTE_SYSTEM) retval |= PM_FILE_SYSTEM;Exit: if (FileHandle) ZwClose(FileHandle); if (uniFile) _PM_FreeUnicodeString(uniFile); return retval;}/****************************************************************************REMARKS:Function to create a directory.****************************************************************************/ibool PMAPI PM_mkdir( const char *filename){ // Not supported in NT drivers (void)filename; return false;}/****************************************************************************REMARKS:Function to remove a directory.****************************************************************************/ibool PMAPI PM_rmdir( const char *filename){ // Not supported in NT drivers (void)filename; return false;}/****************************************************************************REMARKS:Function to get the file time and date for a specific file.****************************************************************************/ibool PMAPI PM_getFileTime( const char *filename, ibool gmTime, PM_time *time){ // Not supported in NT drivers (void)filename; (void)gmTime; (void)time; return false;}/****************************************************************************REMARKS:Function to set the file time and date for a specific file.****************************************************************************/ibool PMAPI PM_setFileTime( const char *filename, ibool gmTime, PM_time *time){ // Not supported in NT drivers (void)filename; (void)gmTime; (void)time; return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -