Skip to content

Instantly share code, notes, and snippets.

@virifi
Created July 24, 2012 08:08
Show Gist options
  • Select an option

  • Save virifi/3168750 to your computer and use it in GitHub Desktop.

Select an option

Save virifi/3168750 to your computer and use it in GitHub Desktop.
SC-06Dの/system/appと/system/framework以下の全ファイルをdeodexするスクリプト
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
use File::Spec;
my $default_boot_class_path = "";
my $boot_class_path_list = {
# app
"AccuweatherWidget.odex" => ":twframework.jar",
"AccuweatherWidget_Main.odex" => ":com.google.android.maps.jar",
"AllshareMediaServer.odex" => ":allsharelib.jar",
"AllshareService.odex" => ":allshare.jar:allsharelib.jar",
"BluetoothMap.odex" => ":javax.obex.jar",
"ClockPackage.odex" => ":twframework.jar",
"CSC.odex" => ":sec_platform_library.jar",
"Exchange.odex" => ":",
"kieswifi.odex" => ":allshare.jar",
"MobilePrint.odex" => ":",
"MobileTV_JPN.odex" => ":secbroadcast.jar:com.nextreaming.player.apps.jar:twframework.jar:minimode.jar",
"MusicPlayer.odex" => ":twframework.jar:allshare.jar",
"PackageInstallerMcAfee.odex" => ":com.mcafee.android.scanner.jar",
"SamsungCamera.odex" => ":secmediarecorder.jar",
"SecBluetooth.odex" => ":javax.obex.jar",
"SecBrowser_DCM.odex" => ":twframework.jar",
"SecCalendar_DCM.odex" => ":com.google.android.maps.jar:twframework.jar",
"SecEmail.odex" => ":com.google.android.maps.jar",
"SecFileShareClient.odex" => ":allshare.jar",
"SecFileShareServer.odex" => ":allsharelib.jar",
"SecGallery2.odex" => ":allshare.jar",
"SecMms.odex" => ":twframework.jar:com.google.android.maps.jar",
"SecPhone_DCM.odex" => ":libvtmanagerjar.jar:secmediarecorder.jar:sec_platform_library.jar",
"SlideShow.odex" => ":",
"SMemo.odex" => ":",
"SPlannerAppWidget.odex" => ":twframework.jar",
"SystemUI.odex" => ":minimode.jar",
"VideoPlayer.odex" => ":allsharelib.jar:allshare.jar:minimode.jar:twframework.jar",
"VoiceRecorder.odex" => ":twframework.jar:secmediarecorder.jar",
# framework
"android.policy.odex" => ":sec_edm.jar",
"apache-xml.odex" => ":sec_edm.jar:seccamera.jar",
"filterfw.odex" => ":sec_edm.jar:seccamera.jar",
"sec_edm.odex" => ":seccamera.jar",
"secbroadcast.odex" => ":com.nextreaming.player.apps.jar",
"services.odex" => ":sec_edm.jar:seccamera.jar",
};
my @ignore_list = (
# app
"Exchange.odex",
"MobilePrint.odex",
"SecEmail.odex",
"SlideShow.odex",
"SMemo.odex",
);
unless (@ARGV == 2 or @ARGV == 3) {
die "Usage\n"
. "$0 <system_dir> <out_dir>\n"
. " or\n"
. "$0 -b <system_dir> <out_dir> # only baksmaling\n";
}
my $only_baksmali = 0;
if (@ARGV == 3) {
unless ($ARGV[0] eq "-b") {
die "Unsupported option : $ARGV[0]";
}
$only_baksmali = 1;
shift @ARGV;
}
my $system_dir = $ARGV[0];
die "$system_dir does not exist" unless -d $system_dir;
my $out_dir_root = $ARGV[1];
system("mkdir -p $out_dir_root") unless -d $out_dir_root;
my $smali_out_dir = "$out_dir_root/smali_out";
system("mkdir -p $smali_out_dir") unless -d $smali_out_dir;
my $deodexed_out_dir = "$out_dir_root/deodexed";
unless ($only_baksmali) {
system("mkdir -p $deodexed_out_dir") unless -d $deodexed_out_dir;
}
do_main("$system_dir/app");
do_main("$system_dir/framework");
sub do_main {
my $target_dir = shift;
opendir my $dh, $target_dir or die "$!:$target_dir";
my @files = readdir $dh;
closedir $dh;
my @deodex_list = ();
my @copy_list = ();
foreach my $file (@files) {
next unless $file =~ /(.jar$)|(.apk$)/;
my $base = $file;
$base =~ s/\.(jar|apk)$//g;
my $odex_file = $base . ".odex";
unless (-e "$target_dir/$odex_file") {
push @copy_list, $file;
next;
}
push @deodex_list, [$file, $odex_file];
}
unless ($only_baksmali) {
foreach my $file (@copy_list) {
my $base = $file;
$base =~ s/\.(jar|apk)$//g;
my $out_dir = "$deodexed_out_dir/" . get_system_dir_name($target_dir);
system("mkdir -p $out_dir") unless -d $out_dir;
system("cp $target_dir/$file $out_dir/$file");
}
}
foreach my $files (@deodex_list) {
baksmali($target_dir, $files->[0], $files->[1]);
smali($target_dir, $files->[0]) unless ($only_baksmali);
print "\n\n";
}
}
sub baksmali {
my ($target_dir, $main_file, $odex_file) = @_;
print "baksmali : $target_dir/$odex_file\n";
my $base = $main_file;
$base =~ s/\.(jar|apk)$//g;
foreach my $ignore_file (@ignore_list) {
if ($ignore_file eq $odex_file) {
print "ignore : $odex_file\n";
return;
}
}
my $boot_class_path = $boot_class_path_list->{$odex_file} || $default_boot_class_path;
my $smali_specific_out_dir = "$smali_out_dir/" . get_system_dir_name($target_dir);
system("mkdir -p $smali_specific_out_dir") unless -d $smali_specific_out_dir;
if (-d "$smali_specific_out_dir/$base") {
print "skip : $odex_file\n";
return;
}
if (system("baksmali -a 15 -d $system_dir/framework -c $boot_class_path -x $target_dir/$odex_file -o $smali_specific_out_dir/$base")) {
system("rm -rf $smali_specific_out_dir/$base");
die "baksmali failed : $target_dir/$odex_file";
}
}
sub smali {
my ($target_dir, $main_file) = @_;
my $base = $main_file;
$base =~ s/\.(jar|apk)$//g;
my $smali_specific_out_dir = "$smali_out_dir/" . get_system_dir_name($target_dir);
print "smali : $smali_specific_out_dir/$base\n";
unless (-d "$smali_specific_out_dir/$base") {
print "$smali_specific_out_dir/$base does not exist\n";
print "skip : $smali_specific_out_dir/$base\n";
return;
}
my $classes_tmp_dir = "/tmp/classes_tmp_dir";
system("rm -rf $classes_tmp_dir") if -e $classes_tmp_dir;
system("mkdir -p $classes_tmp_dir");
die "failed smali : $smali_specific_out_dir/$base" if system("smali -a 15 $smali_specific_out_dir/$base -o $classes_tmp_dir/classes.dex");
my $out_dir = "$deodexed_out_dir/" . get_system_dir_name($target_dir);
system("mkdir -p $out_dir") unless -d $out_dir;
my $abs_out_file = File::Spec->rel2abs("$out_dir/$main_file");
die "failed copy : $target_dir/$main_file" if system("cp -f $target_dir/$main_file $abs_out_file");
die "failed jar uvf : $abs_out_file" if system("jar uvf $abs_out_file -C $classes_tmp_dir ./classes.dex");
system("rm -rf $classes_tmp_dir");
}
sub get_system_dir_name {
my $target_dir = shift;
my $name;
if ($target_dir =~ /app\/*$/) {
$name = "app";
} elsif ($target_dir =~ /framework\/*$/) {
$name = "framework";
} else {
die "unknown system directory name : $target_dir";
}
return $name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment