MiuiCamera Port for Xiaomi's Devices
Self sufficient repository to decompile to smali, recompile, sign, decompile to java, push to device app port.
miui_CEPHEUSGlobal_9.6.27_2b17a775d2_9.0.zip.zip was used as src.
Recommended to open this Repository in VSCode
Also requires Java 1.7 or 1.8, and 7-zip.
Instructions for Development:
- Clone this repository
- Run redo.bat
- Start porting
Instructions for Testing:
- Download the
zip
from https://github.com/XEonAX/ANXCamera/releases/ - Install the Magisk
zip
with Magisk, or Unityzip
with recovery - Reboot Once, if it doesn't work properly, reboot twice.
- Start Testing
Special Thanks to Abhishek Aggarwal (https://github.com/TheScarastic) for bringing this up to Beta version Mustang_ssc (https://github.com/Mustang-ssc) for his help in adding support for other devices Amogha Maiya (https://github.com/amog787) for sponsoring, and all-round help Sandeep (https://github.com/CodeElixir) for help with the libs Psygarden (https://forum.xda-developers.com/member.php?u=7645131) for his general help.
Steps to Port MiuiCamera from scratch:
- Unpack System of Miui ROM
- Mount Rom.zip to E:
- Use Brotli Extracter as below
brotli.exe --decompress --in E:\system.new.dat.br --out <PathToExtractTo>\system.new.dat
- We then use IMG_Extracter to extract
system.new.dat
- For me it doesn't extract properly. So we use 7zip to re-extract the img file it creates, &z should only throw errors about symlink, nothing else. This you can ignore
- Similarly do it for vendor
- Setup Original files for Decompiling
- Copy following to ANXCamera\orig\MiuiFrameworks. Files to be taken from Unpacked ROM above
- framework\framework-ext-res\framework-ext-res.apk
- framework\framework-res.apk
- app\miui\miui.apk
- app\miuisystem\miuisystem.apk
- Copy following to ANXCamera\orig
- priv-app\MiuiCamera\MiuiCamera.apk
- Copy following to ANXCamera\orig\MiuiFrameworks. Files to be taken from Unpacked ROM above
- Prepare APKTool for decompiling
- Install above framework files by running following commands
java -jar ..\ANXMiuiPortTools\apktool.jar if -p ..\ANXMiuiPortTools\MiuiFrameworks .\orig\MiuiFrameworks\framework-res.apk
java -jar ..\ANXMiuiPortTools\apktool.jar if -p ..\ANXMiuiPortTools\MiuiFrameworks .\orig\MiuiFrameworks\miui.apk
java -jar ..\ANXMiuiPortTools\apktool.jar if -p ..\ANXMiuiPortTools\MiuiFrameworks .\orig\MiuiFrameworks\framework-ext-res.apk
java -jar ..\ANXMiuiPortTools\apktool.jar if -p ..\ANXMiuiPortTools\MiuiFrameworks .\orig\MiuiFrameworks\miuisystem.apk
- Or
- Run
preparefw.bat
- Install above framework files by running following commands
- Decompile MiuiCamera by running
java -jar ..\ANXMiuiPortTools\apktool.jar d -p ..\ANXMiuiPortTools\MiuiFrameworks -f -b -o .\src\ANXCamera .\orig\MiuiCamera.apk
- Parameters
- d, decode
- -p, --frame-path
- -f, --force
- -b, --no-debug-info
- -o, --output
- Open
src\ANXCamera\AndroidManifest.xml
and format the document - First Compile Attempt
- Run
recompile.bat
just to check whether we are able to recompile without any modification - Run
sign.bat
to sign and zipalign - Run
jadx.bat
to create java code from compiled apk. This fails, don't worry, it does whatever it can
- Run
- Next we will Deodex rom and decompile the required libs
- Run in WSL or Linux
$ /<path to vdexExtractor>/tools/deodex/run.sh -i /<path to system>/framework -o /<path to deodex destination>/framework
- for e.g.
/mnt/g/Downloads/Android/vdex/vdexExtractor/tools/deodex/run.sh -i /mnt/g/Downloads/Android/systemcephy9627/system/framework -o /mnt/g/Downloads/Android/systemcephy9627deodex/framework
- for e.g.
- Above will deodex the system framework
- Now we decompile the required libs
- Copy latest baksmali.*.jar to
<path to deodex destination>
- To identify what libs you need to decompile. Open
src\ANXCamera\AndroidManifest.xml
- Find the
uses-library
XML Nodes. We need to decompile these - We will skip
miui-stat.jar
as we will disable miui-stats from sending data to miui.
- Find the
- Open a cmd inside
<path to deodex destination>
folder. And run the following:java -jar baksmali-2.2.7.jar d -o android-support-v7-recyclerview .\framework\vdexExtractor_deodexed\android-support-v7-recyclerview\android-support-v7-recyclerview_classes.dex.dex
java -jar baksmali-2.2.7.jar d -o android-support-v13 .\framework\vdexExtractor_deodexed\android-support-v13\android-support-v13_classes.dex.dex
java -jar baksmali-2.2.7.jar d -o boot-framework .\framework\vdexExtractor_deodexed\boot-framework\boot-framework_classes.dex
java -jar baksmali-2.2.7.jar d -o boot-framework2 .\framework\vdexExtractor_deodexed\boot-framework\boot-framework_classes2.dex
java -jar baksmali-2.2.7.jar d -o boot-framework3 .\framework\vdexExtractor_deodexed\boot-framework\boot-framework_classes3.dex
java -jar baksmali-2.2.7.jar d -o boot-miui .\framework\vdexExtractor_deodexed\boot-miui\boot-miui_classes.dex
java -jar baksmali-2.2.7.jar d -o boot-miuisystem .\framework\vdexExtractor_deodexed\boot-miuisystem\boot-miuisystem_classes.dex
java -jar baksmali-2.2.7.jar d -o gson .\framework\vdexExtractor_deodexed\gson\gson_classes.dex.dex
java -jar baksmali-2.2.7.jar d -o volley .\framework\vdexExtractor_deodexed\volley\volley_classes.dex.dex
java -jar baksmali-2.2.7.jar d -o zxing .\framework\vdexExtractor_deodexed\zxing\zxing_classes.dex.dex
- Copy latest baksmali.*.jar to
- Run in WSL or Linux
- Now we will add few of the above decompiles libs to our code
- Create a folder
src\ANXCamera\smali_classes2
- Copy the contents of
<path to deodex destination>\zxing
- to
src\ANXCamera\smali_classes2
. It should finally contain two folderscom
- Create a folder
- Set required = false in AndroidManifest of these libs as their code is now included
- Add missing smali files from decompiled miui rom
- Check
copymiuiclasses.bat
for more info
- Check
- Prepare the Unity Template
- Add native libs
- Hex patched libs
src\ANXCameraUnity\system\lib\libcameraservice.so
src\ANXCameraUnity\system\lib64\libcameraservice.so
- Required Stock Libs to
src\ANXCameraUnity\system\priv-app\ANXCamera\lib\arm64\
- Hex patched libs
- Edit Smali
- ...