Skip to content

Commit

Permalink
kph fs supported features
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Jul 1, 2024
1 parent bf208fa commit 7814421
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SystemInformer/ksisup.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,15 @@ VOID KsiConnect(
config.ObjectName = &objectName->sr;
config.PortName = (portName ? &portName->sr : NULL);
config.Altitude = (altitude ? &altitude->sr : NULL);
config.FsSupportedFeatures = 0;
if (!!PhGetIntegerSetting(L"KsiEnableFsFeatureOffloadRead"))
SetFlag(config.FsSupportedFeatures, SUPPORTED_FS_FEATURES_OFFLOAD_READ);
if (!!PhGetIntegerSetting(L"KsiEnableFsFeatureOffloadWrite"))
SetFlag(config.FsSupportedFeatures, SUPPORTED_FS_FEATURES_OFFLOAD_WRITE);
if (!!PhGetIntegerSetting(L"KsiEnableFsFeatureQueryOpen"))
SetFlag(config.FsSupportedFeatures, SUPPORTED_FS_FEATURES_QUERY_OPEN);
if (!!PhGetIntegerSetting(L"KsiEnableFsFeatureBypassIO"))
SetFlag(config.FsSupportedFeatures, SUPPORTED_FS_FEATURES_BYPASS_IO);
config.Flags.Flags = 0;
config.Flags.DisableImageLoadProtection = !!PhGetIntegerSetting(L"KsiDisableImageLoadProtection");
config.Flags.RandomizedPoolTag = !!PhGetIntegerSetting(L"KsiRandomizedPoolTag");
Expand Down
4 changes: 4 additions & 0 deletions SystemInformer/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ VOID PhAddDefaultSettings(
PhpAddIntegerSetting(L"KsiDynDataNoEmbedded", L"0");
PhpAddIntegerSetting(L"KsiClientProcessProtectionLevel", L"0");
PhpAddStringSetting(L"KsiPreviousTemporaryDriverFile", L"");
PhpAddIntegerSetting(L"KsiEnableFsFeatureOffloadRead", L"1"); // SUPPORTED_FS_FEATURES_OFFLOAD_READ
PhpAddIntegerSetting(L"KsiEnableFsFeatureOffloadWrite", L"1"); // SUPPORTED_FS_FEATURES_OFFLOAD_WRITE
PhpAddIntegerSetting(L"KsiEnableFsFeatureQueryOpen", L"1"); // SUPPORTED_FS_FEATURES_QUERY_OPEN
PhpAddIntegerSetting(L"KsiEnableFsFeatureBypassIO", L"1"); // SUPPORTED_FS_FEATURES_BYPASS_IO
}

VOID PhUpdateCachedSettings(
Expand Down
1 change: 1 addition & 0 deletions phlib/include/kphuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct _KPH_CONFIG_PARAMETERS
_In_ PPH_STRINGREF ObjectName;
_In_opt_ PPH_STRINGREF PortName;
_In_opt_ PPH_STRINGREF Altitude;
_In_ ULONG FsSupportedFeatures;
_In_ KPH_PARAMETER_FLAGS Flags;
_In_opt_ PKPH_COMMS_CALLBACK Callback;

Expand Down
70 changes: 70 additions & 0 deletions phlib/kph.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,71 @@ NTSTATUS KphConnect(
return status;
}

NTSTATUS KphpSetParametersService(
_In_ PKPH_CONFIG_PARAMETERS Config
)
{
#ifdef _WIN64
NTSTATUS status;
HANDLE servicesKeyHandle = NULL;
ULONG disposition;
SIZE_T returnLength;
PH_STRINGREF servicesKeyName;
PH_FORMAT format[2];
WCHAR servicesKeyNameBuffer[MAX_PATH];

PhInitFormatS(&format[0], L"System\\CurrentControlSet\\Services\\");
PhInitFormatSR(&format[1], *Config->ServiceName);

if (!PhFormatToBuffer(
format,
RTL_NUMBER_OF(format),
servicesKeyNameBuffer,
sizeof(servicesKeyNameBuffer),
&returnLength
))
{
return STATUS_UNSUCCESSFUL;
}

servicesKeyName.Buffer = servicesKeyNameBuffer;
servicesKeyName.Length = returnLength - sizeof(UNICODE_NULL);

status = PhCreateKey(
&servicesKeyHandle,
KEY_WRITE | DELETE,
PH_KEY_LOCAL_MACHINE,
&servicesKeyName,
0,
0,
&disposition
);

if (!NT_SUCCESS(status))
return status;

status = PhSetValueKeyZ(
servicesKeyHandle,
L"SupportedFeatures",
REG_DWORD,
&Config->FsSupportedFeatures,
sizeof(ULONG)
);

if (!NT_SUCCESS(status))
goto CleanupExit;

CleanupExit:

if (servicesKeyHandle)
NtClose(servicesKeyHandle);

return status;
#else
return STATUS_NOT_SUPPORTED;
#endif
}

NTSTATUS KphSetParameters(
_In_ PKPH_CONFIG_PARAMETERS Config
)
Expand All @@ -156,6 +221,11 @@ NTSTATUS KphSetParameters(
PH_FORMAT format[3];
WCHAR parametersKeyNameBuffer[MAX_PATH];

// Services key parameters.
status = KphpSetParametersService(Config);
if (!NT_SUCCESS(status))
return status;

if (!Config->PortName && !Config->Altitude && !Config->Flags.Flags)
{
// Don't create parameters key unless we must.
Expand Down
40 changes: 40 additions & 0 deletions phnt/include/ntioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,46 @@ typedef struct _OPLOCK_KEY_CONTEXT

#endif

#if (PHNT_VERSION >= PHNT_WIN8)

// pub
#define SUPPORTED_FS_FEATURES_OFFLOAD_READ 0x00000001
#define SUPPORTED_FS_FEATURES_OFFLOAD_WRITE 0x00000002

#if (PHNT_VERSION >= PHNT_REDSTONE2)

// pub
#define SUPPORTED_FS_FEATURES_QUERY_OPEN 0x00000004

#if (PHNT_VERSION >= PHNT_WIN11)

// pub
#define SUPPORTED_FS_FEATURES_BYPASS_IO 0x00000008

// pub
#define SUPPORTED_FS_FEATURES_VALID_MASK (SUPPORTED_FS_FEATURES_OFFLOAD_READ |\
SUPPORTED_FS_FEATURES_OFFLOAD_WRITE |\
SUPPORTED_FS_FEATURES_QUERY_OPEN |\
SUPPORTED_FS_FEATURES_BYPASS_IO)

#else // (PHNT_VERSION >= PHNT_WIN11)

// pub
#define SUPPORTED_FS_FEATURES_VALID_MASK (SUPPORTED_FS_FEATURES_OFFLOAD_READ |\
SUPPORTED_FS_FEATURES_OFFLOAD_WRITE |\
SUPPORTED_FS_FEATURES_QUERY_OPEN)

#endif // (PHNT_VERSION >= PHNT_WIN11)

#else // (PHNT_VERSION >= PHNT_REDSTONE2)

// pub
#define SUPPORTED_FS_FEATURES_VALID_MASK (SUPPORTED_FS_FEATURES_OFFLOAD_READ |\
SUPPORTED_FS_FEATURES_OFFLOAD_WRITE)

#endif // (PHNT_VERSION >= PHNT_REDSTONE2)
#endif // (PHNT_VERSION >= PHNT_WIN8)

#endif // (PHNT_MODE != PHNT_MODE_KERNEL)

#endif

0 comments on commit 7814421

Please sign in to comment.