Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# How would you calculate this offset? (minesweeper timer)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
twotecs
How do I cheat?
Reputation: 0

Joined: 17 Dec 2014
Posts: 1

PostPosted: Wed Dec 17, 2014 9:45 am    Post subject: C# How would you calculate this offset? (minesweeper timer) Reply with quote

Goal
I'm trying to write a c# program to read the minesweeper timer every time it launches. i.e. not just hardcoding the address.

Cheat engine data
I have found the timer in CE, this picture shows what 'writes to this address'. What is the offset(s) that I add to the base address so that ReadProcessMemory() finds the timer every time I open minesweeper?
i.imgur(DOT)com/K5lQK82.png


c#
Code:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;

public class MemoryRead
{
    const int PROCESS_WM_READ = 0x0010;

    [DllImport("kernel32.dll")]
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

    [DllImport("kernel32.dll")]
    public static extern bool ReadProcessMemory(int hProcess,
      int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);

    public static void Main()
    {
        Process process = Process.GetProcessesByName("minesweeper").FirstOrDefault();

            IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
            ProcessModule myProcessModule;
            myProcessModule = process.MainModule;
            IntPtr baseaddy = myProcessModule.BaseAddress;
            Console.WriteLine("BaseAddress: " + baseaddy);

            int bytesRead = 0;
            byte[] buffer = new byte[4];

            /* IntPtr.Add(baseaddy, offset);
             *
             * How can I determine the offset from the CE data?
            */
            ReadProcessMemory((int)processHandle, 0x0010B230, buffer, buffer.Length, ref bytesRead);
            Console.WriteLine("current time: " + BitConverter.ToSingle(buffer, 0));
     
    }
}
Back to top
View user's profile Send private message
zm0d
Master Cheater
Reputation: 7

Joined: 06 Nov 2013
Posts: 423

PostPosted: Wed Dec 17, 2014 10:11 am    Post subject: Reply with quote

Find out the module where your Opcode (movss [rax+20], xmm0) is placed in and then get the modules base address. This base addres gets subtract from the address where your opcode is placed.

E.g.:
Module base address: 0x1000
Opcode address: 0x1200

So simply subtract 1000 from 1200 and you know that your offset is 200. => module base address + 200 = my opcode.

A more generic solution would be to use an AoB scan.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites