1. 程式人生 > >核心遍歷r3程序模組,獲取資訊(32,64,WoW64)

核心遍歷r3程序模組,獲取資訊(32,64,WoW64)

沒什麼技術含量,只是突然用到了,然後寫出來,又突然想到看雪了,然後又發上來,
一想到長期潛水,看帖不回就羞愧的不要不要的;


//通過程序PID來獲取目標模組路徑;
NTSTATUS GetModulesPathByProcessID (IN HANDLE ProcessId, IN WCHAR* ModuleName, OUT WCHAR* ModulesPath) {
    typedef PPEB (__stdcall * pfn_PsGetProcessPeb) (PEPROCESS pEProcess);
    typedef PPEB32 (__stdcall * pfn_PsGetProcessWow64Process) (PEPROCESS Process);

    NTSTATUS nStatus;
    KAPC_STATE KAPC = { 0 };
    PEPROCESS  pEProcess = NULL; //EPROCESS結構指標;
    PPEB pPEB = NULL; //PEB結構指標;
    UNICODE_STRING uniFunctionName; //查詢的函式名稱;
    PLDR_DATA_TABLE_ENTRY pLdrDataEntry = NULL; //LDR連結串列入口;
    PLIST_ENTRY pListEntryStart = NULL; //連結串列頭節點、尾節點;
    PLIST_ENTRY pListEntryEnd = NULL;

    //函式指標;
    pfn_PsGetProcessPeb  PsGetProcessPeb = NULL;
    //獲取程序的EPROCESS結構指標;
    nStatus = PsLookupProcessByProcessId (ProcessId, &pEProcess);
    if (!NT_SUCCESS (nStatus)) {
        return STATUS_UNSUCCESSFUL;
    }
    //查詢函式地址;
    RtlInitUnicodeString (&uniFunctionName, L"PsGetProcessPeb");
    PsGetProcessPeb = (pfn_PsGetProcessPeb) (SIZE_T)MmGetSystemRoutineAddress (&uniFunctionName);

    pPEB = PsGetProcessPeb (pEProcess);
    KeStackAttachProcess (pEProcess, &KAPC);
    pListEntryStart = pPEB->Ldr->InMemoryOrderModuleList.Flink;
    pListEntryEnd = pPEB->Ldr->InMemoryOrderModuleList.Flink;
    do {//輸出DLL全路徑;
        pLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD (pListEntryStart, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
        //KdPrint (("module:%wZ\n", &pLdrDataEntry->BaseDllName));
        if (_wcsicmp (pLdrDataEntry->BaseDllName.Buffer, ModuleName) == 0) {
            wcscpy (ModulesPath, pLdrDataEntry->FullDllName.Buffer);
            goto end;
        }
        pListEntryStart = pListEntryStart->Flink;
    } while (pListEntryStart != pListEntryEnd);
#ifdef _AMD64_// 或wow64程序;
    PPEB32 pPEB32 = NULL; //PEB結構指標;
    PLDR_DATA_TABLE_ENTRY32 pLdrDataEntry32 = NULL; //LDR連結串列入口;
    PLIST_ENTRY32 pListEntryStart32 = NULL; //連結串列頭節點、尾節點;
    PLIST_ENTRY32 pListEntryEnd32 = NULL;
    //函式指標;
    pfn_PsGetProcessWow64Process PsGetProcessWow64Process = NULL;
    RtlInitUnicodeString (&uniFunctionName, L"PsGetProcessWow64Process");
    PsGetProcessWow64Process = (pfn_PsGetProcessWow64Process) (SIZE_T)MmGetSystemRoutineAddress (&uniFunctionName);
    //獲取PEB指標
    pPEB32 = PsGetProcessWow64Process (pEProcess);
    pListEntryStart32 = (PLIST_ENTRY32) (((PEB_LDR_DATA32*)pPEB32->Ldr)->InMemoryOrderModuleList.Flink);
    pListEntryEnd32 = (PLIST_ENTRY32) (((PEB_LDR_DATA32*)pPEB32->Ldr)->InMemoryOrderModuleList.Flink);
    do {//輸出DLL全路徑;
        pLdrDataEntry32 = (PLDR_DATA_TABLE_ENTRY32)CONTAINING_RECORD (pListEntryStart32, LDR_DATA_TABLE_ENTRY32, InMemoryOrderLinks);
        //KdPrint (("wow64:%ws\n", pLdrDataEntry32->BaseDllName.Buffer));
        if (_wcsicmp ((WCHAR*)pLdrDataEntry32->BaseDllName.Buffer, ModuleName) == 0) {
            wcscpy (ModulesPath, (WCHAR*)pLdrDataEntry32->FullDllName.Buffer);
            goto end;
        }
        pListEntryStart32 = (PLIST_ENTRY32)pListEntryStart32->Flink;
    } while (pListEntryStart32 != pListEntryEnd32);
#endif
end:
    KeUnstackDetachProcess (&KAPC);
    ObDereferenceObject (pEProcess);
    return STATUS_SUCCESS;
}





附上用到的幾個結構
typedef struct _PEB {
    UCHAR InheritedAddressSpace;
    UCHAR ReadImageFileExecOptions;
    UCHAR BeingDebugged;
    UCHAR Spare;
    PVOID Mutant;
    PVOID ImageBaseAddress;
    PPEB_LDR_DATA Ldr;
    PRTL_USER_PROCESS_PARAMETERS  ProcessParameters;
    PVOID SubSystemData;
} PEB, *PPEB;
//專為WoW64準備;
typedef struct _PEB32 {
    UCHAR InheritedAddressSpace;
    UCHAR ReadImageFileExecOptions;
    UCHAR BeingDebugged;
    UCHAR Spare;
    ULONG Mutant;
    ULONG ImageBaseAddress;
    ULONG/*PPEB_LDR_DATA32*/ Ldr;
} PEB32, *PPEB32;

typedef struct _PEB_LDR_DATA {
    ULONG Length;
    UCHAR Initialized;
    PVOID SsHandle;
    LIST_ENTRY InLoadOrderModuleList;
    LIST_ENTRY InMemoryOrderModuleList;
    LIST_ENTRY InInitializationOrderModuleList;
    PVOID EntryInProgress;
} PEB_LDR_DATA, *PPEB_LDR_DATA;
//專為WoW64準備;
typedef struct _PEB_LDR_DATA32 {
    ULONG Length;
    UCHAR Initialized;
    ULONG SsHandle;
    LIST_ENTRY32 InLoadOrderModuleList;
    LIST_ENTRY32 InMemoryOrderModuleList;
    LIST_ENTRY32 InInitializationOrderModuleList;
    ULONG EntryInProgress;
} PEB_LDR_DATA32, *PPEB_LDR_DATA32;

typedef struct _LDR_DATA_TABLE_ENTRY {
    LIST_ENTRY InLoadOrderLinks;
    LIST_ENTRY InMemoryOrderLinks;
    LIST_ENTRY InInitializationOrderLinks;
    PVOID DllBase;
    PVOID EntryPoint;
    ULONG SizeOfImage;
    UNICODE_STRING FullDllName;
    UNICODE_STRING BaseDllName;
    ULONG Flags;
    USHORT LoadCount;
    USHORT TlsIndex;
    LIST_ENTRY HashLinks;
    PVOID SectionPointer;
    ULONG CheckSum;
    ULONG TimeDateStamp;
    PVOID LoadedImports;
    PVOID EntryPointActivationContext;
    PVOID PatchInformation;
    LIST_ENTRY ForwarderLinks;
    LIST_ENTRY ServiceTagLinks;
    LIST_ENTRY StaticLinks;
    PVOID ContextInformation;
    PVOID OriginalBase;
    LARGE_INTEGER LoadTime;
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
//專為WoW64準備;
typedef struct _LDR_DATA_TABLE_ENTRY32 {
    LIST_ENTRY32 InLoadOrderLinks;
    LIST_ENTRY32 InMemoryOrderLinks;
    LIST_ENTRY32 InInitializationOrderLinks;
    ULONG DllBase;
    ULONG EntryPoint;
    ULONG SizeOfImage;
    UNICODE_STRING32 FullDllName;
    UNICODE_STRING32 BaseDllName;
    ULONG Flags;
    USHORT LoadCount;
    USHORT TlsIndex;
    LIST_ENTRY32 HashLinks;
    ULONG SectionPointer;
    ULONG CheckSum;
    ULONG TimeDateStamp;
    ULONG LoadedImports;
    ULONG EntryPointActivationContext;
    ULONG PatchInformation;
    LIST_ENTRY32 ForwarderLinks;

相關推薦

核心r3程序模組,獲取資訊(32,64,WoW64)

沒什麼技術含量,只是突然用到了,然後寫出來,又突然想到看雪了,然後又發上來,一想到長期潛水,看帖不回就羞愧的不要不要的;//通過程序PID來獲取目標模組路徑;NTSTATUS GetModulesPathByProcessID (IN HANDLE ProcessId, I

xml-使用dom去xml檔案和獲取指定節點資訊

classes.xml:<?xml version="1.0" encoding="utf-8" ?> <class> <stu hobby="read"> <name>楊過</name> <sex>

shell-所有txt,並且獲取txt指定的內容

[[email protected] ~]$ cat get_manager_ip.sh  #!/bin/bash# Filename: get_manager_ip.sh# Description: 指令碼包括兩個功能:# 1,獲取各個產品的manager的ip# 2,check各個產

Python:目錄--利用glob模組

#!/usr/bin/env python # coding:UTF-8 """ @version: python3.x @author:曹新健 @contact: [email protected] @software: PyCharm @file: glob模組.py @time:

Linux核心—— net_device 結構

linux核心版本 : 2.6.32<=(這個更早的也許就已經這樣了,具體是從哪個版本開始的,我沒有考證,需要在今後,發現後及時補充。) extern struct net *init_net; /* 存放net_device的全域性變數 */ extern rwl

Python指令碼- 遞迴資料夾,獲取指定副檔名檔案,修改檔案內容

#USAGE: # 1、Choose file path # 2、Choose file type (according to extension name) # 3、Judging condition # 4、The content to insert # 5、Print file pat

串列埠程式設計-列舉串列埠、獲取PC所有串列埠名稱、登錄檔項、RegEnumValue用法

在網上找了幾個關於遍歷串列埠的例子,要麼程式碼不完整,要麼就有Bug,如讀不了串列埠號大於10以上的。  經過本人的整理,現分享最終程式碼,vs2008下編譯通過。  //此方法同樣適用於遍歷windows開機啟動項,只需稍加修改即可.  ? 1 2 3 4 5 6

java複雜json字串獲取想要的資料

https://blog.csdn.net/qq_34309663/article/details/80508125     java如何解析複雜的json資料關於json處理的包有好幾個,比如jackson、Gson、Fastjson。Gson是谷歌做的,功能強大;Fastjson

關於jslist集合,獲取select選中的值以及動態新增option

1,js遍歷list集合 js不能直接遍歷list集合,可以在後臺中將list集合封裝成json格式 封裝格式 JSONArray jsonArray = JSONArray.fromObject( list ); 然後在ajax中遍歷json格式的資料 jQuery.e

指定程序名窗口上的所有控件

inter equal getclass app first acc sum user dllimport using System; using System.Collections.Generic; using System.ComponentModel; using

c++ 後臺程序,並關閉相關程序

                                關閉後臺QQint CMainFrame::AutoSsrStop()             //*遍歷後臺程序,關閉相關程序。{char c[]={"connect.exe"};HANDLE handle; HANDLE handle1;ha

js for in循環對象,獲取key:value值

ole con info 循環 對象 test bsp 技術 inf var testObj = { ‘a‘:‘111‘, ‘b‘:‘222‘, ‘c‘:‘333‘, ‘d‘:‘444‘}for(var i in testObj){ console.log(i);

核心模組程序和任務佇列儲存到proc檔案中

實現一個模組用它遍歷當前程序的父程序和任務佇列,並將遍歷的結果輸出到一個proc 檔案中(遍歷可以從 current 當前程序開始,父程序遍歷到初始化程序,遍歷任務佇列可以利用 for_each_process 巨集)。 下面是我的核心模組的實現部分:

編寫核心模組程序的PID

#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/sched.h> #include <

作業系統程序(進入linux核心實現)

實驗要求概述: Part I—Iterating over Tasks Linearly As illustrated in Section 3.1, the PCB in Linux is represented by the structure task_struct, whic

C#獲取檔案資訊匯出至EXCEL

記錄八月份寫的一個小工具,當需要處理的很多資料在檔名中存在時, 1,使用Directory類下的GetDirectories方法根據檔案地址開啟檔案獲取目錄。 2,然後再使用DirectoryInfo類下的GetFiles獲取具體檔案。 3,根據具體檔案獲取檔名,大小等資訊。 4,匯出至EX

Qt總結之二:資料夾和檔案目錄,並過濾和獲取檔案資訊、字尾名、字首名(二)

前言 需要在特定目錄或磁碟下查詢特定檔案 一、篩選目錄 (一)單一目錄下遍歷,篩選特定檔案 QDir dir("./SaveFiles"); QFileInfoList list = dir.entryInfoList(); (二)裝置所有磁碟中遍歷 QF

Qt總結之一:資料夾和檔案目錄,並過濾和獲取檔案資訊、字尾名、字首名(一)

一、採用遞迴和QDir實現資料夾下所有檔案遍歷的方法 #include <QDir> bool FindFile(const QString & path) {     QDir dir(path);   if (!dir.exists(

Qt總結之三:磁碟檔案操作、資料夾和檔案目錄,並過濾和獲取檔案資訊、字尾名、字首名(三)

前言 本節內容主要包括磁碟容量檢測、磁碟內指定或特定檔案的操作 話不多說,先上效果圖 共分為兩個部分,第一部分是檢測磁碟容量,第二部分是篩選磁碟內指定檔案(test.txt)或特定檔案(.txt / .png型別檔案) 獲取磁碟容量關鍵函式:【fileapi.h】 

Qt實現資料夾和檔案目錄,並過濾和獲取檔案資訊、字尾名、字首名(三)

下面是自己的實際工作中寫的程式碼,請大家斧正#ifndefINQUIRYDIALOG_H#defineINQUIRYDIALOG_H#include<QDialog>#include<QFileDialog>#include<QDir>#i