简体   繁体   English

无法将结构指针转换为 PUCHAR

[英]Cannot cast struct pointer to PUCHAR

I'm testing a code (based in this reference ) and i'm receiving a error that says:我正在测试一个代码(基于this reference ),我收到一条错误消息:

'type cast': cannot convert from 'SYSTEM_SERVICE_TABLE' to 'PUCHAR' “类型转换”:无法从“SYSTEM_SERVICE_TABLE”转换为“PUCHAR”

How can solve it?怎么解决?

Edition:版:

The goal is try find Shadow SSDT table address on Windows 10 32bit.目标是尝试在 Windows 10 32bit 上找到Shadow SSDT表地址。

#include <ntddk.h>

#define NTOSAPI __declspec(dllimport)

typedef struct tag_SYSTEM_SERVICE_TABLE {
    PULONG ServiceTable;
    PULONG CounterTable;
    ULONG ServiceLimit;
    PCHAR ArgumentTable;
} SYSTEM_SERVICE_TABLE, *PSYSTEM_SERVICE_TABLE, **PPSYSTEM_SERVICE_TABLE;

NTOSAPI SYSTEM_SERVICE_TABLE KeServiceDescriptorTable;

NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING RegistryPath) {

    NTSTATUS NtStatus = STATUS_SUCCESS;

    pDriverObject->DriverUnload = DriverUnload;
    
    DbgPrint("DriverEntry()!\n");

    PUCHAR p = NULL;
    PSYSTEM_SERVICE_TABLE KeServiceDescriptorTableWIN32K = NULL;
    
    for (p = (PUCHAR)KeServiceDescriptorTable - PAGE_SIZE; p < (PUCHAR)KeServiceDescriptorTable + PAGE_SIZE; p++)
    {
        if (p != (PUCHAR)KeServiceDescriptorTable)
        {
            if (memcmp(p, &KeServiceDescriptorTable, sizeof(SYSTEM_SERVICE_TABLE)) == 0)
            {
                KeServiceDescriptorTableWIN32K = (PSYSTEM_SERVICE_TABLE)(p + sizeof(SYSTEM_SERVICE_TABLE));
                break;
            }
        }
    }

    return NtStatus;
}

Your title says "Cannot cast struct pointer to PUCHAR", but the code is not trying to cast a pointer , it is trying to cast the struct itself , which is why the compiler complains.您的标题说“无法将结构指针转换为 PUCHAR”,但代码并没有尝试转换指针,而是尝试转换结构本身,这就是编译器抱怨的原因。 You need to get the address of the struct and cast that instead, ie:您需要获取结构的地址并将其转换为,即:

(PUCHAR)&KeServiceDescriptorTable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM