Some time ago while i was searching for a way to find out what i can delete from my Android rom without crippling functions i use, i found deptree
over at the xda forums
. Since this was written back in 2012 it wouldn't work as intended. Updating used tools (dex2jar
, smali
, ...
) plus some minor changes to the scripts (like changing folders to the ones used in Android
by now, for example system/app-private
to system/priv-app/*/
) and i got it running again.
Part of the magic happens in three scripts which are similar to this one:
while [ -n "1ドル" ]; do
for bin in "1ドル"/*; do
[ -f "$bin" ] || continue
case "$bin" in
*.so)
;;
*)
[ -x "$bin" ] || continue
;;
esac
"$FILE_DIR/perls/parse_bin.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_bin.log"
done
shift
done
Through using my superpowers of having never learned to code, i concluded following things to happen here (you may correct me if i got something wrong):
- while accessing the input folder
1ドル
, - every
bin(ary)
file gets - checked if it really is a
binary
file, if so,
( i have no idea what the||
stands for) - it checks for the extension (
.so
ornone
) and - uses the file(s) found (
*.so
and the ones without extension) as input for the scriptparse_bin.pl
The input folder has to be super specific, as for this script these are
$ACTIVE_DB/rom/system/lib $ACTIVE_DB/rom/system/lib/*/ $ACTIVE_DB/rom/system/usr/lib you get how this continues, super long list of folders
What i'd like to know, how would i have to modify these three scripts so that the input folder is $ACTIVE_DB/rom/system
?
EDIT: The mechanism of finding the file(s) in the input folder(s) is the same in all three scripts except that the other two are searching for *.jar
and *.apk
EDIT2: The bash
shell gets used to run this
I know this has to happen somewhere in the first two lines of the script, i already tried fromnaboo
s answer from over here which would spit out every binary inside the folder $ACTIVE_DB/rom
but would not pass them as input to parse_bin.pl
.
Please have a log:
+ PARSE_BIN DB_45763/rom/system
+ '[' -n DB_45763/rom/system ']'
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/CSCVersion.txt ']'
+ case "$bin" in
+ '[' -x DB_45763/rom/system/CSCVersion.txt ']'
+ printf 'DB_45763/rom/system/CSCVersion.txt:\t'
+ echo DB_45763/rom/system/CSCVersion.txt
+ ./files/perls/parse_bin.pl DB_45763/rom/system/CSCVersion.txt dbi:SQLite:dbname=DB_45763/test.sqlite
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/app ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/bin ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/build.prop ']'
+ case "$bin" in
+ '[' -x DB_45763/rom/system/build.prop ']'
+ printf 'DB_45763/rom/system/build.prop:\t'
+ echo DB_45763/rom/system/build.prop
+ ./files/perls/parse_bin.pl DB_45763/rom/system/build.prop dbi:SQLite:dbname=DB_45763/test.sqlite
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/cameradata ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/csc ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/csc_contents ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/etc ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/fonts ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/framework ']'
+ continue
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/kern_sec_info ']'
+ case "$bin" in
+ '[' -x DB_45763/rom/system/kern_sec_info ']'
+ printf 'DB_45763/rom/system/kern_sec_info:\t'
+ echo DB_45763/rom/system/kern_sec_info
+ ./files/perls/parse_bin.pl DB_45763/rom/system/kern_sec_info dbi:SQLite:dbname=DB_45763/test.sqlite
+ for bin in '"1ドル"/*'
+ '[' -f DB_45763/rom/system/lib ']'
+ continue
+ shift
+ '[' -n '' ']'
2 Answers 2
Firstly your assumption of what the script does seems correct.
It looks at all the files, folders, symlinks etc that it finds in 1ドル
, if its a file, then it drills down deeper to determine if its a library or an executable.
In shell scripting 1ドル
is the first argument passed to the script, so to run this script with $ACTIVE_DB/rom/system
in the position of 1ドル
you would simply invoke the script with
./scriptname $ACTIVE_DB/rom/system
Note: If you are calling this from a command prompt $ACTIVE
will have to be substituted for the actual path.
In order to make this script descend recursively into your target directory you could try adding this to your script
while [ -n "1ドル" ]; do
# use globbing to descend into all subdirectories
for bin in $(find "1ドル" | tr '\n' ' '); do
# change this ^^^^
[ -f "$bin" ] || continue
# leave the rest of the script as is
# ....
-
I tried using
$ACTIVE_DB/rom/system
before, but this won't work. As far as i can see the problem is, that the script does not search recursively (?), it just checks the files in$ACTIVE_DB/rom/system
and not the ones in the subdirectories or at least is unable to find files inside them (see the log). Thanks for the testing advice, it's all i do by now^^ I've added the log for what happens when using$ACTIVE_DB/rom/system
as input.chris– chris2016年02月28日 12:26:24 +00:00Commented Feb 28, 2016 at 12:26 -
@chris Ive updated my answer to descend into subdirectoriesthe_velour_fog– the_velour_fog2016年02月28日 12:34:24 +00:00Commented Feb 28, 2016 at 12:34
-
I don't know what's up with me today, like my brain use only 1/3, i should have noted i'm on
OS X
here.globstar
is not available. Did a quick search and installedbash 4
frombrew
(brew install bash
) where this should work but it won't (and yes, i addedbash 4
to/etc/shells
and runchsh -s /usr/local/bin/bash YOUR_USER_NAME
.echo $BASH_VERSION
prints out4.3.42(1)-release
). Seems to be about time for a coffee to kickstart the brainchris– chris2016年02月28日 13:02:14 +00:00Commented Feb 28, 2016 at 13:02 -
Ok Ive updated, this
$(find "1ドル")
substitution will descend recursively , but it will also return a newline delimited string so Im not sure how the for loop will handle it - I suspect it will actually break...the_velour_fog– the_velour_fog2016年02月28日 13:09:18 +00:00Commented Feb 28, 2016 at 13:09 -
Super awesome, this works. But it also uses found
*.apk
as input forparse_bin.pl
. I think i'm gonna try to combine the three scripts, so that found*.apk
and*.jar
get used as input forparse_apk.pl
andparse_jar.pl
chris– chris2016年02月28日 13:15:40 +00:00Commented Feb 28, 2016 at 13:15
So in case anyones wondering what i did, here's the code as of now.
Thanks @the_velour_fog for helping me.
If anyone thinks this is the worst possible solution
(i don't think it's super sexy either but it does what it has to do) get em here.
while [ -n "1ドル" ]; do
for bin in $(find "1ドル"); do
[ -f "$bin" ] || continue
case "$bin" in
*.so)
export start=$(date +"%T")
printf "$bin:\t"
echo -n "$start " >>"$ACTIVE_DB/logs/parse_bin.log"
echo "$bin" >>"$ACTIVE_DB/logs/parse_bin.log"
"$FILE_DIR/perls/parse_bin.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_bin.log"
;;
*.jar)
export start=$(date +"%T")
printf "$bin:\t"
echo -n "$start " >>"$ACTIVE_DB/logs/parse_jar.log"
echo "$bin" >>"$ACTIVE_DB/logs/parse_jar.log"
"$FILE_DIR/perls/parse_jar.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_jar.log"
;;
*.apk)
export start=$(date +"%T")
printf "$bin:\t"
echo -n "$start " >>"$ACTIVE_DB/logs/parse_apk.log"
echo "$bin" >>"$ACTIVE_DB/logs/parse_apk.log"
"$FILE_DIR/perls/parse_apk.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_apk.log"
;;
*)
if [ -x "$bin" ] ; then
export start=$(date +"%T")
printf "$bin:\t"
echo -n "$start " >>"$ACTIVE_DB/logs/parse_bin.log"
echo "$bin" >>"$ACTIVE_DB/logs/parse_bin.log"
"$FILE_DIR/perls/parse_bin.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_bin.log"
else
continue
fi
;;
esac
done
shift
done
As far as i can see for now, this works, but i'm quite unsure about this part at the end
*)
if [ -x "$bin" ] ; then
export start=$(date +"%T")
printf "$bin:\t"
echo -n "$start " >>"$ACTIVE_DB/logs/parse_bin.log"
echo "$bin" >>"$ACTIVE_DB/logs/parse_bin.log"
"$FILE_DIR/perls/parse_bin.pl" "$bin" dbi:SQLite:dbname="$ACTIVE_DB/test.sqlite" 2>>"$ACTIVE_DB/logs/parse_bin.log"
else
continue
fi
The future will show^^
$bin
is a regular file, if not the|| continue
expression is saying go back to the start of the loop and begin with a new$bin
. What shell is being used to run this script?||
, thebash
shell gets used to run this. I've added this info to the question