本文整理汇总了C++中PhAllocate函数的典型用法代码示例。如果您正苦于以下问题:C++ PhAllocate函数的具体用法?C++ PhAllocate怎么用?C++ PhAllocate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PhAllocate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PhGetDrawInfoGraphBuffers
/**
* Sets up a graphing information structure with information
* from a graph buffer management structure.
*
* \param Buffers The buffer management structure.
* \param DrawInfo The graphing information structure.
* \param DataCount The number of data points currently required.
* The buffers are resized if needed.
*/
VOID PhGetDrawInfoGraphBuffers(
__inout PPH_GRAPH_BUFFERS Buffers,
__inout PPH_GRAPH_DRAW_INFO DrawInfo,
__in ULONG DataCount
)
{
DrawInfo->LineDataCount = min(DataCount, PH_GRAPH_DATA_COUNT(DrawInfo->Width, DrawInfo->Step));
// Do we need to allocate or re-allocate the data buffers?
if (Buffers->AllocatedCount < DrawInfo->LineDataCount)
{
if (Buffers->Data1)
PhFree(Buffers->Data1);
if ((DrawInfo->Flags & PH_GRAPH_USE_LINE_2) && Buffers->Data2)
PhFree(Buffers->Data2);
Buffers->AllocatedCount *= 2;
if (Buffers->AllocatedCount < DrawInfo->LineDataCount)
Buffers->AllocatedCount = DrawInfo->LineDataCount;
Buffers->Data1 = PhAllocate(Buffers->AllocatedCount * sizeof(FLOAT));
if (DrawInfo->Flags & PH_GRAPH_USE_LINE_2)
{
Buffers->Data2 = PhAllocate(Buffers->AllocatedCount * sizeof(FLOAT));
}
Buffers->Valid = FALSE;
}
DrawInfo->LineData1 = Buffers->Data1;
DrawInfo->LineData2 = Buffers->Data2;
}
示例2: PhpGetObjectName
NTSTATUS PhpGetObjectName(
__in HANDLE ProcessHandle,
__in HANDLE Handle,
__out PPH_STRING *ObjectName
)
{
NTSTATUS status;
POBJECT_NAME_INFORMATION buffer;
ULONG bufferSize;
ULONG attempts = 8;
bufferSize = 0x200;
buffer = PhAllocate(bufferSize);
// A loop is needed because the I/O subsystem likes to give us the wrong return lengths...
do
{
if (KphIsConnected())
{
status = KphQueryInformationObject(
ProcessHandle,
Handle,
KphObjectNameInformation,
buffer,
bufferSize,
&bufferSize
);
}
else
{
status = NtQueryObject(
Handle,
ObjectNameInformation,
buffer,
bufferSize,
&bufferSize
);
}
if (status == STATUS_BUFFER_OVERFLOW || status == STATUS_INFO_LENGTH_MISMATCH ||
status == STATUS_BUFFER_TOO_SMALL)
{
PhFree(buffer);
buffer = PhAllocate(bufferSize);
}
else
{
break;
}
} while (--attempts);
if (NT_SUCCESS(status))
{
*ObjectName = PhCreateStringEx(buffer->Name.Buffer, buffer->Name.Length);
}
PhFree(buffer);
return status;
}
示例3: AddNetworkAdapterToListView
VOID AddNetworkAdapterToListView(
_In_ PDV_NETADAPTER_CONTEXT Context,
_In_ BOOLEAN AdapterPresent,
_In_ IF_INDEX IfIndex,
_In_ IF_LUID Luid,
_In_ PPH_STRING Guid,
_In_ PPH_STRING Description
)
{
DV_NETADAPTER_ID adapterId;
INT lvItemIndex;
BOOLEAN found = FALSE;
PDV_NETADAPTER_ID newId = NULL;
InitializeNetAdapterId(&adapterId, IfIndex, Luid, Guid);
for (ULONG i = 0; i < NetworkAdaptersList->Count; i++)
{
PDV_NETADAPTER_ENTRY entry = PhReferenceObjectSafe(NetworkAdaptersList->Items[i]);
if (!entry)
continue;
if (EquivalentNetAdapterId(&entry->AdapterId, &adapterId))
{
newId = PhAllocate(sizeof(DV_NETADAPTER_ID));
CopyNetAdapterId(newId, &entry->AdapterId);
if (entry->UserReference)
found = TRUE;
}
PhDereferenceObjectDeferDelete(entry);
if (newId)
break;
}
if (!newId)
{
newId = PhAllocate(sizeof(DV_NETADAPTER_ID));
CopyNetAdapterId(newId, &adapterId);
PhMoveReference(&newId->InterfaceGuid, Guid);
}
lvItemIndex = PhAddListViewGroupItem(
Context->ListViewHandle,
AdapterPresent ? 0 : 1,
MAXINT,
Description->Buffer,
newId
);
if (found)
ListView_SetCheckState(Context->ListViewHandle, lvItemIndex, TRUE);
DeleteNetAdapterId(&adapterId);
}
示例4: AddDiskDriveToListView
VOID AddDiskDriveToListView(
_In_ PDV_DISK_OPTIONS_CONTEXT Context,
_In_ BOOLEAN DiskPresent,
_In_ PPH_STRING DiskPath,
_In_ PPH_STRING DiskName
)
{
DV_DISK_ID adapterId;
INT lvItemIndex;
BOOLEAN found = FALSE;
PDV_DISK_ID newId = NULL;
InitializeDiskId(&adapterId, DiskPath);
for (ULONG i = 0; i < DiskDrivesList->Count; i++)
{
PDV_DISK_ENTRY entry = PhReferenceObjectSafe(DiskDrivesList->Items[i]);
if (!entry)
continue;
if (EquivalentDiskId(&entry->Id, &adapterId))
{
newId = PhAllocate(sizeof(DV_DISK_ID));
CopyDiskId(newId, &entry->Id);
if (entry->UserReference)
found = TRUE;
}
PhDereferenceObjectDeferDelete(entry);
if (newId)
break;
}
if (!newId)
{
newId = PhAllocate(sizeof(DV_DISK_ID));
CopyDiskId(newId, &adapterId);
PhMoveReference(&newId->DevicePath, DiskPath);
}
lvItemIndex = AddListViewItemGroupId(
Context->ListViewHandle,
DiskPresent ? 0 : 1,
MAXINT,
DiskName->Buffer,
newId
);
if (found)
ListView_SetItemState(Context->ListViewHandle, lvItemIndex, ITEM_CHECKED, LVIS_STATEIMAGEMASK);
DeleteDiskId(&adapterId);
}
示例5: EsEnumDependentServices
LPENUM_SERVICE_STATUS EsEnumDependentServices(
__in SC_HANDLE ServiceHandle,
__in_opt ULONG State,
__out PULONG Count
)
{
LOGICAL result;
PVOID buffer;
ULONG bufferSize;
ULONG returnLength;
ULONG servicesReturned;
if (!State)
State = SERVICE_STATE_ALL;
bufferSize = 0x800;
buffer = PhAllocate(bufferSize);
if (!(result = EnumDependentServices(
ServiceHandle,
State,
buffer,
bufferSize,
&returnLength,
&servicesReturned
)))
{
if (GetLastError() == ERROR_MORE_DATA)
{
PhFree(buffer);
bufferSize = returnLength;
buffer = PhAllocate(bufferSize);
result = EnumDependentServices(
ServiceHandle,
State,
buffer,
bufferSize,
&returnLength,
&servicesReturned
);
}
if (!result)
{
PhFree(buffer);
return NULL;
}
}
*Count = servicesReturned;
return buffer;
}
示例6: AddNetworkAdapterToListView
static VOID AddNetworkAdapterToListView(
_In_ PDV_NETADAPTER_CONTEXT Context,
_In_ PIP_ADAPTER_ADDRESSES Adapter
)
{
DV_NETADAPTER_ID adapterId;
INT lvItemIndex;
BOOLEAN found = FALSE;
PDV_NETADAPTER_ID newId = NULL;
InitializeNetAdapterId(&adapterId, Adapter->IfIndex, Adapter->Luid, NULL);
for (ULONG i = 0; i < NetworkAdaptersList->Count; i++)
{
PDV_NETADAPTER_ENTRY entry = PhReferenceObjectSafe(NetworkAdaptersList->Items[i]);
if (!entry)
continue;
if (EquivalentNetAdapterId(&entry->Id, &adapterId))
{
newId = PhAllocate(sizeof(DV_NETADAPTER_ID));
CopyNetAdapterId(newId, &entry->Id);
found = TRUE;
}
PhDereferenceObjectDeferDelete(entry);
if (newId)
break;
}
if (!newId)
{
newId = PhAllocate(sizeof(DV_NETADAPTER_ID));
CopyNetAdapterId(newId, &adapterId);
PhMoveReference(&newId->InterfaceGuid, PhConvertMultiByteToUtf16(Adapter->AdapterName));
}
lvItemIndex = PhAddListViewItem(
Context->ListViewHandle,
MAXINT,
Adapter->Description,
newId
);
if (found)
ListView_SetItemState(Context->ListViewHandle, lvItemIndex, ITEM_CHECKED, LVIS_STATEIMAGEMASK);
DeleteNetAdapterId(&adapterId);
}
示例7: PhMapDisplayIndexTreeNew
VOID PhMapDisplayIndexTreeNew(
__in HWND TreeNewHandle,
__out_opt PULONG *DisplayToId,
__out_opt PWSTR **DisplayToText,
__out PULONG NumberOfColumns
)
{
PPH_TREENEW_COLUMN fixedColumn;
ULONG numberOfColumns;
PULONG displayToId;
PWSTR *displayToText;
ULONG i;
PH_TREENEW_COLUMN column;
fixedColumn = TreeNew_GetFixedColumn(TreeNewHandle);
numberOfColumns = TreeNew_GetVisibleColumnCount(TreeNewHandle);
displayToId = PhAllocate(numberOfColumns * sizeof(ULONG));
if (fixedColumn)
{
TreeNew_GetColumnOrderArray(TreeNewHandle, numberOfColumns - 1, displayToId + 1);
displayToId[0] = fixedColumn->Id;
}
else
{
TreeNew_GetColumnOrderArray(TreeNewHandle, numberOfColumns, displayToId);
}
if (DisplayToText)
{
displayToText = PhAllocate(numberOfColumns * sizeof(PWSTR));
for (i = 0; i < numberOfColumns; i++)
{
if (TreeNew_GetColumn(TreeNewHandle, displayToId[i], &column))
{
displayToText[i] = column.Text;
}
}
*DisplayToText = displayToText;
}
if (DisplayToId)
*DisplayToId = displayToId;
else
PhFree(displayToId);
*NumberOfColumns = numberOfColumns;
}
示例8: PhpGetObjectSecurityWithTimeout
NTSTATUS PhpGetObjectSecurityWithTimeout(
_In_ HANDLE Handle,
_In_ SECURITY_INFORMATION SecurityInformation,
_Out_ PSECURITY_DESCRIPTOR *SecurityDescriptor
)
{
NTSTATUS status;
ULONG bufferSize;
PVOID buffer;
bufferSize = 0x100;
buffer = PhAllocate(bufferSize);
// This is required (especially for File objects) because some drivers don't seem to handle
// QuerySecurity properly.
memset(buffer, 0, bufferSize);
status = PhCallNtQuerySecurityObjectWithTimeout(
Handle,
SecurityInformation,
buffer,
bufferSize,
&bufferSize
);
if (status == STATUS_BUFFER_TOO_SMALL)
{
PhFree(buffer);
buffer = PhAllocate(bufferSize);
memset(buffer, 0, bufferSize);
status = PhCallNtQuerySecurityObjectWithTimeout(
Handle,
SecurityInformation,
buffer,
bufferSize,
&bufferSize
);
}
if (!NT_SUCCESS(status))
{
PhFree(buffer);
return status;
}
*SecurityDescriptor = (PSECURITY_DESCRIPTOR)buffer;
return status;
}
示例9: NtClose
ICLRDataTarget *DnCLRDataTarget_Create(
__in HANDLE ProcessId
)
{
DnCLRDataTarget *dataTarget;
HANDLE processHandle;
BOOLEAN isWow64;
if (!NT_SUCCESS(PhOpenProcess(&processHandle, ProcessQueryAccess | PROCESS_VM_READ, ProcessId)))
return NULL;
#ifdef _M_X64
if (!NT_SUCCESS(PhGetProcessIsWow64(processHandle, &isWow64)))
{
NtClose(processHandle);
return NULL;
}
#else
isWow64 = FALSE;
#endif
dataTarget = PhAllocate(sizeof(DnCLRDataTarget));
dataTarget->VTable = &DnCLRDataTarget_VTable;
dataTarget->RefCount = 1;
dataTarget->ProcessId = ProcessId;
dataTarget->ProcessHandle = processHandle;
dataTarget->IsWow64 = isWow64;
return (ICLRDataTarget *)dataTarget;
}
示例10: CreateClrProcessSupport
PCLR_PROCESS_SUPPORT CreateClrProcessSupport(
__in HANDLE ProcessId
)
{
PCLR_PROCESS_SUPPORT support;
ICLRDataTarget *dataTarget;
IXCLRDataProcess *dataProcess;
dataTarget = DnCLRDataTarget_Create(ProcessId);
if (!dataTarget)
return NULL;
dataProcess = NULL;
CreateXCLRDataProcess(ProcessId, dataTarget, &dataProcess);
ICLRDataTarget_Release(dataTarget);
if (!dataProcess)
return NULL;
support = PhAllocate(sizeof(CLR_PROCESS_SUPPORT));
support->DataProcess = dataProcess;
return support;
}
示例11: PhpReadSignature
PUCHAR PhpReadSignature(
_In_ PWSTR FileName,
_Out_ PULONG SignatureSize
)
{
NTSTATUS status;
HANDLE fileHandle;
PUCHAR signature;
ULONG bufferSize;
IO_STATUS_BLOCK iosb;
if (!NT_SUCCESS(PhCreateFileWin32(&fileHandle, FileName, FILE_GENERIC_READ, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT)))
{
return NULL;
}
bufferSize = 1024;
signature = PhAllocate(bufferSize);
status = NtReadFile(fileHandle, NULL, NULL, NULL, &iosb, signature, bufferSize, NULL, NULL);
NtClose(fileHandle);
if (NT_SUCCESS(status))
{
*SignatureSize = (ULONG)iosb.Information;
return signature;
}
else
{
PhFree(signature);
return NULL;
}
}
示例12: PhpCreateDisabledPlugin
PPH_PLUGIN PhpCreateDisabledPlugin(
_In_ PPH_STRINGREF BaseName
)
{
PPH_PLUGIN plugin;
plugin = PhAllocate(sizeof(PH_PLUGIN));
memset(plugin, 0, sizeof(PH_PLUGIN));
plugin->Name.Length = BaseName->Length;
plugin->Name.Buffer = PhAllocate(BaseName->Length + sizeof(WCHAR));
memcpy(plugin->Name.Buffer, BaseName->Buffer, BaseName->Length);
plugin->Name.Buffer[BaseName->Length / 2] = 0;
return plugin;
}
示例13: DiskDriveQueryMountPointHandles
PPH_LIST DiskDriveQueryMountPointHandles(
_In_ ULONG DeviceNumber
)
{
ULONG driveMask;
PPH_LIST deviceList;
WCHAR deviceNameBuffer[7] = L"\\\\.\\?:";
driveMask = DiskDriveQueryDeviceMap();
deviceList = PhCreateList(2);
// NOTE: This isn't the best way of doing this but it works.
for (INT i = 0; i < 0x1A; i++)
{
if (driveMask & (0x1 << i))
{
HANDLE deviceHandle;
deviceNameBuffer[4] = (WCHAR)('A' + i);
if (NT_SUCCESS(PhCreateFileWin32(
&deviceHandle,
deviceNameBuffer,
PhGetOwnTokenAttributes().Elevated ? FILE_GENERIC_READ : FILE_READ_ATTRIBUTES | FILE_TRAVERSE | SYNCHRONIZE,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
)))
{
ULONG deviceNumber = ULONG_MAX; // Note: Do not initialize to zero.
DEVICE_TYPE deviceType = 0;
if (NT_SUCCESS(DiskDriveQueryDeviceTypeAndNumber(
deviceHandle,
&deviceNumber,
&deviceType
)))
{
// BUG: Device numbers are re-used on seperate device controllers and this
// causes drive letters to be assigned to disks at those same indexes.
// For now, just filter CD_ROM devices but we may need to be a lot more strict and
// only allow devices of type FILE_DEVICE_DISK to be scanned for mount points.
if (deviceNumber == DeviceNumber && deviceType != FILE_DEVICE_CD_ROM)
{
PDISK_HANDLE_ENTRY entry = PhAllocate(sizeof(DISK_HANDLE_ENTRY));
memset(entry, 0, sizeof(DISK_HANDLE_ENTRY));
entry->DeviceLetter = deviceNameBuffer[4];
entry->DeviceHandle = deviceHandle;
PhAddItemList(deviceList, entry);
}
}
}
}
}
return deviceList;
}
示例14: PhCreateServiceListControl
/**
* Creates a service list property page.
*
* \param ParentWindowHandle The parent of the service list.
* \param Services An array of service items. Each
* service item must have a reference that is transferred
* to this function. The array must be allocated using
* PhAllocate() and must not be freed by the caller; it
* will be freed automatically when no longer needed.
* \param NumberOfServices The number of service items
* in \a Services.
*/
HWND PhCreateServiceListControl(
_In_ HWND ParentWindowHandle,
_In_ PPH_SERVICE_ITEM *Services,
_In_ ULONG NumberOfServices
)
{
HWND windowHandle;
PPH_SERVICES_CONTEXT servicesContext;
servicesContext = PhAllocate(sizeof(PH_SERVICES_CONTEXT));
memset(servicesContext, 0, sizeof(PH_SERVICES_CONTEXT));
servicesContext->Services = Services;
servicesContext->NumberOfServices = NumberOfServices;
windowHandle = CreateDialogParam(
PhInstanceHandle,
MAKEINTRESOURCE(IDD_SRVLIST),
ParentWindowHandle,
PhpServicesPageProc,
(LPARAM)servicesContext
);
if (!windowHandle)
{
PhFree(servicesContext);
return windowHandle;
}
return windowHandle;
}
示例15: ExtractResourceToBuffer
PVOID ExtractResourceToBuffer(
_In_ PWSTR Resource
)
{
ULONG resourceLength;
HRSRC resourceHandle = NULL;
HGLOBAL resourceData;
PVOID resourceBuffer;
PVOID buffer = NULL;
if (!(resourceHandle = FindResource(PhInstanceHandle, Resource, RT_RCDATA)))
goto CleanupExit;
resourceLength = SizeofResource(PhInstanceHandle, resourceHandle);
if (!(resourceData = LoadResource(PhInstanceHandle, resourceHandle)))
goto CleanupExit;
if (!(resourceBuffer = LockResource(resourceData)))
goto CleanupExit;
if (!(buffer = PhAllocate(resourceLength)))
goto CleanupExit;
memcpy(buffer, resourceBuffer, resourceLength);
CleanupExit:
if (resourceHandle)
FreeResource(resourceHandle);
return buffer;
}