如何在C#中获得程序地址?

时间:2019-05-19 10:58:29

标签: c# pointers

  

如何获取项目中任何过程的地址? SEE https://github.com/korbaSzael/u-dze-a file gra/Biblioteki.cs or gra/bin/gebug/gra.exe -> Main window->Menu->Pomoc->Biblioteki
  我需要为导出表中的每个条目更正导出地址,因为它为我提供了RVA地址,我需要将其转换为内存地址,然后才能从其他进程和Visual Studio以外的其他编程语言进行远程调用。

I used delegates, Func<> or Action<> like below but it returns address which 
is outside of my loaded into memory program so it is also no use in fixing export tables.

void static myProc(){}
Delegate myDelegate = new Action(myProc);
// GCHandle gch = GCHandle.Alloc(myDelegate);// for nonstatic procedures
IntPtr ptr = Marshal.GetFunctionPointerForDelegate(myDelegate);

如何从加载到我的应用程序内部的导出表中获取内存地址?

  

第二个问题是Visual Studio无法为* .DLL文件设置导入地址表和导出地址表。查看gra / dll并通过单击Biblioteki表单上的ładujbibliotekę按钮将其加载到进程中,然后选择文件gra / dll.dll。然后在上方的组合框中选择dll.dll以查看其详细信息以及导出和导入地址。看到Visual Studio无法设置地址表。如何使Visual Studio填充DLL的导出和导入表?

如果有任何代码可以手动遍历我的程序“导出地址”表,这将有所帮助,因为导出表中应该有所有内存地址,因为我所做的是相对地址,并且不知道如何将其转换为实际内存地址。 / p>

下面是代码:

   DataTable tableExports = null;
    private void bExports_Click(object sender, EventArgs e)
    {
        tableExports = new DataTable();
        tableExports.Columns.Add("export name", typeof(string));
        tableExports.Columns.Add("address", typeof(cAddress));
        tableExports.Columns.Add("size", typeof(cSize));
            IntPtr pHandle = OpenProcess(0x1F0FFF, true, (comboBox2.SelectedItem as cbProcess).id);
            ulong baseOfDll;
            bool status;
            status = SymInitialize(pHandle, null, false);
            baseOfDll = SymLoadModuleEx(pHandle, IntPtr.Zero, (comboBox1.SelectedItem as cbModule).file, null, 0, 0, IntPtr.Zero, 0);
            if (baseOfDll != 0 && SymEnumerateSymbols64(pHandle, baseOfDll, EnumSyms, IntPtr.Zero) != false)
            {
                dataGridView1.DataSource = tableExports;
                (dataGridView1.DataSource as DataTable).DefaultView.Sort = "export name";
            }
            SymCleanup(pHandle);
            CloseHandle(pHandle);
        }
    public bool EnumSyms(string name, ulong address, uint givenSize, IntPtr context)
    {
        tableExports.Rows.Add(name,new cAddress{address = address}, new cSize { size = givenSize });
        return true;
    }

以上针对DLL和EXE文件的导出表中的每个条目返回RVA(相对虚拟地址)。但是它加载模块,获取RVA并卸载模块。由于我从以下位置获取模块的基本地址:

  

Process [] processTable = Process.GetProcesses();

     

baseAddress = processTable [myProcess] .Modules [myModule] .BaseAddress;

因此,由于我同时拥有任何模块的每个过程的RVA和该模块的基本内存地址,

我所需要做的就是计算VA(该过程在物理上所在的实际内存地址)。我知道

必须重新计算:

必须从RVA中减去一些值,然后向其添加基本内存地址...

如何获取该值(我必须减去),因为它应该位于文件头中的某个位置

模块,我可以读取该文件的内容,因为我知道它的基地址?????????

 How to make .NET not to manage code and not to execute under CLR but

我希望.NET制作机器代码。如何将程序编译为机器代码?

0 个答案:

没有答案