投递APC失败,是什么原因?
2014-01-13 18:43
323 查看
我见网上都是用内存映射的方法!而我为了图方便就用的RtlMoveMemory
但是调试发现KeInsertQueueApc函数成功,但是Thread+0x40,也就是ApcState->ApcListHead没有我的ListEntry,头和尾是一样的!不解,难道非要用内存映射的方法?
还是KeInitializeApc的什么出错了?
kd> dt _KAPC 8728a230
ntdll!_KAPC
+0x000 Type : 0x12 ''
+0x001 SpareByte0 : 0 ''
+0x002 Size : 0x30 '0'
+0x003 SpareByte1 : 0 ''
+0x004 SpareLong0 : 0x87286c10
+0x008 Thread : 0x8657ed48 _KTHREAD
+0x00c ApcListEntry : _LIST_ENTRY [ 0x8657ed90 - 0x8657ed90 ]
+0x014 KernelRoutine : 0x9192d6f0 void MyDriver!ApcKernelRoutine+0
+0x018 RundownRoutine : (null)
+0x01c NormalRoutine : 0x012c0000 void +12c0000
+0x020 NormalContext : (null)
+0x024 SystemArgument1 : (null)
+0x028 SystemArgument2 : (null)
+0x02c ApcStateIndex : 0 ''
+0x02d ApcMode : 1 ''
+0x02e Inserted : 0x1 ''
我是想在远程通过投递APC实现运行我的代码,类似于CreateRemoteThread的效果!
望大牛看看!
NTSTATUS InjectCode(PETHREAD Thread,PVOID UserModeCodeAddress)
{
PRKAPC pApc=NULL;
PVOID pMappedAddress=NULL;
KAPC_STATE ApcState;
NTSTATUS Status=STATUS_UNSUCCESSFUL;
PVOID pApcState;
PKAPC_STATE APCSTATE;
if (MmIsAddressValid((PVOID)Thread)==TRUE)
{
pApc=ExAllocatePool(NonPagedPool,sizeof(KAPC));
if(!pApc)
{
DbgPrint("Fail to allocate memory for the APC structure");
return STATUS_UNSUCCESSFUL;
}
KeInitializeApc(pApc,\
(PETHREAD)Thread,\
OriginalApcEnvironment,\
&ApcKernelRoutine,\
NULL,\
(PKNORMAL_ROUTINE)UserModeCodeAddress,\
UserMode,\
(PVOID)NULL
);
if(!KeInsertQueueApc(pApc,0,NULL,0))
{
DbgPrint("KernelExec->Failed to insert APC");
ExFreePool(pApc);
return STATUS_UNSUCCESSFUL;
}else{
DbgPrint("APC delivered");
}
APCSTATE=(PKAPC_STATE)((ULONG)Thread+(ULONG)0x40);
APCSTATE->UserApcPending=TRUE;
}
}
但是调试发现KeInsertQueueApc函数成功,但是Thread+0x40,也就是ApcState->ApcListHead没有我的ListEntry,头和尾是一样的!不解,难道非要用内存映射的方法?
还是KeInitializeApc的什么出错了?
kd> dt _KAPC 8728a230
ntdll!_KAPC
+0x000 Type : 0x12 ''
+0x001 SpareByte0 : 0 ''
+0x002 Size : 0x30 '0'
+0x003 SpareByte1 : 0 ''
+0x004 SpareLong0 : 0x87286c10
+0x008 Thread : 0x8657ed48 _KTHREAD
+0x00c ApcListEntry : _LIST_ENTRY [ 0x8657ed90 - 0x8657ed90 ]
+0x014 KernelRoutine : 0x9192d6f0 void MyDriver!ApcKernelRoutine+0
+0x018 RundownRoutine : (null)
+0x01c NormalRoutine : 0x012c0000 void +12c0000
+0x020 NormalContext : (null)
+0x024 SystemArgument1 : (null)
+0x028 SystemArgument2 : (null)
+0x02c ApcStateIndex : 0 ''
+0x02d ApcMode : 1 ''
+0x02e Inserted : 0x1 ''
我是想在远程通过投递APC实现运行我的代码,类似于CreateRemoteThread的效果!
望大牛看看!
NTSTATUS InjectCode(PETHREAD Thread,PVOID UserModeCodeAddress)
{
PRKAPC pApc=NULL;
PVOID pMappedAddress=NULL;
KAPC_STATE ApcState;
NTSTATUS Status=STATUS_UNSUCCESSFUL;
PVOID pApcState;
PKAPC_STATE APCSTATE;
if (MmIsAddressValid((PVOID)Thread)==TRUE)
{
pApc=ExAllocatePool(NonPagedPool,sizeof(KAPC));
if(!pApc)
{
DbgPrint("Fail to allocate memory for the APC structure");
return STATUS_UNSUCCESSFUL;
}
KeInitializeApc(pApc,\
(PETHREAD)Thread,\
OriginalApcEnvironment,\
&ApcKernelRoutine,\
NULL,\
(PKNORMAL_ROUTINE)UserModeCodeAddress,\
UserMode,\
(PVOID)NULL
);
if(!KeInsertQueueApc(pApc,0,NULL,0))
{
DbgPrint("KernelExec->Failed to insert APC");
ExFreePool(pApc);
return STATUS_UNSUCCESSFUL;
}else{
DbgPrint("APC delivered");
}
APCSTATE=(PKAPC_STATE)((ULONG)Thread+(ULONG)0x40);
APCSTATE->UserApcPending=TRUE;
}
}
相关文章推荐
- 求助:连接mySQL数据库频繁失败,是什么原因?
- Ubuntu 12.04 LTS 64bit安装nodejs-express-npm-jade 我尝试失败不知道什么原因。
- U-Mail邮件系统详解邮件投递失败原因及对策
- 互联网创业公司常见失败原因是什么?
- U-Mail邮件系统详解邮件投递失败原因及对策
- SQL2005下面,安装数据库提示创建数据库失败,是什么原因?
- 判断投递失败原因方法
- U-Mail邮件系统详解邮件投递失败原因及对策
- oracle配置oracle Database Configuration Assistant失败是什么原因?
- RAC 配置server端TAF, 测试失败, 查不出什么原因
- ORA-28547: 连接服务器失败, 可能是 Oracle Net 管理错误 的原因是什么?
- 在SQL Server中出现 “无法打开用户默认数据库,登录失败” 是什么原因?4046错误
- winscp连接linux时提示连接失败OOPS:cannot change directory:/home/....什么的原因以及解决方案
- strcpy()失败的原因是什么?
- mysql 安装到最后一步时,start service 为失败状态 请问是什么原因
- “一键制作启动u盘失败”的主要原因是什么?
- flash builder 启动ios模拟器失败是什么原因?
- 关于对话框DoModal()函数调用失败的原因分析(Debug Assertion Failed)
- Spring task @Async执行失败原因分析
- springdata和elasticsearch整合时报错,这是什么原因???