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 


Java, WriteProcessMemory(...)

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

Joined: 07 Jan 2022
Posts: 2

PostPosted: Fri Jan 07, 2022 8:12 am    Post subject: Java, WriteProcessMemory(...) Reply with quote

I'm trying to figure out how Writeprocess memory works.

Code:

 public static byte[] writeProcessMemory(String szWindowName, long lpBaseAddress, int offsets, int nSize, int data) throws MemoryException {
  WinNT.HANDLE hProcess = openProcess(process.get(szWindowName).wProcessID);
   
  Memory mToken = new Memory(data);
  long lpPointerAddress = ((lpBaseAddress + offsets));

       
  //System.out.println(Kernel32.INSTANCE.ReadProcessMemory(hProcess, new Pointer(lpPointerAddress), mToken, nSize, null));
  boolean success = Kernel32.INSTANCE.WriteProcessMemory(hProcess, new Pointer(lpPointerAddress), mToken, nSize, null);
  return success ? mToken.getByteArray(0, nSize) : null;
}


I'm able to read process memory just fine

Code:

   public static byte[] readProcessMemory(String windowName, int lpBaseAddress, int[] offsets, int nSize) throws MemoryException {
        WinNT.HANDLE hProcess = openProcess(process.get(windowName).wProcessID);
        byte[] result = readProcessMemory(hProcess, offsets, lpBaseAddress);
        return  result;
    }

  public static byte[] readProcessMemory(WinNT.HANDLE hProcess, int[] offsets, long lpBaseAddress) {

    long pointer = lpBaseAddress;
    long lpPointerAddress = 0;
    int i_Size = 4;
    Memory pTemp = new Memory(i_Size);

    for(int i = 0; i < offsets.length; i++) {
    if(i == 0) {
      Kernel32.INSTANCE.ReadProcessMemory(hProcess, new Pointer(pointer), pTemp, i_Size, null);
    }
   
    lpPointerAddress = ((pTemp.getInt(0)+offsets[i]));

    if(i != offsets.length-1)
      Kernel32.INSTANCE.ReadProcessMemory(hProcess, new Pointer(lpPointerAddress), pTemp, i_Size, null);
    }
      System.out.println(Kernel32.INSTANCE.ReadProcessMemory(hProcess, new Pointer(lpPointerAddress), pTemp, i_Size, null));
    boolean success = Kernel32.INSTANCE.ReadProcessMemory(hProcess, new Pointer(lpPointerAddress), pTemp, i_Size, null);
    return success ? pTemp.getByteArray(0, i_Size) : null;
  }




I've edited my writeprocessmemory method so many times it might be even more broken than I would have thought.


I don't thin it matters but here is part of main




Code:

public class Main {

  public static final int
  // Weapon ID in player Weapon Slots, 0 if not exist.
  GRENADE_ID = 0x6fb1c8, WEP_GRENADE_OFFSET = 0x464,
  M16 = 0x6fb1c8, M16_OFFSET = 0x3EC,
  BAT = 0x6fb1c8, BAT_OFFSET = 0x374,
  MOLOTOV = 0x6fb1c8, MOLOTOV_OFFSET = 0x44C,
  COLT45 = 0x6fb1c8, COLT45_OFFSET = 0x38C,
  BOMB = 0xfb1c8, BOMB_OFFSET = 0x47C,
  ROCKETLAUNCHER = 0x6fb1c8, ROCKETLAUNCHER_OFFSET = 0x41C,
  SHOTGUN = 0x6fb1c8, SHOTGUN_OFFSET = 0x3BC;

  public static void main(String[] args) throws WindowNotFoundException, MemoryException {
    Program.windowMemory("Grand Theft Auto III");
    byte[] ADD_M16 = Program.writeProcessMemory("Grand Theft Auto III", M16, M16_OFFSET, 4, 6 );// nop, nop, nop, nop
    //byte[] ADD_M16 = Program.writeProcessMemory("Grand Theft Auto III", M16, new int[] { M16_OFFSET }, 4);
    byte[] WEP_M16 = Program.readProcessMemory("Grand Theft Auto III", M16, new int[] { M16_OFFSET }, 4);
    //byte[] WEP_SHOTGUN = Program.readProcessMemory("Grand Theft Auto III", SHOTGUN, new int[] { SHOTGUN_OFFSET }, 4);
    readByte(ADD_M16);
    readByte(WEP_M16);

  }
  public static void readByte(byte[] readable) {
    if (readable != null) {
      int value = 0;
      value += (readable[3] & 0x000000FF) << 24;
      value += (readable[2] & 0x000000FF) << 16;
      value += (readable[1] & 0x000000FF) << 8;
      value += (readable[0] & 0x000000FF);
      System.out.println(value);
    }
  }
}
Back to top
View user's profile Send private message
Motley
How do I cheat?
Reputation: 0

Joined: 07 Jan 2022
Posts: 2

PostPosted: Sun Jan 09, 2022 6:18 am    Post subject: Reply with quote

Resolved. Java is really difficult for something like this.
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