在bash脚本中运行apktool

时间:2022-05-25 00:08:37

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.

我正在尝试编写一个bash脚本,该脚本使用apktool分解几个.apk文件。每个apk文件都位于示例文件夹的子目录中。

#!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将正常工作。

./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.

我已经将sample文件夹中所有文件的权限更改为rw,以供所有用户使用。我也尝试过用sudo处理shell脚本,但是这会导致脚本挂起。但是,当我在命令行中使用sudo时,它也挂起了。因此,我不确定在apktool上使用sudo是否可行。

Any help is appreciated, thanks.

非常感谢您的帮助,谢谢。

1 个解决方案

#1


2  

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.

看起来这个ls给你一个带有星号*的输出,附加在apk文件名的末尾,因为这个文件是可执行的。

    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:

这不是ls的默认行为,您得到这个可能是因为您已经将ls别名化到ls -F或类似的。要绕过别名,请这样重写这一行:

    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:

顺便问一下,apk文件是可执行的吗?也许您可以删除可执行位:

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

注意,这不是完全相同的东西,因为它可能比两个目录更深入。如果你需要限制深度,那也是可能的,看《人类发现》

#1


2  

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.

看起来这个ls给你一个带有星号*的输出,附加在apk文件名的末尾,因为这个文件是可执行的。

    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:

这不是ls的默认行为,您得到这个可能是因为您已经将ls别名化到ls -F或类似的。要绕过别名,请这样重写这一行:

    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:

顺便问一下,apk文件是可执行的吗?也许您可以删除可执行位:

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

注意,这不是完全相同的东西,因为它可能比两个目录更深入。如果你需要限制深度,那也是可能的,看《人类发现》