标签:des style io color ar os for sp strong
//PVOID oldParseProcedure;
//typedef int (*FP_CALC)(int, int);
NTSTATUS (*oldParseProcedure)(IN PVOID ParseObject,
IN PVOID ObjectType,
IN OUT PACCESS_STATE AccessState,
IN KPROCESSOR_MODE AccessMode,
IN ULONG Attributes,
IN OUT PUNICODE_STRING CompleteName,
IN OUT PUNICODE_STRING RemainingName,
IN OUT PVOID Context OPTIONAL,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
OUT PVOID *Object);
VOID MyObjectHook()
{
UNICODE_STRING uFileName;
OBJECT_ATTRIBUTES ob;
NTSTATUS status;
HANDLE hFile;
IO_STATUS_BLOCK ioStaBlock;
PVOID pObject;
POBJECT_HEADER addr;
POBJECT_TYPE pType;
OBJECT_TYPE_INITIALIZER obTypeInit;
KIRQL irql;
dprintf("enter myObjectHook...\n");
DbgBreakPoint();
RtlInitUnicodeString(&uFileName,L"\\Device\\HarddiskVolume1\\123.txt");//这个文件必需存在
InitializeObjectAttributes(&ob,&uFileName,OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE ,NULL, NULL);
status = ZwOpenFile(&hFile,GENERIC_ALL,&ob,&ioStaBlock,0,FILE_NON_DIRECTORY_FILE);
if (!NT_SUCCESS(status))
{
dprintf("ZwOpenFile error..\n");
return ;
}
status = ObReferenceObjectByHandle(hFile,GENERIC_ALL,NULL,KernelMode,&pObject,NULL);
if (!NT_SUCCESS(status))
{
dprintf("ObReferenceObjectByHandle:Object is Null\n");
return ;
}
dprintf("pObject is 0x%08X\n",pObject);
addr = OBJECT_TO_OBJECT_HEADER(pObject);
dprintf("addr is 0x%08X\n",addr); //这里是pObject-0x18的位置
pType = addr->Type;
dprintf("pType is 0x%08X\n",pType);
//oldParseProcedure = (PVOID)(pType->TypeInfo.ParseProcedure);
oldParseProcedure = pType->TypeInfo.ParseProcedure;
dprintf("OldParseProcedure addrs is %08X\n",oldParseProcedure);
//HOOK 一下下
irql = WPOFF();
pType->TypeInfo.ParseProcedure = NewParseProcedure;//hook
WPON(irql);
//关闭句柄
ZwClose(hFile);
}
//OBJECT HOOK 函数
NTSTATUS NewParseProcedure(IN PVOID ParseObject,
IN PVOID ObjectType,
IN OUT PACCESS_STATE AccessState,
IN KPROCESSOR_MODE AccessMode,
IN ULONG Attributes,
IN OUT PUNICODE_STRING CompleteName,
IN OUT PUNICODE_STRING RemainingName,
IN OUT PVOID Context OPTIONAL,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
OUT PVOID *Object)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
PVOID namePool;
if (RemainingName->Buffer)
{
namePool = ExAllocatePool(NonPagedPool, RemainingName->Buffer+2);
RtlZeroMemory(namePool, RemainingName->Buffer+2);
if (namePool)
{
RtlCopyMemory(namePool, RemainingName->Buffer,RemainingName->Length);
_wcsupr((wchar_t*)namePool);
if (wcsstr(namePool, L"TEST.TXT"))
{
ExFreePool(namePool);
return STATUS_ACCESS_DENIED;
}
}
}
return oldParseProcedure(ParseObject,
ObjectType,
AccessState,
AccessMode,
Attributes,
CompleteName,
RemainingName,
Context,
SecurityQos,
*Object);
}
//object hook
VOID MyObjectHook();
#define OBJECT_TO_OBJECT_HEADER(o)\
CONTAINING_RECORD((o),OBJECT_HEADER,Body)
typedef struct _OBJECT_HEADER {
LONG PointerCount;
union {
LONG HandleCount;
PSINGLE_LIST_ENTRY SEntry;
};
POBJECT_TYPE Type;
UCHAR NameInfoOffset;
UCHAR HandleInfoOffset;
UCHAR QuotaInfoOffset;
UCHAR Flags;
union
{
PVOID ObjectCreateInfo;
PVOID QuotaBlockCharged;
};
PSECURITY_DESCRIPTOR SecurityDescriptor;
QUAD Body;
} OBJECT_HEADER, *POBJECT_HEADER;
NTSTATUS NewParseProcedure(IN PVOID ParseObject,
IN PVOID ObjectType,
IN OUT PACCESS_STATE AccessState,
IN KPROCESSOR_MODE AccessMode,
IN ULONG Attributes,
IN OUT PUNICODE_STRING CompleteName,
IN OUT PUNICODE_STRING RemainingName,
IN OUT PVOID Context OPTIONAL,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
OUT PVOID *Object);
标签:des style io color ar os for sp strong
原文地址:http://blog.csdn.net/xiaocaiju/article/details/40826549