I am trying to write a bash script that decompiles several .apk files using apktool. Each apk file is located in a subdirectory of the sample folder.
#!bin/bash
for item in $(ls samples);
do
for apk in $(ls "samples/$item");
do
echo ./apktool/apktool d "./samples/$item$apk"
$(./apktool/apktool d "./samples/$item$apk")
done
done
When I run the script I get the following output:
./apktool/apktool d ./samples/ADRD/53dc.apk*
Input file (./samples/ADRD/53dc.apk*) was not found or was not readable.
The input file error message is the standard for when apktool cannot find a file. However, if I run the following command in the terminal the apktool will work correctly.
./apktool/apktool d ./samples/ADRD/53dc.apk*
I have changed the permissions of all the files located in the samples folder to rw for all users. I also have tried using sudo with the shell script, but this causes the script to hang. However, when I use sudo with the apktool in the command line it also hangs. Therefore, I am not sure if using sudo with apktool is doable.
Any help is appreciated, thanks.
So it looks like this ls gives you an output with an asterisk * appended at the end of the apk filename, because the file is executable.
for apk in $(ls "samples/$item");
This is not the default behaviour of ls, you are getting this probably because you have aliased ls to ls -F or similar. To bypass the alias, rewrite the line this way:
for apk in $(\ls "samples/$item");
Notice the \ I added there.
BTW, is it normal that an apk file is executable? Perhaps you can remove the executable bit:
find samples -name '*.apk' -exec chmod -x {} \;
Also, possibly your script can be replaced with this one liner:
find samples -name '*.apk' -exec ./apktool/apktool d {} \;
Mind you, this is not exactly the same thing, because it may go deeper than two directories. If you need to limit the depth, that's possible too, see man find
Related
In native android development I could check whether my minifyEnabled had taken effect.
I used this script (in linux) which allows me to extract the apk and view the java files to see if my code is readable, or has been obfuscated :
#! /bin/bash
d2j=/work/installs/dex2jar-2.0
jdgui=/work/installs/jd-gui-1.4.0.jar
apk_loc=/work/projects/my_app/build/app/outputs/app-release.apk
mkdir -p /work/tmp/dex
rm -rf /work/tmp/dex/*
cd /work/tmp
cp $apk_loc ./app-release.zip
unzip app-release.zip -d dex
cd dex
chmod +x $d2j/*.sh
$d2j/d2j-dex2jar.sh classes.dex
java -jar $jdgui classes-dex2jar.jar
If I use this script on a flutter apk, I don't see any files containing anything related to my original code.
Flutter's dart code is compiled to native and embedded to flutter.so runtime, so decompiling flutter is not as easy as byte code of java/kotlin
However decompiling .so file is possible. You can use the toolchains inside the android ndk to perform the type of disassembling you want to
./android-ndk-r15b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objdump -T "flutter.so | less
but this is just give you an objdump.
I have many APK (Android package) files in a folder and I want to extract the manifest files from each of them. I am using Android apktool to convert them and since there are many APK files I want to convert them in a loop, not one by one.
apktool d hello.apk ./hello is the command for extracting manifest files from hello.apk and produces the output folder named hello.
I tried the command in the command prompt using for loop in the current directory in which all APK files are stored:
for \r %v in (*.apk) do apktool d "%v" "./%v".
I want the output folder of same name for each APK file, i.e. if APK is hello.apk the output folder should be hello. The above command is producing an error: cannot generate the output folder. How can I extract manifest files from all such APK files at once from a loop?
Maybe you forgot -o parameter?
That command works fine for me:
for /r %v in (*.apk) do apktool.jar d "%v" -o "./%~Nv"
i'm looking to write (or find :D) a script to convert an exisisting Android Project Source to a copy with another package name, that i provide.
Source have package like it.pinco.pallino.source and Copy will be like it.pinco.pallino.test1 etc etc...where test1 is a parameter.
I'm looking to use ANT or this script https://github.com/lijunjieone/RenameAndroidPackage, but there's no README and i don't know python..
Any suggestion?
Thanks
This is what I have written to change the package name without having to duplicate any code (for maintainability reasons, I use the same code for the free and pro version of my app).
Here's the script that converts Free version to Pro. It should be pretty easy to adapt it to your needs (provided you work under Linux, or use Cygwin or a linux virtual machine)
# 1- rename src folder
mv src/com/lulo/scrabble/dico src/com/lulo/scrabble/dicopro
# 2- replace references to package in Java, XML and CFG (proguard) files
find . \( -name "*xml" -o -name "*.java" -o -name "*.cfg" \) -print0 | xargs -0 sed -ri 's/scrabble.dico/scrabble.dicopro/g'
# 3- change the application name
find . -name "*.xml" -print0 | xargs -0 sed -ri 's/\(Free\)/Pro/g'
# 4- change the icon
cp ../IMAGES/LOGODICO_V2_2012_96px.png res/drawable-xhdpi/icon.png
cp ../IMAGES/LOGODICO_V2_2012_72px.png res/drawable-hdpi/icon.png
cp ../IMAGES/LOGODICO_V2_2012_48px.png res/drawable-mdpi/icon.png
cp ../IMAGES/LOGODICO_V2_2012_36px.png res/drawable-ldpi/icon.png
After this I just need to Refresh, Build and Export using Eclipse.
Right now I am using rm -r /blaa/* to delete all folders and files in the blaa directory. What I am looking for is a way to remove all folders and files in the blaa directory except if the folder is named abc.
Any ideas?
In Linux:
There are many ways to this; however I believe the best way to do this is to simply use the "find" tool.
find ! -iname "abc" -exec rm -rf {} \;
We can easily find and delete the every file and folder that is not named "abc".
find - to find files
! -iname - to filter files/folders, the "!" means not
-exec - to execute a command on every file
rm -rf - remove/delete files -r for folders as well and -f for force
"{} \;" - allows the commands to be used on every file
In Android:
Since you can't use "rm -rf" and when you use "rm -r" it will delete the folder "." which ends up deleting everything.
I am guessing you have "root" on your phone because you can use the "find" tool.
find ! -iname "abc" | sed 1d | xargs rm -r
find - to find files
! -iname - to filter files/folders, the "!" means not
| - pipe sends data to next command
sed - replace text/output
"1d" - removes first line when you do "find ! -iname" by itself
xargs - runs commands after pipe
rm -r - remove/delete files, "-r" for recursive for folders
Edit: Fixed and tested in Android
You can easily change this to suite your needs, please let me know if this helps!
The Adopted Solution
...and the final hoorah... This is what worked for the use case (helps to sum up the comments below as well):
find ! -iname "abc" -maxdepth 1 -depth -print0 | sed '$d' | xargs -0 rm -r;
Notes:
-depth — reverses the output (so you dont delete sub-dirs first
-maxdepth 1 — kind of voids the use of -depth, but hey... this says only output contents of the current directory and not sub-dirs (which are removed by the -r option anyway)
-print0 and -0 — splits on line feeds instead of white space (for dirs with space in the name)
sed "$d" — says to remove the last line (cause its now reversed). The last line is just a period which including would make the call delete everything in the directory (and subs!)
I am sure someone can tighten this up, but it works and was a great learning op!
Thanks again to Jared Burrows(and the Unix community in general — go team!) — MindWire
I would like to covert odex file to dex file. I already pulled framework folder from system. I tried the following command,
java -jar baksmali-2.1.2.jar -d system/framework -x temp.odex
but error was produced - error message is like below.
Error occurred while loading boot class path files. Aborting. org.jf.util.ExceptionWithContext: Cannot locate boot class path file /system/framework/core.jar
at org.jf.dexlib2.analysis.ClassPath.loadClassPathEntry(ClassPath.java:277)
at org.jf.dexlib2.analysis.ClassPath.fromClassPath(ClassPath.java:182)
at org.jf.baksmali.baksmali.disassembleDexFile(baksmali.java:67)
at org.jf.baksmali.main.run(main.java:113)
at org.jf.baksmali.main.main(main.java:322)
I could not find "core.jar" in my android system framework folder.
As of 2017-06-09 baksmali has changed. It works like this.
java -jar baksmali-2.2.0.jar d SamsungInCallUI.odex -o SamsungInCallUI
Then assemble the dex file.
java -jar smali-2.2.0.jar ass SamsungInCallUI -o SamsungInCallUI.dex
Try this instead:
java -jar baksmali-2.1.2.jar -c boot.oat -d system/framework/arm/boot.oat -x temp.odex
The specific path to your boot.oat might be different.
Also note that baksmali doesn't yet support deodexing the N preview images.
This worked for me adb pull /system/framework/arm/boot.oat /tmp/framework/boot.oat Placing the apk and the odex file baksmali.jar -x -c boot.oat -d /tmp/framework APKname.odex -o APKname
I'm not sure that I've understood correctly your question (kindly correct me if I'm wrong), but if you are trying to convert an odex to dex, I've already replied to a similar question here: https://reverseengineering.stackexchange.com/questions/12393/reverse-engineering-android-vendor-system-apps/12406#12406
Anyway, to my knowledge you have two chooice:
Follow this guide: http://www.naldotech.com/how-to-deodex-applications-on-android-5-0-lollipop/
Or use oat2dex as pointed out by the user who commented my answer on RE stackexchange.
Good luck
This is an extension of #kakopappa's answer.
Get the latest version of baksmali and smali jar from here and put them in a folder and add this method to your .bash_profile file if you are a mac/linux user.
Get baksmali and smali jar in your computer and assign it to these variables from terminal.
BAKSMALI_JAR_PATH = ""
SMALI_JAR_PATH=""
Note : After editing the value should look something like
BAKSMALI_JAR_PATH = "/Users/rabbit/tools/baksmali-2.2.7.jar"
SMALI_JAR_PATH = "/Users/rabbit/tools/smali-2.2.7.jar"
Copy paste this script in your terminal and restart your terminal. This is a shortcut function which would get added to .bash_profile and you would get it handy.
echo "BAKSMALI_JAR_PATH="$BAKSMALI_JAR_PATH >> ~/.bash_profile
echo "SMALI_JAR_PATH="$SMALI_JAR_PATH >> ~/.bash_profile
echo >>
function odextodex() {
odex_file_name=$1
deassembled_file=${odex_file_name%.odex}
java -jar $BAKSMALI_JAR_PATH d $1 -o $deassembled_file
java -jar $SMALI_JAR_PATH ass $deassembled_file -o $deassembled_file.dex
rm -rf $deassembled_file
}
After doing this type odextodex filename.odex - you should see filename.jar file in your current directory.