本文整理汇总了C++中RtlAllocateHeap函数的典型用法代码示例。如果您正苦于以下问题:C++ RtlAllocateHeap函数的具体用法?C++ RtlAllocateHeap怎么用?C++ RtlAllocateHeap使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RtlAllocateHeap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateBaseAcls
NTSTATUS
NTAPI
CreateBaseAcls(OUT PACL* Dacl,
OUT PACL* RestrictedDacl)
{
PSID SystemSid, WorldSid, RestrictedSid;
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
SID_IDENTIFIER_AUTHORITY WorldAuthority = {SECURITY_WORLD_SID_AUTHORITY};
NTSTATUS Status;
#if 0 // Unused code
UCHAR KeyValueBuffer[0x40];
PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
UNICODE_STRING KeyName;
ULONG ProtectionMode = 0;
#endif
ULONG AclLength;
#if 0 // Unused code
ULONG ResultLength;
HANDLE hKey;
OBJECT_ATTRIBUTES ObjectAttributes;
/* Open the Session Manager Key */
RtlInitUnicodeString(&KeyName, SM_REG_KEY);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenKey(&hKey, KEY_READ, &ObjectAttributes);
if (NT_SUCCESS(Status))
{
/* Read the key value */
RtlInitUnicodeString(&KeyName, L"ProtectionMode");
Status = NtQueryValueKey(hKey,
&KeyName,
KeyValuePartialInformation,
KeyValueBuffer,
sizeof(KeyValueBuffer),
&ResultLength);
/* Make sure it's what we expect it to be */
KeyValuePartialInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer;
if ((NT_SUCCESS(Status)) && (KeyValuePartialInfo->Type == REG_DWORD) &&
(*(PULONG)KeyValuePartialInfo->Data))
{
/* Save the Protection Mode */
ProtectionMode = *(PULONG)KeyValuePartialInfo->Data;
}
/* Close the handle */
NtClose(hKey);
}
#endif
/* Allocate the System SID */
Status = RtlAllocateAndInitializeSid(&NtAuthority,
1, SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0,
&SystemSid);
ASSERT(NT_SUCCESS(Status));
/* Allocate the World SID */
Status = RtlAllocateAndInitializeSid(&WorldAuthority,
1, SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0,
&WorldSid);
ASSERT(NT_SUCCESS(Status));
/* Allocate the restricted SID */
Status = RtlAllocateAndInitializeSid(&NtAuthority,
1, SECURITY_RESTRICTED_CODE_RID,
0, 0, 0, 0, 0, 0, 0,
&RestrictedSid);
ASSERT(NT_SUCCESS(Status));
/* Allocate one ACL with 3 ACEs each for one SID */
AclLength = sizeof(ACL) + 3 * sizeof(ACCESS_ALLOWED_ACE) +
RtlLengthSid(SystemSid) +
RtlLengthSid(WorldSid) +
RtlLengthSid(RestrictedSid);
*Dacl = RtlAllocateHeap(BaseSrvHeap, 0, AclLength);
ASSERT(*Dacl != NULL);
/* Set the correct header fields */
Status = RtlCreateAcl(*Dacl, AclLength, ACL_REVISION2);
ASSERT(NT_SUCCESS(Status));
/* Give the appropriate rights to each SID */
/* FIXME: Should check SessionId/ProtectionMode */
Status = RtlAddAccessAllowedAce(*Dacl, ACL_REVISION2, DIRECTORY_QUERY | DIRECTORY_TRAVERSE | DIRECTORY_CREATE_OBJECT | DIRECTORY_CREATE_SUBDIRECTORY | READ_CONTROL, WorldSid);
ASSERT(NT_SUCCESS(Status));
Status = RtlAddAccessAllowedAce(*Dacl, ACL_REVISION2, DIRECTORY_ALL_ACCESS, SystemSid);
ASSERT(NT_SUCCESS(Status));
Status = RtlAddAccessAllowedAce(*Dacl, ACL_REVISION2, DIRECTORY_TRAVERSE, RestrictedSid);
ASSERT(NT_SUCCESS(Status));
/* Now allocate the restricted DACL */
*RestrictedDacl = RtlAllocateHeap(BaseSrvHeap, 0, AclLength);
ASSERT(*RestrictedDacl != NULL);
//.........这里部分代码省略.........
示例2: Fat12WriteFAT
static NTSTATUS
Fat12WriteFAT(IN HANDLE FileHandle,
IN ULONG SectorOffset,
IN PFAT16_BOOT_SECTOR BootSector,
IN OUT PFORMAT_CONTEXT Context)
{
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
PUCHAR Buffer;
LARGE_INTEGER FileOffset;
ULONG i;
ULONG Size;
ULONG Sectors;
/* Allocate buffer */
Buffer = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(),
0,
32 * 1024);
if (Buffer == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
/* Zero the buffer */
memset(Buffer, 0, 32 * 1024);
/* FAT cluster 0 & 1*/
Buffer[0] = 0xf8; /* Media type */
Buffer[1] = 0xff;
Buffer[2] = 0xff;
/* Write first sector of the FAT */
FileOffset.QuadPart = (SectorOffset + BootSector->ReservedSectors) * BootSector->BytesPerSector;
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatusBlock,
Buffer,
BootSector->BytesPerSector,
&FileOffset,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status;
}
UpdateProgress(Context, 1);
/* Zero the begin of the buffer */
memset(Buffer, 0, 3);
/* Zero the rest of the FAT */
Sectors = 32 * 1024 / BootSector->BytesPerSector;
for (i = 1; i < (ULONG)BootSector->FATSectors; i += Sectors)
{
/* Zero some sectors of the FAT */
FileOffset.QuadPart = (SectorOffset + BootSector->ReservedSectors + i) * BootSector->BytesPerSector;
if (((ULONG)BootSector->FATSectors - i) <= Sectors)
{
Sectors = (ULONG)BootSector->FATSectors - i;
}
Size = Sectors * BootSector->BytesPerSector;
Status = NtWriteFile(FileHandle,
NULL,
NULL,
NULL,
&IoStatusBlock,
Buffer,
Size,
&FileOffset,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status;
}
UpdateProgress(Context, Sectors);
}
/* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
return Status;
}
示例3: GetDisplayIdentifier
//.........这里部分代码省略.........
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
BusInstanceKey,
NULL);
Status = NtOpenKey(&ControllerKey,
KEY_ENUMERATE_SUB_KEYS,
&ObjectAttributes);
if (NT_SUCCESS(Status))
{
ControllerInstance = 0;
while (TRUE)
{
/* Open the pointer controller instance key */
swprintf(Buffer, L"%lu", ControllerInstance);
RtlInitUnicodeString(&KeyName,
Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
ControllerKey,
NULL);
Status = NtOpenKey(&ControllerInstanceKey,
KEY_QUERY_VALUE,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
NtClose(ControllerKey);
NtClose(BusInstanceKey);
NtClose(BusKey);
return FALSE;
}
/* Get controller identifier */
RtlInitUnicodeString(&KeyName,
L"Identifier");
BufferLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
256 * sizeof(WCHAR);
ValueInfo = (KEY_VALUE_PARTIAL_INFORMATION*) RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferLength);
if (ValueInfo == NULL)
{
DPRINT("RtlAllocateHeap() failed\n");
NtClose(ControllerInstanceKey);
NtClose(ControllerKey);
NtClose(BusInstanceKey);
NtClose(BusKey);
return FALSE;
}
Status = NtQueryValueKey(ControllerInstanceKey,
&KeyName,
KeyValuePartialInformation,
ValueInfo,
BufferLength,
&ReturnedLength);
if (NT_SUCCESS(Status))
{
DPRINT("Identifier: %S\n", (PWSTR)ValueInfo->Data);
BufferLength = min(ValueInfo->DataLength / sizeof(WCHAR), IdentifierLength);
RtlCopyMemory (Identifier,
ValueInfo->Data,
BufferLength * sizeof(WCHAR));
Identifier[BufferLength] = 0;
RtlFreeHeap(RtlGetProcessHeap(),
0,
ValueInfo);
NtClose(ControllerInstanceKey);
NtClose(ControllerKey);
NtClose(BusInstanceKey);
NtClose(BusKey);
return TRUE;
}
NtClose(ControllerInstanceKey);
ControllerInstance++;
}
NtClose(ControllerKey);
}
NtClose(BusInstanceKey);
BusInstance++;
}
NtClose(BusKey);
return FALSE;
}
示例4: CreateLanguageList
PGENERIC_LIST
CreateLanguageList(HINF InfFile, WCHAR * DefaultLanguage)
{
CHAR Buffer[128];
PGENERIC_LIST List;
INFCONTEXT Context;
PWCHAR KeyName;
PWCHAR KeyValue;
PWCHAR UserData;
ULONG uIndex = 0;
/* Get default language id */
if (!SetupFindFirstLineW (InfFile, L"NLS", L"DefaultLanguage", &Context))
return NULL;
if (!INF_GetData (&Context, NULL, &KeyValue))
return NULL;
wcscpy(DefaultLanguage, KeyValue);
SelectedLanguageId = KeyValue;
List = CreateGenericList();
if (List == NULL)
return NULL;
if (!SetupFindFirstLineW (InfFile, L"Language", NULL, &Context))
{
DestroyGenericList(List, FALSE);
return NULL;
}
do
{
if (!INF_GetData (&Context, &KeyName, &KeyValue))
{
/* FIXME: Handle error! */
DPRINT("INF_GetData() failed\n");
break;
}
UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap,
0,
(wcslen(KeyName) + 1) * sizeof(WCHAR));
if (UserData == NULL)
{
/* FIXME: Handle error! */
}
wcscpy(UserData, KeyName);
if (!_wcsicmp(KeyName, DefaultLanguage)) DefaultLanguageIndex = uIndex;
sprintf(Buffer, "%S", KeyValue);
AppendGenericListEntry(List,
Buffer,
UserData,
FALSE);
uIndex++;
} while (SetupFindNextLine(&Context, &Context));
return List;
}
示例5: GetStartupInfoA
/*
* @implemented
*/
VOID
WINAPI
GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)
{
PRTL_USER_PROCESS_PARAMETERS Params;
ANSI_STRING AnsiString;
if (lpStartupInfo == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return;
}
Params = NtCurrentPeb ()->ProcessParameters;
RtlAcquirePebLock ();
/* FIXME - not thread-safe */
if (lpLocalStartupInfo == NULL)
{
/* create new local startup info (ansi) */
lpLocalStartupInfo = RtlAllocateHeap(RtlGetProcessHeap(),
0,
sizeof(STARTUPINFOA));
if (lpLocalStartupInfo == NULL)
{
RtlReleasePebLock();
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return;
}
lpLocalStartupInfo->cb = sizeof(STARTUPINFOA);
/* copy window title string */
RtlUnicodeStringToAnsiString(&AnsiString,
&Params->WindowTitle,
TRUE);
lpLocalStartupInfo->lpTitle = AnsiString.Buffer;
/* copy desktop info string */
RtlUnicodeStringToAnsiString(&AnsiString,
&Params->DesktopInfo,
TRUE);
lpLocalStartupInfo->lpDesktop = AnsiString.Buffer;
/* copy shell info string */
RtlUnicodeStringToAnsiString(&AnsiString,
&Params->ShellInfo,
TRUE);
lpLocalStartupInfo->lpReserved = AnsiString.Buffer;
lpLocalStartupInfo->dwX = Params->StartingX;
lpLocalStartupInfo->dwY = Params->StartingY;
lpLocalStartupInfo->dwXSize = Params->CountX;
lpLocalStartupInfo->dwYSize = Params->CountY;
lpLocalStartupInfo->dwXCountChars = Params->CountCharsX;
lpLocalStartupInfo->dwYCountChars = Params->CountCharsY;
lpLocalStartupInfo->dwFillAttribute = Params->FillAttribute;
lpLocalStartupInfo->dwFlags = Params->WindowFlags;
lpLocalStartupInfo->wShowWindow = (WORD)Params->ShowWindowFlags;
lpLocalStartupInfo->cbReserved2 = Params->RuntimeData.Length;
lpLocalStartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
lpLocalStartupInfo->hStdInput = Params->StandardInput;
lpLocalStartupInfo->hStdOutput = Params->StandardOutput;
lpLocalStartupInfo->hStdError = Params->StandardError;
}
RtlReleasePebLock();
/* copy local startup info data to external startup info */
memcpy(lpStartupInfo,
lpLocalStartupInfo,
sizeof(STARTUPINFOA));
}
示例6: GetComputerIdentifier
static BOOLEAN
GetComputerIdentifier(PWSTR Identifier,
ULONG IdentifierLength)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
LPCWSTR ComputerIdentifier;
HANDLE ProcessorsKey;
PKEY_FULL_INFORMATION pFullInfo;
ULONG Size, SizeNeeded;
NTSTATUS Status;
DPRINT("GetComputerIdentifier() called\n");
Size = sizeof(KEY_FULL_INFORMATION);
pFullInfo = (PKEY_FULL_INFORMATION)RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
if (!pFullInfo)
{
DPRINT("RtlAllocateHeap() failed\n");
return FALSE;
}
/* Open the processors key */
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenKey(&ProcessorsKey,
KEY_QUERY_VALUE ,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
DPRINT("NtOpenKey() failed (Status 0x%lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo);
return FALSE;
}
/* Get number of subkeys */
Status = NtQueryKey(
ProcessorsKey,
KeyFullInformation,
pFullInfo,
Size,
&Size);
NtClose(ProcessorsKey);
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
{
DPRINT("NtQueryKey() failed (Status 0x%lx)\n", Status);
RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo);
return FALSE;
}
/* Find computer identifier */
if (pFullInfo->SubKeys == 0)
{
/* Something strange happened. No processor detected */
RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo);
return FALSE;
}
if (IsAcpiComputer())
{
if (pFullInfo->SubKeys == 1)
{
/* Computer is mono-CPU */
ComputerIdentifier = L"ACPI UP";
}
else
{
/* Computer is multi-CPUs */
ComputerIdentifier = L"ACPI MP";
}
}
else
{
if (pFullInfo->SubKeys == 1)
{
/* Computer is mono-CPU */
ComputerIdentifier = L"PC UP";
}
else
{
/* Computer is multi-CPUs */
ComputerIdentifier = L"PC MP";
}
}
RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo);
/* Copy computer identifier to return buffer */
SizeNeeded = (wcslen(ComputerIdentifier) + 1) * sizeof(WCHAR);
if (SizeNeeded > IdentifierLength)
return FALSE;
RtlCopyMemory(Identifier, ComputerIdentifier, SizeNeeded);
//.........这里部分代码省略.........
示例7: DnsQuery_W
DNS_STATUS WINAPI
DnsQuery_W(LPCWSTR Name,
WORD Type,
DWORD Options,
PIP4_ARRAY Servers,
PDNS_RECORD *QueryResultSet,
PVOID *Reserved)
{
UINT i;
PCHAR Buffer;
DNS_STATUS Status;
PDNS_RECORD QueryResultWide;
PDNS_RECORD ConvertedRecord = 0, LastRecord = 0;
Buffer = DnsWToC(Name);
Status = DnsQuery_A(Buffer, Type, Options, Servers, &QueryResultWide, Reserved);
while(Status == ERROR_SUCCESS && QueryResultWide)
{
switch(QueryResultWide->wType)
{
case DNS_TYPE_A:
case DNS_TYPE_WKS:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
ConvertedRecord->pName = (PCHAR)DnsCToW(QueryResultWide->pName);
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = QueryResultWide->wDataLength;
memcpy(ConvertedRecord, QueryResultWide, QueryResultWide->wDataLength);
break;
case DNS_TYPE_CNAME:
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_MB:
case DNS_TYPE_MD:
case DNS_TYPE_MF:
case DNS_TYPE_MG:
case DNS_TYPE_MR:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
ConvertedRecord->pName = (PCHAR)DnsCToW(QueryResultWide->pName);
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = sizeof(DNS_PTR_DATA);
ConvertedRecord->Data.PTR.pNameHost = (PCHAR)DnsCToW(QueryResultWide->Data.PTR.pNameHost);
break;
case DNS_TYPE_MINFO:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
ConvertedRecord->pName = (PCHAR)DnsCToW(QueryResultWide->pName);
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = sizeof(DNS_MINFO_DATA);
ConvertedRecord->Data.MINFO.pNameMailbox = (PCHAR)DnsCToW(QueryResultWide->Data.MINFO.pNameMailbox);
ConvertedRecord->Data.MINFO.pNameErrorsMailbox = (PCHAR)DnsCToW(QueryResultWide->Data.MINFO.pNameErrorsMailbox);
break;
case DNS_TYPE_MX:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
ConvertedRecord->pName = (PCHAR)DnsCToW(QueryResultWide->pName);
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = sizeof(DNS_MX_DATA);
ConvertedRecord->Data.MX.pNameExchange = (PCHAR)DnsCToW( QueryResultWide->Data.MX.pNameExchange);
ConvertedRecord->Data.MX.wPreference = QueryResultWide->Data.MX.wPreference;
break;
case DNS_TYPE_HINFO:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_TXT_DATA) + QueryResultWide->Data.TXT.dwStringCount);
ConvertedRecord->pName = (PCHAR)DnsCToW( QueryResultWide->pName );
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = sizeof(DNS_TXT_DATA) + (sizeof(PWCHAR) * QueryResultWide->Data.TXT.dwStringCount);
ConvertedRecord->Data.TXT.dwStringCount = QueryResultWide->Data.TXT.dwStringCount;
for(i = 0; i < ConvertedRecord->Data.TXT.dwStringCount; i++)
ConvertedRecord->Data.TXT.pStringArray[i] = (PCHAR)DnsCToW(QueryResultWide->Data.TXT.pStringArray[i]);
break;
case DNS_TYPE_NULL:
ConvertedRecord = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_NULL_DATA) + QueryResultWide->Data.Null.dwByteCount);
ConvertedRecord->pName = (PCHAR)DnsCToW(QueryResultWide->pName);
ConvertedRecord->wType = QueryResultWide->wType;
ConvertedRecord->wDataLength = sizeof(DNS_NULL_DATA) + QueryResultWide->Data.Null.dwByteCount;
ConvertedRecord->Data.Null.dwByteCount = QueryResultWide->Data.Null.dwByteCount;
memcpy(&ConvertedRecord->Data.Null.Data, &QueryResultWide->Data.Null.Data, QueryResultWide->Data.Null.dwByteCount);
break;
}
if(LastRecord)
{
LastRecord->pNext = ConvertedRecord;
LastRecord = LastRecord->pNext;
}
else
{
LastRecord = *QueryResultSet = ConvertedRecord;
}
}
if (LastRecord)
LastRecord->pNext = 0;
//.........这里部分代码省略.........
示例8: DnsQuery_A
DNS_STATUS WINAPI
DnsQuery_A(LPCSTR Name,
WORD Type,
DWORD Options,
PIP4_ARRAY Servers,
PDNS_RECORD *QueryResultSet,
PVOID *Reserved)
{
adns_state astate;
int quflags = 0;
int adns_error;
adns_answer *answer;
LPSTR CurrentName;
unsigned i, CNameLoop;
*QueryResultSet = 0;
switch(Type)
{
case DNS_TYPE_A:
adns_error = adns_init(&astate, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn, 0);
if(adns_error != adns_s_ok)
return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
if (Servers)
{
for(i = 0; i < Servers->AddrCount; i++)
{
adns_addserver(astate, *((struct in_addr *)&Servers->AddrArray[i]));
}
}
/*
* adns doesn't resolve chained CNAME records (a CNAME which points to
* another CNAME pointing to another... pointing to an A record), according
* to a mailing list thread the authors believe that chained CNAME records
* are invalid and the DNS entries should be fixed. That's a nice academic
* standpoint, but there certainly are chained CNAME records out there,
* even some fairly major ones (at the time of this writing
* download.mozilla.org is a chained CNAME). Everyone else seems to resolve
* these fine, so we should too. So we loop here to try to resolve CNAME
* chains ourselves. Of course, there must be a limit to protect against
* CNAME loops.
*/
#define CNAME_LOOP_MAX 16
CurrentName = (LPSTR) Name;
for (CNameLoop = 0; CNameLoop < CNAME_LOOP_MAX; CNameLoop++)
{
adns_error = adns_synchronous(astate, CurrentName, adns_r_addr, quflags, &answer);
if(adns_error != adns_s_ok)
{
adns_finish(astate);
if (CurrentName != Name)
RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
}
if(answer && answer->rrs.addr)
{
if (CurrentName != Name)
RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
*QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
if (NULL == *QueryResultSet)
{
adns_finish( astate );
return ERROR_OUTOFMEMORY;
}
(*QueryResultSet)->pNext = NULL;
(*QueryResultSet)->wType = Type;
(*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
(*QueryResultSet)->Data.A.IpAddress = answer->rrs.addr->addr.inet.sin_addr.s_addr;
adns_finish(astate);
(*QueryResultSet)->pName = xstrsave( Name );
return NULL != (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
}
if (NULL == answer || adns_s_prohibitedcname != answer->status || NULL == answer->cname)
{
adns_finish(astate);
if (CurrentName != Name)
RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
return ERROR_FILE_NOT_FOUND;
}
if (CurrentName != Name)
//.........这里部分代码省略.........
示例9: calloc
void *__cdecl
calloc(size_t nmemb, size_t size)
{
return (void *)RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, nmemb * size);
}
示例10: NlInitialize
NTSTATUS
NlInitialize(
VOID
)
/*++
Routine Description:
Initialize NETLOGON portion of msv1_0 authentication package.
Arguments:
None.
Return Status:
STATUS_SUCCESS - Indicates NETLOGON successfully initialized.
--*/
{
NTSTATUS Status;
LPWSTR ComputerName;
DWORD ComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
NT_PRODUCT_TYPE NtProductType;
UNICODE_STRING TempUnicodeString;
//
// Initialize global data
//
NlpEnumerationHandle = 0;
NlpSessionCount = 0;
NlpComputerName.Buffer = NULL;
NlpSamDomainName.Buffer = NULL;
NlpSamDomainId = NULL;
NlpSamDomainHandle = NULL;
//
// Get the name of this machine.
//
ComputerName = RtlAllocateHeap(
MspHeap, 0,
ComputerNameLength * sizeof(WCHAR) );
if (ComputerName == NULL ||
!GetComputerNameW( ComputerName, &ComputerNameLength )) {
KdPrint(( "MsV1_0: Cannot get computername %lX\n", GetLastError() ));
NlpLanmanInstalled = FALSE;
RtlFreeHeap( MspHeap, 0, ComputerName );
ComputerName = NULL;
} else {
NlpLanmanInstalled = TRUE;
}
RtlInitUnicodeString( &NlpComputerName, ComputerName );
//
// Determine if this machine is running Windows NT or Lanman NT.
// LanMan NT runs on a domain controller.
//
if ( !RtlGetNtProductType( &NtProductType ) ) {
KdPrint(( "MsV1_0: Nt Product Type undefined (WinNt assumed)\n" ));
NtProductType = NtProductWinNt;
}
NlpWorkstation = (BOOLEAN)(NtProductType != NtProductLanManNt);
#ifdef notdef
//
// Initialize any locks.
//
RtlInitializeCriticalSection(&NlpActiveLogonLock);
RtlInitializeCriticalSection(&NlpSessionCountLock);
//
// initialize the cache - creates a critical section is all
//
NlpCacheInitialize();
#endif // notdef
//
// Attempt to load Netapi.dll
//
NlpLoadNetapiDll();
//.........这里部分代码省略.........
示例11: malloc
/* Needed by zlib, but we don't want the dependency on msvcrt.dll */
void *__cdecl
malloc(size_t size)
{
return RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, size);
}
示例12: MSZipAlloc
voidpf
MSZipAlloc(voidpf opaque, uInt items, uInt size)
{
return (voidpf)RtlAllocateHeap(ProcessHeap, 0, items * size);
}
示例13: ReadRecord
static NTSTATUS
ReadRecord(IN PEVTLOGFILE LogFile,
IN ULONG RecordNumber,
OUT PEVENTLOGRECORD Record,
IN SIZE_T BufSize, // Length
OUT PSIZE_T BytesRead OPTIONAL,
OUT PSIZE_T BytesNeeded OPTIONAL,
IN BOOLEAN Ansi)
{
NTSTATUS Status;
PEVENTLOGRECORD UnicodeBuffer = NULL;
PEVENTLOGRECORD Src, Dst;
ANSI_STRING StringA;
UNICODE_STRING StringW;
PVOID SrcPtr, DstPtr;
DWORD i;
DWORD dwPadding;
DWORD dwRecordLength;
PDWORD pLength;
if (!Ansi)
{
return ElfReadRecord(LogFile,
RecordNumber,
Record,
BufSize,
BytesRead,
BytesNeeded);
}
if (BytesRead)
*BytesRead = 0;
if (BytesNeeded)
*BytesNeeded = 0;
UnicodeBuffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, BufSize);
if (UnicodeBuffer == NULL)
{
DPRINT1("Alloc failed!\n");
return STATUS_NO_MEMORY;
}
Status = ElfReadRecord(LogFile,
RecordNumber,
UnicodeBuffer,
BufSize,
BytesRead,
BytesNeeded);
if (!NT_SUCCESS(Status))
goto Quit;
Src = UnicodeBuffer;
Dst = Record;
Dst->Reserved = Src->Reserved;
Dst->RecordNumber = Src->RecordNumber;
Dst->TimeGenerated = Src->TimeGenerated;
Dst->TimeWritten = Src->TimeWritten;
Dst->EventID = Src->EventID;
Dst->EventType = Src->EventType;
Dst->EventCategory = Src->EventCategory;
Dst->NumStrings = Src->NumStrings;
Dst->UserSidLength = Src->UserSidLength;
Dst->DataLength = Src->DataLength;
SrcPtr = (PVOID)((ULONG_PTR)Src + sizeof(EVENTLOGRECORD));
DstPtr = (PVOID)((ULONG_PTR)Dst + sizeof(EVENTLOGRECORD));
/* Convert the module name */
RtlInitUnicodeString(&StringW, SrcPtr);
Status = RtlUnicodeStringToAnsiString(&StringA, &StringW, TRUE);
if (NT_SUCCESS(Status))
{
RtlCopyMemory(DstPtr, StringA.Buffer, StringA.MaximumLength);
DstPtr = (PVOID)((ULONG_PTR)DstPtr + StringA.MaximumLength);
RtlFreeAnsiString(&StringA);
}
else
{
RtlZeroMemory(DstPtr, StringW.MaximumLength / sizeof(WCHAR));
DstPtr = (PVOID)((ULONG_PTR)DstPtr + StringW.MaximumLength / sizeof(WCHAR));
}
SrcPtr = (PVOID)((ULONG_PTR)SrcPtr + StringW.MaximumLength);
/* Convert the computer name */
RtlInitUnicodeString(&StringW, SrcPtr);
Status = RtlUnicodeStringToAnsiString(&StringA, &StringW, TRUE);
if (NT_SUCCESS(Status))
{
RtlCopyMemory(DstPtr, StringA.Buffer, StringA.MaximumLength);
DstPtr = (PVOID)((ULONG_PTR)DstPtr + StringA.MaximumLength);
RtlFreeAnsiString(&StringA);
}
else
{
RtlZeroMemory(DstPtr, StringW.MaximumLength / sizeof(WCHAR));
DstPtr = (PVOID)((ULONG_PTR)DstPtr + StringW.MaximumLength / sizeof(WCHAR));
//.........这里部分代码省略.........
示例14: SetCtrlHandler
BOOL
SetCtrlHandler(
IN PHANDLER_ROUTINE HandlerRoutine
)
/*++
Routine Description:
This routine adds a ctrl handler to the process's list.
Arguments:
HandlerRoutine - pointer to ctrl handler.
Return Value:
TRUE - success.
--*/
{
PHANDLER_ROUTINE *NewHandlerList;
//
// NULL handler routine is not stored in table. It is
// used to temporarily inhibit ^C event handling
//
if ( !HandlerRoutine ) {
NtCurrentPeb()->ProcessParameters->ConsoleFlags = IGNORE_CTRL_C;
return TRUE;
}
if (HandlerListLength == AllocatedHandlerListLength) {
//
// grow list
//
NewHandlerList = (PHANDLER_ROUTINE *) RtlAllocateHeap( RtlProcessHeap(), 0,
sizeof(PHANDLER_ROUTINE) * (HandlerListLength + LIST_INCREMENT));
if (!NewHandlerList) {
SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
//
// copy list
//
RtlCopyMemory(NewHandlerList,HandlerList,sizeof(PHANDLER_ROUTINE) * HandlerListLength);
if (HandlerList != SingleHandler) {
//
// free old list
//
RtlFreeHeap(RtlProcessHeap(), 0, HandlerList);
}
HandlerList = NewHandlerList;
AllocatedHandlerListLength += LIST_INCREMENT;
}
ASSERT (HandlerListLength < AllocatedHandlerListLength);
HandlerList[HandlerListLength] = HandlerRoutine;
HandlerListLength++;
return TRUE;
}
示例15: LogfAllocAndBuildNewRecord
PEVENTLOGRECORD
LogfAllocAndBuildNewRecord(PSIZE_T pRecSize,
ULONG Time,
USHORT wType,
USHORT wCategory,
ULONG dwEventId,
PUNICODE_STRING SourceName,
PUNICODE_STRING ComputerName,
ULONG dwSidLength,
PSID pUserSid,
USHORT wNumStrings,
PWSTR pStrings,
ULONG dwDataSize,
PVOID pRawData)
{
SIZE_T RecSize;
SIZE_T SourceNameSize, ComputerNameSize, StringLen;
PBYTE Buffer;
PEVENTLOGRECORD pRec;
PWSTR str;
UINT i, pos;
SourceNameSize = (SourceName && SourceName->Buffer) ? SourceName->Length : 0;
ComputerNameSize = (ComputerName && ComputerName->Buffer) ? ComputerName->Length : 0;
RecSize = sizeof(EVENTLOGRECORD) + /* Add the sizes of the strings, NULL-terminated */
SourceNameSize + ComputerNameSize + 2*sizeof(UNICODE_NULL);
/* Align on DWORD boundary for the SID */
RecSize = ROUND_UP(RecSize, sizeof(ULONG));
RecSize += dwSidLength;
/* Add the sizes for the strings array */
ASSERT((pStrings == NULL && wNumStrings == 0) ||
(pStrings != NULL && wNumStrings >= 0));
for (i = 0, str = pStrings; i < wNumStrings; i++)
{
StringLen = wcslen(str) + 1; // str must be != NULL
RecSize += StringLen * sizeof(WCHAR);
str += StringLen;
}
/* Add the data size */
RecSize += dwDataSize;
/* Align on DWORD boundary for the full structure */
RecSize = ROUND_UP(RecSize, sizeof(ULONG));
/* Size of the trailing 'Length' member */
RecSize += sizeof(ULONG);
Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RecSize);
if (!Buffer)
{
DPRINT1("Cannot allocate heap!\n");
return NULL;
}
pRec = (PEVENTLOGRECORD)Buffer;
pRec->Length = RecSize;
pRec->Reserved = LOGFILE_SIGNATURE;
/*
* Do not assign here any precomputed record number to the event record.
* The true record number will be assigned atomically and sequentially in
* LogfWriteRecord, so that all the event records will have consistent and
* unique record numbers.
*/
pRec->RecordNumber = 0;
/*
* Set the generated time, and temporarily set the written time
* with the generated time.
*/
pRec->TimeGenerated = Time;
pRec->TimeWritten = Time;
pRec->EventID = dwEventId;
pRec->EventType = wType;
pRec->EventCategory = wCategory;
pos = sizeof(EVENTLOGRECORD);
/* NOTE: Equivalents of RtlStringCbCopyUnicodeString calls */
if (SourceNameSize)
{
StringCbCopyNW((PWSTR)(Buffer + pos), SourceNameSize + sizeof(UNICODE_NULL),
SourceName->Buffer, SourceNameSize);
}
pos += SourceNameSize + sizeof(UNICODE_NULL);
if (ComputerNameSize)
{
StringCbCopyNW((PWSTR)(Buffer + pos), ComputerNameSize + sizeof(UNICODE_NULL),
ComputerName->Buffer, ComputerNameSize);
}
pos += ComputerNameSize + sizeof(UNICODE_NULL);
/* Align on DWORD boundary for the SID */
pos = ROUND_UP(pos, sizeof(ULONG));
//.........这里部分代码省略.........