博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android反编译 -- 错误代码还原
阅读量:6307 次
发布时间:2019-06-22

本文共 5743 字,大约阅读时间需要 19 分钟。

PS:假设阅读体验不好,能够尝试 (<-点左边)

1. setColor(-16777216)

反编译的代码中会有非常多setColor(int)的情况,比方setColor(-16777216),这个值比較特别,能轻易的查到Android文档中对这个整数的定义:

public static final int BLACK.

Added in API level 1
Constant Value: -16777216 ( 0xff000000).

也就是说setColor(-16777216)-16777216相应的颜色是BLACK(0xff000000),那么其它系统没有定义成某个颜色名的值呢?

-16777216 相应 0xff000000       -1 相应 0xffffffff 0xffffff 的值 16777215那么对随意的 setColor(int)中的int值,我们能够:0xffffffff+(int)+1 或 0xffffffff-(-int+1) 则对于 :setColor(-16777216)可写成 :setColor(0xffffffff - 16777215)) 或 setColor(-16777216 + 1 + 0xffffffff))这样,我们就不用查文档寻找特定的颜色值。也能解决随意颜色的设置。

2.MeasureSpec.makeMeasureSpec(xx, int)

反编译的代码中MeasureSpec.makeMeasureSpec(xx, int)的第二个參数是个int类型的数,这个比較简单,直接看文档或者源代码就可以找到:

源代码:

public static class MeasureSpec {
public static final int UNSPECIFIED = 0; public static final int EXACTLY = 1073741824; public static final int AT_MOST = -2147483648; ... }

文档:

public static final int AT_MOSTAdded in API level 1Measure specification mode: The child can be as large as it wants up to the specified size.Constant Value: -2147483648 (0x80000000)public static final int EXACTLYAdded in API level 1Measure specification mode: The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.Constant Value: 1073741824 (0x40000000)public static final int UNSPECIFIEDAdded in API level 1Measure specification mode: The parent has not imposed any constraint on the child. It can be whatever size it wants.Constant Value: 0 (0x00000000)

则对于:

MeasureSpec.makeMeasureSpec(xx, 0)
我们应该改动为
MeasureSpec.makeMeasureSpec(xx, View.MeasureSpec.UNSPECIFIED)

其它依次类推。

3.setVisibility(int)

这个同[2],看文档或者看源代码:

public static final int VISIBLE = 0;public static final int INVISIBLE = 4;public static final int GONE = 8;

则对于:setVisibility(0) ==> setVisibility(View.VISIBLE)

其它依次类推。

4.new Runnable()...

反编译的代码中:

new Runnable() {    final /* synthetic */ AbstractButton a;        {        this.a = r1;       }       public final void run() {          this.a.xxxxx();       }};

可直接去掉成员变量:

new Runnable() {       public final void run() {          xxxxx();       }};

5.new Handler()...

[4],直接去掉成员变量:

new Handler() {            final /* synthetic */ ButtonSave a;            {                this.a = r1;            }            public final void handleMessage(Message message) {                    this.a.xxx();            }        };//改动为new Handler() {            public final void handleMessage(Message message) {                xxx();            }        };

6.context.getSystemService("layout_inflater")

直接看源代码就可以:

public static final String POWER_SERVICE = "power";public static final String WINDOW_SERVICE = "window";public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";public static final String ACCOUNT_SERVICE = "account";public static final String ACTIVITY_SERVICE = "activity";public static final String ALARM_SERVICE = "alarm";public static final String NOTIFICATION_SERVICE = "notification";public static final String ACCESSIBILITY_SERVICE = "accessibility";...

context.getSystemService("layout_inflater") ==> context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)

其它依次类推。

7.intent.setFlags(335544320)

先看源代码:

Intent implements Parcelable, Cloneable  {    public static final int FLAG_GRANT_READ_URI_PERMISSION = 1;    public static final int FLAG_GRANT_WRITE_URI_PERMISSION = 2;    public static final int FLAG_FROM_BACKGROUND = 4;    public static final int FLAG_DEBUG_LOG_RESOLUTION = 8;    public static final int FLAG_EXCLUDE_STOPPED_PACKAGES = 16;    public static final int FLAG_INCLUDE_STOPPED_PACKAGES = 32;    public static final int FLAG_ACTIVITY_NO_HISTORY = 1073741824;    public static final int FLAG_ACTIVITY_SINGLE_TOP = 536870912;    public static final int FLAG_ACTIVITY_NEW_TASK = 268435456;    public static final int FLAG_ACTIVITY_MULTIPLE_TASK = 134217728;    public static final int FLAG_ACTIVITY_CLEAR_TOP = 67108864;    public static final int FLAG_ACTIVITY_FORWARD_RESULT = 33554432;    public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 16777216;    public static final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 8388608;    public static final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 4194304;    public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 2097152;    public static final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 1048576;    public static final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 524288;    public static final int FLAG_ACTIVITY_NO_USER_ACTION = 262144;    public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 131072;    public static final int FLAG_ACTIVITY_NO_ANIMATION = 65536;    public static final int FLAG_ACTIVITY_CLEAR_TASK = 32768;    public static final int FLAG_ACTIVITY_TASK_ON_HOME = 16384;    public static final int FLAG_RECEIVER_REGISTERED_ONLY = 1073741824;    public static final int FLAG_RECEIVER_REPLACE_PENDING = 536870912;    public static final int FLAG_RECEIVER_FOREGROUND = 268435456;

那么对于intent.setFlags(int);int值是上面四种之中的一个的话就比較简单,比如:

intent.setFlags(536870912); ==> intent.setFlags(PendingIntent.FLAG_NO_CREATE);

可是遇到一个比較特别的:intent.setFlags(335544320);

源代码里根本没有这样一个值啊,事实上intent.setFlags( A | B )是能够使用|(或运算)的,那么:

10000000000000000000000000000 = 268435456                    |               |  100000000000000000000000000 =  6710886410100000000000000000000000000 = 335544320即 268435456 | 67108864 = 335544320

从而:

intent.setFlags(335544320);==>

intent.setFlags( FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP )

或者

intent.setFlags( FLAG_RECEIVER_FOREGROUND | FLAG_ACTIVITY_CLEAR_TOP )

从 中搜索intent.setFlags(335544320);看到的是第一种情况。结合intent.setFlags()的使用方法,应该也是第一种情况。

相关资料:

反编译和代码解读/

PS:

本文已整理到Github上,欢迎提交很多其它代码!

你能够关注的我、和

转载地址:http://ugnxa.baihongyu.com/

你可能感兴趣的文章
Docker 自定义SSH服务镜像
查看>>
JavaScript强化教程 —— Cocos2d-JS自动JSB绑定规则修改
查看>>
configure: error: in `/root/httpd-2.2.11/srclib/apr': c
查看>>
CentOS7搭建Kubernetes-dashboard管理服务
查看>>
buildroot下查找外部编译器通过ext-toolchain-wrapper调用的参数
查看>>
MySQL Replication 主主配置详细说明
查看>>
Linux的任务调度
查看>>
在Android studio中添加jar包方法如下
查看>>
iframe 在ie下面总是弹出新窗口解决方法
查看>>
分享10款漂亮实用的CSS3按钮
查看>>
安装nginx 常见错误及 解决方法
查看>>
Gorun8电子商城
查看>>
在之前链表的基础上改良的链表
查看>>
android编译系统makefile(Android.mk)写法
查看>>
MD5源代码C++
查看>>
Eclipse 添加 Ibator
查看>>
Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义
查看>>
Python编程语言
查看>>
十四、转到 linux
查看>>
Got error 241 'Invalid schema
查看>>