当前位置:   article > 正文

使用java来写一个游戏外挂-内存修改程序(辅助-开篇)_java写外挂

java写外挂

很久以前研究过如何使用java写一个内存读写的程序,但是java都是知道的

它是在虚拟机上进行运行的,所以没办法进行内存的读写

所以用到了jan来执行windows自带的 kernel32.dll程序

感谢

Java - 游戏内存外挂 - 腾讯云开发者社区-腾讯云 (tencent.com)

的相应教程,我只是结合一下目前教程和没有提到的知识

首先引入jar包

  1. <dependency>
  2. <groupId>net.java.dev.jna</groupId>
  3. <artifactId>jna</artifactId>
  4. <version>4.1.0</version>
  5. </dependency>
  1. package cn.ttext.test.wg;
  2. import com.sun.jna.Library;
  3. import java.io.IOException;
  4. public interface MemoryManager extends Library {
  5. int OpenProcess(int processId);
  6. int OpenProcess(String processName) throws IOException;
  7. void CloseHandle(int processId);
  8. int ReadIntProcessMemory(int processId,int address);
  9. int ReadIntProcessMemory(int processId,int ... addresss);
  10. void WriteIntProcessMemory(int processId,long value,int address);
  11. void WriteIntProcessMemory(int processId,long value,int ... addresss);
  12. }

这是接口MemoryManager

MemoryManagerImpl

  1. package cn.ttext.test.wg;
  2. import com.sun.jna.Library;
  3. import com.sun.jna.Native;
  4. import com.sun.jna.Pointer;
  5. import java.io.BufferedInputStream;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.nio.charset.Charset;
  10. public class MemoryManagerImpl implements MemoryManager {
  11. private interface Memory extends Library {
  12. Memory INSTANCE = (Memory) Native.loadLibrary("kernel32", Memory.class);
  13. int OpenProcess(int desiredAccess,boolean heritHandle,int pocessID);
  14. void CloseHandle(int process);
  15. boolean ReadProcessMemory(int process, int baseAddress, Pointer buffer, int size, int bytesread);
  16. boolean WriteProcessMemory(int process,int baseAddress,long[] value,int size,int byteswrite);
  17. }
  18. public int OpenProcess(int processId) {
  19. //0x1F0FFF获取最大权限
  20. return Memory.INSTANCE.OpenProcess(0x1F0FFF, false, processId);
  21. }
  22. public int OpenProcess(String processName) throws IOException {
  23. Process process = Runtime.getRuntime().exec("TASKLIST /FI \"IMAGENAME eq " + processName + "\"");
  24. BufferedReader bufferedReader = new BufferedReader(
  25. new InputStreamReader(
  26. new BufferedInputStream(process.getInputStream()), Charset.forName("UTF-8")));
  27. String str;
  28. int pid = -1;
  29. while ((str = bufferedReader.readLine()) != null){
  30. if (str.contains(processName)){
  31. pid = Integer.parseInt(str.substring(processName.length(),str.indexOf("Console")).trim());
  32. }
  33. }
  34. if (pid != -1){
  35. return this.OpenProcess(pid);
  36. }else{
  37. return -1;
  38. }
  39. }
  40. public void CloseHandle(int processId) {
  41. Memory.INSTANCE.CloseHandle(processId);
  42. }
  43. public int ReadIntProcessMemory(int processId, int address) {
  44. Pointer buffer = new com.sun.jna.Memory(4);
  45. Memory.INSTANCE.ReadProcessMemory(processId,address,buffer,4,0);
  46. return buffer.getInt(0);
  47. }
  48. public int ReadIntProcessMemory(int processId, int... addresss) {
  49. int address = 0;
  50. for (int addr:addresss){
  51. address = ReadIntProcessMemory(processId, addr + address);
  52. }
  53. return address;
  54. }
  55. public void WriteIntProcessMemory(int processId, long value, int address) {
  56. Memory.INSTANCE.WriteProcessMemory(processId,address,new long[]{value},4,0);
  57. }
  58. public void WriteIntProcessMemory(int processId, long value, int... addresss) {
  59. int[] t_a = new int[addresss.length - 1];
  60. for (int i = 0; i < t_a.length; i++) {
  61. t_a[i] = addresss[i];
  62. }
  63. WriteIntProcessMemory(processId,value,
  64. this.ReadIntProcessMemory(processId, t_a) + addresss[addresss.length - 1]);
  65. }
  66. }

我们本次使用到的游戏是 植物大战僵尸作为参考

著名:如果需要写其他游戏辅助等,做好还是用其他语言(因为教程很多)

首先,我们需要获取到游戏的pid

其次需要一定的逆向基础等 可以参考其他论坛来学习

并在学习过程中发现各大教程或者讨论贴都没有相应的介绍和详细的使用

因为那些都是只可以获取动态内存,所以说没办法从基地址进行偏移来获取指针的值

现在先拿一个案例来示范和探讨,有错误请指出,看到会改,或者问题 会回复

main方法

  1. //用来获取游戏pid
  2. int process = memoryManager.OpenProcess("PlantsVsZombies.exe");
  1. package cn.ttext.test.wg;
  2. import java.io.IOException;
  3. public class Main {
  4. public static void main(String[] args) throws Exception {
  5. MemoryManager memoryManager = new MemoryManagerImpl();
  6. //打开进程名:PlantsVsZombies.exe
  7. int process = memoryManager.OpenProcess("PlantsVsZombies.exe");
  8. System.out.println("启动成功。。。。。。。。。。");
  9. //向阳光的地址写入数量
  10. memoryManager.WriteIntProcessMemory(process,999999,0x006A9EC0, 0x768, 0x5560);
  11. //清除冷却,每500毫秒清一次
  12. new Thread(()->{
  13. while (true){
  14. for (int i = 0; i < 7; i++) {
  15. memoryManager.WriteIntProcessMemory(process,1,0x006A9EC0, 0x768, 0x144,0x70 + 0x50 * i);
  16. }
  17. try {
  18. Thread.sleep(500);
  19. } catch (InterruptedException e) {
  20. e.printStackTrace();
  21. }
  22. }
  23. }).start();
  24. //退出进程
  25. //memoryManager.CloseHandle(process);
  26. }
  27. }

好了,问题来了,我想获取CSGO中的矩阵基地址该怎么读呢?

  1. int process = memoryManager.OpenProcess("cstrike.exe");
  2. System.out.println(process);
  3. System.out.println("启动成功。。。。。。。。。。");
  4. //读取矩阵cstrike.exe+1820100
  5. float[] Matrix=new float[16];
  6. Matrix= memoryManager.ReadMatrixProcessMemory(process, 0x1400000+0x1820100);
  7. for (int i=0;i<Matrix.length;i++){
  8. System.out.print(Matrix[i]+"\t");
  9. }
  10. System.out.println();

其次我们要明白 0x1400000是基地址 0x1820100 是偏移量

这就是锁定本地静态地址,每次可便宜到,如果需要画框则需要swing等,请自行研究,仅供学习和参考!

如果有新的我会补充,仅供学习使用!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/934308
推荐阅读
相关标签
  

闽ICP备14008679号