title: Memory address, knowing the offsets and the base address of a dll how can I obtain the memory adress to set values
body: <p>I have my base memory address <code>&quot;GameAssembly.dll&quot;+00DA5A84</code> and some offets. Adding this up I got the address I need. (The red rectangle). This one changes every time that the game is reset.</p>
  <p><a href="https://i.stack.imgur.com/GcBvW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GcBvW.png" alt="Figure1" /></a></p>
  <p>Once I got the memory address I can do the following:</p>
  <pre><code>public void isImpostor(IntPtr addrs, int valueToWriteInMemory)
  {
     using (var sharp = new MemorySharp(Process.GetProcessesByName(&quot;Among Us&quot;).FirstOrDefault()))
     {
         sharp[addrs, false].Write(valueToWriteInMemory);
     }
  }
  
  var addrs = new IntPtr(0x210A83A8);
  isImpostor(addrs, 0x0);
  </code></pre>
  <p>nevertheless I'm not sure how I can get that memory address. Not sure how to do:</p>
  <p><code>&quot;GameAssembly.dll&quot; + 0x00DA5A94 + 0x28 + 0x34 + 0x0 + 0x5C</code> and obtain as a result <code>0x210A83A8</code>.</p>
  <hr />
  <p>Updated:</p>
  <p>In order to know what the AddressBase from GameAssembly.dll is I have this method.</p>
  <pre><code>public int GetModuleAddress(String pName, String dllName)
  {
           Process p = Process.GetProcessesByName(pName).FirstOrDefault();
           foreach(ProcessModule pm in p.Modules) 
                if (pm.ModuleName.Equals(dllName)) 
                     return (int)pm.BaseAddress;
           return 0;
  }
  
  Console.WriteLine(GetModuleAddress(&quot;Among Us&quot;, &quot;GameAssembly.dll&quot;);
  Console.WriteLine((IntPtr)GetModuleAddress(&quot;Among Us&quot;, &quot;GameAssembly.dll&quot;)); 
  </code></pre>
  <pre><code>Result1 (As integer): 2043150336
  Result2 (After Casting to IntPtr): 2043150336 here I can do the addition I mentioned before.
  </code></pre>
  <p>it returns an <code>int</code> so I can't do the addition of GameAssembly.dll + 0x00DA5A94. Assuming this I cast this result to <code>IntPtr</code>.  once it was cast to IntPtr I can do this.</p>
  <pre><code>IntPtr A_ptr =(IntPtr)GetModuleAddress(&quot;Among Us&quot;, &quot;GameAssembly.dll&quot;) + 0x00DA5A94;
  </code></pre>
  <p>But I got this message error:</p>
  <pre><code>System.ComponentModel.Win32Exception: 'Couldn't read 4 byte(s) from 0x5C.'
  </code></pre>
  <p>I tried also to cast the address to HEX, with <code>toString(&quot;X&quot;)</code> method and I got as result <code>79C80000</code> but I can't do neither <code>79C80000 + 0x00DA5A94 </code> nor <code>0x79C80000 + 0x00DA5A94</code>.</p>
  <p>looking at values inside of variables I got this.</p>
  <pre><code>BaseAdressDLL: 2043150336
  A: 0, Aptr: 2057460372 (or 0x00000000 and 0x7aa25a94 respectively)
  Bptr: 92 (or 0x0000005c)
  </code></pre>
  <p>What I'm doing wrong? I'm also sorry for my English.</p>
  <p>I tried using the BaseAdress that Cheat engines gives me, and it works perfectly so I assume that I don't know how to get the AdressBase properly.</p>
  <pre><code>var sharp = new MemorySharp(Process.GetProcessesByName(&quot;Among Us&quot;).FirstOrDefault());
  
  
  /* This does`t work 
  IntPtr GameB = (IntPtr)GetModuleAddress(&quot;Among Us&quot;, &quot;GameAssembly.dll&quot;);
  IntPtr GameAssemblyDllBaseAddress = sharp.Read&lt;IntPtr&gt;(GameB, false);
  IntPtr A_ptr = GameAssemblyDllBaseAddress + 0x00DA5A94;
  IntPtr A = sharp.Read&lt;IntPtr&gt;(A_ptr, false);
  */
  
  
  // But this does it.
  IntPtr A = (IntPtr)0x11F7FC18; // Using AddressBase directly.
  
  // -------------
  IntPtr B_ptr = A + 0x5C;
  IntPtr B = sharp.Read&lt;IntPtr&gt;(B_ptr, false);
  
  IntPtr C_ptr = B + 0x0;
  IntPtr C = sharp.Read&lt;IntPtr&gt;(C_ptr, false);
  
  IntPtr D_ptr = C + 0x34;
  IntPtr D = sharp.Read&lt;IntPtr&gt;(D_ptr, false);
  
  IntPtr isImpostor_ptr = D + 0x28;
  // read
  int isImpostor = sharp.Read&lt;int&gt;(isImpostor_ptr, false);
  // write
  sharp[isImpostor_ptr, false].Write(0x1);
  </code></pre>