龙马谷

 找回密码
 立即注册

QQ登录

只需一步,快速开始

龙马谷VIP会员办理客服QQ:82926983(如果临时会话没有收到回复,请先加QQ好友再发。)
1 [已完结] GG修改器新手入门与实战教程 31课 2 [已完结] GG修改器美化修改教程 6课 3 [已完结] GG修改器Lua脚本新手入门教程 12课
4 [已完结] 触动精灵脚本新手入门必学教程 22课 5 [已完结] 手游自动化脚本入门实战教程 9课 6 [已完结] C++射击游戏方框骨骼透视与自瞄教程 27课
7 [已完结] C++零基础UE4逆向开发FPS透视自瞄教程 29课 8 [已完结] C++零基础大漠模拟器手游自动化辅助教程 22课 9 [已完结] C++零基础开发DXF内存脚本辅助教程 32课
以下是天马阁VIP教程,本站与天马阁合作,赞助VIP可以获得天马阁对应VIP会员,名额有限! 点击进入天马阁论坛
1 [已完结] x64CE与x64dbg入门基础教程 7课 2 [已完结] x64汇编语言基础教程 16课 3 [已完结] x64辅助入门基础教程 9课
4 [已完结] C++x64内存辅助实战技术教程 149课 5 [已完结] C++x64内存检测与过检测技术教程 10课 6 [已完结] C+x64二叉树分析遍历与LUA自动登陆教程 19课
7 [已完结] C++BT功能原理与x64实战教程 29课 8 [已完结] C+FPS框透视与自瞄x64实现原理及防护思路
查看: 7593|回复: 0

内核遍历R3进程模块 获取信息(32,64,WoW64)

[复制链接]

14

主题

3

回帖

22

积分

编程入门

Rank: 1

龙马币
48

没什么技术含量,只是突然用到了,然后写出来,又突然想到看流星了,然后又发上来,

一想到长期潜水,看帖不回就羞愧的不要不要的;


  1. //通过进程PID来获取目标模块路径;
  2. NTSTATUS GetModulesPathByProcessID (IN HANDLE ProcessId, IN WCHAR* ModuleName, OUT WCHAR* ModulesPath) {
  3.     typedef PPEB (__stdcall * pfn_PsGetProcessPeb) (PEPROCESS pEProcess);
  4.     typedef PPEB32 (__stdcall * pfn_PsGetProcessWow64Process) (PEPROCESS Process);
  5.     NTSTATUS nStatus;
  6.     KAPC_STATE KAPC = { 0 };
  7.     PEPROCESS  pEProcess = NULL; //EPROCESS结构指针;
  8.     PPEB pPEB = NULL; //PEB结构指针;
  9.     UNICODE_STRING uniFunctionName; //查找的函数名称;
  10.     PLDR_DATA_TABLE_ENTRY pLdrDataEntry = NULL; //LDR链表入口;
  11.     PLIST_ENTRY pListEntryStart = NULL; //链表头节点、尾节点;
  12.     PLIST_ENTRY pListEntryEnd = NULL;
  13.     //函数指针;
  14.     pfn_PsGetProcessPeb  PsGetProcessPeb = NULL;
  15.     //获取进程的EPROCESS结构指针;
  16.     nStatus = PsLookupProcessByProcessId (ProcessId, &pEProcess);
  17.     if (!NT_SUCCESS (nStatus)) {
  18.         return STATUS_UNSUCCESSFUL;
  19.     }
  20.     //查找函数地址;
  21.     RtlInitUnicodeString (&uniFunctionName, L"PsGetProcessPeb");
  22.     PsGetProcessPeb = (pfn_PsGetProcessPeb) (SIZE_T)MmGetSystemRoutineAddress (&uniFunctionName);
  23.     pPEB = PsGetProcessPeb (pEProcess);
  24.     KeStackAttachProcess (pEProcess, &KAPC);
  25.     pListEntryStart = pPEB->Ldr->InMemoryOrderModuleList.Flink;
  26.     pListEntryEnd = pPEB->Ldr->InMemoryOrderModuleList.Flink;
  27.     do {//输出DLL全路径;
  28.         pLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD (pListEntryStart, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
  29.         //KdPrint (("module:%wZ\n", &pLdrDataEntry->BaseDllName));
  30.         if (_wcsicmp (pLdrDataEntry->BaseDllName.Buffer, ModuleName) == 0) {
  31.             wcscpy (ModulesPath, pLdrDataEntry->FullDllName.Buffer);
  32.             goto end;
  33.         }
  34.         pListEntryStart = pListEntryStart->Flink;
  35.     } while (pListEntryStart != pListEntryEnd);
  36. #ifdef _AMD64_// 或wow64进程;
  37.     PPEB32 pPEB32 = NULL; //PEB结构指针;
  38.     PLDR_DATA_TABLE_ENTRY32 pLdrDataEntry32 = NULL; //LDR链表入口;
  39.     PLIST_ENTRY32 pListEntryStart32 = NULL; //链表头节点、尾节点;
  40.     PLIST_ENTRY32 pListEntryEnd32 = NULL;
  41.     //函数指针;
  42.     pfn_PsGetProcessWow64Process PsGetProcessWow64Process = NULL;
  43.     RtlInitUnicodeString (&uniFunctionName, L"PsGetProcessWow64Process");
  44.     PsGetProcessWow64Process = (pfn_PsGetProcessWow64Process) (SIZE_T)MmGetSystemRoutineAddress (&uniFunctionName);
  45.     //获取PEB指针
  46.     pPEB32 = PsGetProcessWow64Process (pEProcess);
  47.     pListEntryStart32 = (PLIST_ENTRY32) (((PEB_LDR_DATA32*)pPEB32->Ldr)->InMemoryOrderModuleList.Flink);
  48.     pListEntryEnd32 = (PLIST_ENTRY32) (((PEB_LDR_DATA32*)pPEB32->Ldr)->InMemoryOrderModuleList.Flink);
  49.     do {//输出DLL全路径;
  50.         pLdrDataEntry32 = (PLDR_DATA_TABLE_ENTRY32)CONTAINING_RECORD (pListEntryStart32, LDR_DATA_TABLE_ENTRY32, InMemoryOrderLinks);
  51.         //KdPrint (("wow64:%ws\n", pLdrDataEntry32->BaseDllName.Buffer));
  52.         if (_wcsicmp ((WCHAR*)pLdrDataEntry32->BaseDllName.Buffer, ModuleName) == 0) {
  53.             wcscpy (ModulesPath, (WCHAR*)pLdrDataEntry32->FullDllName.Buffer);
  54.             goto end;
  55.         }
  56.         pListEntryStart32 = (PLIST_ENTRY32)pListEntryStart32->Flink;
  57.     } while (pListEntryStart32 != pListEntryEnd32);
  58. #endif
  59. end:
  60.     KeUnstackDetachProcess (&KAPC);
  61.     ObDereferenceObject (pEProcess);
  62.     return STATUS_SUCCESS;
  63. }
复制代码


附上用到的几个结构
  1. typedef struct _PEB {
  2.     UCHAR InheritedAddressSpace;
  3.     UCHAR ReadImageFileExecOptions;
  4.     UCHAR BeingDebugged;
  5.     UCHAR Spare;
  6.     PVOID Mutant;
  7.     PVOID ImageBaseAddress;
  8.     PPEB_LDR_DATA Ldr;
  9.     PRTL_USER_PROCESS_PARAMETERS  ProcessParameters;
  10.     PVOID SubSystemData;
  11. } PEB, *PPEB;
  12. //专为WoW64准备;
  13. typedef struct _PEB32 {
  14.     UCHAR InheritedAddressSpace;
  15.     UCHAR ReadImageFileExecOptions;
  16.     UCHAR BeingDebugged;
  17.     UCHAR Spare;
  18.     ULONG Mutant;
  19.     ULONG ImageBaseAddress;
  20.     ULONG/*PPEB_LDR_DATA32*/ Ldr;
  21. } PEB32, *PPEB32;

  22. typedef struct _PEB_LDR_DATA {
  23.     ULONG Length;
  24.     UCHAR Initialized;
  25.     PVOID SsHandle;
  26.     LIST_ENTRY InLoadOrderModuleList;
  27.     LIST_ENTRY InMemoryOrderModuleList;
  28.     LIST_ENTRY InInitializationOrderModuleList;
  29.     PVOID EntryInProgress;
  30. } PEB_LDR_DATA, *PPEB_LDR_DATA;
  31. //专为WoW64准备;
  32. typedef struct _PEB_LDR_DATA32 {
  33.     ULONG Length;
  34.     UCHAR Initialized;
  35.     ULONG SsHandle;
  36.     LIST_ENTRY32 InLoadOrderModuleList;
  37.     LIST_ENTRY32 InMemoryOrderModuleList;
  38.     LIST_ENTRY32 InInitializationOrderModuleList;
  39.     ULONG EntryInProgress;
  40. } PEB_LDR_DATA32, *PPEB_LDR_DATA32;

  41. typedef struct _LDR_DATA_TABLE_ENTRY {
  42.     LIST_ENTRY InLoadOrderLinks;
  43.     LIST_ENTRY InMemoryOrderLinks;
  44.     LIST_ENTRY InInitializationOrderLinks;
  45.     PVOID DllBase;
  46.     PVOID EntryPoint;
  47.     ULONG SizeOfImage;
  48.     UNICODE_STRING FullDllName;
  49.     UNICODE_STRING BaseDllName;
  50.     ULONG Flags;
  51.     USHORT LoadCount;
  52.     USHORT TlsIndex;
  53.     LIST_ENTRY HashLinks;
  54.     PVOID SectionPointer;
  55.     ULONG CheckSum;
  56.     ULONG TimeDateStamp;
  57.     PVOID LoadedImports;
  58.     PVOID EntryPointActivationContext;
  59.     PVOID PatchInformation;
  60.     LIST_ENTRY ForwarderLinks;
  61.     LIST_ENTRY ServiceTagLinks;
  62.     LIST_ENTRY StaticLinks;
  63.     PVOID ContextInformation;
  64.     PVOID OriginalBase;
  65.     LARGE_INTEGER LoadTime;
  66. } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
  67. //专为WoW64准备;
  68. typedef struct _LDR_DATA_TABLE_ENTRY32 {
  69.     LIST_ENTRY32 InLoadOrderLinks;
  70.     LIST_ENTRY32 InMemoryOrderLinks;
  71.     LIST_ENTRY32 InInitializationOrderLinks;
  72.     ULONG DllBase;
  73.     ULONG EntryPoint;
  74.     ULONG SizeOfImage;
  75.     UNICODE_STRING32 FullDllName;
  76.     UNICODE_STRING32 BaseDllName;
  77.     ULONG Flags;
  78.     USHORT LoadCount;
  79.     USHORT TlsIndex;
  80.     LIST_ENTRY32 HashLinks;
  81.     ULONG SectionPointer;
  82.     ULONG CheckSum;
  83.     ULONG TimeDateStamp;
  84.     ULONG LoadedImports;
  85.     ULONG EntryPointActivationContext;
  86.     ULONG PatchInformation;
  87.     LIST_ENTRY32 ForwarderLinks;
  88.     LIST_ENTRY32 ServiceTagLinks;
  89.     LIST_ENTRY32 StaticLinks;
  90.     ULONG ContextInformation;
  91.     ULONG OriginalBase;
  92.     LARGE_INTEGER LoadTime;
  93. } LDR_DATA_TABLE_ENTRY32, *PLDR_DATA_TABLE_ENTRY32;
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

龙马谷| C/C++辅助教程| 安卓逆向安全| 论坛导航| 免责申明|Archiver|
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表龙马谷立场!
任何人不得以任何方式翻录、盗版或出售本站视频,一经发现我们将追究其相关责任!
我们一直在努力成为最好的编程论坛!
Copyright© 2018-2021 All Right Reserved.
在线客服
快速回复 返回顶部 返回列表