Android反编译 -- 错误代码还原
PS:如果阅读体验不好,可以尝试Github版 (<-点左边)
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_MOST
Added in API level 1
Measure specification mode: The child can be as large as it wants up to the specified size.
Constant Value: -2147483648 (0x80000000)
public static final int EXACTLY
Added in API level 1
Measure 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 UNSPECIFIED
Added in API level 1
Measure 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 = 67108864
10100000000000000000000000000 = 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 )
从 Codota 中搜索intent.setFlags(335544320);
看到的是第一种情况,结合intent.setFlags()
的用法,应该也是第一种情况。
相关资料:
PS:
Android反编译 -- 错误代码还原的更多相关文章
- Android 反编译
Android 反编译 步骤:1.下载apktool 工具,这一步 主要是反编译 xml 文件. 步骤:2 把xx.smali 文件转为java 工具 (单个) 图形界面 下载dex2jar 和xj ...
- 转 谈谈android反编译和防止反编译的方法
谈谈android反编译和防止反编译的方法 android基于java的,而java反编译工具很强悍,所以对正常apk应用程序基本上可以做到100%反编译还原. 因此开发人员如果不准备开源自己的项 ...
- 谈谈android反编译和防止反编译的方法(转)
谈谈android反编译和防止反编译的方法(转) android基于java的,而java反编译工具很强悍,所以对正常apk应用程序基本上可以做到100%反编译还原. 因此开发人员如果不准备开源自己的 ...
- ubuntu下Android反编译详细教程-apktool,dex2jar,jd-gui的使用
转载请注明出处:http://blog.csdn.net/fightlei/article/details/52432161 最近在学习Android反编译的一些知识,虽然在网上搜到了很多相关的文章, ...
- Android反编译与防止反编译
1.Android反编译 1)下载两个工具 dex2jar,jar2java,相关阅读下载见:http://www.linuxidc.com/Linux/2011-02/32775.htm ...
- Android反编译(三)之重签名
Android反编译(三) 之重签名 [目录] 1.原理 2.工具与准备工作 3.操作步骤 4.装X技巧 5.问题 1.原理 1).APK签名的要点 a.所有的应用程序都必须有数字证书 ,Androi ...
- Android反编译(二)之反编译XML资源文件
Android反编译(二) 之反编译XML资源文件 [目录] 1.工具 2.反编译步骤 3.重新编译APK 4.实例 5.装X技巧 6.学习总结 1.工具 1).反编译工具 apktool http ...
- Android反编译(一)之反编译JAVA源码
Android反编译(一) 之反编译JAVA源码 [目录] 1.工具 2.反编译步骤 3.实例 4.装X技巧 1.工具 1).dex反编译JAR工具 dex2jar http://code.go ...
- Atitti.java android反编译解决方案-----虚拟机方案
Atitti.java android反编译解决方案-----虚拟机方案 哈哈,终极解决方案是虚拟机...c++也可以反编译为汇编代码,但无需担心,因为读懂汇编太麻烦..只要不能拿到c++源码就可.. ...
随机推荐
- hdu 2896 病毒侵袭 AC自动机(查找包含哪些子串)
病毒侵袭 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 4638 树状数组 区间内连续区间的个数(尽可能长)
Group Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- [BZOJ]1079 着色方案(SCOI2008)
相邻色块不同的着色方案,似乎这道题已经见过3个版本了. Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够 ...
- [济南集训 2017] 求gcd之和
题目大意: 求\(\sum_{i=1}^n\sum_{j=1}^mgcd(i,j)\) 解题报告: 有一个结论:一个数的所有因子的欧拉函数之和等于这个数本身 运用这个我们可以开始推: \(\sum_{ ...
- BZOJ1187 [HNOI2007]神奇游乐园(插头dp)
麻麻我会写插头dp了! 推荐陈丹琦论文:https://wenku.baidu.com/view/3e90d32b453610661ed9f4bd.html 破题调一年 #include <cs ...
- 《Java技术》第二次作业--面向对象基础
(一)学习总结 1.什么是构造方法?什么是构造方法的重载?下面的程序是否可以通过编译?为什么? public class Test { public static void main(String a ...
- localStorage 存取与删除
部分转自 http://blog.csdn.net/oo191416903/article/details/64122379 <!DOCTYPE html> <html> &l ...
- mac下怎么删除隐藏文件比如 .Trashes文件
U盘和移动硬盘接入Mac时会产生.Trashes,.Spotlight-V100,.fseventsd等文件 每插入Mac一次,都会检查是否有这些文件,如果没有,就会创建这些文件 特别是有时候,在文件 ...
- struct2 拿到url的方法
在Action中: HttpServletRequest request = ServletActionContext.getRequest(); String url =request.getReq ...
- 解读Raft(二 选举和日志复制)
Leader election Raft采用心跳机制来触发Leader选举.Leader周期性的发送心跳(如果有正常的RPC的请求情况下可以不发心跳)包保持自己Leader的角色(避免集群中其他节点认 ...