Closed sekaiacg closed 1 year ago
This issue is fixed on ARSCLib, you can build your own jar or download updated release APKEditor-1.2.0.jar
Tip:
Decompile/Build in JSON format is highly accurate even if obfuscated, however if your apk's resources are not obfuscated you can do the same in XML format by adding option -t xml
to decode args like: java -jar APKEditor.jar d -t xml -i your_file.apk
Thanks! no more json errors, this problem has been perfectly fixed. I tried -t xml but it causes incorrect ui layout. Using other tools to view the compiled resources.arsc file prompts an error. Maybe some apk in this rom is obfuscated, everything works fine with json.
UI problem after using xml:
error info:
TAG: 2.13.4(23040183)
ROOT: true
ABI: arm64-v8a
MODEL: 22021211RC
SDK: 33
RELEASE: 13
---StackTrace---
java.lang.RuntimeException: [com.android](http://com.android/) .settings/attr/actionBarSplitMaxPercentageHeight 192 65472
at l.ۧ۟ۛ.ۨ(L63Q:152)
at l.۠۟ۛ.ۨ(05W2:138)
at l.ۖ۟ۛ.ۨ(15Y4:149)
at l.۟۟ۛ.ۨ(D622:174)
at l.ۢ۟ۛ.ۨ(W54R:118)
at l.ۛ۟ۛ.ۨ(S4NY:62)
at l.ۗۡۧ.ۨ(21FW:1008)
at l.ۗۡۧ.ۖ(21FW:835)
at l.ۗ۟ۧ.ۥ(81KA:569)
at l.ۨۙۨۨ.ۨ(U4WR:101)
at l.ۤۤ۟.run(DATL:0)
at java.util.concurrent.ThreadPoolExecutor.runWorker( [ThreadPoolExecutor.java:1137](http://threadpoolexecutor.java:1137/) )
at java.util.concurrent.ThreadPoolExecutor$Worker.run( [ThreadPoolExecutor.java:637](http://threadpoolexecutor.java:637/) )
at [java.lang.Thread.run](http://java.lang.thread.run/) ( [Thread.java:1012](http://thread.java:1012/) )
The original version of the apk in question is the one compiled with xml: Settings_use_xml.apk
thanks for your work.
I thought I fixed this issue a while ago. Now I fixed the issue and updated all along with the release APKEditor-1.2.0.jar Your apk should work fine with this
I conducted a test, resources.arsc is no longer wrong. but the UI layout is not correct, is there a problem with xml parsing? I used the recompiled apk (xml) to decompile to json format again, and found that it could not match the original apk decompiled json file in some places.
The left side uses the xml format and decompiles it into json again.(Settings_decompile_xml_out_decompile_json) Settinhs_test.zip example: base/res-json/res/drawable-sw600dp-v13/core_scan_gesture_broadside.xml.json
The error was DIMESION value encode/decode. On this case raw value -47615 supposed to be decoded as -186.0dp. Now this issue seems to be fixed and check the latest update.
You are pointing out good issues, hope you will keep doing same. Thank You !
The error was DIMESION value encode/decode. On this case raw value -47615 supposed to be decoded as -186.0dp. Now this issue seems to be fixed and check the latest update.
You are pointing out good issues, hope you will keep doing same. Thank You !
After testing, the UI layout is normal. Another question: value_type: INT_COLOR_ARGB8(xml) and INT_COLOR_RGB8(json) represent the same type? The results of xml and json are inconsistent.
Question 1: I found that some resource hooks in the apk compiled back using xml are invalid (third-party themes can change the text options in the settings, but some do not take effect).
If it does not take effect, the default content will be used:
"entry_name": "personalize_title",
"value": {
"value_type": "STRING",
"data": "壁纸与个性化"
},
The strange thing is that the problem disappears after decompiling the problematic apk using json and then compiling it back to apk. Settings_decompile_xml_out.apk : not take effect Settings_decompile_xml_out_decompile_json_out.apk : take effect apk file: Settings_test2.zip
I think compiling back to apk with xml might cause some unknown issues.
Question 2: When decompiling AndroidManifest.xml, extra spaces and characters appear: '
Question 1: I found that some resource hooks in the apk compiled back using xml are invalid (third-party themes can change the text options in the settings, but some do not take effect).
On your apk, the value was decoded as
<string name="personalize_title">Wallpaper &amp; personalization</string>
for value of
Wallpaper & personalization
. But I am not sure it will fix this issue, I will get back after making some investigation, in the meantime check the latest update
Another question: value_type: INT_COLOR_ARGB8(xml) and INT_COLOR_RGB8(json) represent the same type? The results of xml and json are inconsistent.
This was wrong, now fixed
Question 2: When decompiling AndroidManifest.xml, extra spaces and characters appear: '
This is correct parsing, those additional characters are existed on original bin xml
Another question: value_type: INT_COLOR_ARGB8(xml) and INT_COLOR_RGB8(json) represent the same type? The results of xml and json are inconsistent.
This was wrong, now fixed
Question 2: When decompiling AndroidManifest.xml, extra spaces and characters appear: '
This is correct parsing, those additional characters are existed on original bin xml
I use the latest updated version for testing: 1.INT_COLOR_RGB8 fixed. 2.Question 1 still exists. 3.Because there are special characters in the original AndroidManifest.xml, it can also be expected.
2.Question 1 still exists. 3.Because there are special characters in the original AndroidManifest.xml, it can also be expected.
The developer of this apk put those characters AndroidManifest.xml for some reason or mistake. Not the problem of the parser. Check AndroidManifest.xml.json
{
"node_type": "text",
"text": " ' "
}
ok, I know, thank you.
Hi, the problem caused by using xml was also found in other apk.
In the following apk, after compiling back with xml, the options in the red box are not displayed. apk file: Home_test.zip
At the same time, some devices may crash after installing the apk.
05-04 20:28:37.629 15524 15524 E AndroidRuntime: FATAL EXCEPTION: main
05-04 20:28:37.629 15524 15524 E AndroidRuntime: Process: com.miui.home, PID: 15524
05-04 20:28:37.629 15524 15524 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at miuix.preference.DropDownPreference$1$1.run(DropDownPreference.java:67)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:942)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:210)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at android.os.Looper.loop(Looper.java:299)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8116)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
05-04 20:28:37.629 15524 15524 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
There is no problem parsing with json, all works fine.
Odd apk , arrays supposed to have attributes 0x01000000
, 0x01000001
, 0x01000002
... but this apk has all name values 0. My guess is that it was modified by non aapt tool.
Anyways it's fixed now check the latest updates
Odd apk , arrays supposed to have attributes
0x01000000
,0x01000001
,0x01000002
... but this apk has all name values 0. My guess is that it was modified by non aapt tool.Anyways it's fixed now check the latest updates
I used the latest updated version to test, and the problem still persists. Is there a better way to find the problem? Now the problem I found is no longer easy to locate by simple file comparison...
In addition, I may have found the cause of the problem by using grep. Using json, its value_type is string The one on the right is parsed directly using json Home_decompile_xml_out_decompile_json------Home_decompile_json resources.arsc.json:
I got some wrong places after I used regex to exclude "line": There may be more than one file with the same type of problem. navigation_bar_type_settings.xml.json:
miui_home_dialog_anim_pop_in_center.xml.json:
material_ic_clear_black_24dp.xml.json:
material_ic_clear_black_24dp.xml.json:
smallwindow_icon.xml.json:
notification_action_background.xml.json:
miuix_sbl_tracking_progress_ellipse_bg.xml.json:
I thought of a way: create an apk with all value_type, using json and xml respectively (again using json decompilation). Compare their differences separately, so the workload is much less.
Why is json parsing correct and xml wrong? Are their implementations different?
Why is json parsing correct and xml wrong? Are their implementations different?
Good question, Consider dex(dalvik) decompiling we can decompile/compile to smali
or java
but most of the times java gets error
ARSC
to/from XML
is like converting DEX
to/from JAVA
ARSC
to/from JSON
is like converting DEX
to/from SMALI
Decompiling to XML is not 1:1 it is based on guess and assumptions e.g. you have a value 1234
there is no direct way to tell for XML this is STRING
or INTEGER
or FLOAT
but for JSON you simply specify it with value_type:"xxxx"
. XML by itself has its own limitation/weakness.
This is the reason why i came up with idea of JSON format as an agent between low level byte code and humans to modify binary resources with 100% accuracy. If you check commits history I added XML support lately because most developers are used to XML and got confused with the new JSON.
I always recommend to use JSON format (if you are good at it) it is guaranteed to be 100% accurate.
Anyways we will keep improving XML conversion but there is no logical way to reach 100% error free.
smallwindow_icon.xml.json:
Fixed with this commit I will update releases latter after fixing other issues
Thanks for your answer, I understand the difference between xml and json. I will test it after fixing the problem.
Fixed major issues and release updated, you can test it now
Fixed major issues and release updated, you can test it now
I tested with the latest update:
At the same time, compared with the previous APK, it is found that some xml has special characters, but after parsing the xml for the second time, there are more newlines and spaces after the special characters, which is different from the previous format. Probably similar to the json in the previous question. apk file: Settings_test3.zip The right is parsed directly through XML. Settings_decompile_xml_out_decompile_xml---------------------------------Settings_decompile_xml res/drawable/color_bar_progress.xml:
Through simple comparison, it is found that the content in some xml is different or missing: res/values/colors.xml:
res/values/dimens.xml:
res/values/strings.xml:
The right side is parsed directly using json. Settings_decompile_xml_out_decompile_json----------------------------------------Settings_decompile_json res/layout/accessibility_edit_shortcut_magnification_pad.xml.json: value_type inconsistent
Seems to be fixed now, check updates
- Color
- Style string
Seems to be fixed now, check updates
1.Color has been fixed.
Question 1: I found that some resource hooks in the apk compiled back using xml are invalid (third-party themes can change the text options in the settings, but some do not take effect).
If it does not take effect, the default content will be used: "entry_name": "personalize_title", "value": { "value_type": "STRING", "data": "壁纸与个性化" },
The strange thing is that the problem disappears after decompiling the problematic apk using json and then compiling it back to apk. Settings_decompile_xml_out.apk : not take effect Settings_decompile_xml_out_decompile_json_out.apk : take effect apk file: Settings_test2.zip
I think compiling back to apk with xml might cause some unknown issues.
Question 2: When decompiling AndroidManifest.xml, extra spaces and characters appear: '
At the same time, if the APK is processed smoothly according to the following three items, the results obtained will be inconsistent.
apk→xml→apk: not take effect apk→xml→apk→json→apk: take effect apk→json→apk: take effect
Add 2 content that has no effect:
"entry_name": "display_settings",
"value": {
"value_type": "STRING",
"data": "Display"
},
...
"entry_name": "sound_haptic_settings",
"value": {
"value_type": "STRING",
"data": "Sound & touch"
},
I'm using the latest updated version and haven't modified anything, so I don't understand what the difference is. This is a very miraculous phenomenon. Because the problem can be solved by recompiling the APK that has no effect using json decompilation again.
DIMENSION:
1) When you divide/multiply integers to float you will loose fractional values , e.g if you encode-decode-encode value 1.0dp
without any adjustment the result will be 0.999999dp, that is why I tried to round up digits with best result possible.
2) Encoding dimension to integer is a bit complicated check AOSP Line 379-386 e.g value 180.0dp
can be encoded to integer 46081
or 5898257
if you decode this values the result is the same. So you might see different integer result on JSON but it is the same.
STRING: 1) > 2 . There is still a problem with the string, the content lacks spaces
Yes I confirm, it will be fixed
I will fix this and other issues and get back to you
Question 1: I found that some resource hooks in the apk compiled back using xml are invalid (third-party themes can change the text options in the settings, but some do not take effect).
I can't figure out where exactly this problem is. I compared (using custom program byte level) files built with json & xml, most differences are irrelevant except config size 64(xml) & 48(json) and I doubt this fixes your issue.
I updated releases, you can test now and it will be better if you can get some stacktraces/logs
I tested with the latest updated version. The latest version causes APK language resource exception. It is set to Simplified Chinese, but it is actually Traditional Chinese, and the language cannot be switched. Sorry, I have no way to continue testing... The results after 2 decompilations using xml cannot be compared... Settings_decompile_xml_out_decompile_xml--------------------------------Settings_decompile_xml
I think the new version may have broken some resource. Using json works fine.
Ohh I made silly mistake here. Check the latest update
Tested with the latest version, Question 1 is not resolved. i didn't find the log...
Can you send me some of "third-party" apps ?
Can you send me some of "third-party" apps ?
The theme will not generate effects on third-party apps.
This is the theme supported by MIUI ROM. It requires the built-in ThemeManager.apk to apply. It can modify option text in settings (Settings.apk). Using -t xml to compile APK (Settings.apk) will cause the text of some options to fail to take effect.
Like I said above, just compiling again with json will solve the problem. This shows that xml and json are correct when parsing the content of the ARSC file. I'm guessing the problem might be remaking the ARSC file.
There are no relevant errors in the logs. I don't know how to go about debugging it.
This is the value_xml(com.android.settings) file of Settings
<?xml version='1.1' encoding='utf-8' standalone='yes' ?>
<MIUI_Theme_Values>
<string name="miui_more_special_feature">探索功能</string>
<string name="data_usage_summary_title">流量情况</string>
<string name="ai_button_title">智能按键</string>
<string name="emergency_sos_title">紧急求助</string>
<string name="my_device">我的设备</string>
<string name="about_settings">关于手机</string>
<string name="header_category_wireless_networks">网络连接</string>
<string name="sim_management_title">双卡网络</string>
<string name="wifi_settings_title">无线网络</string>
<string name="bluetooth_settings_title">蓝牙连接</string>
<string name="wifi_tether_settings_title">个人热点</string>
<string name="app_name_na">网络助手</string>
<string name="vpn_settings_title">代理设置</string>
<string name="radio_controls_title">更多方式</string>
<string name="display_settings">显示设置</string>
<string name="sound_vibrate_settings">声音振动</string>
<string name="lock_settings">锁屏密码</string>
<string name="lock_settings_with_fingerprint">密码指纹</string>
<string name="status_bar_settings">通知设置</string>
<string name="infinity_display_title">全屏手势</string>
<string name="second_space">手机分身</string>
<string name="do_not_disturb_mode">勿扰模式</string>
<string name="power_usage_summary_title">电量性能</string>
<string name="pref_edge_handgrip">边缘触控</string>
<string name="game_mode_settings">游戏模式</string>
<string name="miui_lab_settings">实验功能</string>
<string name="oldman_mode_entry_name">极简桌面</string>
<string name="other_advanced_settings">更多设置</string>
<string name="xiaomi_account">小米帐号</string>
<string name="sync_settings">自动同步</string>
<string name="system_app_settings">系统应用</string>
<string name="applications_settings">更多应用</string>
<string name="xspace">应用双开</string>
<string name="permission_manager">授权管理</string>
<string name="application_lock_name">应用守护</string>
<string name="usage_state_app_timer">屏幕时间</string>
<string name="launcher_title">桌面管理</string>
<string name="account_list">其他账号</string>
<string name="header_category_accounts">账号管理</string>
<string name="home_title">桌面管理</string>
<string name="aod_and_lock_screen_settings_title">息屏锁屏</string>
<string name="password_security_settings_title">密码安全</string>
<string name="security_settings_title">密码管理</string>
<string name="lock_screen_settings_title">锁屏管理</string>
<string name="security_keyguard_category_name">锁屏管理</string>
<string name="password_and_security">密码安全</string>
<string name="connection_and_sharing">连接共享</string>
<string name="notification_control_center">通知控制</string>
<string name="feedback_settings">服务反馈</string>
<string name="power_usage_summary_title_new">电量性能</string>
<string name="wallpaper_settings_title">桌面壁纸</string>
<string name="personalize_title">桌面壁纸</string>
<string name="wallet_header_title">钱包支付</string>
<string name="card_holder_header_title">钱包支付</string>
<string name="sound_haptic_settings">声音触感</string>
<string name="security_center_title">安全管理</string>
<string name="fingerprint_face_password_unlock">密码管理</string>
<string-array name="handy_mode_size_text_entries">
<item>4.5 英寸</item>
<item>4.0 英寸</item>
<item>3.5 英寸</item>
<item>2.5 英寸</item>
<item>2.0 英寸</item>
<item>1.5 英寸</item>
<item>1.0 英寸</item>
<item>0.5 英寸</item>
</string-array>
......
</MIUI_Theme_Values>
some of them don't work
<string name="personalize_title">桌面壁纸</string>
<string name="display_settings">显示设置</string>
<string name="sound_haptic_settings">声音触感</string>
...
It's possible that it has something to do with the frame. json can guarantee 100% correctness. If no progress is made, this issue can be closed first.
Thanks for your work.
No point closing this issue without finding out the exact problem. I am making new separate program to compare resources in detail. I will get back to you when it is done
Here I made a massive change you can test it with APKEditor-1.2.0-UPDATE-01.jar
Here I made a massive change you can test it with APKEditor-1.2.0-UPDATE-01.jar
- The only problem I found was it doesn't remove unused strings from pool
This version does not solve the problem. This question is very peculiar....
Your link is APKEditor-1.2.0-UPDATE-01.jar But I downloaded it again: https://github.com/REAndroid/APKEditor/releases/download/V1.2.0/APKEditor-1.2.0-UPDATE-02.jar
Sorry, the problem is not resolved... json works fine.
I used other tools to modify the contents of the ARSC file individually(Then it took effect):
Settings_decompile_xml_out.apk: not take effect Settings_decompile_xml_out_other_tool_mod.apk: take effect
Can you use it to figure out why?
APK file: Settings_test6.zip
Settings_decompile_xml_out.apk: not take effect Settings_decompile_xml_out_other_tool_mod.apk: take effect
This files are wrongly edited by your tool and the resource ids are distorted.
Since your apk is also framework, resources must be publicized to be accessible by other apps.
Here is an update with other major issues fixed: APKEditor-1.2.0-UPDATE-03.jar
Settings_decompile_xml_out.apk: not take effect Settings_decompile_xml_out_other_tool_mod.apk: take effect
This files are wrongly edited by your tool and the resource ids are distorted.
I don't know what's wrong with this. But this tool recompiles the ARSC file, just modifying it with it will solve the problem. This has the same effect as recompiling with json. After these tests, it is also proved that the ARSC file compiled by json (APKEditor) is correct.
Since your apk is also framework, resources must be publicized to be accessible by other apps. Here is an update with other major issues fixed: APKEditor-1.2.0-UPDATE-03.jar
After testing, this version does not solve the problem. Below is the original APK/JSON and XML compiled effect. There should be some errors in the ARSC file compiled by xml.
Sorry I don't know chinese and your screenshots are not helping me at all. If you place it here in raw strings I might be able to copy and do string search it. for example:
Correct-Text | Wrong-Text |
---|---|
无无无无 | 寸寸寸寸寸 |
uuuuuu | vvvvvvvvvv |
wwwww | xxxxxxxxx |
Is this problem happening on chinese (zh-rCN) language only ? If not please change it to english for better communication.
Here is my builds based on your original file, now tell me which one is working and which is not (sign it if required)
original
> decompile to xml
> compile
Settings_decompile_xml_out.apkapk from 1
> decompile to json
> compile
Settings_decompile_xml_out_decompile_json_out.apkI changed the text to English. custom theme value:
<?xml version='1.1' encoding='utf-8' standalone='yes' ?>
<MIUI_Theme_Values>
......
<string name="personalize_title">Wallpaper & personalization test1</string>
<string name="display_settings">Display test2</string>
......
</MIUI_Theme_Values>
original apk/json(APK Default Text) | original apk/json(custom theme: Correct-Text) | xml(custom theme: Wrong-Text) |
---|---|---|
Wallpaper & personalization | Wallpaper & personalization test1 | Wallpaper & personalization |
Display | Display test2 | Display |
I think I misunderstood you this whole time, when you mean by "apply-theme" do you mean edit the apk with other tool ?
This reply explains the phenomenon of the problem in detail: https://github.com/REAndroid/APKEditor/issues/20#issuecomment-1555944377
"apply-theme" does not mean modifying the APK. Theme Manager:
I found issue on duplicate resource names, check this update APKEditor-1.2.0-UPDATE-04.jar
I found issue on duplicate resource names, check this update APKEditor-1.2.0-UPDATE-04.jar
Great, this version fixes the problem.
Thanks for your work.
Good ! We have solved a lot of issue on the way. I will update repos with proper release and I will credit you for your contribution. Thank you!
1.APKEditor version: 1.2.0 2.apk file: Settings.apk
3.run: java -jar APKEditor.jar d -i Settings.apk
do not make any changes.
4.run: java -jar APKEditor.jar b -i Settings_decompile_null