Created
March 20, 2016 14:48
-
-
Save tako0910/d152cc036f33ce0863e6 to your computer and use it in GitHub Desktop.
HTL21convert_20140525
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use Archive::Zip; | |
| use File::Basename; | |
| use File::Copy; | |
| use File::Path qw(rmtree); | |
| use Term::ReadKey; | |
| use Time::HiRes; | |
| my $version = "20140525"; | |
| my $apktool = "apktool_2.0.0b9"; | |
| my $zip_orig; | |
| my $zip_ver; | |
| my $network; | |
| my $line; | |
| my @split; | |
| my $device = ""; | |
| my @buildprop_new; | |
| my @updaterscript_new; | |
| print "\n"; | |
| # Platform判定 | |
| unless($^O eq "darwin" || $^O eq "linux" || $^O eq "MSWin32") { | |
| &error("Unsupported Host OS.") | |
| }else{ | |
| #print "DEBUG::$^O\n\n"; | |
| } | |
| print "HTL21 Convert Tool $version\n"; | |
| # 引数がない場合、Usageを表示 | |
| if(!$ARGV[0]) { | |
| print "This tool can convert AOSP-based ROM for\n dlx to for dlxj (HTL21).\n"; | |
| print "Usage(Windows) : convert.exe zipfile version [network]\n"; | |
| print "Usage(Mac/Linux): convert.pl zipfile version [network]\n"; | |
| print " version: 42->Android 4.2.2(cm-10.1), 43->Android 4.3.x(cm-10.2), 44->Android 4.4.x(cm-11.0)\n"; | |
| print " network: 1->CDMA, 2->GSM/WCDMA (default:CDMA)\n\n"; | |
| print "For more details : https://github.com/tako0910/release/wiki/HTL21_ROMConvertTool\n"; | |
| print "Press Enter key to exit.\n"; | |
| while (not defined (my $key = ReadKey(-1))) { | |
| Time::HiRes::sleep(0.1); | |
| } | |
| exit; | |
| } else { | |
| $zip_orig = $ARGV[0]; | |
| } | |
| # バージョン指定 | |
| if(defined $ARGV[1] && ($ARGV[1] eq 42 || $ARGV[1] eq 43 || $ARGV[1] eq 44)) { | |
| $zip_ver = $ARGV[1]; | |
| } else { | |
| &error("Unknown version. Please set version."); | |
| } | |
| # ネットワークタイプの設定 | |
| if(defined $ARGV[2] && $ARGV[2] eq 2) { | |
| $network = "GSM/WCDMA"; | |
| } elsif((defined $ARGV[2] && $ARGV[2] eq 1) || !$ARGV[2]) { | |
| $network = "CDMA"; | |
| } else { | |
| &error("Unknown network type."); | |
| } | |
| # 対象のZipファイルが見つからない | |
| if(!-e $zip_orig) { | |
| &error("Can't find Zipfile."); | |
| } | |
| # 引数は全て正常 | |
| print "Zipfile : $zip_orig\n"; | |
| print "Network : $network\n\n"; | |
| # (正常終了しなかった場合の一時ファイルを削除) | |
| rmtree "./res"; | |
| rmtree "./framework-res"; | |
| unlink "./framework-res.apk"; | |
| unlink "./framework-res-tmp.apk"; | |
| rmtree "tmp"; | |
| unlink "tmp.zip"; | |
| # Zipを解凍 | |
| print "Extracting files..."; | |
| sleep 3; | |
| mkdir "./tmp"; | |
| my $zip = Archive::Zip->new($zip_orig); | |
| my @members = $zip->memberNames(); | |
| foreach(@members) { | |
| $zip->extractMember($_, "./tmp/$_") | |
| } | |
| print "done\n"; | |
| # device検出 | |
| print "Detecting device..."; | |
| open IN, "./tmp/system/build.prop" or &error("Can't find build.prop.\nIs this zipfile correct ROM?"); | |
| while(<IN>) { | |
| $line = $_; | |
| @split = split(/=/, $line); | |
| if($split[0] eq "ro.product.device") { | |
| &error("duplicate device name in build.prop") if($device); | |
| chop $split[1]; | |
| if($split[1] eq "dlx") { | |
| $device = $split[1]; | |
| }else{ | |
| &error("Unsupported device.($split[1])"); | |
| } | |
| } | |
| } | |
| close IN; | |
| if(!$device) { | |
| &error("Can't detect device."); | |
| }else{ | |
| print "$device\n"; | |
| } | |
| # build.propを編集 | |
| print "Modifying build.prop..."; | |
| open IN, "./tmp/system/build.prop" or &error("Can't find build.prop.\nIs this zipfile correct ROM?"); | |
| while(<IN>) { | |
| $line = $_; | |
| $line =~ s/ *= */=/g; | |
| $line =~ s/ro.product.model=.*/ro.product.model=HTL21/; | |
| $line =~ s/HTC6435LVW/HTL21/; | |
| $line =~ s/$device/dlxj/; | |
| $line =~ s/ro.build.description=.*/ro.build.description=1.15.970.1 CL133490 release-keys/; | |
| $line =~ s%ro.build.fingerprint=.*%ro.build.fingerprint=KDDI/HTL21/dlxj:4.1.1/JRO03C/133490.1:user/release-keys%; | |
| $line =~ s/telephony.lteOnCdmaDevice=.*//; | |
| $line =~ s/telephony.rilV7NeedCDMALTEPhone=.*//; | |
| $line =~ s/telephony.lteOnGsmDevice=.*//; | |
| push @buildprop_new, $line; | |
| } | |
| close IN; | |
| if($network eq "CDMA") { | |
| push @buildprop_new, "telephony.lteOnCdmaDevice=1\n"; | |
| } else { | |
| push @buildprop_new, "telephony.lteOnGsmDevice=1\n"; | |
| push @buildprop_new, "ro.telephony.ril.v3=subscriptionFromSource,skipCdmaSubcription\n"; | |
| } | |
| open OUT, "> ./tmp/system/build.prop"; | |
| foreach(@buildprop_new) { | |
| print OUT $_; | |
| } | |
| close OUT; | |
| print "done\n"; | |
| # updater-scriptを編集 | |
| print "Modifying updater-script..."; | |
| open IN, "./tmp/META-INF/com/google/android/updater-script" or &error("Can't find updater-script.\nIs this zipfile correct ROM?"); | |
| while(<IN>) { | |
| $line = $_; | |
| $line =~ s/'$device'/'dlxj'/g; | |
| $line =~ s/"$device"/"dlxj"/g; | |
| push @updaterscript_new, $line; | |
| } | |
| close IN; | |
| open OUT, "> ./tmp/META-INF/com/google/android/updater-script"; | |
| foreach(@updaterscript_new) { | |
| print OUT $_; | |
| } | |
| close OUT; | |
| print "done\n"; | |
| # framework-resをデコード | |
| print "Decoding framework-res..."; | |
| copy "./tmp/system/framework/framework-res.apk", "./framework-res.apk"; | |
| system("java -jar ./tool/$apktool.jar d -o ./framework-res ./framework-res.apk"); | |
| if(!-e "./framework-res") { | |
| &error("failed to decode framework-res.apk!"); | |
| }else{ | |
| print "done\n"; | |
| } | |
| # apns.xml, storage_list.xmlをコピー | |
| print "Modifying framework-res..."; | |
| copy "./diff/apns.xml", "./framework-res/res/xml/apns.xml"; | |
| copy "./diff/storage_list.xml", "./framework-res/res/xml/storage_list.xml"; | |
| print "done\n"; | |
| # framework-resをビルド | |
| print "Building framework-res..."; | |
| if($^O eq "MSWin32") { | |
| system("java -jar ./tool/$apktool.jar b -a ./tool/win/aapt.exe -o ./framework-res-tmp.apk ./framework-res"); | |
| }elsif($^O eq "darwin") { | |
| system("java -jar ./tool/$apktool.jar b -a ./tool/mac/aapt -o ./framework-res-tmp.apk ./framework-res"); | |
| }else{ | |
| system("java -jar ./tool/$apktool.jar b -a ./tool/linux/aapt -o ./framework-res-tmp.apk ./framework-res"); | |
| } | |
| if(!-e "./framework-res/build/apk/resources.arsc") { | |
| &error("Can't find resources.arsc.\nBuild failed."); | |
| } | |
| if($^O eq "MSWin32") { | |
| system("./tool/win/7za.exe u -tzip -mx=0 ./framework-res.apk ./framework-res/build/apk/resources.arsc"); | |
| }elsif($^O eq "darwin") { | |
| system("./tool/mac/7za u -tzip -mx=0 ./framework-res.apk ./framework-res/build/apk/resources.arsc"); | |
| }else{ | |
| system("7za u -tzip -mx=0 ./framework-res.apk ./framework-res/build/apk/resources.arsc"); | |
| } | |
| mkdir "res"; | |
| mkdir "res/xml"; | |
| copy "./framework-res/build/apk/res/xml/apns.xml", "res/xml/apns.xml"; | |
| copy "./framework-res/build/apk/res/xml/storage_list.xml", "res/xml/storage_list.xml"; | |
| if($^O eq "MSWin32") { | |
| system("./tool/win/7za.exe a -tzip -mx=0 ./framework-res.apk ./res"); | |
| }elsif($^O eq "darwin") { | |
| system("./tool/mac/7za a -tzip -mx=0 ./framework-res.apk ./res"); | |
| }else{ | |
| # Linux | |
| system("7za a -tzip -mx=0 ./framework-res.apk ./res"); | |
| } | |
| print "done\n"; | |
| # framework-res.apkをコピー | |
| print "Copying framework-res..."; | |
| copy "./framework-res.apk", "./tmp/system/framework/framework-res.apk"; | |
| print "done\n"; | |
| # 一時ファイル削除 | |
| print "Removing tempolary files..."; | |
| rmtree "./res"; | |
| rmtree "./framework-res"; | |
| unlink "./framework-res.apk"; | |
| unlink "./framework-res-tmp.apk"; | |
| print "done\n"; | |
| # HTL21固有ファイルをコピー | |
| print "Replacing files..."; | |
| unlink "./tmp/system/lib/hw/sensors.dlx.so"; | |
| copy "./diff/boot${zip_ver}.img", "./tmp/boot.img"; | |
| copy "./diff/sensors.dlxj.so", "./tmp/system/lib/hw/sensors.dlxj.so"; | |
| if($zip_ver eq 42) { | |
| print "\nModifying for Android 4.2.2..."; | |
| copy "./diff/42/vold.fstab", "./tmp/system/etc/vold.fstab"; | |
| copy "./diff/42/lights.msm8960.so", "./tmp/system/lib/hw/lights.msm8960.so"; | |
| }elsif($zip_ver eq 43) { | |
| print "\nModifying for Android 4.3.x..."; | |
| copy "./diff/43/lights.msm8960.so", "./tmp/system/lib/hw/lights.msm8960.so"; | |
| }elsif($zip_ver eq 44) { | |
| print "\nModifying for Android 4.4.x..."; | |
| copy "./diff/44/lights.msm8960.so", "./tmp/system/lib/hw/lights.msm8960.so"; | |
| copy "./diff/44/sensors.dlxj.so", "./tmp/system/lib/hw/sensors.dlxj.so"; | |
| } | |
| print "done\n"; | |
| # modulesフォルダが存在するか | |
| if(!-d "./tmp/system/lib/modules") { | |
| mkdir "./tmp/system/lib/modules", 0755; | |
| open OUT, ">", "./tmp/system/lib/modules/dummy" or &error("dummy file can't create."); | |
| close OUT; | |
| } | |
| # Windowsのみ、改行コードを編集する | |
| if($^O eq "MSWin32") { | |
| print "Modifying some files more..."; | |
| system("tool\\win\\tr.exe -d '\\r' < ./tmp/system/build.prop > ./tmp/system/build.prop_new"); | |
| system("tool\\win\\tr.exe -d '\\r' < ./tmp/META-INF/com/google/android/updater-script > ./tmp/META-INF/com/google/android/updater-script_new"); | |
| unlink "./tmp/system/build.prop"; | |
| unlink "./tmp/META-INF/com/google/android/updater-script"; | |
| move "./tmp/system/build.prop_new", "./tmp/system/build.prop"; | |
| move "./tmp/META-INF/com/google/android/updater-script_new", "./tmp/META-INF/com/google/android/updater-script"; | |
| print "done\n"; | |
| } | |
| print "Archiving files..."; | |
| $zip = Archive::Zip->new(); | |
| $zip->addTree("./tmp"); | |
| $zip->writeToFileNamed("./tmp.zip"); | |
| print "done\n"; | |
| my $output = basename($zip_orig, ".zip"); | |
| print "Signing Zipfile..."; | |
| system("java -jar ./tool/signapk.jar ./tool/testkey.x509.pem ./tool/testkey.pk8 ./tmp.zip ./${output}_converted.zip"); | |
| # Zipfileの署名に失敗 | |
| if(!-e "./${output}_converted.zip") { | |
| &error("failed to create signed zip file!"); | |
| } | |
| print "done\n"; | |
| # 一時ファイルを削除 | |
| rmtree "tmp"; | |
| unlink "tmp.zip"; | |
| print "All Done!!\n"; | |
| exit; | |
| sub error { | |
| print $_[0] . "\n"; | |
| exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment