QuestionReading Memory C#

Posts 15 of 5 · Page 1 of 1
Reading Memory C#
I'm having a little trouble with a radar that I'm trying to make... The thing is that the ReadProcessMemory reads a byte array from the memory, and I have a class (CG_T) where I want to store the values read... My question is, how can I "copy" the byte array to the class? If there's any other easy way, please let me know.

Here's my class:
Code:
public class cg_t
        {
            int ServerTime;
            int PlayerState;
            int StaminaTimer;
            ushort PlayerStance;
            char[] _0x000E = new char[0x2];
            public int IsIngame;
            char [] _0x00D6 = new char[0x4];
            int iVelocity;
            public Vector3 Origin;
            public Vector3 Velocity;
            char[] _0x0034 = new char[0x2C];
            float RefViewAngleY;
            float RefViewAngleX;
            char[] _0x0068 = new char[0xE8];
            int ClientNum;
            char[] _0x0154 = new char[0x4];
            float ViewAngleY;
            float ViewAngleX;
            char[] _0x0160 = new char[0x3C];
            int Health;
            char[] _0x01A0 = new char[0x1C];
            int MaxEntities;
            char[] _0x01C0 = new char[0x44];
            int AdvancedUAV;
            char[] _0x0208 = new char[0x38];
            int NextAttack;
            char[] _0x0244 = new char[0x12C];
            int WeaponID;
            ushort EquipmentState;
            ushort WeaponSwapState;
            float WeaponZoom;
            float MovementSpreadMultiplier;
            char[] _0x0380 = new char[0x16C];
            byte PerkSlot3;
            char[] _0x04ED = new char[0x6ACFF];
            int Seed;
            char[] _0x6B1F0 = new char[0x20];
            refdef_t RefDef;
            char[] _0x6FD80 = new char[0x8D958];
            client_t[] Client = new client_t[18];
            char[] _0x1037E0 = new char[0x1148];
            float SpreadMultiplier;
            char[] _0x10492C = new char[0x4CDC];
            entity_t[] Entity = new entity_t[2048];
        }
And, ReadProcessMemory PInvoke:
Code:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess,IntPtr lpBaseAddress, byte[] lpBuffer,int dwSize, out int lpNumberOfBytesRead);
Thanks in Advance
You mean copy the array to another array in the class, or different array elements to different members of the class?
No... When I read from the memory, I'm reading an array with the class size, so, what I'm trying to do is copy the array to the whole class.. like we know that as int its 4 bytes long (I guess), so the first 4 bytes from the array will be copied to the first field of the class, ServerTime in this case, the next 4 bytes will be copied to PlayerState and so on... But I have a couple of classes (4 to be precise) so I need a method to do this... Any ideas? I'm not good at explaining things btw :P

EDIT: After a lot of searching and posts on many forums, I've found a solution

Code:
unsafe void ReadGame() {
      fixed (byte* pBuffer = ReadBytes(OFFSET_CG, Marshal.SizeOf(CG))) {
           CG = *(Cg_1*) pBuffer;
      }
}
Thanks for your answer anyways
@Hassan, this is Solved, you may close if u want
Marked solved.
Code:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess,IntPtr lpBaseAddress, object lpBuffer,int dwSize, out int lpNumberOfBytesRead);
Actually ReadProcessMemory uses a LPVOID as a lpBuffer, which means that in the managed languages you can mark it as an object.
Everything can be converted to VOID* just like every class can be cast as an Object.
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?