Skip to content

Commit 2dd536e

Browse files
committed
Add PhGetFileText UTF8 support
1 parent 0da25e8 commit 2dd536e

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

phlib/include/phutil.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,17 +1311,19 @@ PhLoadAllImportsForDll(
13111311
);
13121312

13131313
PHLIBAPI
1314-
PPH_STRING
1314+
PVOID
13151315
NTAPI
13161316
PhGetFileText(
1317-
_In_ HANDLE FileHandle
1317+
_In_ HANDLE FileHandle,
1318+
_In_ BOOLEAN Unicode
13181319
);
13191320

13201321
PHLIBAPI
1321-
PPH_STRING
1322+
PVOID
13221323
NTAPI
13231324
PhFileReadAllText(
1324-
_In_ PWSTR FileName
1325+
_In_ PWSTR FileName,
1326+
_In_ BOOLEAN Unicode
13251327
);
13261328

13271329
PHLIBAPI

phlib/lsasup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ VOID PhInitializeCapabilitySidCache(
673673
capabilityListFileName = PhConcatStringRefZ(&applicationDirectory->sr, L"capslist.txt");
674674
PhDereferenceObject(applicationDirectory);
675675

676-
capabilityListString = PhFileReadAllText(capabilityListFileName->Buffer);
676+
capabilityListString = PhFileReadAllText(capabilityListFileName->Buffer, TRUE);
677677
PhDereferenceObject(capabilityListFileName);
678678
}
679679

phlib/util.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6664,11 +6664,12 @@ PPH_STRING PhGetExportNameFromOrdinal(
66646664
return NULL;
66656665
}
66666666

6667-
PPH_STRING PhGetFileText(
6668-
_In_ HANDLE FileHandle
6667+
PVOID PhGetFileText(
6668+
_In_ HANDLE FileHandle,
6669+
_In_ BOOLEAN Unicode
66696670
)
66706671
{
6671-
PPH_STRING string = NULL;
6672+
PVOID string = NULL;
66726673
PSTR data;
66736674
ULONG allocatedLength;
66746675
ULONG dataLength;
@@ -6717,19 +6718,24 @@ PPH_STRING PhGetFileText(
67176718
if (dataLength > 0)
67186719
{
67196720
data[dataLength] = ANSI_NULL;
6720-
string = PhConvertUtf8ToUtf16Ex(data, dataLength);
6721+
6722+
if (Unicode)
6723+
string = PhConvertUtf8ToUtf16Ex(data, dataLength);
6724+
else
6725+
string = PhCreateBytesEx(data, dataLength);
67216726
}
67226727

67236728
PhFree(data);
67246729

67256730
return string;
67266731
}
67276732

6728-
PPH_STRING PhFileReadAllText(
6729-
_In_ PWSTR FileName
6733+
PVOID PhFileReadAllText(
6734+
_In_ PWSTR FileName,
6735+
_In_ BOOLEAN Unicode
67306736
)
67316737
{
6732-
PPH_STRING string = NULL;
6738+
PVOID string = NULL;
67336739
HANDLE fileHandle;
67346740

67356741
if (NT_SUCCESS(PhCreateFileWin32(
@@ -6742,7 +6748,7 @@ PPH_STRING PhFileReadAllText(
67426748
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
67436749
)))
67446750
{
6745-
string = PhGetFileText(fileHandle);
6751+
string = PhGetFileText(fileHandle, Unicode);
67466752
NtClose(fileHandle);
67476753
}
67486754

phlib/wslsup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ ULONG PhCreateProcessLxss(
384384
NtClose(outputWriteHandle);
385385

386386
// Read the pipe data. (dmex)
387-
lxssOutputString = PhGetFileText(outputReadHandle);
387+
lxssOutputString = PhGetFileText(outputReadHandle, TRUE);
388388

389389
// Get the exit code after we finish reading the data from the pipe. (dmex)
390390
if (NT_SUCCESS(status = PhGetProcessBasicInformation(processHandle, &basicInfo)))

0 commit comments

Comments
 (0)