小小滑块可笑可笑-安卓滑块验证码通杀方案研究(3)

前言

本章继续研究滑块的对抗,来到了核心的轨迹生成部分

录制工具的编写

所谓录制工具其实就是记下时间点的坐标位置

关于坐标位置的记录,请各位安卓开发人员自行复习:

Android 事件传递机制详解

事件顺序 Activity--> Window-->DecorView --> 布局View

实体类point_time定义

public class TimePoint {
    private long time;
    private float x;
    private float y;

    public TimePoint(long time, float x, float y) {
        this.time = time;
        this.x = x;
        this.y = y;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }
}

保存point time

触摸事件拦截记录

public class MainActivity extends AppCompatActivity {

    ArrayList<TimePoint> timePoints = new ArrayList<>();
    long startTime = 0L;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    //事件顺序 Activity--> Window-->DecorView --> 布局View

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        //从按下开始 0
        //从离开结束 1

        if(ev.getAction()==0){
            startTime = TimeUtils.getNowMills();
            timePoints.clear();
        }
        if(ev.getAction()==2){
            timePoints.add(new TimePoint(TimeUtils.getNowMills()-startTime,ev.getRawX(),ev.getRawY()));
        }

        if(ev.getAction()==1){
            timePoints.add(new TimePoint(TimeUtils.getNowMills()-startTime,ev.getRawX(),ev.getRawY()));
            String data = new Gson().toJson(timePoints);
            Log.e("xxx",data);
        }

        return super.dispatchTouchEvent(ev);
    }

}

核心就是dispatchTouchEvent方法中拦截事件记录下来

测试生成的轨迹记录

随便一滑

[{"time":7,"x":180.83257,"y":1229.4462},{"time":39,"x":182.83072,"y":1229.4462},{"time":41,"x":194.08751,"y":1231.0153},{"time":55,"x":204.31084,"y":1231.9451},{"time":58,"x":222.06346,"y":1237.169},{"time":73,"x":238.27936,"y":1241.9404},{"time":75,"x":254.25331,"y":1247.2677},{"time":89,"x":268.2516,"y":1251.936},{"time":91,"x":285.22064,"y":1254.8489},{"time":106,"x":303.7188,"y":1257.9333},{"time":108,"x":325.78207,"y":1262.648},{"time":122,"x":344.68085,"y":1266.4294},{"time":124,"x":367.20758,"y":1271.279},{"time":139,"x":387.64105,"y":1275.9253},{"time":140,"x":412.6566,"y":1280.6907},{"time":158,"x":450.11096,"y":1286.1744},{"time":188,"x":504.03333,"y":1296.416},{"time":190,"x":551.3913,"y":1306.5754},{"time":206,"x":572.4699,"y":1310.4097},{"time":208,"x":595.25433,"y":1316.845},{"time":222,"x":617.4283,"y":1323.9038},{"time":224,"x":638.30457,"y":1330.0212},{"time":239,"x":660.88806,"y":1336.898},{"time":242,"x":677.3767,"y":1339.2922},{"time":273,"x":733.32104,"y":1354.8896},{"time":276,"x":748.3225,"y":1358.791},{"time":291,"x":763.79285,"y":1361.8865},{"time":294,"x":779.26654,"y":1366.5145},{"time":305,"x":793.765,"y":1370.3826},{"time":306,"x":806.70953,"y":1374.2257},{"time":321,"x":819.74097,"y":1376.8799},{"time":322,"x":833.0282,"y":1380.0782},{"time":339,"x":844.2183,"y":1382.8772},{"time":342,"x":853.7906,"y":1383.8988},{"time":357,"x":873.35693,"y":1387.523},{"time":372,"x":881.68365,"y":1389.3743},{"time":373,"x":887.5774,"y":1389.9404},{"time":388,"x":893.173,"y":1390.8734},{"time":389,"x":896.481,"y":1391.9508},{"time":406,"x":900.16656,"y":1392.8726},{"time":410,"x":903.26733,"y":1392.9243},{"time":422,"x":905.1619,"y":1393.8721},{"time":425,"x":905.6614,"y":1394.8718},{"time":427,"x":905.16187,"y":1394.372}]

如果要指定滑动距离 只需要做好位置标记即可,

假设生成了100条从

100-200到100-1000之间的轨迹记录,接下来在复用轨迹记录的时候。

比较要滑动的距离离哪个最近 就用哪个去匹配即可。

总结

轨迹记录工具源代码放在仓库https://github.com/HuRuWo/KillerAndroidSlide

接下来一节就是实战滑动

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注