Application.exe + 000000 Read Memorry - PullRequest
0 голосов
/ 06 июля 2018

Итак, как вы можете видеть, у меня возникли проблемы с получением базового адреса .exe.

В данном случае, скажем, это был Tutorial-x86_64.exe

Как получить адрес процесса?

Надеюсь, что кто-нибудь может помочь.

Ответы [ 2 ]

0 голосов
/ 25 мая 2019
using System.Diagnostics;
using System.Linq;

public IntPtr GetModuleBaseAddress(string processName, string moduleName)
{
    // Get an instance of the specified process
    Process process;

    try
    {
        process = Process.GetProcessesByName(processName)[0];
    }

    catch (IndexOutOfRangeException)
    {
        // The process isn't currently running
        throw new ArgumentException($"No process with name {processName} is currently running");
    }

    // Get an instance of the specified module in the process
    // We use linq here to avoid unnecesary for loops
    var module = process.Modules.Cast<ProcessModule>().SingleOrDefault(m => string.Equals(m.ModuleName, moduleName, StringComparison.OrdinalIgnoreCase));

    //Return IntPtr.Zero if the module doesn't exist in the process
    return module?.BaseAddress ?? IntPtr.Zero;
}



var modBaseAddress = GetModuleBaseAddress("Tutorial-x86_64.exe", "Tutorial-x86_64.exe");
0 голосов
/ 06 июля 2018
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Tutorial-x86_64"); 

int base = processes[0].MainModule.BaseAddress.ToInt32(); 

Вы также можете получить EntryPoint

int base_adr = processes[0].MainModule.EntryPointAddress.ToInt32();
int height_offset = 0x0007E1BC; //some address example

int height_adr = (IntPtr)(base_adr + height_offset); 

Вот еще одна функция.

   private static IntPtr GetModuleBaseAddress(string AppName, string ModuleName) 
    { 
        IntPtr BaseAddress = IntPtr.Zero; 
        Process[] myProcess = null; 
        ProcessModule myProcessModule = null; 

        myProcess = Process.GetProcessesByName(AppName); 

        if (myProcess.Length > 0) 
        { 
            ProcessModuleCollection myProcessModuleCollection; 

            try 
            { 
                myProcessModuleCollection = myProcess[0].Modules; 
            } 
            catch { return IntPtr.Zero; /*Maybe would be ok show the exception after/instead return*/ } 

            for (int i = 0; i < myProcessModuleCollection.Count; i++) 
            { 
                myProcessModule = myProcessModuleCollection[i]; 
                if (myProcessModule.ModuleName.Contains(ModuleName)) 
                { 
                    BaseAddress = myProcessModule.BaseAddress; 
                    break; 
                } 
            } 
        } 

        return BaseAddress; 
    }
...