JAVA(JNA)内联汇编之外挂编写()

 

 

MyKernel32类

 

  1. package com.jna;  
  2.   
  3. import com.sun.jna.Native;  
  4. import com.sun.jna.Structure;  
  5. import com.sun.jna.examples.win32.Kernel32;  
  6. import com.sun.jna.examples.win32.W32API;  
  7. import com.sun.jna.ptr.IntByReference;  
  8.   
  9.    
  10.   
  11. public interface MyKernel32 extends Kernel32{  
  12.    
  13.  public MyKernel32 INSTANCE=(MyKernel32)Native.loadLibrary("kernel32",MyKernel32.class);  
  14.    
  15.  public W32API.HANDLE OpenProcess(int dwDesiredAccess,boolean flag,int dwProcessid);  
  16.    
  17.  public boolean ReadProcessMemory(W32API.HANDLE hProcess,int ipBaseAddress,Object ipBuffer,int nSize,IntByReference ipNumberOfBytesRead);  
  18.    
  19.  public boolean ReadProcesMemorey(W32API.HANDLE hProcess,int IntBaseAddress,byte []ipBuffer,int nSize,IntByReference ipNumberOfBytesRead);  
  20.   
  21.  public int VirtualAllocEx(W32API.HANDLE hProcess,IntByReference lpAddress,int dwSize,int flAllocationType,int flProtect);  
  22.   
  23.  public HANDLE CreateRemoteThread(W32API.HANDLE hProcess,Structure lpThreadAttributes,int dwStackSize,int lpStartAddress,Structure lpParameter,int dwCreationFlags,IntByReference lpThreadId);  
  24.    
  25.  public boolean WriteProcessMemory(W32API.HANDLE hProcess,int lpBaseAddress,byte []lpBuffer,int nSize,IntByReference lpNumberOfBytesWritten);  
  26.   
  27.    
  28.   
  29.   
  30.    
  31.   
  32.   
  33. }  
package com.jna;

import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.examples.win32.Kernel32;
import com.sun.jna.examples.win32.W32API;
import com.sun.jna.ptr.IntByReference;

 

public interface MyKernel32 extends Kernel32{
 
 public MyKernel32 INSTANCE=(MyKernel32)Native.loadLibrary("kernel32",MyKernel32.class);
 
 public W32API.HANDLE OpenProcess(int dwDesiredAccess,boolean flag,int dwProcessid);
 
 public boolean ReadProcessMemory(W32API.HANDLE hProcess,int ipBaseAddress,Object ipBuffer,int nSize,IntByReference ipNumberOfBytesRead);
 
 public boolean ReadProcesMemorey(W32API.HANDLE hProcess,int IntBaseAddress,byte []ipBuffer,int nSize,IntByReference ipNumberOfBytesRead);

 public int VirtualAllocEx(W32API.HANDLE hProcess,IntByReference lpAddress,int dwSize,int flAllocationType,int flProtect);

 public HANDLE CreateRemoteThread(W32API.HANDLE hProcess,Structure lpThreadAttributes,int dwStackSize,int lpStartAddress,Structure lpParameter,int dwCreationFlags,IntByReference lpThreadId);
 
 public boolean WriteProcessMemory(W32API.HANDLE hProcess,int lpBaseAddress,byte []lpBuffer,int nSize,IntByReference lpNumberOfBytesWritten);

 


 


}


 

Main类

  1. package com.main;  
  2.   
  3. import com.jna.MyKernel32;  
  4. import com.sun.jna.Structure;  
  5. import com.sun.jna.examples.win32.User32;  
  6. import com.sun.jna.examples.win32.W32API;  
  7. import com.sun.jna.examples.win32.W32API.HANDLE;  
  8. import com.sun.jna.examples.win32.W32API.HWND;  
  9. import com.sun.jna.ptr.IntByReference;  
  10. import org.loon.framework.os.ASM;  
  11.   
  12. @SuppressWarnings({"unused","static-access"})  
  13. public class Main {  
  14.  private static final int PROCESS_ALL_ACCESS=2035711//权限  
  15.   
  16.    
  17.  public void Game(){  
  18.   //获得窗口句柄  
  19.   W32API.HWND hwnd = User32.INSTANCE.FindWindow(null"【魔域】");  
  20.     
  21.   //获得窗口进程ID  
  22.   IntByReference lpdwProcessId=new IntByReference();  
  23.   int Tid = User32.INSTANCE.GetWindowThreadProcessId(hwnd, lpdwProcessId);  
  24.     
  25.   W32API.HANDLE processHandle=null;  
  26.     
  27.   //获得进程句柄  
  28.   processHandle=MyKernel32.INSTANCE.OpenProcess(PROCESS_ALL_ACCESS,false, lpdwProcessId.getValue());   
  29.     
  30.   //开辟内存空间  
  31.   int l=MyKernel32.INSTANCE.VirtualAllocEx(processHandle, null0x30000x10000x40);  
  32.     
  33.   if(l==0){  
  34.    System.out.println("分配内存失败");  
  35.    return;  
  36.   }else{  
  37.    System.out.println("分配内存成功");  
  38.    System.out.println("内存地址:"+l);  
  39.   }  
  40.     
  41.   //编写汇编码  
  42.   ASM asm = new ASM();  
  43.     
  44.   //寄存器全部入栈  
  45.   asm._PUSHAD();  
  46.   //写入CALL汇编码  
  47.   
  48.  //BB出征CALL  
  49.   asm._PUSH(0);  
  50.   asm._PUSH(0x83afe631);  
  51.   asm._MOV_ECX(0x01170090);  
  52.   asm._CALL(0x00C88890);  
  53.   //寄存器全部出栈  
  54.   asm._POPAD();  
  55.   //结尾标记  
  56.   asm._RET();  
  57.     
  58.   boolean b = MyKernel32.INSTANCE.WriteProcessMemory(processHandle, l, ASM.getHexToBytes(asm.getASMCode()), 0x3000null);  
  59.   if(b){  
  60.    System.out.println("写入成功");  
  61.   }else{  
  62.    System.out.println("写入失败");  
  63.    return;  
  64.   }  
  65.   int lpThreadId=0;  
  66.   MyKernel32.INSTANCE.CreateRemoteThread(processHandle, null0, l,null , 0null);  
  67.   
  68.  }  
  69.   
  70.  public static void main(String[] args) {  
  71.     
  72.   Main main = new Main();  
  73.   main.Game();  
  74.     
  75.   
  76.     
  77.  }  
  78.   
  79. }  
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值