0

I am using Visual Studio 2019 - Visual Basic.

I am trying to find the base address of a program via code. I know the base address already, but I need the program I am making to find it on its own.

I use this and it shows a lot of addresses from the modules:

Dim target As Process = Process.GetProcessesByName("The Program")(0)
For Each mo As ProcessModule In target.Modules
    ListBox1.Items.Add(mo.BaseAddress.ToString())

    'MsgBox(Hex(mo.BaseAddress.ToString()))
Next

(I renamed the name of the program from the above code in case there are issues with the program as in copyright stuff.)

I am trying to get the base address My base address I have is:

Base Address in Hex = 00007FF7BE6B0000
Base Address in Dec = 140702028333056

When I run the above code none of the addresses it lists are the base addresses I have.

I used a PE Editor to see the base address of the program. I used a program called PE Tools from GitHub.

So how do I code to get this Image Base Address?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Link Zelda
  • 11
  • 2
  • The base address is `target.MainModule.BaseAddress`, the Entry Point is `target.MainModule.EntryPointAddress` and the RVA is `p.MainModule.EntryPointAddress.ToInt64() - target.MainModule.BaseAddress.ToInt64()` – Jimi Apr 25 '21 at 13:57
  • I have no idea what all that means... I apologize... I am still new to this... – Link Zelda Apr 25 '21 at 14:18
  • Don't you have a Process object you got with `Dim target As Process = Process.GetProcessesByName("The Program)(0)`? Isn't this instance named `target`? (all right I wrote `p.MainModule.EntryPointAddress.ToInt64()` instead of `target. ...`, just a typo) Then... – Jimi Apr 25 '21 at 14:19

1 Answers1

0

I got it to work with this code:

Dim p As Process = Process.GetProcessesByName(GetCurrentProcessName)(0)
For Each moz As System.Diagnostics.ProcessModule In p.Modules
    If moz.FileName.IndexOf(GetCurrentProcessName) <> -1 Then
      Hex(moz.BaseAddress.ToString)
    End If
Next
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Link Zelda
  • 11
  • 2
  • please consider [accepting the answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Xingyu Zhao May 06 '21 at 07:13