VC驱动监控进程的创建(2)
//通过文件句柄获得文件名
hand=(HANDLE)arg[6];//获得执行文件句柄
ObReferenceObjectByHandle(hand,0,0,KernelMode,&file,info);//&file获得对象体指针
if(!file)return 1;
RtlUnicodeStringToAnsiString(&str,&file->FileName,1);
a=str.Length;buff=str.Buffer;
while(1)//通过循环判断是不是有". "标志
{
if(buff[a]=='.')
{a++;break;}
a--;
}
ObDereferenceObject(file);
if(_stricmp(&buff[a],"exe")){RtlFreeAnsiString(&str);return 1;}//判断是否为可执行文件
KeWaitForSingleObject(&event,Executive,KernelMode,0,0);//将当前线程置于等待状态知道信号态
strcpy(&output[8],buff);//将string复制进buff
RtlFreeAnsiString(&str);
a=1;//用户的决定通过a的制来反映
memmove(&output[0],&a,4);
while(1)
{
KeDelayExecutionThread(KernelMode,0,&li);//在一个固定时间间隔内当前线程处于等待状态
memmove(&a,&output[0],4);
if(!a)break;
}
memmove(&a,&output[4],4);
KeSetEvent(&event,0,0);
return a;
}
//保存执行文件上下文,调用check()函数
_declspec(naked) Proxy()
{
_asm{
pushfd
pushad
mov ebx,esp