strstr在内核空间中无法正常工作

时间:2016-01-24 12:26:45

标签: c windows kernel

如果进程名称为“System”,请不要DbgPrint。如果现在任何其他过程都没关系DbgPrint,但由于某种原因它不能正常工作。

我试过了: if(strstr(ImageName,“System”)!= NULL){

if(strncmp(ImageName,“System”,6)!= NULL){

if(RtlCompareMemory(ImageName,“System”,length)== length){

如果它不是“系统”

,我只想打印

以下无效的代码:

int ThreadHooK( PEPROCESS Process, DWORD dw, HANDLE Handle, KPROCESSOR_MODE PreviousMode ){             
    char *ImageName = (char*)(Process + 0x2e0);
    char *System = "System";
    if( PreviousMode == KernelMode ) {
        if( strstr( ImageName, System ) == NULL ) {
            DbgPrintEx( DPFLTR_IHVDRIVER_ID,  DPFLTR_ERROR_LEVEL, "[ThreadHooK]:  Attempt To Close The Handle: [0x%016X] To A Process Opened By A Kernel Process : [%s]\n", Handle, (PUCHAR)Process + 0x2e0 );
        }
    }
    return 1;
}

我希望有人能解决这个问题

1 个答案:

答案 0 :(得分:0)

我需要改变这一行:

char *ImageName = (char*)(Process + 0x2e0);

到此:

char *ImageName = (char*)((PUCHAR)Process + 0x2e0);