Created
June 17, 2020 23:11
-
-
Save argaghulamahmad/e54cc34cf83da85d5119561ace48e1c5 to your computer and use it in GitHub Desktop.
process of decompiling recompiling apk with APKTool and 7zip-zstd, zipalign, keytool and jarsigner.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. extract without source: | |
| call "bin\apktool.cmd" --no-src d "myapp.apk" | |
| 2. modify Android.manifest - add: | |
| android:debuggable="false" android:versionCode="90" android:versionName="3.3" | |
| to | |
| <application | |
| get the versioncode and versionname information from 'apktool.yml', | |
| the information is near the bottom of the file. | |
| --------------------------------------------------------- | |
| really remove ads: | |
| backup Android.manifest, and edit it, removing 'activity' and 'service' of your choice (ad-related). | |
| hide ad-containers: | |
| backup the 'res/layout' folder, edit xml files in it: | |
| set ad-containers to zero width/height: | |
| android:layout_height="0dip" android:layout_width="0dip" | |
| if you see an ad-related xml-file that is called from another xmls, | |
| you can null'ify the xml by making its content simply: | |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout android:layout_width="0.0dip" android:layout_height="0.0dip" xmlns:android="http://schemas.android.com/apk/res/android"></LinearLayout> | |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| removing all the complex content. | |
| if there is a problem in the app because of the activity/service removal, | |
| bring back the backup of the 'Android.manifest', and just stick to hiding the ad-containers | |
| (editing xml files from 'res/layout') | |
| if you get an error from the app try bringing the backup of 'res/layout' back, | |
| and essentially recompile the app with minimal (or no) changes, if the app still | |
| shows an error - the app might compare checksum of the signature/certificate against the one from Google-Play store. this means you need to change the package(application)-name and remove the service that calls for 'com.google.android.gms.version' (or more), even start over extracting "with source" and editing smali sources... | |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| Android.manifest | |
| there is another way of removing: | |
| adding: | |
| tools:node="remove" | |
| for example: | |
| <uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" tools:node="remove" /> | |
| or | |
| <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-6451301793732562~8392801132" tools:node="remove"/> | |
| to use that you need manifest to have | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" | |
| ------won't work, only works if you actually build the apk... | |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| --------------------------------------------------------- | |
| 3. simple recompile without "copying original": | |
| call "bin\apktool.cmd" b "myapp" | |
| 4. look in the decompiled-project-folder under "dist" for the APK. | |
| 5. use 7zip-zstd to extract the content to a folder. | |
| 6. go to original and copy the content of the 'META-INF' except | |
| 'CERT.RSA', 'CERT.SF', 'MANIFEST.MF' | |
| to the 'META-INF' folder in what you've extracted in (5), don't overwrite anything if asked | |
| (keep the existing copies) | |
| this will fill up the "services", "nanohttpd", 'rxjava.properties' and many "android.arch._xxxxxxxxx_.version" files and folders. needed for the specific project. | |
| this is done manually since we want to keep the modified 'Android.manifest'. | |
| 7. use winzip to legacy compress the folder content to a zip. | |
| 8. rename the zip-file-extension to apk . | |
| 9. realign zip: | |
| zipalign.exe -v 4 myapp.apk | |
| rename result to myapp.apk | |
| ****. generate keystore/certificate: | |
| keytool.exe -genkeypair -alias "alias_name" -keyalg "RSA" -keysize "2048" -sigalg "SHA1withRSA" -validity "10000" -keypass "111111" -keystore "bin/foo.keystore" -storepass "111111" -dname "CN=*, OU=*, O=*, L=*, S=*, C=*" -v | |
| 10. sign the APK (with pre-generated keystore and certificate) | |
| jarsigner.exe -keystore "bin\foo.keystore" -storepass "111111" -keypass "111111" -digestalg "SHA1" -sigalg "SHA1withRSA" "-verbose:all" "myapp.apk" "alias_name" | |
| 11. copy the signed apk to mobile-device, try to install | |
| ---------------------- | |
| more information at: | |
| https://github.com/eladkarako/icompile/tree/master/removing-ads-from-apk | |
| https://icompile.eladkarako.com/removing-ads-from-apk | |
| some test APKs each contains original APK and modified APK (can compare the two): | |
| https://github.com/eladkarako/icompile/releases/download/latest/removing_ads_from_apk__com.radiosonline.radiofmisrael.7z | |
| https://github.com/eladkarako/icompile/releases/download/latest/removing_ads_from_apk__il.co.globes.android.7z | |
| ---------------------------------- | |
| removing ads (not hiding) | |
| I was trying to remove ads in a deeper way, | |
| ignoring the stages above, I've tried to start over: | |
| first I decompiled the APK with just 'd' (with source, without --no-src), | |
| then I've entered the smali folders and tried to rename (added '_') | |
| the gms folder from under 'com/google/android/gms', | |
| after I've recompiled everything the APK openeded successfully (failed silently when tried to use files from the 'gms' folder, which is good!) | |
| but no ads were gone. | |
| there were other potential folders 'com/crashlytics' which used for reports, 'com/chartbeat', 'com/sekindo' and 'com/google/ads' (there are few more but I'll start with those). | |
| I've renamed all of them the next stage (added '_') and hoped it will too fail silently :/ | |
| I had to repeat the process in 'smali', 'smali_classes2', 'smali_classes3' and 'smali_classes4' under the main folder. | |
| there were stuff such as 'com/amazonaws' and 'com/facebook' which I really wanted to remove, | |
| but suspected they are integrated too deep so I've left them. | |
| I also renamed 'smali/im' folder and 'smali/spot' which are part of 'spot.im' ads system, | |
| I removed a lot and I hoped that everything will fail silently. | |
| ... | |
| it seems to compile OK but same amount of ads were there, | |
| I saw sekindo even that I've renamed the folder, weird. | |
| I've repeated recompiling with renamed 'com/safedk' --- same result. | |
| I've figured that there must be a shared resource on the phone that supplied ads as part of Google-Play services... | |
| time to search smali files... :( | |
| setVisibility is a function that shows ads, | |
| you can see variations of it along the smali files, for example: | |
| const-string v2, "Lcom/google/android/gms/ads/doubleclick/PublisherAdView;->setVisibility(I)V" | |
| to "comment-out" simple add '#' in-front of it - note that commenting out strings isn't always a good idea. | |
| I've found some method invoking too and commented-them out, this is a lot safer to comment-out. | |
| #invoke-direct {p0}, Lcom/google/android/gms/ads/AdListener;-><init>()V | |
| and quite a lot of those: | |
| invoke-direct {p0}, Lcom/google/android/gms/ads/AdListener;-><init>()V | |
| smali editing is a b!tch!!! | |
| there are a lot of them and you need to actually read and figure out some of the logic, | |
| it is very long so I've only edited few smali files in the first and second folder, to see how those will compile eventually, | |
| I've done a semi-good job in commenting out consts and methods (I hope invalid consts will cause silent failing too...) | |
| something got kind of wrong, | |
| and the application actually got my phone to restart, | |
| usually its because of a hanged applications... | |
| so I've figured this smali editing should be researched more before... | |
| ...well doing it, | |
| to sum things up (for stage two) deleting the folderd ('ads', 'gms',... ) didn't change anything, | |
| removing ads through smali editing is too long/complex (but potentially can remove full-page ads), | |
| editing android.manifest (stage one) shouldn't be done, it breaks the application, | |
| the only somewhat good method is xml-layout editing, which still leaves complex-er ads such as full-page ones. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment