Update phlib typedefs

This commit is contained in:
dmex
2023-06-29 17:01:30 +10:00
parent 16568d69d4
commit ff694e97f6
14 changed files with 297 additions and 215 deletions
+5 -3
View File
@@ -364,14 +364,16 @@ BOOLEAN PhpStartPhSvcProcess(
&applicationFileName->sr
);
if (fileFullPath = PhGetFullPath(fileName->Buffer, NULL))
if (NT_SUCCESS(PhGetFullPath(PhGetString(fileName), &fileFullPath, NULL)))
{
PhMoveReference(&fileName, fileFullPath);
}
if (PhDoesFileExistWin32(fileName->Buffer))
if (PhDoesFileExistWin32(PhGetString(fileName)))
{
if (PhShellProcessHackerEx(
hWnd,
fileName->Buffer,
PhGetString(fileName),
L"-phsvc",
SW_HIDE,
PH_SHELL_EXECUTE_DEFAULT,
+1 -1
View File
@@ -1026,7 +1026,7 @@ VOID PhpInitializeSettings(
//if (PhStartupParameters.SettingsFileName)
//{
// // Get an absolute path now.
// PhSettingsFileName = PhGetFullPath(PhStartupParameters.SettingsFileName->Buffer, NULL);
// PhGetFullPath(PhStartupParameters.SettingsFileName->Buffer, &PhSettingsFileName, NULL);
//}
// 2. File in program directory
+14 -27
View File
@@ -61,12 +61,7 @@
#include <phintrin.h>
#include <circbuf.h>
#define PH_VECTOR_LEVEL_NONE 0
#define PH_VECTOR_LEVEL_SSE2 1
#define PH_VECTOR_LEVEL_AVX 2
#define PH_NATIVE_STRING_CONVERSION 1
#define PH_NATIVE_THREAD_CREATE 1
typedef struct _PHP_BASE_THREAD_CONTEXT
{
@@ -240,6 +235,19 @@ NTSTATUS PhCreateUserThread(
)
{
#if (PH_NATIVE_THREAD_CREATE)
return RtlCreateUserThread(
ProcessHandle,
ThreadSecurityDescriptor,
BooleanFlagOn(CreateFlags, THREAD_CREATE_FLAGS_CREATE_SUSPENDED),
(ULONG)ZeroBits,
MaximumStackSize,
StackSize,
StartRoutine,
Argument,
ThreadHandle,
ClientId
);
#else
NTSTATUS status;
HANDLE threadHandle;
OBJECT_ATTRIBUTES objectAttributes;
@@ -247,15 +255,7 @@ NTSTATUS PhCreateUserThread(
PPS_ATTRIBUTE_LIST attributeList = (PPS_ATTRIBUTE_LIST)buffer;
CLIENT_ID clientId = { 0 };
InitializeObjectAttributes(
&objectAttributes,
NULL,
0,
NULL,
NULL
);
objectAttributes.SecurityDescriptor = ThreadSecurityDescriptor;
InitializeObjectAttributes(&objectAttributes, NULL, 0, NULL, NULL);
attributeList->TotalLength = sizeof(buffer);
attributeList->Attributes[0].Attribute = PS_ATTRIBUTE_CLIENT_ID;
attributeList->Attributes[0].Size = sizeof(CLIENT_ID);
@@ -294,19 +294,6 @@ NTSTATUS PhCreateUserThread(
}
return status;
#else
return RtlCreateUserThread(
ProcessHandle,
ThreadSecurityDescriptor,
BooleanFlagOn(CreateFlags, THREAD_CREATE_FLAGS_CREATE_SUSPENDED),
(ULONG)ZeroBits,
MaximumStackSize,
StackSize,
StartRoutine,
Argument,
ThreadHandle,
ClientId
);
#endif
}
+20 -7
View File
@@ -2985,8 +2985,21 @@ BOOLEAN PhGetSystemResourcesFileName(
return FALSE;
}
// rev from PrivateExtractIconExW with changes
// for using SEC_COMMIT instead of SEC_IMAGE. (dmex)
/**
* \brief Extracts icons from the specified executable file.
*
* \param FileName A string containing a file name.
* \param NativeFileName The type of name format.
* \param IconIndex The zero-based index of the icon within the group or a negative number for a specific resource identifier.
* \param IconLarge A handle to the large icon within the group or handle to the an icon from the resource identifier.
* \param IconSmall A handle to the small icon within the group or handle to the an icon from the resource identifier.
* \param WindowDpi The DPI to use for scaling the metric.
*
* \return Successful or errant status.
*
* \remarks Use this function instead of PrivateExtractIconExW() because images are mapped with SEC_COMMIT and READONLY
* while PrivateExtractIconExW loads images with EXECUTE and SEC_IMAGE (section allocations and relocation processing).
*/
_Success_(return)
BOOLEAN PhExtractIconEx(
_In_ PPH_STRINGREF FileName,
@@ -2994,7 +3007,7 @@ BOOLEAN PhExtractIconEx(
_In_ INT32 IconIndex,
_Out_opt_ HICON *IconLarge,
_Out_opt_ HICON *IconSmall,
_In_ LONG SystemDpi
_In_ LONG WindowDpi
)
{
NTSTATUS status;
@@ -3089,8 +3102,8 @@ BOOLEAN PhExtractIconEx(
&mappedImage,
resourceDirectory,
iconDirectoryResource,
PhGetSystemMetrics(SM_CXICON, SystemDpi),
PhGetSystemMetrics(SM_CYICON, SystemDpi),
PhGetSystemMetrics(SM_CXICON, WindowDpi),
PhGetSystemMetrics(SM_CYICON, WindowDpi),
LR_DEFAULTCOLOR
);
}
@@ -3101,8 +3114,8 @@ BOOLEAN PhExtractIconEx(
&mappedImage,
resourceDirectory,
iconDirectoryResource,
PhGetSystemMetrics(SM_CXSMICON, SystemDpi),
PhGetSystemMetrics(SM_CYSMICON, SystemDpi),
PhGetSystemMetrics(SM_CXSMICON, WindowDpi),
PhGetSystemMetrics(SM_CYSMICON, WindowDpi),
LR_DEFAULTCOLOR
);
}
+4 -2
View File
@@ -189,14 +189,16 @@ typedef LONG (WINAPI* _DnsQuery_W)(
_Outptr_opt_result_maybenull_ PVOID* Reserved
);
typedef struct _DNS_MESSAGE_BUFFER* PDNS_MESSAGE_BUFFER;
typedef LONG (WINAPI* _DnsExtractRecordsFromMessage_W)(
_In_ struct _DNS_MESSAGE_BUFFER* DnsBuffer,
_In_ PDNS_MESSAGE_BUFFER DnsBuffer,
_In_ USHORT MessageLength,
_Out_ PVOID* DnsRecordList
);
typedef BOOL (WINAPI* _DnsWriteQuestionToBuffer_W)(
_Inout_ struct _DNS_MESSAGE_BUFFER* DnsBuffer,
_Inout_ PDNS_MESSAGE_BUFFER DnsBuffer,
_Inout_ PULONG BufferSize,
_In_ PWSTR Name,
_In_ USHORT Type,
+20
View File
@@ -73,6 +73,13 @@ PhGetJsonValueAsUInt64(
_In_ PSTR Key
);
PHLIBAPI
ULONG
NTAPI
PhGetJsonUInt32Object(
_In_ PVOID Object
);
PHLIBAPI
PVOID
NTAPI
@@ -223,6 +230,19 @@ PhGetJsonArrayIndexObject(
_In_ ULONG Index
);
typedef BOOLEAN (NTAPI* PPH_ENUM_JSON_OBJECT_CALLBACK)(
_In_ PVOID Object,
_In_ PSTR Key,
_In_ PVOID Value,
_In_opt_ PVOID Context
);
VOID PhEnumJsonArrayObject(
_In_ PVOID Object,
_In_ PPH_ENUM_JSON_OBJECT_CALLBACK Callback,
_In_opt_ PVOID Context
);
PHLIBAPI
PVOID
NTAPI
+8 -4
View File
@@ -19,7 +19,7 @@ EXTERN_C_START
#define SYSTEM_IDLE_PROCESS_ID ((HANDLE)0)
/** The PID of the system process. */
#define SYSTEM_PROCESS_ID ((HANDLE)4)
/** The name of the system idle process. */
#define SYSTEM_IDLE_PROCESS_NAME ((UNICODE_STRING)RTL_CONSTANT_STRING(L"System Idle Process"))
#define PhNtPathSeperatorString ((PH_STRINGREF)PH_STRINGREF_INIT(L"\\")) // OBJ_NAME_PATH_SEPARATOR // RtlNtPathSeperatorString
@@ -1568,10 +1568,12 @@ PhEnumProcessesEx(
_In_ SYSTEM_INFORMATION_CLASS SystemInformationClass
);
typedef BOOLEAN (NTAPI *PPH_ENUM_NEXT_PROCESS)(
_Function_class_(PH_ENUM_NEXT_PROCESS)
typedef NTSTATUS (NTAPI PH_ENUM_NEXT_PROCESS)(
_In_ HANDLE ProcessHandle,
_In_opt_ PVOID Context
);
typedef PH_ENUM_NEXT_PROCESS* PPH_ENUM_NEXT_PROCESS;
PHLIBAPI
NTSTATUS
@@ -1583,10 +1585,12 @@ PhEnumNextProcess(
_In_opt_ PVOID Context
);
typedef BOOLEAN (NTAPI *PPH_ENUM_NEXT_THREAD)(
_Function_class_(PH_ENUM_NEXT_THREAD)
typedef NTSTATUS (NTAPI PH_ENUM_NEXT_THREAD)(
_In_ HANDLE ThreadHandle,
_In_opt_ PVOID Context
);
typedef PH_ENUM_NEXT_THREAD* PPH_ENUM_NEXT_THREAD;
PHLIBAPI
NTSTATUS
@@ -2081,7 +2085,7 @@ NTSTATUS
NTAPI
PhLoadAppKey(
_Out_ PHANDLE KeyHandle,
_In_ PWSTR FileName,
_In_ PPH_STRINGREF FileName,
_In_ ACCESS_MASK DesiredAccess,
_In_opt_ ULONG Flags
);
+10 -11
View File
@@ -202,6 +202,14 @@ PhLargeIntegerToLocalSystemTime(
_In_ PLARGE_INTEGER LargeInteger
);
PHLIBAPI
BOOLEAN
NTAPI
PhLocalSystemTimeToLargeInteger(
_Out_ PLARGE_INTEGER LargeInteger,
_In_ PSYSTEMTIME SystemTime
);
// Error messages
PHLIBAPI
@@ -751,23 +759,14 @@ PhFlushImageVersionInfoCache(
);
PHLIBAPI
_Success_(return != NULL)
PPH_STRING
NTSTATUS
NTAPI
PhGetFullPath(
_In_ PWSTR FileName,
_Out_ PPH_STRING *FullPath,
_Out_opt_ PULONG IndexOfFileName
);
PHLIBAPI
NTSTATUS
NTAPI
PhGetFullPathEx(
_In_ PWSTR FileName,
_Out_opt_ PULONG IndexOfFileName,
_Out_ PPH_STRING *FullPath
);
PHLIBAPI
PPH_STRING
NTAPI
+2 -2
View File
@@ -48,8 +48,8 @@ PhEditSecurity(
_In_opt_ HWND WindowHandle,
_In_ PWSTR ObjectName,
_In_ PWSTR ObjectType,
_In_ PPH_OPEN_OBJECT OpenCallback,
_In_opt_ PPH_CLOSE_OBJECT CloseCallback,
_In_ PPH_OPEN_OBJECT OpenObject,
_In_opt_ PPH_CLOSE_OBJECT CloseObject,
_In_opt_ PVOID Context
);
+78 -14
View File
@@ -5,7 +5,7 @@
*
* Authors:
*
* dmex 2017-2022
* dmex 2017-2023
*
*/
@@ -169,6 +169,13 @@ ULONGLONG PhGetJsonValueAsUInt64(
return json_object_get_uint64(json_get_object(Object, Key));
}
ULONG PhGetJsonUInt32Object(
_In_ PVOID Object
)
{
return json_object_get_int(Object);
}
PVOID PhCreateJsonObject(
VOID
)
@@ -345,6 +352,19 @@ PVOID PhGetJsonArrayIndexObject(
return json_object_array_get_idx(Object, Index);
}
VOID PhEnumJsonArrayObject(
_In_ PVOID Object,
_In_ PPH_ENUM_JSON_OBJECT_CALLBACK Callback,
_In_opt_ PVOID Context
)
{
json_object_object_foreach(Object, key, value)
{
if (!Callback(Object, key, value, Context))
break;
}
}
PVOID PhGetJsonObjectAsArrayList(
_In_ PVOID Object
)
@@ -372,7 +392,18 @@ PVOID PhLoadJsonObjectFromFile(
_In_ PPH_STRINGREF FileName
)
{
return json_object_from_file(FileName->Buffer);
PPH_BYTES content;
PVOID object;
if (content = PhFileReadAllText(FileName, FALSE))
{
object = PhCreateJsonParserEx(content, FALSE);
PhDereferenceObject(content);
return object;
}
return NULL;
}
NTSTATUS PhSaveJsonObjectToFile(
@@ -380,19 +411,52 @@ NTSTATUS PhSaveJsonObjectToFile(
_In_ PVOID Object
)
{
#ifdef _DEBUG
if (json_object_to_file_ext(FileName->Buffer, Object, JSON_C_TO_STRING_PRETTY) == -1)
{
return STATUS_UNSUCCESSFUL;
}
#else
if (json_object_to_file_ext(FileName->Buffer, Object, 0) == -1)
{
return STATUS_UNSUCCESSFUL;
}
#endif
INT json_flags = JSON_C_TO_STRING_PRETTY;
NTSTATUS status;
HANDLE fileHandle;
IO_STATUS_BLOCK isb;
size_t json_length;
PCSTR json_string;
return STATUS_SUCCESS;
json_string = json_object_to_json_string_length(
Object,
json_flags,
&json_length
);
if (json_length == 0)
{
return STATUS_UNSUCCESSFUL;
}
status = PhCreateFile(
&fileHandle,
FileName,
FILE_GENERIC_WRITE,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OVERWRITE_IF,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
);
if (!NT_SUCCESS(status))
return status;
status = NtWriteFile(
fileHandle,
NULL,
NULL,
NULL,
&isb,
(PVOID)json_string,
(ULONG)json_length,
NULL,
NULL
);
NtClose(fileHandle);
return status;
}
// XML support
+19 -20
View File
@@ -6879,8 +6879,13 @@ NTSTATUS PhEnumNextProcess(
while (TRUE)
{
if (!Callback(processHandle, Context))
status = Callback(processHandle, Context);
if (!NT_SUCCESS(status))
{
NtClose(processHandle);
break;
}
status = NtGetNextProcess(
processHandle,
@@ -6934,8 +6939,13 @@ NTSTATUS PhEnumNextThread(
while (TRUE)
{
if (!Callback(threadHandle, Context))
status = Callback(threadHandle, Context);
if (!NT_SUCCESS(status))
{
NtClose(threadHandle);
break;
}
status = NtGetNextThread(
ProcessHandle,
@@ -10104,13 +10114,13 @@ NTSTATUS PhOpenKey(
* Loads the specified registry hive file into a private application hive.
*
* \param KeyHandle A variable which receives a handle to the key.
* \param FileName The Win32 file name.
* \param FileName A string containing a file name.
* \param DesiredAccess The desired access to the key.
* \param Flags Optional flags for loading the hive.
*/
NTSTATUS PhLoadAppKey(
_Out_ PHANDLE KeyHandle,
_In_ PWSTR FileName,
_In_ PPH_STRINGREF FileName,
_In_ ACCESS_MASK DesiredAccess,
_In_opt_ ULONG Flags
)
@@ -10122,6 +10132,9 @@ NTSTATUS PhLoadAppKey(
OBJECT_ATTRIBUTES targetAttributes;
OBJECT_ATTRIBUTES sourceAttributes;
if (!PhStringRefToUnicodeString(FileName, &fileName))
return STATUS_NAME_TOO_LONG;
PhGenerateGuid(&guid);
#if (PHNT_USE_NATIVE_APPEND)
@@ -10150,20 +10163,10 @@ NTSTATUS PhLoadAppKey(
if (!PhStringRefToUnicodeString(&guidString->sr, &objectName))
{
PhDereferenceObject(guidString);
return STATUS_UNSUCCESSFUL;
return STATUS_NAME_TOO_LONG;
}
#endif
status = PhDosLongPathNameToNtPathNameWithStatus(
FileName,
&fileName,
NULL,
NULL
);
if (!NT_SUCCESS(status))
goto CleanupExit;
InitializeObjectAttributes(
&targetAttributes,
&objectName,
@@ -10191,13 +10194,9 @@ NTSTATUS PhLoadAppKey(
NULL
);
RtlFreeUnicodeString(&fileName);
#if (PHNT_USE_NATIVE_APPEND)
CleanupExit:
RtlFreeUnicodeString(&guidStringUs);
#else
CleanupExit:
PhDereferenceObject(guidString);
#endif
@@ -15142,7 +15141,7 @@ NTSTATUS PhSetSystemEnvironmentBootToFirmware(
VOID
)
{
static GUID EFI_GLOBAL_VARIABLE_GUID = { 0x8be4df61, 0x93ca, 0x11d2, { 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c } };
static const GUID EFI_GLOBAL_VARIABLE_GUID = { 0x8be4df61, 0x93ca, 0x11d2, { 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c } };
static UNICODE_STRING OsIndicationsSupportedName = RTL_CONSTANT_STRING(L"OsIndicationsSupported");
static UNICODE_STRING OsIndicationsName = RTL_CONSTANT_STRING(L"OsIndications");
const ULONG64 EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x0000000000000001ULL;
+23 -31
View File
@@ -548,19 +548,6 @@ _May_raise_ VOID PhSetStringRefSetting(
PhRaiseStatus(STATUS_NOT_FOUND);
}
_May_raise_ VOID PhSetBinarySetting(
_In_ PWSTR Name,
_In_ PVOID Buffer,
_In_ ULONG Length
)
{
PPH_STRING binaryString;
binaryString = PhBufferToHexString((PUCHAR)Buffer, Length);
PhSetStringSetting(Name, binaryString->Buffer);
PhDereferenceObject(binaryString);
}
VOID PhpFreeIgnoredSetting(
_In_ PPH_SETTING Setting
)
@@ -917,19 +904,18 @@ VOID PhLoadWindowPlacementFromSetting(
_In_ HWND WindowHandle
)
{
PH_RECTANGLE windowRectangle = {0};
LONG dpiValue = 0;
if (PositionSettingName && SizeSettingName)
{
PH_RECTANGLE windowRectangle = { 0 };
LONG dpi;
RECT rect;
RECT rectForAdjust;
windowRectangle.Position = PhGetIntegerPairSetting(PositionSettingName);
rect = PhRectangleToRect(windowRectangle);
dpiValue = PhGetMonitorDpi(&rect);
dpi = PhGetMonitorDpi(&rect);
windowRectangle.Size = PhGetScalableIntegerPairSetting(SizeSettingName, TRUE, dpiValue).Pair;
windowRectangle.Size = PhGetScalableIntegerPairSetting(SizeSettingName, TRUE, dpi).Pair;
PhAdjustRectangleToWorkingArea(NULL, &windowRectangle);
// Let the window adjust for the minimum size if needed.
@@ -942,9 +928,11 @@ VOID PhLoadWindowPlacementFromSetting(
}
else
{
PH_RECTANGLE windowRectangle;
PH_INTEGER_PAIR position;
PH_INTEGER_PAIR size;
ULONG flags;
LONG dpi;
flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER;
@@ -959,11 +947,10 @@ VOID PhLoadWindowPlacementFromSetting(
position.Y = 0;
}
dpiValue = PhGetWindowDpi(WindowHandle);
if (SizeSettingName)
{
size = PhGetScalableIntegerPairSetting(SizeSettingName, TRUE, dpiValue).Pair;
dpi = PhGetWindowDpi(WindowHandle);
size = PhGetScalableIntegerPairSetting(SizeSettingName, TRUE, dpi).Pair;
flags &= ~SWP_NOSIZE;
}
else
@@ -996,8 +983,8 @@ VOID PhSaveWindowPlacementToSetting(
WINDOWPLACEMENT placement = { sizeof(placement) };
PH_RECTANGLE windowRectangle;
MONITORINFO monitorInfo = { sizeof(MONITORINFO) };
//RECT rect;
LONG windowDpi;
RECT rect;
LONG dpi;
GetWindowPlacement(WindowHandle, &placement);
windowRectangle = PhRectToRectangle(placement.rcNormalPosition);
@@ -1009,13 +996,13 @@ VOID PhSaveWindowPlacementToSetting(
windowRectangle.Top += monitorInfo.rcWork.top - monitorInfo.rcMonitor.top;
}
//rect = PhRectangleToRect(windowRectangle);
windowDpi = PhGetWindowDpi(WindowHandle); // PhGetMonitorDpi(&rect);
rect = PhRectangleToRect(windowRectangle);
dpi = PhGetMonitorDpi(&rect); // PhGetWindowDpi(WindowHandle);
if (PositionSettingName)
PhSetIntegerPairSetting(PositionSettingName, windowRectangle.Position);
if (SizeSettingName)
PhSetScalableIntegerPairSetting2(SizeSettingName, windowRectangle.Size, windowDpi);
PhSetScalableIntegerPairSetting2(SizeSettingName, windowRectangle.Size, dpi);
}
BOOLEAN PhLoadListViewColumnSettings(
@@ -1029,12 +1016,17 @@ BOOLEAN PhLoadListViewColumnSettings(
ULONG orderArray[ORDER_LIMIT]; // HACK, but reasonable limit
ULONG maxOrder;
ULONG scale;
LONG dpiValue;
LONG dpi;
#ifdef DEBUG
HWND headerHandle = ListView_GetHeader(ListViewHandle);
assert(Header_GetItemCount(headerHandle) < ORDER_LIMIT);
#endif
if (PhIsNullOrEmptyString(Settings))
return FALSE;
dpiValue = PhGetWindowDpi(ListViewHandle);
dpi = PhGetWindowDpi(ListViewHandle);
remainingPart = Settings->sr;
columnIndex = 0;
@@ -1056,7 +1048,7 @@ BOOLEAN PhLoadListViewColumnSettings(
}
else
{
scale = dpiValue;
scale = dpi;
}
while (remainingPart.Length != 0)
@@ -1101,8 +1093,8 @@ BOOLEAN PhLoadListViewColumnSettings(
width = (LONG)integer;
if (scale != dpiValue && scale != 0)
width = PhMultiplyDivideSigned(width, dpiValue, scale);
if (scale != dpi && scale != 0)
width = PhMultiplyDivideSigned(width, dpi, scale);
lvColumn.mask = LVCF_WIDTH;
lvColumn.cx = width;
+92 -92
View File
@@ -425,6 +425,22 @@ VOID PhLargeIntegerToLocalSystemTime(
#endif
}
BOOLEAN PhLocalSystemTimeToLargeInteger(
_Out_ PLARGE_INTEGER LargeInteger,
_In_ PSYSTEMTIME SystemTime
)
{
LARGE_INTEGER timeZoneBias;
if (!PhSystemTimeToLargeInteger(LargeInteger, SystemTime))
return FALSE;
PhQueryTimeZoneBias(&timeZoneBias);
LargeInteger->QuadPart += timeZoneBias.QuadPart;
return TRUE;
}
/**
* Gets a string stored in a DLL's message table.
*
@@ -2809,18 +2825,20 @@ VOID PhFlushImageVersionInfoCache(
* Gets an absolute file name.
*
* \param FileName A file name.
* \param FullPath An absolute file name, or NULL if the function failed.
* \param IndexOfFileName A variable which receives the index of the base name.
*
* \return An absolute file name, or NULL if the function failed.
* \return Successful or errant status.
*/
_Success_(return != NULL)
PPH_STRING PhGetFullPath(
NTSTATUS PhGetFullPath(
_In_ PWSTR FileName,
_Out_ PPH_STRING *FullPath,
_Out_opt_ PULONG IndexOfFileName
)
{
NTSTATUS status;
PPH_STRING fullPath;
ULONG bufferSize;
ULONG fullPathLength;
ULONG returnLength;
PWSTR filePart;
@@ -2828,92 +2846,46 @@ PPH_STRING PhGetFullPath(
assert(RtlEqualMemory(FileName, RtlNtPathSeperatorString.Buffer, RtlNtPathSeperatorString.Length) == FALSE);
#endif
bufferSize = 0x80;
fullPath = PhCreateStringEx(NULL, bufferSize * sizeof(WCHAR));
returnLength = RtlGetFullPathName_U(FileName, bufferSize, fullPath->Buffer, &filePart);
if (returnLength > bufferSize)
{
PhDereferenceObject(fullPath);
bufferSize = returnLength;
fullPath = PhCreateStringEx(NULL, bufferSize * sizeof(WCHAR));
returnLength = RtlGetFullPathName_U(FileName, bufferSize, fullPath->Buffer, &filePart);
}
if (returnLength == 0)
{
PhDereferenceObject(fullPath);
return NULL;
}
PhTrimToNullTerminatorString(fullPath);
if (IndexOfFileName)
{
if (filePart)
{
// The path points to a file.
*IndexOfFileName = (ULONG)(filePart - fullPath->Buffer);
}
else
{
// The path points to a directory.
*IndexOfFileName = ULONG_MAX;
}
}
return fullPath;
}
NTSTATUS PhGetFullPathEx(
_In_ PWSTR FileName,
_Out_opt_ PULONG IndexOfFileName,
_Out_ PPH_STRING *FullPath
)
{
#if (PHNT_VERSION >= PHNT_WIN7)
NTSTATUS status;
PPH_STRING fullPath;
ULONG bufferSize;
ULONG returnLength = 0;
PWSTR filePart;
bufferSize = 0x80;
fullPath = PhCreateStringEx(NULL, bufferSize * sizeof(WCHAR));
fullPathLength = DOS_MAX_PATH_LENGTH;
fullPath = PhCreateStringEx(NULL, fullPathLength);
status = RtlGetFullPathName_UEx(
FileName,
bufferSize,
fullPathLength,
fullPath->Buffer,
&filePart,
&returnLength
);
if (returnLength > bufferSize)
{
PhDereferenceObject(fullPath);
bufferSize = returnLength;
fullPath = PhCreateStringEx(NULL, bufferSize * sizeof(WCHAR));
status = RtlGetFullPathName_UEx(
FileName,
bufferSize,
fullPath->Buffer,
&filePart,
&returnLength
);
}
if (!NT_SUCCESS(status))
{
PhDereferenceObject(fullPath);
return status;
}
fullPath->Length = returnLength;
//PhTrimToNullTerminatorString(fullPath);
if (returnLength > fullPathLength)
{
PhDereferenceObject(fullPath);
fullPathLength = returnLength;
fullPath = PhCreateStringEx(NULL, fullPathLength);
status = RtlGetFullPathName_UEx(
FileName,
fullPathLength,
fullPath->Buffer,
&filePart,
&returnLength
);
if (!NT_SUCCESS(status))
{
PhDereferenceObject(fullPath);
return status;
}
}
PhTrimToNullTerminatorString(fullPath);
*FullPath = fullPath;
if (IndexOfFileName)
{
@@ -2929,20 +2901,7 @@ NTSTATUS PhGetFullPathEx(
}
}
*FullPath = fullPath;
return status;
#else
PPH_STRING fullPath;
if (fullPath = PhGetFullPath(FileName, IndexOfFileName))
{
*FullPath = fullPath;
return STATUS_SUCCESS;
}
return STATUS_UNSUCCESSFUL;
#endif
}
/**
@@ -3193,6 +3152,46 @@ VOID PhGetSystemRoot(
systemRoot.Buffer = localSystemRoot.Buffer;
}
/**
* Retrieves the Windows directory path.
*/
PPH_STRING PhGetWindowsDirectory(
_In_opt_ PPH_STRINGREF AppendPath
)
{
PH_STRINGREF systemRoot;
PPH_STRING systemRootNative;
PhGetSystemRoot(&systemRoot);
systemRootNative = PhDosPathNameToNtPathName(&systemRoot);
if (systemRootNative && AppendPath)
{
PhMoveReference(&systemRootNative, PhConcatStringRef2(&systemRootNative->sr, AppendPath));
}
return systemRootNative;
}
/**
* Retrieves the Windows directory path.
*/
PPH_STRING PhGetWindowsDirectoryWin32(
_In_opt_ PPH_STRINGREF AppendPath
)
{
PH_STRINGREF systemRoot;
PhGetSystemRoot(&systemRoot);
if (AppendPath)
{
return PhConcatStringRef2(&systemRoot, AppendPath);
}
return PhCreateString2(&systemRoot);
}
PPH_STRING PhGetApplicationFileName(
VOID
)
@@ -3252,7 +3251,7 @@ PPH_STRING PhGetApplicationFileNameWin32(
//{
// PPH_STRING fullPath;
//
// if (fullPath = PhGetFullPath(PhGetString(fileName), NULL))
// if (NT_SUCCESS(PhGetFullPath(PhGetString(fileName), &fullPath, NULL)))
// {
// PhMoveReference(&fileName, fullPath);
// }
@@ -6994,7 +6993,8 @@ PPH_STRING PhSearchFilePath(
if (!NT_SUCCESS(PhQueryAttributesFileWin32(fullPath->Buffer, &basicInfo)))
goto CleanupExit;
if (basicInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
if (FlagOn(basicInfo.FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
goto CleanupExit;
return fullPath;
@@ -7157,7 +7157,7 @@ VOID PhDeleteCacheFile(
PhDeleteFileWin32(PhGetString(FileName));
}
if (cacheFullFilePath = PhGetFullPath(PhGetString(FileName), &indexOfFileName))
if (NT_SUCCESS(PhGetFullPath(PhGetString(FileName), &cacheFullFilePath, &indexOfFileName)))
{
if (indexOfFileName != ULONG_MAX && (cacheDirectory = PhSubstring(cacheFullFilePath, 0, indexOfFileName)))
{
+1 -1
View File
@@ -1065,7 +1065,7 @@ PPH_STRING SetupCreateFullPath(
pathString = PhConcatStringRefZ(&Path->sr, FileName);
if (NT_SUCCESS(PhGetFullPathEx(pathString->Buffer, NULL, &tempString)))
if (NT_SUCCESS(PhGetFullPath(pathString->Buffer, &tempString, NULL)))
{
PhMoveReference(&pathString, tempString);
return pathString;