Skip to content

Commit

Permalink
add: 初始提交
Browse files Browse the repository at this point in the history
  • Loading branch information
陈亮 committed Jan 2, 2018
0 parents commit 8174952
Show file tree
Hide file tree
Showing 36 changed files with 533 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 腾讯微信跳一跳破解(目前最高19844分)

## 一. 效果展示

![](img/1.jpg)
![](img/2.png)
![](img/5.gif)

## 二. 实现原理

具体识别的算法,我现在没有时间总结了,大家可以先看源码。源码中部分参数是在笔者的手机上进行调试的(分辨率为1080),大家可以根据自己手机,进行相应修改。

### 主要步骤

1. 识别玩家位置

如下图中白色空心方格所示:

![](img/3.png)

1. 识别目标方块位置

如下图中红色实心方格所示,识别最上面的顶点,最左边的点,与最右边的点,从而计算出中心点:

![](img/4.png)

1. 识别目标方块中心圆点的位置

如果你前一次踩中中心点,会有下一个中心点的提示(一个白色的圆点)。

### 流程

1. 通过ADB截屏;
2. 通过ADB将截屏保存到电脑;
3. 识别玩家位置;
4. 识别目标方块位置;
5. 识别目标方块中心圆点的位置;
6. 如果第5步成功,则取第5步的中心点为下一步的位置;否则,取第4步的中心点为下一步的位置;
7. 计算玩家位置与下一步的位置,乘以一定的系数,得到长按的时间;
8. 通过ADB,触发长按;

## 三. 运行条件

1. 准备Java运行与编译环境;
2. 安装Android SDK;
3. 准备好一部已经打开开发者模式的Android手机;
4. 修改com.skyline.wxjumphack.Hack中ADB_PATH,将其改为你自己的ADB位置;
5. 运行程序吧,少年;
Binary file added img/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions src/com/skyline/wxjumphack/Hack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.skyline.wxjumphack;

import java.awt.image.BufferedImage;
import java.io.File;

/**
* Created by chenliang on 2018/1/1.
*/
public class Hack {


static final String ADB_PATH = "/Users/chenliang/Library/Android/sdk/platform-tools/adb";

public static void main(String... strings) {
//System.out.print(Math.sqrt(4));
String root = Hack.class.getResource("/").getPath();
System.out.println("root: " + root);
File srcDir = new File(root, "imgs/input");
srcDir.mkdirs();
System.out.println("srcDir: " + srcDir.getAbsolutePath());
MyPosFinder myPosFinder = new MyPosFinder();
NextCenterFinder nextCenterFinder = new NextCenterFinder();
WhitePointFinder whitePointFinder = new WhitePointFinder();
for (int i = 0; i < 2048; i++) {
try {
File file = new File(srcDir, i + ".png");
if (file.exists()) {
file.deleteOnExit();
}
Runtime.getRuntime().exec(ADB_PATH + " shell /system/bin/screencap -p /sdcard/screenshot.png");
Thread.sleep(800);
Runtime.getRuntime().exec(ADB_PATH + " pull /sdcard/screenshot.png " + file.getAbsolutePath());
Thread.sleep(800);

System.out.println("screenshot, file: " + file.getAbsolutePath());
BufferedImage image = ImgLoader.load(file.getAbsolutePath());
int[] myPos = myPosFinder.find(image);
if (myPos != null) {
System.out.println("find myPos, succ, (" + myPos[0] + ", " + myPos[1] + ")");
int[] excepted = {myPos[0] - 30, myPos[0] + 30};
int[] nextCenter = nextCenterFinder.find(image, excepted, myPos[1]);
if (nextCenter == null || nextCenter[0] == 0) {
System.err.println("find nextCenter, fail");
break;
} else {
int centerX, centerY;
int[] whitePoint = whitePointFinder.find(image, nextCenter[0] - 120, nextCenter[1], nextCenter[0] + 120, nextCenter[1] + 180);
if (whitePoint != null) {
centerX = whitePoint[0];
centerY = whitePoint[1];
System.out.println("find whitePoint, succ, (" + centerX + ", " + centerY + ")");
} else {
if (nextCenter[2] != Integer.MAX_VALUE && nextCenter[4] != Integer.MIN_VALUE) {
centerX = (nextCenter[2] + nextCenter[4]) / 2;
centerY = (nextCenter[3] + nextCenter[5]) / 2;
} else {
centerX = nextCenter[0];
centerY = nextCenter[1] + 48;
}
}
System.out.println("find nextCenter, succ, (" + centerX + ", " + centerY + ")");
int distance = (int) (Math.sqrt((centerX - myPos[0]) * (centerX - myPos[0]) + (centerY - myPos[1]) * (centerY - myPos[1])) * 1.386);
System.out.println("distance: " + distance);
System.out.println(ADB_PATH + " shell input swipe 100 100 100 100 " + distance);
Runtime.getRuntime().exec(ADB_PATH + " shell input swipe 100 100 100 100 " + distance);

}
} else {
System.err.println("find myPos, fail");
break;
}
} catch (Exception e) {
e.printStackTrace();
break;
}
try {
Thread.sleep(3_000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}

}

}
28 changes: 28 additions & 0 deletions src/com/skyline/wxjumphack/ImgLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.skyline.wxjumphack;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
* Created by chenliang on 2017/12/31.
*/
public class ImgLoader {

public static BufferedImage load(String path) throws IOException {
BufferedImage image = null;
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(path));
image = ImageIO.read(is);
} finally {
if (is != null) {
is.close();
}
}
return image;
}
}
81 changes: 81 additions & 0 deletions src/com/skyline/wxjumphack/MyPosFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.skyline.wxjumphack;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
* Created by chenliang on 2017/12/31.
*/
public class MyPosFinder {

public static final int R_TARGET = 40;

public static final int G_TARGET = 43;

public static final int B_TARGET = 86;

public int[] find(BufferedImage image) {
if (image == null) {
return null;
}
int width = image.getWidth();
int height = image.getHeight();

int[] ret = {0, 0};
int maxX=Integer.MIN_VALUE;
int minX=Integer.MAX_VALUE;
int maxY=Integer.MIN_VALUE;
int minY=Integer.MAX_VALUE;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height*3/4; j++) {
int pixel = image.getRGB(i, j);
int r = (pixel & 0xff0000) >> 16;
int g = (pixel & 0xff00) >> 8;
int b = (pixel & 0xff);
if (ToleranceHelper.match(r, g, b, R_TARGET, G_TARGET, B_TARGET, 16) && j > ret[1]) {
maxX=Integer.max(maxX, i);
minX=Integer.min(minX, i);
maxY=Integer.max(maxY, j);
minY=Integer.min(minY, j);
}
}
}
ret[0]=(maxX+minX)/2;
ret[1]=maxY;
System.out.println(maxX+", "+minX);
System.out.println("pos, x: " + ret[0] + ", y: " + ret[1]);
return ret;
}

public static void main(String... strings) throws IOException {
MyPosFinder t = new MyPosFinder();
String root = t.getClass().getResource("/").getPath();
System.out.println("root: " + root);
String imgsSrc = root + "imgs/src";
String imgsDesc = root + "imgs/my_pos";
File srcDir = new File(imgsSrc);
System.out.println(srcDir);
for (File file : srcDir.listFiles()) {

if(!file.getName().endsWith(".png")){
continue;
}
System.out.println(file);
BufferedImage img = ImgLoader.load(file.getAbsolutePath());
int[] pos = t.find(img);

BufferedImage desc = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
desc.getGraphics().drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null); // 绘制缩小后的图
desc.getGraphics().drawRect(pos[0] - 5, pos[1] - 5, 10, 10);
File descFile = new File(imgsDesc, file.getName());
if (!descFile.exists()) {
descFile.mkdirs();
descFile.createNewFile();
}
ImageIO.write(desc, "png", descFile);
}

}
}
Loading

0 comments on commit 8174952

Please sign in to comment.