- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试编写一个 APC dll 注入(inject)驱动程序,我找到了 this示例并考虑根据我的需要对其进行修改。
在我理解了代码之后,我想到了如何修改它(我的问题由此而来)。
在code ,作者使用了PsLookupThreadByThreadId接收指向目标进程的 ETHREAD 结构的引用指针。
PsLookupThreadByThreadId(pSpi->Threads[0].ClientId.UniqueThread,&Thread)
但要得到 SYSTEM_THREAD_INFORMATION对于UniqueThread handle ,他用过ZwQuerySystemInformation
我想在加载 ntdll 后立即加载我的 dll,所以我想使用 PsSetCreateProcessNotifyRoutineEx并保存 UniqueThread来自 PS_CREATE_NOTIFY_INFO当我的目标进程调用回调时,我得到了。
在加载 ntdll 之后,我会知道这要感谢 PsSetLoadImageNotifyRoutineEx我可以使用他的 APC 注入(inject)逻辑注入(inject)我的 dll。
我的目标是将我的 dll 注入(inject) PloadImageNotifyRoutine回调,但不要使用 ZwQuerySystemInformation正如他为获得 UniqueThread 所做的那样, 但将其保存在 PcreateProcessNotifyRoutineEx 中回调。
因此,我的问题是:我可以信任 UniqueThread 吗?我从 PS_CREATE_NOTIFY_INFO 得到在所有进程加载时间内是否相同?
最佳答案
I want to use
PsSetCreateProcessNotifyRoutineEx
and save theUniqueThread
from thePS_CREATE_NOTIFY_INFO
I got when the callback is called for the process I'm targeting.
关于 CreatingThreadId
来自 PS_CREATE_NOTIFY_INFO
The process ID and thread ID of the process and thread that created the new process
此 id 不是针对新创建的进程/线程,而是针对创建者。如果你想在 PloadImageNotifyRoutine
回调中注入(inject)自己的 dll - PcreateProcessNotifyRoutineEx
对你没用。
图像映射到目标进程时调用的 PloadImageNotifyRoutine
- 内部 ZwMapViewOfSection
.您需要检查 ProcessId
(PcreateProcessNotifyRoutineEx
的第二个参数 - 加载图像的进程的进程 ID)是否等于 PsGetCurrentProcessId()
.这意味着图像已加载到当前进程,您可以使用 KeGetCurrentThread()
- 你根本不需要PsLookupThreadByThreadId
I want to load my dll right after ntdll is loaded
此刻,任何用户模式结构都在处理中,但尚未初始化。因为它是由 ntdll 初始化的。结果 - 如果你注入(inject)你的 apc 并在此时强制执行它 - 你会遇到进程崩溃。仅此而已
我可以建议您在加载 kernel32.dll 时注入(inject)您的 dll。在这里你需要检查这是作为 dll 加载,而不仅仅是图像映射 - 检查线程 teb 中的 ArbitraryUserPointer
- 它是否指向 L"*\\kernel32.dll"
: smss.exe 在创建 \\KnownDlls
期间映射 kernel32.dll (在本例中为 ArbitraryUserPointer == 0
) , wow64 处理多个时间映射 kernel32.dll(32 位和 64 位),L"WOW64_IMAGE_SECTION"
或 L"NOT_AN_IMAGE"
名称在 任意用户指针
关于Windows 内核驱动程序 : Does the "HANDLE UniqueThread" in "CLIENT_ID CreatingThreadId" is the same during the process loading?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50304383/
我是一名优秀的程序员,十分优秀!