日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android反编译 -- 错误代码还原

發布時間:2024/1/17 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 相應 0xffffffff0xffffff 的值 16777215那么對隨意的 setColor(int)中的int值,我們能夠: 0xffffffff+(int)+1 或 0xffffffff-(-int+1) 則對于 :setColor(-16777216) 可寫成 :setColor(0xffffffff - 16777215)) 或 setColor(-16777216 + 1 + 0xffffffff))這樣,我們就不用查文檔尋找特定的顏色值。也能解決隨意顏色的設置。

Stackoverflow : How to set color using integer?

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 = 335544320268435456 | 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()的使用方法,應該也是第一種情況。

相關資料:

http://farwmarth.com/2013/04/23/android%20反編譯和代碼解讀/

PS:

本文已整理到Github上,歡迎提交很多其它代碼!
你能夠關注的我Github、CSDN和微博

轉載于:https://www.cnblogs.com/yangykaifa/p/7279292.html

總結

以上是生活随笔為你收集整理的Android反编译 -- 错误代码还原的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。