• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ NtCreateFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中NtCreateFile函数的典型用法代码示例。如果您正苦于以下问题:C++ NtCreateFile函数的具体用法?C++ NtCreateFile怎么用?C++ NtCreateFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NtCreateFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: GetDriveGeometry

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Reads or writes specified number of sectors from/to specified buffer.
//
static	BOOL  GetDriveGeometry(
						   PWCHAR			Drive,			// drive name to read/write sectors from/to
						   PDISK_GEOMETRY	DiskGeometry
			   )
{
	BOOL		Ret = FALSE;
	HANDLE		hDrive;
	NTSTATUS	ntStatus;
	OBJECT_ATTRIBUTES	oa = {0};
	UNICODE_STRING		us;
	IO_STATUS_BLOCK		IoStatus = {0};
	HANDLE				hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	RtlInitUnicodeString(&us, Drive);
	InitializeObjectAttributes(&oa, &us, OBJ_CASE_INSENSITIVE, NULL, NULL);

	ntStatus = NtCreateFile(&hDrive, GENERIC_WRITE | GENERIC_READ, &oa, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL,
								FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, 0, NULL, 0);
	
	if (NT_SUCCESS(ntStatus))
	{
		ntStatus = NtDeviceIoControlFile(hDrive, hEvent, NULL, NULL, &IoStatus, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, DiskGeometry, sizeof(DISK_GEOMETRY));
		if (ntStatus == STATUS_PENDING)
			WaitForSingleObject(hEvent, INFINITE);

		NtClose(hDrive);

		if (NT_SUCCESS(IoStatus.Status))
			Ret = TRUE;
	}	// if (NT_SUCCESS(ntStatus))
 
   return(Ret);
}
开发者ID:12019,项目名称:Carberp,代码行数:36,代码来源:install.c


示例2: SfuIsDirectoryExists

//@@unimplemented
BOOL SfuIsDirectoryExists(
	_In_ PWSTR DirectoryName
	)
{
	UNICODE_STRING   usDirectoryName;
	NTSTATUS         status;
	HANDLE           DirectoryHandle;
	IO_STATUS_BLOCK  IoStatusBlock;
	OBJECT_ATTRIBUTES ObjectAttributes;

	RtlInitUnicodeString(&usDirectoryName, DirectoryName);
	InitializeObjectAttributes(&ObjectAttributes, &usDirectoryName, OBJ_CASE_INSENSITIVE, 0, NULL);

	status = NtCreateFile(&DirectoryHandle,
		SYNCHRONIZE,
		&ObjectAttributes,
		&IoStatusBlock,
		NULL,
		FILE_ATTRIBUTE_READONLY,
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
		FILE_OPEN_IF,
		FILE_DIRECTORY_FILE,
		NULL,
		0
		);
	if (NT_SUCCESS(status)) {
		NtClose(DirectoryHandle);
		return TRUE;
	}
	return FALSE;
}
开发者ID:0day1day,项目名称:ZeroAccess,代码行数:32,代码来源:util.c


示例3: SafeNtCreateFile

NTSTATUS WINAPI SafeNtCreateFile(
  PHANDLE              FileHandle,
  ACCESS_MASK          DesiredAccess,
  POBJECT_ATTRIBUTES   ObjectAttributes,
  PIO_STATUS_BLOCK     IoStatusBlock,
  PLARGE_INTEGER       AllocationSize,
  ULONG                FileAttributes,
  ULONG                ShareAccess,
  ULONG                CreateDisposition,
  ULONG                CreateOptions,
  PVOID                EaBuffer,
  ULONG                EaLength 
)
{
	NTSTATUS rc;

	if (CheckOldFunction(&OldNtCreateFile))
		rc=OldNtCreateFile(FileHandle,DesiredAccess,ObjectAttributes,IoStatusBlock,AllocationSize,FileAttributes,
				ShareAccess,CreateDisposition,CreateOptions,EaBuffer,EaLength);
	else
		rc=NtCreateFile(FileHandle,DesiredAccess,ObjectAttributes,IoStatusBlock,AllocationSize,FileAttributes,
				ShareAccess,CreateDisposition,CreateOptions,EaBuffer,EaLength);
	
	return rc;
}
开发者ID:Artorios,项目名称:rootkit.com,代码行数:25,代码来源:safe.c


示例4: MyCreateDirectory

static NTSTATUS MyCreateDirectory(TFileTestData * pData, POBJECT_ATTRIBUTES pObjAttr, PIO_STATUS_BLOCK pIoStatus)
{
    NTSTATUS Status;
    HANDLE SaveTransactionHandle = NULL;
    HANDLE DirectoryHandle = NULL;

    if(pData->bUseTransaction)
    {
        SaveTransactionHandle = pfnRtlGetCurrentTransaction();
        pfnRtlSetCurrentTransaction(pData->hTransaction);
    }

    Status = NtCreateFile(&DirectoryHandle,
                           FILE_ADD_FILE,
                           pObjAttr,
                           pIoStatus,
                           NULL,
                           FILE_ATTRIBUTE_DIRECTORY,
                           FILE_SHARE_READ,
                           FILE_OPEN_IF,
                           FILE_DIRECTORY_FILE,
                           NULL,
                           0);
    
    if(DirectoryHandle != NULL)
        NtClose(DirectoryHandle);

    if(pData->bUseTransaction)
    {
        pfnRtlSetCurrentTransaction(SaveTransactionHandle);
    }

    // If the directory already exists, take it as success
    return Status;
}
开发者ID:maodapeng,项目名称:FileTest,代码行数:35,代码来源:Page02NtCreate.cpp


示例5: SfuCreateDirectory

/*
* SfuCreateDirectory
*
* Purpose:
*
* Native create directory.
*
*/
BOOL SfuCreateDirectory(
	_In_ OBJECT_ATTRIBUTES *ObjectAttributes
	)
{
	NTSTATUS         status;
	HANDLE           DirectoryHandle;
	IO_STATUS_BLOCK  IoStatusBlock;

	status = NtCreateFile(&DirectoryHandle,
		FILE_GENERIC_WRITE,
		ObjectAttributes,
		&IoStatusBlock,
		NULL,
		FILE_ATTRIBUTE_NORMAL,//za use hidden+system
		0,
		FILE_OPEN_IF,
		FILE_DIRECTORY_FILE,
		NULL,
		0
		);
	if (!NT_SUCCESS(status)) {
		return FALSE;
	}
	NtClose(DirectoryHandle);
	return TRUE;
}
开发者ID:0day1day,项目名称:ZeroAccess,代码行数:34,代码来源:util.c


示例6: CreateRegistryFile

/*
 * Should be called under privileges
 */
static NTSTATUS
CreateRegistryFile(
    IN HANDLE RootDirectory OPTIONAL,
    IN PUNICODE_STRING RootPath OPTIONAL,
    IN PCWSTR RegistryKey,
    IN HANDLE ProtoKeyHandle)
{
    NTSTATUS Status;
    HANDLE RootPathHandle, FileHandle;
    UNICODE_STRING FileName;
    OBJECT_ATTRIBUTES ObjectAttributes;
    IO_STATUS_BLOCK IoStatusBlock;

    /* Open the root directory */
    Status = OpenDirectoryByHandleOrPath(&RootPathHandle, RootDirectory, RootPath);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("OpenDirectoryByHandleOrPath failed, Status 0x%08lx\n", Status);
        return Status;
    }

    /* Create the file */
    RtlInitUnicodeString(&FileName, RegistryKey);
    InitializeObjectAttributes(&ObjectAttributes,
                               &FileName,
                               OBJ_CASE_INSENSITIVE,
                               (HANDLE)((ULONG_PTR)RootPathHandle & ~1), // Remove the opened-locally flag
                               NULL);
    Status = NtCreateFile(&FileHandle,
                          FILE_GENERIC_WRITE /* | DELETE */,
                          &ObjectAttributes,
                          &IoStatusBlock,
                          NULL,
                          FILE_ATTRIBUTE_NORMAL /* | FILE_FLAG_DELETE_ON_CLOSE */,
                          0,
                          FILE_OVERWRITE_IF,
                          FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE,
                          NULL,
                          0);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("NtCreateFile(%wZ) failed, Status 0x%08lx\n", &FileName, Status);
        goto Cleanup;
    }

    /* Save the selected hive into the file */
    Status = NtSaveKeyEx(ProtoKeyHandle, FileHandle, REG_LATEST_FORMAT);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("NtSaveKeyEx(%wZ) failed, Status 0x%08lx\n", &FileName, Status);
    }

    /* Close the file, the root directory (if opened locally), and return */
    NtClose(FileHandle);
Cleanup:
    if ((ULONG_PTR)RootPathHandle & 1) NtClose((HANDLE)((ULONG_PTR)RootPathHandle & ~1));
    return Status;
}
开发者ID:Moteesh,项目名称:reactos,代码行数:61,代码来源:NtLoadUnloadKey.c


示例7: NtDeleteFile2

NTSTATUS NtDeleteFile2(POBJECT_ATTRIBUTES ObjectAttributes)
{
	HANDLE hFile;

	IO_STATUS_BLOCK IoStatusBlock;

	auto Status = NtOpenFile(&hFile, SYNCHRONIZE | DELETE, ObjectAttributes, &IoStatusBlock, FILE_SHARE_DELETE | FILE_SHARE_READ, FILE_OPEN_REPARSE_POINT | FILE_OPEN_FOR_BACKUP_INTENT);

	if (Status)
	{
		return Status;
	}

	FILE_DISPOSITION_INFORMATION Dispostion = { TRUE };

	Status = NtSetInformationFile(hFile, &IoStatusBlock, &Dispostion, sizeof(Dispostion), FileDispositionInformation);

	NtClose(hFile);

	if (Status == 0)
		return 0;

	//使用文件取代法删除
	auto cbData = ObjectAttributes->ObjectName->Length + sizeof(L"~$") - 2;
	UNICODE_STRING TempFileName = { cbData,cbData, (wchar_t*)new byte[cbData] };

	memcpy(TempFileName.Buffer, ObjectAttributes->ObjectName->Buffer, ObjectAttributes->ObjectName->Length);
	*(wchar_t*)(((byte*)TempFileName.Buffer) + ObjectAttributes->ObjectName->Length) = L'~';
	*(wchar_t*)(((byte*)TempFileName.Buffer) + ObjectAttributes->ObjectName->Length + 2) = L'$';


	OBJECT_ATTRIBUTES ObjectAttributes2 = { sizeof(OBJECT_ATTRIBUTES),ObjectAttributes->RootDirectory, &TempFileName, OBJ_CASE_INSENSITIVE };

	auto Status2 = NtCreateFile(&hFile, SYNCHRONIZE | DELETE, &ObjectAttributes2, &IoStatusBlock, 0, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_OPEN_FOR_BACKUP_INTENT | FILE_DELETE_ON_CLOSE, NULL, 0);

	delete[](byte*)TempFileName.Buffer;


	cbData = sizeof(FILE_RENAME_INFORMATION) + ObjectAttributes->ObjectName->Length;

	FILE_RENAME_INFORMATION* pRenameInfo = (FILE_RENAME_INFORMATION*)new byte[cbData];

	memcpy(pRenameInfo->FileName, ObjectAttributes->ObjectName->Buffer, ObjectAttributes->ObjectName->Length);
	pRenameInfo->ReplaceIfExists = TRUE;
	pRenameInfo->RootDirectory = ObjectAttributes->RootDirectory;
	pRenameInfo->FileNameLength = ObjectAttributes->ObjectName->Length;
	//FILE_RENAME_INFORMATION RenameInfo = {TRUE,hRootDir ,FileName.};

	Status2 = NtSetInformationFile(hFile, &IoStatusBlock, pRenameInfo, cbData, FileRenameInformation);

	delete[](byte*)pRenameInfo;

	NtClose(hFile);

	return Status2 == 0 ? 0 : Status;
}
开发者ID:Chuyu-Team,项目名称:CPPHelper,代码行数:56,代码来源:FileHelper.cpp


示例8: Mkdir

VOID Mkdir(
    IN PCHAR String
    )
{
    NTSTATUS Status;

    HANDLE FileHandle;
    OBJECT_ATTRIBUTES ObjectAttributes;
    STRING NameString;
    IO_STATUS_BLOCK IoStatus;
    LARGE_INTEGER AllocationSize;

    //
    //  Get the filename
    //

    simprintf("Mkdir ", 0);
    simprintf(String, 0);
    simprintf("\n", 0);

    //
    //  Create the new directory
    //

    AllocationSize = LiFromLong( 4 );
    RtlInitString( &NameString, String );
    InitializeObjectAttributes( &ObjectAttributes, &NameString, 0, NULL, NULL );
    if (!NT_SUCCESS(Status = NtCreateFile( &FileHandle,
                               SYNCHRONIZE,
                               &ObjectAttributes,
                               &IoStatus,
                               &AllocationSize,
                               0L,
                               0L,
                               FILE_CREATE,
                               WriteThrough | FILE_DIRECTORY_FILE,
                               (PVOID)NULL,
                               0L ))) {
        CreateFileError( Status , String );
        return;
    }

    //
    //  Now close the directory
    //

    if (!NT_SUCCESS(Status = NtClose( FileHandle ))) {
        CloseError( Status );
    }

    //
    //  And return to our caller
    //

    return;
}
开发者ID:BillTheBest,项目名称:WinNT4,代码行数:56,代码来源:tfatwinn.c


示例9: XDeleteDirectory

int XDeleteDirectory(char *directoryName)
{
	ANSI_STRING                  xboxFilename;
	IO_STATUS_BLOCK              ioStatusBlock;
	OBJECT_ATTRIBUTES            objectAttributes;
	FILE_DISPOSITION_INFORMATION deleteInfo;
	NTSTATUS                     status;
	int                          handle;

#ifdef DEBUG
	debugPrint("XDeleteDirectory directoryName=%s\n", directoryName);
#endif

	char tmp[200];
	int rc = XConvertDOSFilenameToXBOX(directoryName, tmp);
	if (rc != STATUS_SUCCESS)
		return rc;
	RtlInitAnsiString(&xboxFilename, tmp);

	objectAttributes.RootDirectory = NULL;
	objectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
	objectAttributes.ObjectName = &xboxFilename;

	// Open the file for deletion
	status = NtCreateFile(
		(PHANDLE)&handle, 
		DELETE | SYNCHRONIZE, 
		&objectAttributes,
		&ioStatusBlock, 
		NULL, 
		0, 
		FILE_SHARE_DELETE, 
		FILE_OPEN,
		FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
		
	if (!NT_SUCCESS(status))
		return RtlNtStatusToDosError(status);
		
	// Delete the file
	deleteInfo.DeleteFile = TRUE;
	status = NtSetInformationFile(
		(HANDLE)handle, 
		&ioStatusBlock, 
		&deleteInfo,
		sizeof(deleteInfo), 
		FileDispositionInformation);

	if (!NT_SUCCESS(status))
		return RtlNtStatusToDosError(status);
	else
	{
		// Close the dead handle and return
		NtClose((HANDLE)handle);
		return STATUS_SUCCESS;
	}
}
开发者ID:vrichomme,项目名称:posix4msvc,代码行数:56,代码来源:nt_fileio.c


示例10: RtlCliOpenInputDevice

/*++
 * @name RtlCliOpenInputDevice
 *
 * The RtlCliOpenInputDevice routine opens an input device.
 *
 * @param Handle
 *        Pointer where the handle for the input device will be returned.
 *
 * @param Type
 *        Type of the input device to use.
 *
 * @return STATUS_SUCCESS or error code when attemping to open the device.
 *
 * @remarks This routine supports both mouse and keyboard input devices.
 *
 *--*/
NTSTATUS
RtlCliOpenInputDevice(OUT PHANDLE Handle,
                      IN CON_DEVICE_TYPE Type)
{
    UNICODE_STRING Driver;
    OBJECT_ATTRIBUTES ObjectAttributes;
    IO_STATUS_BLOCK Iosb;
    HANDLE hDriver;
    NTSTATUS Status;

    //
    // Chose the driver to use
    // FIXME: Support MouseType later
    // FIXME: Don't hardcode keyboard path
    //
    if (Type == KeyboardType)
    {
        RtlInitUnicodeString(&Driver, L"\\Device\\KeyboardClass0");
    }

    //
    // Initialize the object attributes
    //
    InitializeObjectAttributes(&ObjectAttributes,
                               &Driver,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);

    //
    // Open a handle to it
    //
    Status = NtCreateFile(&hDriver,
                          SYNCHRONIZE | GENERIC_READ | FILE_READ_ATTRIBUTES,
                          &ObjectAttributes,
                          &Iosb,
                          NULL,
                          FILE_ATTRIBUTE_NORMAL,
                          0,
                          FILE_OPEN,
                          FILE_DIRECTORY_FILE,
                          NULL,
                          0);

    //
    // Now create an event that will be used to wait on the device
    //
    InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
    Status = NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, &ObjectAttributes, 1, 0);

    //
    // Return the handle
    //
    *Handle = hDriver;
    return Status;
}
开发者ID:aaam,项目名称:NativeShell,代码行数:72,代码来源:input.c


示例11: SetupCreateSingleDirectory

static
NTSTATUS
SetupCreateSingleDirectory(
    PWCHAR DirectoryName)
{
    OBJECT_ATTRIBUTES ObjectAttributes;
    IO_STATUS_BLOCK IoStatusBlock;
    UNICODE_STRING PathName;
    HANDLE DirectoryHandle;
    NTSTATUS Status;

    if(!RtlCreateUnicodeString(&PathName, DirectoryName))
        return STATUS_NO_MEMORY;

    if (PathName.Length > sizeof(WCHAR) &&
        PathName.Buffer[PathName.Length / sizeof(WCHAR) - 2] == L'\\' &&
        PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'.')
    {
        PathName.Length -= sizeof(WCHAR);
        PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
    }

    if (PathName.Length > sizeof(WCHAR) &&
        PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'\\')
    {
        PathName.Length -= sizeof(WCHAR);
        PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
    }

    InitializeObjectAttributes(&ObjectAttributes,
                               &PathName,
                               OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
                               NULL,
                               NULL);

    Status = NtCreateFile(&DirectoryHandle,
                          DIRECTORY_ALL_ACCESS,
                          &ObjectAttributes,
                          &IoStatusBlock,
                          NULL,
                          FILE_ATTRIBUTE_DIRECTORY,
                          FILE_SHARE_READ | FILE_SHARE_WRITE,
                          FILE_OPEN_IF,
                          FILE_DIRECTORY_FILE,
                          NULL,
                          0);
    if (NT_SUCCESS(Status))
    {
        NtClose(DirectoryHandle);
    }

    RtlFreeUnicodeString(&PathName);

    return Status;
}
开发者ID:amaneureka,项目名称:reactos,代码行数:55,代码来源:filesup.c


示例12: SmpDeleteFile

/*++
* @name SmpDeleteFile
*
* The SmpDeleteFile function deletes a specify file.
*
* @param    lpFileName
*           the name of a file which should be deleted
*
* @return   STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
*           othwerwise.
*
* @remarks
* This function is called by SmpMoveFilesQueryRoutine().
*
*
*--*/
NTSTATUS
SmpDeleteFile( IN LPCWSTR lpFileName )
{
	FILE_DISPOSITION_INFORMATION FileDispInfo;
	OBJECT_ATTRIBUTES ObjectAttributes;
	IO_STATUS_BLOCK IoStatusBlock;
	UNICODE_STRING FileNameU;
	HANDLE FileHandle;
	NTSTATUS Status;

	DPRINT("SmpDeleteFile ( %S )\n", lpFileName);

	if( !lpFileName )
		return (STATUS_INVALID_PARAMETER);

	RtlInitUnicodeString(&FileNameU, lpFileName);

	InitializeObjectAttributes(&ObjectAttributes,
		&FileNameU,
		OBJ_CASE_INSENSITIVE,
		NULL,
		NULL);

	Status = NtCreateFile (&FileHandle,
		DELETE,
		&ObjectAttributes,
		&IoStatusBlock,
		NULL,
		FILE_ATTRIBUTE_NORMAL,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		FILE_OPEN,
		FILE_SYNCHRONOUS_IO_NONALERT,
		NULL,
		0);

	if( !NT_SUCCESS(Status) ) {
		DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
		return (Status);
	}

	FileDispInfo.DeleteFile = TRUE;

	Status = NtSetInformationFile(
		FileHandle,
		&IoStatusBlock,
		&FileDispInfo,
		sizeof(FILE_DISPOSITION_INFORMATION),
		FileDispositionInformation );

	NtClose(FileHandle);

	return (Status);
}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:69,代码来源:initmv.c


示例13: IthOpenPipe

HANDLE IthOpenPipe(LPWSTR name, ACCESS_MASK direction)
{
	UNICODE_STRING us;
	RtlInitUnicodeString(&us,name);
	SECURITY_DESCRIPTOR sd={1};
	OBJECT_ATTRIBUTES oa={sizeof(oa),0,&us,OBJ_CASE_INSENSITIVE,&sd,0};
	HANDLE hFile;
	IO_STATUS_BLOCK isb;
	if (NT_SUCCESS(NtCreateFile(&hFile,direction,&oa,&isb,0,0,FILE_SHARE_READ,FILE_OPEN,0,0,0)))
		return hFile;
	else return INVALID_HANDLE_VALUE;
}
开发者ID:Alex12235,项目名称:interactive-text-hooker-andys,代码行数:12,代码来源:pipe.cpp


示例14: LogfBackupFile

NTSTATUS
LogfBackupFile(PLOGFILE LogFile,
               PUNICODE_STRING BackupFileName)
{
    NTSTATUS Status;
    LOGFILE BackupLogFile;
    OBJECT_ATTRIBUTES ObjectAttributes;
    IO_STATUS_BLOCK IoStatusBlock;

    DPRINT1("LogfBackupFile(%p, %wZ)\n", LogFile, BackupFileName);

    /* Lock the log file shared */
    RtlAcquireResourceShared(&LogFile->Lock, TRUE);

    InitializeObjectAttributes(&ObjectAttributes,
                               BackupFileName,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);

    Status = NtCreateFile(&BackupLogFile.FileHandle,
                          GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
                          &ObjectAttributes,
                          &IoStatusBlock,
                          NULL,
                          FILE_ATTRIBUTE_NORMAL,
                          FILE_SHARE_READ,
                          FILE_CREATE,
                          FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT,
                          NULL,
                          0);
    if (!NT_SUCCESS(Status))
    {
        DPRINT("Cannot create backup file `%wZ' (Status 0x%08lx)\n", BackupFileName, Status);
        goto Quit;
    }

    Status = ElfBackupFile(&LogFile->LogFile,
                           &BackupLogFile.LogFile);

Quit:
    /* Close the backup file */
    if (BackupLogFile.FileHandle != NULL)
        NtClose(BackupLogFile.FileHandle);

    /* Unlock the log file */
    RtlReleaseResource(&LogFile->Lock);

    return Status;
}
开发者ID:reactos,项目名称:reactos,代码行数:50,代码来源:file.c


示例15: winfs_symlink

static int winfs_symlink(struct mount_point *mp, const char *target, const char *linkpath)
{
	WCHAR wlinkpath[PATH_MAX];
	int len = filename_to_nt_pathname(mp, linkpath, wlinkpath, PATH_MAX);
	if (len <= 0)
		return -L_ENOENT;

	UNICODE_STRING pathname;
	RtlInitCountedUnicodeString(&pathname, wlinkpath, len * sizeof(WCHAR));
	IO_STATUS_BLOCK status_block;
	OBJECT_ATTRIBUTES attr;
	attr.Length = sizeof(OBJECT_ATTRIBUTES);
	attr.RootDirectory = NULL;
	attr.ObjectName = &pathname;
	attr.Attributes = 0;
	attr.SecurityDescriptor = NULL;
	attr.SecurityQualityOfService = NULL;
	HANDLE handle;
	NTSTATUS status = NtCreateFile(&handle, SYNCHRONIZE | FILE_WRITE_DATA, &attr, &status_block, NULL,
		FILE_ATTRIBUTE_SYSTEM, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_CREATE,
		FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);

	if (!NT_SUCCESS(status))
	{
		if (status == STATUS_OBJECT_NAME_EXISTS || status == STATUS_OBJECT_NAME_COLLISION)
		{
			log_warning("File already exists.");
			return -L_EEXIST;
		}
		log_warning("NtCreateFile() failed, status: %x", status);
		return -L_ENOENT;
	}

	DWORD num_written;
	if (!WriteFile(handle, WINFS_SYMLINK_HEADER, WINFS_SYMLINK_HEADER_LEN, &num_written, NULL) || num_written < WINFS_SYMLINK_HEADER_LEN)
	{
		log_warning("WriteFile() failed, error code: %d.", GetLastError());
		NtClose(handle);
		return -L_EIO;
	}
	DWORD targetlen = strlen(target);
	if (!WriteFile(handle, target, targetlen, &num_written, NULL) || num_written < targetlen)
	{
		log_warning("WriteFile() failed, error code: %d.", GetLastError());
		NtClose(handle);
		return -L_EIO;
	}
	NtClose(handle);
	return 0;
}
开发者ID:Logan-lu,项目名称:flinux,代码行数:50,代码来源:winfs.c


示例16: NtOpenFile

NTSTATUS NTAPI NtOpenFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes,
    PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions)
{
    CHECK_POINTER(FileHandle);
    CHECK_POINTER(IoStatusBlock);

#ifdef REDIR_IO
    {
        IO_STATUS_BLOCK iob;
        FILE_STANDARD_INFORMATION fi;
        DECLAREVARCONV(ObjectAttributesA);
        HANDLE hFile;

        NTSTATUS res = ftbl.nt.NtOpenFile(&hFile, DesiredAccess, ObjectAttributes, IoStatusBlock, ShareAccess, OpenOptions);

        OA2STR(ObjectAttributes);

        if (res < 0)
        {
            Log("ntdll.NtOpenFile(\"%s\", 0x%08x) = 0x%08x\n", ObjectAttributesA, DesiredAccess, res);
            return res;
        }

        __CreateHandle(*FileHandle, HANDLE_FILE, ObjectAttributesA);
        (*FileHandle)->file.mode = DesiredAccess;
        (*FileHandle)->file.fh = hFile;

        res = ftbl.nt.NtQueryInformationFile(hFile, &iob, &fi, sizeof(fi), FileStandardInformation);

        if (res == STATUS_SUCCESS)
            (*FileHandle)->file.st.st_size = fi.EndOfFile.QuadPart;
        else
        {
            GET_LENGTH_INFORMATION gli;
            if ((res = ftbl.nt.NtDeviceIoControlFile(hFile, NULL, NULL, NULL, IoStatusBlock, IOCTL_DISK_GET_LENGTH_INFO,
                NULL, 0, &gli, sizeof(GET_LENGTH_INFORMATION))) < 0)
            {
                fprintf(stderr, "NtOpenFile() - Unable to get size of %s: 0x%08x\n", ObjectAttributesA, res);
                abort();
            }
            (*FileHandle)->file.st.st_size = gli.Length.QuadPart;
        }

        Log("ntdll.NtOpenFile(\"%s\", 0x%08x)\n", ObjectAttributesA, DesiredAccess);
        return res;
    }
#else
    return NtCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, NULL, 0, ShareAccess, OPEN_EXISTING, OpenOptions, NULL, 0);
#endif
}
开发者ID:sherpya,项目名称:nloader,代码行数:50,代码来源:io.c


示例17: BackupWriteAlternateData

BOOL
BackupWriteAlternateData(HANDLE hFile, BACKUPCONTEXT *pbuc, BACKUPIOFRAME *pbif)
{
    if (pbuc->fStreamStart) {
	NTSTATUS Status;
	UNICODE_STRING strName;
	OBJECT_ATTRIBUTES oa;
	IO_STATUS_BLOCK iosb;

	strName.Length = (USHORT) pbuc->head.dwStreamNameSize;
	strName.MaximumLength = strName.Length;
	strName.Buffer = pbuc->head.cStreamName;

	InitializeObjectAttributes(
		&oa,
		&strName,
		OBJ_CASE_INSENSITIVE,
		hFile,
		NULL);

	Status = NtCreateFile(
		    &pbuc->hAlternate,
		    FILE_GENERIC_WRITE,
		    &oa,
		    &iosb,
		    NULL,
		    FILE_ATTRIBUTE_NORMAL,
		    FILE_SHARE_READ | FILE_SHARE_WRITE,
		    FILE_OVERWRITE_IF,
		    FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT,
		    NULL,
		    0L);

	if (!NT_SUCCESS(Status)) {
	    BaseSetLastNTError(Status);
	    pbuc->fAccessError = TRUE;
	    return(FALSE);
	}
	pbuc->fStreamStart = FALSE;
    }

    if (pbuc->hAlternate == INVALID_HANDLE_VALUE) {
	pbuc->fAccessError = TRUE;
	return(FALSE);
    }
    return(BackupWriteStream(pbuc->hAlternate, pbuc, pbif));
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:47,代码来源:backup.c


示例18: DirectIo

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Reads or writes specified number of sectors from/to specified buffer.
//
static	BOOL	DirectIo(
			   PWCHAR	Drive,			// drive name to read/write sectors from/to
			   PCHAR	Buffer,			// bufer to store the data
			   ULONG	Length,			// size of the buffer
			   ULONG	LBASector,		// starting LBA sector
			   ULONG	Count,			// number of sectors to read/write
			   ULONG	Flags			// variouse operation flags
			   )
{
	BOOL		Ret = FALSE;
	HANDLE		hDrive;
	NTSTATUS	ntStatus;
	OBJECT_ATTRIBUTES	oa = {0};
	UNICODE_STRING		us;
	IO_STATUS_BLOCK		IoStatus = {0};
	LARGE_INTEGER		FilePos = {0};
	HANDLE				hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	RtlInitUnicodeString(&us, Drive);
	InitializeObjectAttributes(&oa, &us, OBJ_CASE_INSENSITIVE, NULL, NULL);

	if ((Count * BIOS_DEFAULT_SECTOR_SIZE) <= Length)
	{
		ntStatus = NtCreateFile(&hDrive, GENERIC_WRITE | GENERIC_READ, &oa, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL,
								FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, 0, NULL, 0);
	
		if (NT_SUCCESS(ntStatus))
		{
			FilePos.QuadPart = ((ULONGLONG)LBASector * BIOS_DEFAULT_SECTOR_SIZE);

			if (Flags & SCSI_IO_WRITE_SECTOR)
				ntStatus = NtWriteFile(hDrive, hEvent, NULL, NULL, &IoStatus, Buffer, (Count*BIOS_DEFAULT_SECTOR_SIZE), &FilePos, NULL);
			else
				ntStatus = NtReadFile(hDrive, hEvent, NULL, NULL, &IoStatus, Buffer, (Count*BIOS_DEFAULT_SECTOR_SIZE), &FilePos, NULL);

			if (ntStatus == STATUS_PENDING)
				WaitForSingleObject(hEvent, INFINITE);

			NtClose(hDrive);

			if (NT_SUCCESS(IoStatus.Status))
				Ret = TRUE;
		}	// if (hDrive != INVALID_HANDLE_VALUE)
	}	// 	if ((Count * BIOS_DEFAULT_SECTOR_SIZE) <= Length)
 
   return(Ret);
}
开发者ID:12019,项目名称:Carberp,代码行数:50,代码来源:install.c


示例19: AG_XBOX_GetXbeTitleId

DWORD
AG_XBOX_GetXbeTitleId(const char *xbePath)
{
	HANDLE h;
	DWORD titleId = -1;
	DWORD loadAddress;
	DWORD certLocation;
	DWORD bytesRead;
	ANSI_STRING file;
	OBJECT_ATTRIBUTES attr;
	IO_STATUS_BLOCK status;

	if(!xbePath)
		return -1;

	RtlInitAnsiString(&file, xbePath);

	InitializeObjectAttributes(&attr, &file, OBJ_CASE_INSENSITIVE, NULL);

	if(SUCCEEDED(NtCreateFile(&h, FILE_GENERIC_READ, &attr, &status,
	                           NULL, 0, 0, FILE_OPEN,
	                           FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT))) {
		if(SetFilePointer(h,  0x104, NULL, FILE_BEGIN) == 0x104) {
			ReadFile(h, &loadAddress, sizeof(DWORD), &bytesRead, NULL);
			if(bytesRead == sizeof(DWORD)) {
				if(SetFilePointer(h, 0x118, NULL, FILE_BEGIN ) == 0x118) {
					ReadFile(h, &certLocation, sizeof(DWORD), &bytesRead, NULL);
					if(bytesRead == sizeof(DWORD)) {
						certLocation -= loadAddress;
						certLocation += 8;
						titleId = 0;
						if(SetFilePointer(h, certLocation, NULL, FILE_BEGIN) == certLocation) {
							ReadFile(h, &titleId, sizeof(DWORD), &bytesRead, NULL);
							if(bytesRead != sizeof(DWORD)) {
								titleId = 0;
							}
						}
					}
				}
			}
		}
		CloseHandle(h);
	}

	return titleId;
}
开发者ID:adsr,项目名称:agar,代码行数:46,代码来源:xbox.c


示例20: InternalOpenDirW

HANDLE
WINAPI
InternalOpenDirW(IN LPCWSTR DirName,
                 IN BOOLEAN Write)
{
    UNICODE_STRING NtPathU;
    OBJECT_ATTRIBUTES ObjectAttributes;
    NTSTATUS errCode;
    IO_STATUS_BLOCK IoStatusBlock;
    HANDLE hFile;

    if (!RtlDosPathNameToNtPathName_U(DirName, &NtPathU, NULL, NULL))
    {
        WARN("Invalid path\n");
        SetLastError(ERROR_BAD_PATHNAME);
        return INVALID_HANDLE_VALUE;
    }

    InitializeObjectAttributes(&ObjectAttributes,
                               &NtPathU,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);

    errCode = NtCreateFile(&hFile,
                           Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ,
                           &ObjectAttributes,
                           &IoStatusBlock,
                           NULL,
                           0,
                           FILE_SHARE_READ | FILE_SHARE_WRITE,
                           FILE_OPEN,
                           0,
                           NULL,
                           0);

    RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathU.Buffer);

    if (!NT_SUCCESS(errCode))
    {
        BaseSetLastNTError(errCode);
        return INVALID_HANDLE_VALUE;
    }

    return hFile;
}
开发者ID:RPG-7,项目名称:reactos,代码行数:46,代码来源:volume.c



注:本文中的NtCreateFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NtCurrentPeb函数代码示例发布时间:2022-05-30
下一篇:
C++ NtClose函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap