本文整理汇总了C++中RtlGetProcessHeap函数的典型用法代码示例。如果您正苦于以下问题:C++ RtlGetProcessHeap函数的具体用法?C++ RtlGetProcessHeap怎么用?C++ RtlGetProcessHeap使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RtlGetProcessHeap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetAdministratorPassword
NTSTATUS
SetAdministratorPassword(LPCWSTR Password)
{
PPOLICY_ACCOUNT_DOMAIN_INFO OrigInfo = NULL;
PUSER_ACCOUNT_NAME_INFORMATION AccountNameInfo = NULL;
USER_SET_PASSWORD_INFORMATION PasswordInfo;
LSA_OBJECT_ATTRIBUTES ObjectAttributes;
LSA_HANDLE PolicyHandle = NULL;
SAM_HANDLE ServerHandle = NULL;
SAM_HANDLE DomainHandle = NULL;
SAM_HANDLE UserHandle = NULL;
NTSTATUS Status;
DPRINT("SYSSETUP: SetAdministratorPassword(%p)\n", Password);
memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
Status = LsaOpenPolicy(NULL,
&ObjectAttributes,
POLICY_VIEW_LOCAL_INFORMATION | POLICY_TRUST_ADMIN,
&PolicyHandle);
if (Status != STATUS_SUCCESS)
{
DPRINT1("LsaOpenPolicy() failed (Status: 0x%08lx)\n", Status);
return Status;
}
Status = LsaQueryInformationPolicy(PolicyHandle,
PolicyAccountDomainInformation,
(PVOID *)&OrigInfo);
if (!NT_SUCCESS(Status))
{
DPRINT1("LsaQueryInformationPolicy() failed (Status: 0x%08lx)\n", Status);
goto done;
}
Status = SamConnect(NULL,
&ServerHandle,
SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("SamConnect() failed (Status: 0x%08lx)\n", Status);
goto done;
}
Status = SamOpenDomain(ServerHandle,
DOMAIN_LOOKUP,
OrigInfo->DomainSid,
&DomainHandle);
if (!NT_SUCCESS(Status))
{
DPRINT1("SamOpenDomain() failed (Status: 0x%08lx)\n", Status);
goto done;
}
Status = SamOpenUser(DomainHandle,
USER_FORCE_PASSWORD_CHANGE | USER_READ_GENERAL,
DOMAIN_USER_RID_ADMIN,
&UserHandle);
if (!NT_SUCCESS(Status))
{
DPRINT1("SamOpenUser() failed (Status %08lx)\n", Status);
goto done;
}
RtlInitUnicodeString(&PasswordInfo.Password, Password);
PasswordInfo.PasswordExpired = FALSE;
Status = SamSetInformationUser(UserHandle,
UserSetPasswordInformation,
(PVOID)&PasswordInfo);
if (!NT_SUCCESS(Status))
{
DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
goto done;
}
Status = SamQueryInformationUser(UserHandle,
UserAccountNameInformation,
(PVOID*)&AccountNameInfo);
if (!NT_SUCCESS(Status))
{
DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
goto done;
}
AdminInfo.Name = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
AccountNameInfo->UserName.Length + sizeof(WCHAR));
if (AdminInfo.Name != NULL)
RtlCopyMemory(AdminInfo.Name,
AccountNameInfo->UserName.Buffer,
AccountNameInfo->UserName.Length);
AdminInfo.Domain = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
OrigInfo->DomainName.Length + sizeof(WCHAR));
if (AdminInfo.Domain != NULL)
//.........这里部分代码省略.........
示例2: MoveFileWithProgressW
/*
* @implemented
*/
BOOL
WINAPI
MoveFileWithProgressW (
LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine,
LPVOID lpData,
DWORD dwFlags
)
{
HANDLE hFile = NULL, hNewFile = NULL;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES ObjectAttributes;
PFILE_RENAME_INFORMATION FileRename;
NTSTATUS errCode;
BOOL Result;
UNICODE_STRING DstPathU;
BOOL folder = FALSE;
TRACE("MoveFileWithProgressW()\n");
if (dwFlags & MOVEFILE_DELAY_UNTIL_REBOOT)
return add_boot_rename_entry( lpExistingFileName, lpNewFileName, dwFlags );
// if (dwFlags & MOVEFILE_WRITE_THROUGH)
// FIXME("MOVEFILE_WRITE_THROUGH unimplemented\n");
if (!lpNewFileName)
return DeleteFileW(lpExistingFileName);
/* validate & translate the filename */
if (!RtlDosPathNameToNtPathName_U (lpNewFileName,
&DstPathU,
NULL,
NULL))
{
WARN("Invalid destination path\n");
SetLastError(ERROR_PATH_NOT_FOUND);
return FALSE;
}
InitializeObjectAttributes(&ObjectAttributes,
&DstPathU,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
errCode = NtOpenFile( &hNewFile,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
0,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT |
((dwFlags & MOVEFILE_WRITE_THROUGH) ? FILE_WRITE_THROUGH : 0) );
if (NT_SUCCESS(errCode)) /* Destination exists */
{
NtClose(hNewFile);
if (!(dwFlags & MOVEFILE_REPLACE_EXISTING))
{
SetLastError(ERROR_ALREADY_EXISTS);
return FALSE;
}
else if (GetFileAttributesW(lpNewFileName) & FILE_ATTRIBUTE_DIRECTORY)
{
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
}
hFile = CreateFileW (lpExistingFileName,
GENERIC_ALL,
FILE_SHARE_WRITE|FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS |
((dwFlags & MOVEFILE_WRITE_THROUGH) ? FILE_FLAG_WRITE_THROUGH : 0),
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return FALSE;
}
FileRename = RtlAllocateHeap(
RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length);
if( !FileRename ) {
CloseHandle(hFile);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
if( dwFlags & MOVEFILE_REPLACE_EXISTING ) {
FileRename->ReplaceIfExists = TRUE;
}
//.........这里部分代码省略.........
示例3: ScanForUnpartitionedDiskSpace
static
VOID
ScanForUnpartitionedDiskSpace(
PDISKENTRY DiskEntry)
{
ULONGLONG LastStartSector;
ULONGLONG LastSectorCount;
ULONGLONG LastUnusedSectorCount;
PPARTENTRY PartEntry;
PPARTENTRY NewPartEntry;
PLIST_ENTRY Entry;
DPRINT("ScanForUnpartitionedDiskSpace()\n");
if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
{
DPRINT1("No primary partition!\n");
/* Create a partition table that represents the empty disk */
NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(PARTENTRY));
if (NewPartEntry == NULL)
return;
NewPartEntry->DiskEntry = DiskEntry;
NewPartEntry->IsPartitioned = FALSE;
NewPartEntry->StartSector.QuadPart = (ULONGLONG)DiskEntry->SectorAlignment;
NewPartEntry->SectorCount.QuadPart = AlignDown(DiskEntry->SectorCount.QuadPart, DiskEntry->SectorAlignment) -
NewPartEntry->StartSector.QuadPart;
DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
InsertTailList(&DiskEntry->PrimaryPartListHead,
&NewPartEntry->ListEntry);
return;
}
/* Start partition at head 1, cylinder 0 */
LastStartSector = DiskEntry->SectorAlignment;
LastSectorCount = 0ULL;
LastUnusedSectorCount = 0ULL;
Entry = DiskEntry->PrimaryPartListHead.Flink;
while (Entry != &DiskEntry->PrimaryPartListHead)
{
PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (PartEntry->PartitionType != PARTITION_ENTRY_UNUSED ||
PartEntry->SectorCount.QuadPart != 0ULL)
{
LastUnusedSectorCount =
PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount);
if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) &&
LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
{
DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(PARTENTRY));
if (NewPartEntry == NULL)
return;
NewPartEntry->DiskEntry = DiskEntry;
NewPartEntry->IsPartitioned = FALSE;
NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
NewPartEntry->StartSector.QuadPart;
DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
/* Insert the table into the list */
InsertTailList(&PartEntry->ListEntry,
&NewPartEntry->ListEntry);
}
LastStartSector = PartEntry->StartSector.QuadPart;
LastSectorCount = PartEntry->SectorCount.QuadPart;
}
Entry = Entry->Flink;
}
/* Check for trailing unpartitioned disk space */
if ((LastStartSector + LastSectorCount) < DiskEntry->SectorCount.QuadPart)
{
LastUnusedSectorCount = AlignDown(DiskEntry->SectorCount.QuadPart - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment);
//.........这里部分代码省略.........
示例4: ExpandEnvironmentStringsA
/*
* @implemented
*/
DWORD
WINAPI
ExpandEnvironmentStringsA (
LPCSTR lpSrc,
LPSTR lpDst,
DWORD nSize
)
{
ANSI_STRING Source;
ANSI_STRING Destination;
UNICODE_STRING SourceU;
UNICODE_STRING DestinationU;
NTSTATUS Status;
ULONG Length = 0;
RtlInitAnsiString (&Source,
(LPSTR)lpSrc);
Status = RtlAnsiStringToUnicodeString (&SourceU,
&Source,
TRUE);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return 0;
}
/* make sure we don't overflow the maximum ANSI_STRING size */
if (nSize > 0x7fff)
nSize = 0x7fff;
Destination.Length = 0;
Destination.MaximumLength = (USHORT)nSize;
Destination.Buffer = lpDst;
DestinationU.Length = 0;
DestinationU.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
DestinationU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0,
DestinationU.MaximumLength);
if (DestinationU.Buffer == NULL)
{
RtlFreeUnicodeString(&SourceU);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
Status = RtlExpandEnvironmentStrings_U (NULL,
&SourceU,
&DestinationU,
&Length);
RtlFreeUnicodeString (&SourceU);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
if (Status != STATUS_BUFFER_TOO_SMALL)
{
RtlFreeHeap (RtlGetProcessHeap (),
0,
DestinationU.Buffer);
return 0;
}
}
RtlUnicodeStringToAnsiString (&Destination,
&DestinationU,
FALSE);
RtlFreeHeap (RtlGetProcessHeap (),
0,
DestinationU.Buffer);
return (Length / sizeof(WCHAR));
}
示例5: EnumerateBiosDiskEntries
static
VOID
EnumerateBiosDiskEntries(VOID)
{
RTL_QUERY_REGISTRY_TABLE QueryTable[3];
WCHAR Name[120];
ULONG AdapterCount;
ULONG DiskCount;
NTSTATUS Status;
PCM_INT13_DRIVE_PARAMETER Int13Drives;
PBIOSDISKENTRY BiosDiskEntry;
memset(QueryTable, 0, sizeof(QueryTable));
QueryTable[1].Name = L"Configuration Data";
QueryTable[1].QueryRoutine = SystemConfigurationDataQueryRoutine;
Int13Drives = NULL;
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System",
&QueryTable[1],
(PVOID)&Int13Drives,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("Unable to query the 'Configuration Data' key in '\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System', status=%lx\n", Status);
return;
}
AdapterCount = 0;
while (1)
{
swprintf(Name, L"%s\\%lu", ROOT_NAME, AdapterCount);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
Name,
&QueryTable[2],
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
break;
}
swprintf(Name, L"%s\\%lu\\DiskController", ROOT_NAME, AdapterCount);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
Name,
&QueryTable[2],
NULL,
NULL);
if (NT_SUCCESS(Status))
{
while (1)
{
swprintf(Name, L"%s\\%lu\\DiskController\\0", ROOT_NAME, AdapterCount);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
Name,
&QueryTable[2],
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(), 0, Int13Drives);
return;
}
swprintf(Name, L"%s\\%lu\\DiskController\\0\\DiskPeripheral", ROOT_NAME, AdapterCount);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
Name,
&QueryTable[2],
NULL,
NULL);
if (NT_SUCCESS(Status))
{
QueryTable[0].Name = L"Identifier";
QueryTable[0].QueryRoutine = DiskIdentifierQueryRoutine;
QueryTable[1].Name = L"Configuration Data";
QueryTable[1].QueryRoutine = DiskConfigurationDataQueryRoutine;
DiskCount = 0;
while (1)
{
BiosDiskEntry = (BIOSDISKENTRY*)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BIOSDISKENTRY));
if (BiosDiskEntry == NULL)
{
break;
}
swprintf(Name, L"%s\\%lu\\DiskController\\0\\DiskPeripheral\\%lu", ROOT_NAME, AdapterCount, DiskCount);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
Name,
QueryTable,
(PVOID)BiosDiskEntry,
NULL);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
break;
}
BiosDiskEntry->DiskNumber = DiskCount;
BiosDiskEntry->Recognized = FALSE;
//.........这里部分代码省略.........
示例6: WaitNamedPipeW
/*
* @implemented
*/
BOOL
WINAPI
WaitNamedPipeW(LPCWSTR lpNamedPipeName,
DWORD nTimeOut)
{
UNICODE_STRING NamedPipeName, NewName, DevicePath, PipePrefix;
ULONG NameLength;
ULONG i;
PWCHAR p;
ULONG Type;
OBJECT_ATTRIBUTES ObjectAttributes;
NTSTATUS Status;
HANDLE FileHandle;
IO_STATUS_BLOCK IoStatusBlock;
ULONG WaitPipeInfoSize;
PFILE_PIPE_WAIT_FOR_BUFFER WaitPipeInfo;
/* Start by making a unicode string of the name */
TRACE("Sent path: %S\n", lpNamedPipeName);
RtlCreateUnicodeString(&NamedPipeName, lpNamedPipeName);
NameLength = NamedPipeName.Length / sizeof(WCHAR);
/* All slashes must become backslashes */
for (i = 0; i < NameLength; i++)
{
/* Check and convert */
if (NamedPipeName.Buffer[i] == L'/') NamedPipeName.Buffer[i] = L'\\';
}
/* Find the path type of the name we were given */
NewName = NamedPipeName;
Type = RtlDetermineDosPathNameType_U(lpNamedPipeName);
/* Check if this was a device path, ie : "\\.\pipe\name" */
if (Type == RtlPathTypeLocalDevice)
{
/* Make sure it's a valid prefix */
RtlInitUnicodeString(&PipePrefix, L"\\\\.\\pipe\\");
RtlPrefixString((PANSI_STRING)&PipePrefix, (PANSI_STRING)&NewName, TRUE);
/* Move past it */
NewName.Buffer += 9;
NewName.Length -= 9 * sizeof(WCHAR);
/* Initialize the Dos Devices name */
TRACE("NewName: %wZ\n", &NewName);
RtlInitUnicodeString(&DevicePath, L"\\DosDevices\\pipe\\");
}
else if (Type == RtlPathTypeRootLocalDevice)
{
/* The path is \\server\\pipe\name; find the pipename itself */
p = &NewName.Buffer[2];
/* First loop to get past the server name */
do
{
/* Check if this is a backslash */
if (*p == L'\\') break;
/* Check next */
p++;
} while (*p);
/* Now make sure the full name contains "pipe\" */
if ((*p) && !(_wcsnicmp(p + 1, L"pipe\\", sizeof("pipe\\"))))
{
/* Get to the pipe name itself now */
p += sizeof("pipe\\") - 1;
}
else
{
/* The name is invalid */
WARN("Invalid name!\n");
BaseSetLastNTError(STATUS_OBJECT_PATH_SYNTAX_BAD);
return FALSE;
}
/* FIXME: Open \DosDevices\Unc\Server\Pipe\Name */
}
else
{
WARN("Invalid path type\n");
BaseSetLastNTError(STATUS_OBJECT_PATH_SYNTAX_BAD);
return FALSE;
}
/* Now calculate the total length of the structure and allocate it */
WaitPipeInfoSize = FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[0]) +
NewName.Length;
WaitPipeInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, WaitPipeInfoSize);
if (WaitPipeInfo == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
/* Initialize the object attributes */
//.........这里部分代码省略.........
示例7: LsapEnumLogonSessions
NTSTATUS
LsapEnumLogonSessions(IN OUT PLSA_API_MSG RequestMsg)
{
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE ProcessHandle = NULL;
PLIST_ENTRY SessionEntry;
PLSAP_LOGON_SESSION CurrentSession;
PLUID SessionList;
ULONG i, Length, MemSize;
PVOID ClientBaseAddress = NULL;
NTSTATUS Status;
TRACE("LsapEnumLogonSessions(%p)\n", RequestMsg);
Length = SessionCount * sizeof(LUID);
SessionList = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
Length);
if (SessionList == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
i = 0;
SessionEntry = SessionListHead.Flink;
while (SessionEntry != &SessionListHead)
{
CurrentSession = CONTAINING_RECORD(SessionEntry,
LSAP_LOGON_SESSION,
Entry);
RtlCopyLuid(&SessionList[i],
&CurrentSession->LogonId);
SessionEntry = SessionEntry->Flink;
i++;
}
InitializeObjectAttributes(&ObjectAttributes,
NULL,
0,
NULL,
NULL);
Status = NtOpenProcess(&ProcessHandle,
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION,
&ObjectAttributes,
&RequestMsg->h.ClientId);
if (!NT_SUCCESS(Status))
{
TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
goto done;
}
TRACE("Length: %lu\n", Length);
MemSize = Length;
Status = NtAllocateVirtualMemory(ProcessHandle,
&ClientBaseAddress,
0,
&MemSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
goto done;
}
TRACE("MemSize: %lu\n", MemSize);
TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
Status = NtWriteVirtualMemory(ProcessHandle,
ClientBaseAddress,
SessionList,
Length,
NULL);
if (!NT_SUCCESS(Status))
{
TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
goto done;
}
RequestMsg->EnumLogonSessions.Reply.LogonSessionCount = SessionCount;
RequestMsg->EnumLogonSessions.Reply.LogonSessionBuffer = ClientBaseAddress;
done:
if (ProcessHandle != NULL)
NtClose(ProcessHandle);
if (SessionList != NULL)
RtlFreeHeap(RtlGetProcessHeap(), 0, SessionList);
return Status;
}
示例8: PeekNamedPipe
/*
* @implemented
*/
BOOL
WINAPI
PeekNamedPipe(HANDLE hNamedPipe,
LPVOID lpBuffer,
DWORD nBufferSize,
LPDWORD lpBytesRead,
LPDWORD lpTotalBytesAvail,
LPDWORD lpBytesLeftThisMessage)
{
PFILE_PIPE_PEEK_BUFFER Buffer;
IO_STATUS_BLOCK Iosb;
ULONG BufferSize;
ULONG BytesRead;
NTSTATUS Status;
/* Calculate the buffer space that we'll need and allocate it */
BufferSize = FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[nBufferSize]);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
if (Buffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
/* Tell the driver to seek */
Status = NtFsControlFile(hNamedPipe,
NULL,
NULL,
NULL,
&Iosb,
FSCTL_PIPE_PEEK,
NULL,
0,
Buffer,
BufferSize);
if (Status == STATUS_PENDING)
{
/* Wait for npfs to be done, and update the status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
if (NT_SUCCESS(Status))
Status = Iosb.Status;
}
/* Overflow is success for us */
if (Status == STATUS_BUFFER_OVERFLOW)
Status = STATUS_SUCCESS;
/* If we failed */
if (!NT_SUCCESS(Status))
{
/* Free the buffer and return failure */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
BaseSetLastNTError(Status);
return FALSE;
}
/* Check if caller requested bytes available */
if (lpTotalBytesAvail)
{
/* Return bytes available */
*lpTotalBytesAvail = Buffer->ReadDataAvailable;
}
/* Calculate the bytes returned, minus our structure overhead */
BytesRead = (ULONG)(Iosb.Information -
FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
ASSERT(BytesRead <= nBufferSize);
/* Check if caller requested bytes read */
if (lpBytesRead)
{
/* Return the bytes read */
*lpBytesRead = BytesRead;
}
/* Check if caller requested bytes left */
if (lpBytesLeftThisMessage)
{
/* Calculate total minus what we returned and our structure overhead */
*lpBytesLeftThisMessage = Buffer->MessageLength - BytesRead;
}
/* Check if the caller wanted to see the actual data */
if (lpBuffer)
{
/* Give him what he wants */
RtlCopyMemory(lpBuffer,
Buffer->Data,
BytesRead);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return TRUE;
}
示例9: CreateNamedPipeW
//.........这里部分代码省略.........
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
{
CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
}
/* Handle all open modes */
if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
{
ShareAccess |= FILE_SHARE_READ;
DesiredAccess |= GENERIC_WRITE;
}
if (dwOpenMode & PIPE_ACCESS_INBOUND)
{
ShareAccess |= FILE_SHARE_WRITE;
DesiredAccess |= GENERIC_READ;
}
/* Handle the type flags */
if (dwPipeMode & PIPE_TYPE_MESSAGE)
{
WriteModeMessage = FILE_PIPE_MESSAGE_TYPE;
}
else
{
WriteModeMessage = FILE_PIPE_BYTE_STREAM_TYPE;
}
/* Handle the mode flags */
if (dwPipeMode & PIPE_READMODE_MESSAGE)
{
ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
}
else
{
ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
}
/* Handle the blocking mode */
if (dwPipeMode & PIPE_NOWAIT)
{
NonBlocking = FILE_PIPE_COMPLETE_OPERATION;
}
else
{
NonBlocking = FILE_PIPE_QUEUE_OPERATION;
}
/* Check if we have a timeout */
if (nDefaultTimeOut)
{
/* Convert the time to NT format */
DefaultTimeOut.QuadPart = UInt32x32To64(nDefaultTimeOut, -10000);
}
else
{
/* Use default timeout of 50 ms */
DefaultTimeOut.QuadPart = -500000;
}
/* Now create the pipe */
Status = NtCreateNamedPipeFile(&PipeHandle,
DesiredAccess,
&ObjectAttributes,
&Iosb,
ShareAccess,
FILE_OPEN_IF,
CreateOptions,
WriteModeMessage,
ReadModeMessage,
NonBlocking,
nMaxInstances,
nInBufferSize,
nOutBufferSize,
&DefaultTimeOut);
/* Normalize special error codes */
if ((Status == STATUS_INVALID_DEVICE_REQUEST) ||
(Status == STATUS_NOT_SUPPORTED))
{
Status = STATUS_OBJECT_NAME_INVALID;
}
/* Free the name */
RtlFreeHeap(RtlGetProcessHeap(),
0,
NamedPipeName.Buffer);
/* Check status */
if (!NT_SUCCESS(Status))
{
/* Failed to create it */
WARN("NtCreateNamedPipe failed (Status %x)!\n", Status);
BaseSetLastNTError (Status);
return INVALID_HANDLE_VALUE;
}
/* Return the handle */
return PipeHandle;
}
示例10: DeleteFileW
//.........这里部分代码省略.........
{
/* There is, so now try to open it with reparse behavior */
NtClose(FileHandle);
Status = NtOpenFile(&FileHandle,
DELETE,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_DELETE |
FILE_SHARE_READ |
FILE_SHARE_WRITE,
FILE_NON_DIRECTORY_FILE |
FILE_OPEN_FOR_BACKUP_INTENT);
if (!NT_SUCCESS(Status))
{
/* We failed -- maybe whoever is handling this tag isn't there */
if (Status == STATUS_IO_REPARSE_TAG_NOT_HANDLED)
{
/* Try to open it for delete, without reparse behavior */
Status = NtOpenFile(&FileHandle,
DELETE,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ |
FILE_SHARE_WRITE |
FILE_SHARE_DELETE,
FILE_NON_DIRECTORY_FILE |
FILE_OPEN_FOR_BACKUP_INTENT |
FILE_OPEN_REPARSE_POINT);
}
if (!NT_SUCCESS(Status))
{
RtlReleaseRelativeName(&RelativeName);
RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
BaseSetLastNTError(Status);
return FALSE;
}
}
}
else if (!(NT_SUCCESS(Status)) &&
(Status != STATUS_NOT_IMPLEMENTED) &&
(Status != STATUS_INVALID_PARAMETER))
{
/* We had some critical error querying the attributes, bail out */
RtlReleaseRelativeName(&RelativeName);
RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
NtClose(FileHandle);
BaseSetLastNTError(Status);
return FALSE;
}
}
else
{
/* It's possible that FILE_OPEN_REPARSE_POINT was not understood */
if (Status == STATUS_INVALID_PARAMETER)
{
/* Try opening the file normally, with reparse behavior */
Status = NtOpenFile(&FileHandle,
DELETE,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_DELETE |
FILE_SHARE_READ |
FILE_SHARE_WRITE,
FILE_NON_DIRECTORY_FILE |
FILE_OPEN_FOR_BACKUP_INTENT);
示例11: ExtCreatePen
/*
* @implemented
*/
HPEN
APIENTRY
ExtCreatePen(DWORD dwPenStyle,
DWORD dwWidth,
CONST LOGBRUSH *lplb,
DWORD dwStyleCount,
CONST DWORD *lpStyle)
{
PVOID lpPackedDIB = NULL;
HPEN hPen = NULL;
PBITMAPINFO pConvertedInfo = NULL;
UINT ConvertedInfoSize = 0, lbStyle;
BOOL Hit = FALSE;
if ((dwPenStyle & PS_STYLE_MASK) == PS_USERSTYLE)
{
if(!lpStyle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
} // This is an enhancement and prevents a call to kernel space.
else if ((dwPenStyle & PS_STYLE_MASK) == PS_INSIDEFRAME &&
(dwPenStyle & PS_TYPE_MASK) != PS_GEOMETRIC)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
else if ((dwPenStyle & PS_STYLE_MASK) == PS_ALTERNATE &&
(dwPenStyle & PS_TYPE_MASK) != PS_COSMETIC)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
else
{
if (dwStyleCount || lpStyle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
}
lbStyle = lplb->lbStyle;
if (lplb->lbStyle > BS_HATCHED)
{
if (lplb->lbStyle == BS_PATTERN)
{
pConvertedInfo = (PBITMAPINFO)lplb->lbHatch;
if (!pConvertedInfo) return 0;
}
else
{
if ((lplb->lbStyle == BS_DIBPATTERN) || (lplb->lbStyle == BS_DIBPATTERNPT))
{
if (lplb->lbStyle == BS_DIBPATTERN)
{
lbStyle = BS_DIBPATTERNPT;
lpPackedDIB = GlobalLock((HGLOBAL)lplb->lbHatch);
if (lpPackedDIB == NULL) return 0;
}
pConvertedInfo = ConvertBitmapInfo((PBITMAPINFO)lpPackedDIB,
lplb->lbColor,
&ConvertedInfoSize,
TRUE);
Hit = TRUE; // We converted DIB.
}
else
pConvertedInfo = (PBITMAPINFO)lpStyle;
}
}
else
pConvertedInfo = (PBITMAPINFO)lplb->lbHatch;
hPen = NtGdiExtCreatePen(dwPenStyle,
dwWidth,
lbStyle,
lplb->lbColor,
lplb->lbHatch,
(ULONG_PTR)pConvertedInfo,
dwStyleCount,
(PULONG)lpStyle,
ConvertedInfoSize,
FALSE,
NULL);
if (lplb->lbStyle == BS_DIBPATTERN) GlobalUnlock((HGLOBAL)lplb->lbHatch);
if (Hit)
{
if ((PBITMAPINFO)lpPackedDIB != pConvertedInfo)
RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
}
return hPen;
//.........这里部分代码省略.........
示例12: CsrServerInitialization
/*++
* @name CsrServerInitialization
* @implemented NT4
*
* The CsrServerInitialization routine is the native (not Server) entrypoint
* of this Server DLL. It serves as the entrypoint for CSRSS.
*
* @param ArgumentCount
* Number of arguments on the command line.
*
* @param Arguments
* Array of arguments from the command line.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
*--*/
NTSTATUS
NTAPI
CsrServerInitialization(IN ULONG ArgumentCount,
IN PCHAR Arguments[])
{
NTSTATUS Status = STATUS_SUCCESS;
/* Create the Init Event */
Status = NtCreateEvent(&CsrInitializationEvent,
EVENT_ALL_ACCESS,
NULL,
SynchronizationEvent,
FALSE);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: NtCreateEvent failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Cache System Basic Information so we don't always request it */
Status = NtQuerySystemInformation(SystemBasicInformation,
&CsrNtSysInfo,
sizeof(SYSTEM_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Save our Heap */
CsrHeap = RtlGetProcessHeap();
/* Set our Security Descriptor to protect the process */
Status = CsrSetProcessSecurity();
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Set up Session Support */
Status = CsrInitializeNtSessionList();
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Set up Process Support and allocate the CSR Root Process */
Status = CsrInitializeProcessStructure();
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Parse the command line */
Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Finish to initialize the CSR Root Process */
Status = CsrInitCsrRootProcess();
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=%08lx)\n",
__FUNCTION__, Status);
return Status;
}
/* Now initialize our API Port */
Status = CsrApiPortInitialize();
//.........这里部分代码省略.........
示例13: GetEnvironmentVariableA
/*
* @implemented
*/
DWORD
WINAPI
GetEnvironmentVariableA (
LPCSTR lpName,
LPSTR lpBuffer,
DWORD nSize
)
{
ANSI_STRING VarName;
ANSI_STRING VarValue;
UNICODE_STRING VarNameU;
UNICODE_STRING VarValueU;
NTSTATUS Status;
/* initialize unicode variable name string */
RtlInitAnsiString (&VarName,
(LPSTR)lpName);
RtlAnsiStringToUnicodeString (&VarNameU,
&VarName,
TRUE);
/* initialize ansi variable value string */
VarValue.Length = 0;
VarValue.MaximumLength = (USHORT)nSize;
VarValue.Buffer = lpBuffer;
/* initialize unicode variable value string and allocate buffer */
VarValueU.Length = 0;
if (nSize != 0)
{
VarValueU.MaximumLength = (USHORT)(nSize - 1) * sizeof(WCHAR);
VarValueU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0,
nSize * sizeof(WCHAR));
if (VarValueU.Buffer != NULL)
{
/* NULL-terminate the buffer in any case! RtlQueryEnvironmentVariable_U
only terminates it if MaximumLength < Length! */
VarValueU.Buffer[nSize - 1] = L'\0';
}
}
else
{
VarValueU.MaximumLength = 0;
VarValueU.Buffer = NULL;
}
if (VarValueU.Buffer != NULL || nSize == 0)
{
/* get unicode environment variable */
Status = RtlQueryEnvironmentVariable_U (NULL,
&VarNameU,
&VarValueU);
if (!NT_SUCCESS(Status))
{
/* free unicode buffer */
RtlFreeHeap (RtlGetProcessHeap (),
0,
VarValueU.Buffer);
/* free unicode variable name string */
RtlFreeUnicodeString (&VarNameU);
SetLastErrorByStatus (Status);
if (Status == STATUS_BUFFER_TOO_SMALL)
{
return (VarValueU.Length / sizeof(WCHAR)) + 1;
}
else
{
return 0;
}
}
/* convert unicode value string to ansi */
RtlUnicodeStringToAnsiString (&VarValue,
&VarValueU,
FALSE);
if (VarValueU.Buffer != NULL)
{
/* free unicode buffer */
RtlFreeHeap (RtlGetProcessHeap (),
0,
VarValueU.Buffer);
}
/* free unicode variable name string */
RtlFreeUnicodeString (&VarNameU);
return (VarValueU.Length / sizeof(WCHAR));
}
else
{
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
//.........这里部分代码省略.........
示例14: LsapGetLogonSessionData
NTSTATUS
LsapGetLogonSessionData(IN OUT PLSA_API_MSG RequestMsg)
{
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE ProcessHandle = NULL;
PLSAP_LOGON_SESSION Session;
PSECURITY_LOGON_SESSION_DATA LocalSessionData;
PVOID ClientBaseAddress = NULL;
ULONG Length, MemSize;
LPWSTR Ptr;
NTSTATUS Status;
TRACE("LsapGetLogonSessionData(%p)\n", RequestMsg);
TRACE("LogonId: %lx\n", RequestMsg->GetLogonSessionData.Request.LogonId.LowPart);
Session = LsapGetLogonSession(&RequestMsg->GetLogonSessionData.Request.LogonId);
if (Session == NULL)
return STATUS_NO_SUCH_LOGON_SESSION;
Length = sizeof(SECURITY_LOGON_SESSION_DATA);
/*
Session->UserName.MaximumLength +
Session->LogonDomain.MaximumLength +
Session->AuthenticationPackage.MaximumLength +
Session->LogonServer.MaximumLength +
Session->DnsDomainName.MaximumLength +
Session->Upn.MaximumLength;
if (Session->Sid != NULL)
RtlLengthSid(Session->Sid);
*/
TRACE("Length: %lu\n", Length);
LocalSessionData = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
Length);
if (LocalSessionData == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
Ptr = (LPWSTR)((ULONG_PTR)LocalSessionData + sizeof(SECURITY_LOGON_SESSION_DATA));
TRACE("LocalSessionData: %p Ptr: %p\n", LocalSessionData, Ptr);
LocalSessionData->Size = sizeof(SECURITY_LOGON_SESSION_DATA);
RtlCopyLuid(&LocalSessionData->LogonId,
&RequestMsg->GetLogonSessionData.Request.LogonId);
InitializeObjectAttributes(&ObjectAttributes,
NULL,
0,
NULL,
NULL);
Status = NtOpenProcess(&ProcessHandle,
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION,
&ObjectAttributes,
&RequestMsg->h.ClientId);
if (!NT_SUCCESS(Status))
{
TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
goto done;
}
MemSize = Length;
Status = NtAllocateVirtualMemory(ProcessHandle,
&ClientBaseAddress,
0,
&MemSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
goto done;
}
TRACE("MemSize: %lu\n", MemSize);
TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
Status = NtWriteVirtualMemory(ProcessHandle,
ClientBaseAddress,
LocalSessionData,
Length,
NULL);
if (!NT_SUCCESS(Status))
{
TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
goto done;
}
RequestMsg->GetLogonSessionData.Reply.SessionDataBuffer = ClientBaseAddress;
done:
if (ProcessHandle != NULL)
NtClose(ProcessHandle);
if (LocalSessionData != NULL)
RtlFreeHeap(RtlGetProcessHeap(), 0, LocalSessionData);
//.........这里部分代码省略.........
示例15: GetEnvironmentStringsA
/*
* @implemented
*/
LPSTR
WINAPI
GetEnvironmentStringsA (
VOID
)
{
UNICODE_STRING UnicodeString;
ANSI_STRING AnsiString;
PWCHAR EnvU;
PWCHAR PtrU;
ULONG Length;
PCHAR EnvPtr = NULL;
EnvU = (PWCHAR)(NtCurrentPeb ()->ProcessParameters->Environment);
if (EnvU == NULL)
return NULL;
if (*EnvU == 0)
return NULL;
/* get environment size */
PtrU = EnvU;
while (*PtrU)
{
while (*PtrU)
PtrU++;
PtrU++;
}
Length = (ULONG)(PtrU - EnvU);
DPRINT("Length %lu\n", Length);
/* allocate environment buffer */
EnvPtr = RtlAllocateHeap (RtlGetProcessHeap (),
0,
Length + 1);
if (EnvPtr == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
DPRINT("EnvPtr %p\n", EnvPtr);
/* convert unicode environment to ansi */
UnicodeString.MaximumLength = (USHORT)Length * sizeof(WCHAR) + sizeof(WCHAR);
UnicodeString.Buffer = EnvU;
AnsiString.MaximumLength = (USHORT)Length + 1;
AnsiString.Length = 0;
AnsiString.Buffer = EnvPtr;
DPRINT ("UnicodeString.Buffer \'%S\'\n", UnicodeString.Buffer);
while (*(UnicodeString.Buffer))
{
UnicodeString.Length = wcslen (UnicodeString.Buffer) * sizeof(WCHAR);
UnicodeString.MaximumLength = UnicodeString.Length + sizeof(WCHAR);
if (UnicodeString.Length > 0)
{
AnsiString.Length = 0;
AnsiString.MaximumLength = (USHORT)Length + 1 - (AnsiString.Buffer - EnvPtr);
RtlUnicodeStringToAnsiString (&AnsiString,
&UnicodeString,
FALSE);
AnsiString.Buffer += (AnsiString.Length + 1);
UnicodeString.Buffer += ((UnicodeString.Length / sizeof(WCHAR)) + 1);
}
}
*(AnsiString.Buffer) = 0;
return EnvPtr;
}