Skip to content

Instantly share code, notes, and snippets.

@alexdong
Last active December 19, 2015 23:29
Show Gist options
  • Save alexdong/6034934 to your computer and use it in GitHub Desktop.
Save alexdong/6034934 to your computer and use it in GitHub Desktop.
Some short-lifed Android apps will quit before we had a chance to attach strace to it and inspect its internal state. So this script will put itself in an endless loop and wait for the certain process to show up. Once the process appears, it will attach the strace to it and start writing output to a log file.
#!/system/bin/sh
#
# Attach strace to a process as soon as it starts up.
#
# Some short-lifed Android apps will quit before we
# had a chance to attach strace to it and inspect its
# internal state. So this script will put itself in
# an endless loop and wait for the certain process to
# show up. Once the process appears, it will attach
# the strace to it and start writing output to a log file.
#
# We are using "strace -f" so that it will also track
# forked processes.
# Usage:
# ambush process_name_pattern /data/local/bin
#
# The strace result will be written to the same directory
# under the same {pattern}-strace.log
while true; do
while ! ps | grep -q -i $1; do :; done;
ps | grep -i $1 | while read a b c; do
$2/strace -f -p $b -o $2/$1-strace.log;
done;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment