Artemis.Utilities.Memory.MemoryHelpers.FindAddress C# (CSharp) Method

FindAddress() public static method

public static FindAddress ( IntPtr pHandle, IntPtr baseAddress, IntPtr staticPointer, int offsets ) : IntPtr
pHandle System.IntPtr
baseAddress System.IntPtr
staticPointer System.IntPtr
offsets int
return System.IntPtr
        public static IntPtr FindAddress(IntPtr pHandle, IntPtr baseAddress, IntPtr staticPointer, int[] offsets)
        {
            // Create a buffer that is 4 bytes on a 32-bit system or 8 bytes on a 64-bit system. 
            var tmp = new byte[IntPtr.Size];
            var address = baseAddress;
            // We must check for 32-bit vs 64-bit. 
            address = IntPtr.Size == 4
                ? new IntPtr(address.ToInt32() + staticPointer.ToInt32())
                : new IntPtr(address.ToInt64() + staticPointer.ToInt64());

            // Loop through each offset to find the address 
            foreach (IntPtr t in offsets)
            {
                var lpNumberOfBytesRead = 0;
                ReadProcessMemory(pHandle, address, tmp, IntPtr.Size, ref lpNumberOfBytesRead);
                address = IntPtr.Size == 4
                    ? new IntPtr(BitConverter.ToInt32(tmp, 0) + t.ToInt32())
                    : new IntPtr(BitConverter.ToInt64(tmp, 0) + t.ToInt64());
            }
            return address;
        }