当前位置:网站首页>APC(三)
APC(三)
2022-04-22 06:19:00 【Misaka10046】
内核APC插入
VOID KeInitializeApc (
__out PRKAPC Apc, //输出APC
__in PRKTHREAD Thread, //要插入的线程
__in KAPC_ENVIRONMENT Environment, //APC的线程环境
__in PKKERNEL_ROUTINE KernelRoutine, //内核函数
__in_opt PKRUNDOWN_ROUTINE RundownRoutine, //特殊函数
__in_opt PKNORMAL_ROUTINE NormalRoutine, //一般函数
__in_opt KPROCESSOR_MODE ApcMode, //用户APC还是内核APC
__in_opt PVOID NormalContext //传的参数
) //初始化APC
typedef enum _KAPC_ENVIRONMENT {
OriginalApcEnvironment, //原始进程环境
AttachedApcEnvironment, //插入后的进程环境
CurrentApcEnvironment,
InsertApcEnvironment
} KAPC_ENVIRONMENT;
#include<ntifs.h>
typedef enum _KAPC_ENVIRONMENT {
OriginalApcEnvironment,
AttachedApcEnvironment,
CurrentApcEnvironment,
InsertApcEnvironment
} KAPC_ENVIRONMENT;
typedef VOID(*PKNORMAL_ROUTINE) (
IN PVOID NormalContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2
);
typedef VOID(*PKKERNEL_ROUTINE) (
IN struct _KAPC* Apc,
IN OUT PKNORMAL_ROUTINE* NormalRoutine,
IN OUT PVOID* NormalContext,
IN OUT PVOID* SystemArgument1,
IN OUT PVOID* SystemArgument2
);
typedef VOID(*PKRUNDOWN_ROUTINE) (
IN struct _KAPC* Apc
);
VOID KeInitializeApc(
__out PRKAPC Apc,
__in PRKTHREAD Thread,
__in KAPC_ENVIRONMENT Environment,
__in PKKERNEL_ROUTINE KernelRoutine,
__in_opt PKRUNDOWN_ROUTINE RundownRoutine,
__in_opt PKNORMAL_ROUTINE NormalRoutine,
__in_opt KPROCESSOR_MODE ApcMode,
__in_opt PVOID NormalContext
);
BOOLEAN KeInsertQueueApc(
__inout PRKAPC Apc,
__in_opt PVOID SystemArgument1,
__in_opt PVOID SystemArgument2,
__in KPRIORITY Increment
); //未文档化手动导入
VOID kernelRoutineFunc(
IN struct _KAPC* Apc, IN OUT PKNORMAL_ROUTINE* NormalRoutine, IN OUT PVOID* NormalContext, IN OUT PVOID* SystemArgument1, IN OUT PVOID* SystemArgument2
)
{
DbgPrintEx(77, 0, "kernelRoutineFunc\r\n");
ExFreePool(Apc);//释放APC
}
VOID DriverUnload(PDRIVER_OBJECT pDriver) {
DbgPrintEx(77, 0, "Exit");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pReg) {
PKAPC pApc = ExAllocatePool(NonPagedPool, sizeof(KAPC));
memset(pApc, 0, sizeof(KAPC));
KeInitializeApc(pApc, //APC的值
KeGetCurrentThread(), //当前线程
OriginalApcEnvironment,//环境
kernelRoutineFunc, //kernel函数 插入就立即调用
NULL,
NULL, //特殊函数和一般函数都不是必须的
KernelMode, //内核APC
NULL);
//初始化APC
KeInsertQueueApc(pApc, NULL, NULL, 0);//当前线程插入APC
DbgPrintEx(77, 0, "-----------------------\r\n");
pDriver->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}

插入其他线程
#include<ntifs.h>
typedef enum _KAPC_ENVIRONMENT {
OriginalApcEnvironment,
AttachedApcEnvironment,
CurrentApcEnvironment,
InsertApcEnvironment
} KAPC_ENVIRONMENT;
typedef VOID(*PKNORMAL_ROUTINE) (
IN PVOID NormalContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2
);
typedef VOID(*PKKERNEL_ROUTINE) (
IN struct _KAPC* Apc,
IN OUT PKNORMAL_ROUTINE* NormalRoutine,
IN OUT PVOID* NormalContext,
IN OUT PVOID* SystemArgument1,
IN OUT PVOID* SystemArgument2
);
typedef VOID(*PKRUNDOWN_ROUTINE) (
IN struct _KAPC* Apc
);
VOID KeInitializeApc(
__out PRKAPC Apc,
__in PRKTHREAD Thread,
__in KAPC_ENVIRONMENT Environment,
__in PKKERNEL_ROUTINE KernelRoutine,
__in_opt PKRUNDOWN_ROUTINE RundownRoutine,
__in_opt PKNORMAL_ROUTINE NormalRoutine,
__in_opt KPROCESSOR_MODE ApcMode,
__in_opt PVOID NormalContext
);
BOOLEAN KeInsertQueueApc(
__inout PRKAPC Apc,
__in_opt PVOID SystemArgument1,
__in_opt PVOID SystemArgument2,
__in KPRIORITY Increment
);
VOID kernelRoutineFunc(
IN struct _KAPC* Apc, IN OUT PKNORMAL_ROUTINE* NormalRoutine, IN OUT PVOID* NormalContext, IN OUT PVOID* SystemArgument1, IN OUT PVOID* SystemArgument2
)
{
DbgPrintEx(77, 0, "kernelRoutineFunc\r\n");
ExFreePool(Apc);
}
VOID NormalRoutineFunc(
IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2
)
{
DbgPrintEx(77, 0, "NormalRoutineFunc\r\n");
}
VOID DriverUnload(PDRIVER_OBJECT pDriver) {
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING pReg) {
PKAPC pApc = ExAllocatePool(NonPagedPool, sizeof(KAPC));
memset(pApc, 0, sizeof(KAPC));
PETHREAD eThread = NULL;
PsLookupThreadByThreadId(852, &eThread);//传入线程ID获取其结构体指针
DbgPrintEx(77, 0, "---------main pid = %d--------------\r\n", PsGetCurrentProcessId());//当前线程的进程ID
KeInitializeApc(pApc, eThread, OriginalApcEnvironment,/*最后还是要返回当前线程所以还是这个值*/
kernelRoutineFunc, NULL, NormalRoutineFunc/*一般函数表*/, KernelMode, NULL);
KeInsertQueueApc(pApc, NULL, NULL, 0);
DbgPrintEx(77, 0, "-----------------------\r\n");
pDriver->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}

版权声明
本文为[Misaka10046]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Misaka10046/article/details/121643352
边栏推荐
- Codeforces Round #780 (Div. 3)
- L2-001 emergency rescue (extension of shortest Dijkstra - number of shortest paths & maximum weight of paths)
- Hand tearing algorithm -- LRU cache elimination strategy, asked so often
- Detailed overview of this keyword
- 867 · 四键键盘
- [solution] Luogu p6186 [noi online 1 improvement group] bubble sorting: [bubble sorting] and [reverse order pair] problems
- L1-071 前世档案 (20 分) (类似二分)
- E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )
- Codeforces Round #779 (Div. 2)
- LeetCode - 8 - (三数之和、Z字形变换、两数之和<链表>、盛最多水的容器、电话号码的字母组合)
猜你喜欢

Minimum circle coverage (basis of computational geometry)

A. Alice and Bob (game? Thinking & Violence) (2021 Niuke summer multi school training camp 1)

LeetCode - 7 - (二叉树的最近公共祖先、轮转数组、二叉树的直接、下一个排列、组合总和)

The system log file is too large

1005 Monopoly 同余求解(2021中国大学生程序设计竞赛CCPC-网络选拔赛重赛)

D. Determine the photo position (simply find the substring) (2021 Niuke summer multi school training camp 1)

LeetCode -3 - (字符串相加、最大连续1的个数<ⅠⅢ>、考试的最大困扰度、删除链表的倒数第N个结点)

Leetcode - 7 - (nearest common ancestor of binary tree, rotation array, direct of binary tree, next permutation, combined sum)

Leetcode - 5 - (repeated substring < KMP >, longest palindrome substring, transpose matrix, binary tree (left and right) view)

363 · rainwater connection
随机推荐
15. Full arrangement
I.Jam-packed (均分/最大最小值) (2021年度训练联盟热身训练赛第五场)
278 · 绘制填充
843 · Digital Flip
C language | pointer
1232 · 爆破气球的最小箭头数
Kotlin协程+Flow+Retrofit实现网络请求
CF1547E Air Conditioners
D. Determine the photo position (simply find the substring) (2021 Niuke summer multi school training camp 1)
Introduction
抽象类和抽象方法
A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)
D. Determine the Photo Position (简单找子串)(2021牛客暑期多校训练营1)
L2-005 集合相似度(set判重)
B. Ball Dropping (简单几何计算 / 相似三角形) (2021牛客暑期多校训练营1)
HDU Ice_cream‘s world I (并查集判环)
Leetcode - 7 - (nearest common ancestor of binary tree, rotation array, direct of binary tree, next permutation, combined sum)
C language | array
If I make this silly mistake again/ (ㄒoㄒ)/~~
Bom 浏览器对象模型