开发者社区> 科技小能手> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

Java外挂开发入门示例

简介:
+关注继续查看
  由于原文较长,图又比较多,且CSDN博客图片目前无法外部访问|||,所以仅发来部分,全文请去鄙人CSDN的博客:[url]http://blog.csdn.net/cping1982[/url] ,希望51cto能早日提供博客迁移功能……

  示例运行结果如下图:
  
 
package org.loon.test.os;

/**
        * Copyright 2008
        *
        * Licensed under the Apache License, Version 2.0 (the "License"); you may not
        * use this file except in compliance with the License. You may obtain a copy of
        * the License at
        *
        * [url]http://www.apache.org/licenses/LICENSE-2.0[/url]
        *
        * Unless required by applicable law or agreed to in writing, software
        * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
        * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
        * License for the specific language governing permissions and limitations under
        * the License.
        *
        * @project loonframework
        * @author chenpeng
        * @email:[email]ceponline@yahoo.com.cn[/email]
        * @version 0.1
        */

import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.EventQueue;
import java.awt.SystemColor;
import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;

import org.loon.framework.os.ASM;
import org.loon.framework.os.OSProcess;


public class TestCallForm extends JFrame {

                 private static final long serialVersionUID = 1L;

                 private JPanel jContentPane = null;

                 private JButton btnHP = null;

                 private JButton btnHome = null;

                 private JButton btnBaseEax = null;

                 private JButton btnIce = null;

                 private JButton btnFire = null;

                 private JButton btnSP = null;

                 private JTextField txtIntPtr = null;

                 private JLabel jLabel = null;

                 public TestCallForm() {
                                 super();
                                 initialize();
                 }

                 private void initialize() {

                                 this.setResizable(false);
                                 this.setSize(238, 315);
                                 this.setContentPane(getJContentPane());
                                 this.setTitle("Java外挂开发入门示例");
                                 this.setLocationRelativeTo(null);
                                 this.addWindowListener(new WindowAdapter() {
                                                 public void windowClosing(WindowEvent e) {
                                                                 System.exit(0);
                                                 }
                                 });
                 }

                 private JPanel getJContentPane() {
                                 if (jContentPane == null) {
                                                 jLabel = new JLabel();
                                                 jLabel.setBounds(new Rectangle(30, 20, 180, 30));
                                                 jLabel.setForeground(Color.white);
                                                 jLabel.setText("寄存器EAX值(针对本机环境)");
                                                 jContentPane = new JPanel();
                                                 jContentPane.setLayout(null);
                                                 jContentPane.setSize(new Dimension(236, 241));
                                                 jContentPane.setBackground(SystemColor.activeCaption);
                                                 jContentPane.add(getBtnHP(), null);
                                                 jContentPane.add(getBtnHome(), null);
                                                 jContentPane.add(getBaseIntPtr(), null);
                                                 jContentPane.add(getBtnIce(), null);
                                                 jContentPane.add(getBtnFire(), null);
                                                 jContentPane.add(getBtnSP(), null);
                                                 jContentPane.add(getTxtIntPtr(), null);
                                                 jContentPane.add(jLabel, null);
                                 }
                                 return jContentPane;
                 }

                 private JButton getBtnHP() {
                                 if (btnHP == null) {
                                                 btnHP = new JButton();
                                                 btnHP.setBounds(new Rectangle(15, 106, 95, 30));
                                                 btnHP.setText("吃血");
                                                 btnHP.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("hp");
                                                                 }
                                                 });
                                 }
                                 return btnHP;
                 }

                 private JButton getBtnHome() {
                                 if (btnHome == null) {
                                                 btnHome = new JButton();
                                                 btnHome.setBounds(new Rectangle(15, 195, 200, 30));
                                                 btnHome.setText("回城");
                                                 btnHome.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("home");
                                                                 }
                                                 });
                                 }
                                 return btnHome;
                 }

                 private JButton getBtnIce() {
                                 if (btnIce == null) {
                                                 btnIce = new JButton();
                                                 btnIce.setBounds(new Rectangle(120, 150, 95, 30));
                                                 btnIce.setText("冰系魔法");
                                                 btnIce.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("ice");
                                                                 }
                                                 });
                                 }
                                 return btnIce;
                 }

                 private JButton getBtnFire() {
                                 if (btnFire == null) {
                                                 btnFire = new JButton();
                                                 btnFire.setBounds(new Rectangle(15, 150, 95, 30));
                                                 btnFire.setText("火系魔法");
                                                 btnFire.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("fire");
                                                                 }
                                                 });
                                 }
                                 return btnFire;
                 }

                 private JButton getBtnSP() {
                                 if (btnSP == null) {
                                                 btnSP = new JButton();
                                                 btnSP.setBounds(new Rectangle(120, 106, 95, 30));
                                                 btnSP.setText("加蓝");
                                                 btnSP.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("sp");
                                                                 }
                                                 });
                                 }
                                 return btnSP;
                 }

                 private JButton getBaseIntPtr() {
                                 if (btnBaseEax == null) {
                                                 btnBaseEax = new JButton();
                                                 btnBaseEax.setBounds(new Rectangle(15, 235, 200, 30));
                                                 btnBaseEax.setText("获得本机EAX数值");
                                                 btnBaseEax.addMouseListener(new java.awt.event.MouseAdapter() {
                                                                 public void mouseClicked(java.awt.event.MouseEvent e) {
                                                                                 clickEvent("find");
                                                                 }
                                                 });
                                 }
                                 return btnBaseEax;
                 }

                 private JTextField getTxtIntPtr() {
                                 if (txtIntPtr == null) {
                                                 txtIntPtr = new JTextField();
                                                 txtIntPtr.setBounds(new Rectangle(18, 57, 199, 30));
                                                 txtIntPtr.setText("00D52070");
                                 }
                                 return txtIntPtr;
                 }

                 /**
                        * 触发事件
                        *
                        * @param eventName
                        */

                 private void clickEvent(final String eventName) {
                                 int pid = OSProcess.findWindowProcessId("TForm1""游戏找CALL练习实例one");
                                 if (pid == 0) {
                                                 JOptionPane.showMessageDialog(this"您的游戏程序尚未启动,外挂无法加载!");
                                                 return;
                                 }
                                 int eaxPtr = 0;
                                 try {
                                                 eaxPtr = ASM.getHexStringToInt(this.txtIntPtr.getText().trim());
                                 } catch (Exception ex) {
                                                 JOptionPane.showMessageDialog(this"寄存器数值设定格式有误,外挂无法加载!");
                                                 return;
                                 }
                                 // 从基址获取寄存器中eax数值
                                 if ("find".equalsIgnoreCase(eventName)) {
                                                 this.txtIntPtr.setText(OSProcess.readProcessMemory(pid, 0x456D68));
                                 }
                                 // 实例化asm类以进行java与汇编混合操作
                                 ASM asm = new ASM();

                                 // 保存所有寄存器,即全部进栈
                                 asm._PUSHAD();
                                 // 示例程序执行时,目标寄存器eax中的必备数值(PS:在我的机器上是00D52070,
                                 // 而找Call测试程序作者提供的是00D51FE4,请自行查找。错误时目标程序将崩溃。)
                                 asm._MOV_EAX(eaxPtr);
                                 // 吃红
                                 if ("hp".equalsIgnoreCase(eventName)) {
                                                 asm._MOV_EDX(0x453028);
                                                 asm._CALL(0x452E98);
                                 }
                                 // 吃蓝
                                 else if ("sp".equalsIgnoreCase(eventName)) {
                                                 asm._MOV_EDX(0x453040);
                                                 asm._CALL(0x452E98);
                                 }
                                 // 火系魔法
                                 else if ("fire".equalsIgnoreCase(eventName)) {
                                                 asm._MOV_ECX(0x45309C);
                                                 asm._MOV_EDX(2);
                                                 asm._CALL(0x452DF8);
                                                 // 冰系魔法
                                 } else if ("ice".equalsIgnoreCase(eventName)) {
                                                 asm._MOV_ECX(0x45307C);
                                                 asm._MOV_EDX(1);
                                                 asm._CALL(0x452DF8);
                                 }
                                 // 回城
                                 else if ("home".equalsIgnoreCase(eventName)) {
                                                 asm._MOV_EDX(0x45305C);
                                                 asm._CALL(0x452E98);
                                 }
                                 // 还原所有寄存器,即全部出栈
                                 asm._POPAD();
                                 // 结尾标记,操作开始执行
                                 asm._RET();

                                 // 要求进行代码注入的进程id
                                 asm.doInject(pid);

                 }


                 public static void main(String[] args) {

                                 EventQueue.invokeLater(new Runnable() {
                                                 public void run() {
                                                                 TestCallForm callForm = new TestCallForm();
                                                                 callForm.setVisible(true);
                                                 }
                                 });

                 }

}

最后,再额外补充两点:

 一,示例程序和真正的CALL外挂开发虽然原理上一样,工作量却是天差地别的,时间不充裕者请不要轻易尝试--|||

 二,这个示例仅仅演示了localos的一部分功能,比如dll注入的接口在其中也提供了, 有兴趣者可以尝试一下,但要注意权限问题.           

 程序源码及示例下载地址:[url]http://code.google.com/p/greenvm/downloads/list[/url] (暂时先丢这里,源码在jar内)

 OD下载地址:[url]http://download.csdn.net/source/940795[/url]

 PS:由于本例中有些敏感API的调用,运行时杀软对Javaw.exe报警请不要少见多怪...下个版本争取干掉杀软^^


本文转自 cping 51CTO博客,原文链接:http://blog.51cto.com/cping1982/125588


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Java入门必备知识(上)
目录 一、前言 二、HelloWord案例编写 三、基础语法 1.快速生成语句:(IDEA编辑器下) 2.注释: 3.标识符 标识符: 标识符的组成: 标识符的组成规则: 4.标识符命名约定: 小驼峰命名法: 命名规则: 大驼峰命名法: 命名规则:
45 0
Java入门必备知识(下)
5.变量 变量的注意事项: 6.常量 常量的概述: 常量的种类: 7.关键字 关键字的描述: 关键字的特点: 8.java数据类型 9.类型转化 自动类型转化: 自动类型转化的原因: 强制类型转化:
28 0
Java实现生产者消费者的四种方法
Java生产者和消费者问题是线程安全模型中的经典问题:生产者和消费者在同一个时间段共用同一个存储空间,生产者向存储空间中添加产品呢,消费者取走产品,当存储空间为空时,消费者阻塞,当存储空间满时,生产者阻塞
75 0
Java实现七牛云文件或图片上传下载
Java实现七牛云文件或图片上传下载
84 0
java实现多线程的三种方式
java实现多线程的三种方式
19 0
Java神鬼莫测之MyBatis实现分页全过程(三)
Java神鬼莫测之MyBatis实现分页全过程(三)
67 0
Java实现登录功能(含修改密码 退出登录等)
Java实现登录功能(含修改密码 退出登录等)
446 0
详解冒泡排序算法及其java实现
冒泡排序是一种交换排序算法,元素通过两两的比较,交换不满足次序要求的元素,直到整个数组都满足次序要求为止。
27 0
Java数据结构-------单链表(图解增删改查详细实现,附反转链表实现)(下)
Java数据结构-------单链表(图解增删改查详细实现,附反转链表实现)(下)
22 0
Java数据结构——————双向链表(详细图解,增删改查详细实现)(下)
Java数据结构——————双向链表(详细图解,增删改查详细实现)(下)
36 0
23703
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载