我很难将从用户模式类型LPWSTR传递的字符串与LDR表条目类型UNICODE_STRING进行比较
内核C:
struct {
int pid;
int user_pid;
int size;
int protection_mode;
int allocation_type;
void* address;
void* write_buffer;
LPWSTR module_name;
}
userland_operation;这个结构通过deviceiocontrol传递给内核。对应的userland结构如下:
public struct MemOperation
{
public int Pid;
public int UserPid;
public int Size;
public int protection_mode;
public int allocation_type;
public IntPtr Addr;
public IntPtr WriteBuffer;
[MarshalAs(UnmanagedType.LPWStr)] public String ModuleName;
}其中字符串ModuleName被编组为LPWStr。
ModuleName是进程中已加载模块的所需搜索词。现在,这是事情变得棘手的地方。我可以通过_LDR_DATA_TABLE_ENTRY访问的字符串是一个UNICODE_STRING。我想将这个UNICODE_STRING与我的LPWSTR进行比较。
我尝试了以下方法,但不起作用:
{
UNICODE_STRING str;
RtlInitUnicodeString(&str, module_name) // module name is the userland passed string LPWSTR
if (RtlCompareUnicodeString(&str, &module_ldr->BaseDllName, TRUE) {
}
}我还尝试过wcscmp和其他一些东西。我不确定如何才能正确地比较这两个。我在函数中添加了一些小伪代码,以便为我要做的事情提供额外的上下文。
NTSTATUS GetModuleList(HANDLE PID, PVOID UserBuffer, LPWSTR module_name) {
KAPC_STATE APC;
__try {
PEPROCESS TargetProcess;
PsLookupProcessByProcessId(PID, &TargetProcess);
PPEB Peb = PsGetProcessPeb(TargetProcess);
if (!Peb)
return STATUS_INVALID_PARAMETER;
KeStackAttachProcess(TargetProcess, &APC);
UINT64 Ldr = (UINT64)Peb + PEBLDR_OFFSET;
ProbeForRead((CONST PVOID)Ldr, 8, 8);
PLIST_ENTRY ModListHead = (PLIST_ENTRY)(*(PULONG64)Ldr + PEBLDR_MEMORYLOADED_OFFSET);
ProbeForRead((CONST PVOID)ModListHead, 8, 8);
PLIST_ENTRY Module = ModListHead->Flink;
while (ModListHead != Module) {
LDR_DATA_TABLE_ENTRY* Module_Ldr = (LDR_DATA_TABLE_ENTRY*)(Module);
//psuedo if (module_name is in Module_Ldr->BaseDllName) // the comparison, where BaseDllName is type UNICODE_STRING
Module = Module->Flink;
}
KeUnstackDetachProcess(&APC);
ObDereferenceObject(TargetProcess);
return STATUS_SUCCESS;发布于 2020-06-05 13:41:47
在下面的调用中:
if (RtlCompareUnicodeString(&str, &module_ldr->BaseDllName) {这个函数接受一个你没有传递的额外参数。请参考https://docs.microsoft.com/en-us/windows/win32/devnotes/rtlcompareunicodestring
https://stackoverflow.com/questions/62208433
复制相似问题