Android Decompile
Apk
tool项目地址(反编译资源和代码):
Dex2jar()项目地址(将classes.dex转换成Jar):
Smali项目地址(Baksmali:反编译代码;Smali:生成classes.dex):
JD-GUI项目地址(反编译查看Jar):
反编译流程:
情形一:单个Apk
test.apk
----Apktool---->代码和资源同时被反编译----Dex2jar---->将classes.dex转换成Jar。
情形二:Apk文件被拆分成Apk和Odex
test.odex----Baksmali---->反编译代码生成class文件----Smali---->通过class文件生成classes.dex文件----Dex2jar---->将classes.dex转换成Jar。
test.apk----Apktool---->反编译资源
反编译步骤:
情形一:
0.apktool
d test.apk
1.dex2jar-0.0.9.8/dex2jar.sh
./test-dex/classes.dex
情形二:
0.java
-jar baksmali-1.4.2.jar -a 17 -x test.odex -o test-odex
1.java
-jar smali-1.4.2.jar test-odex/ -o test-dex/classes.dex
2.dex2jar-0.0.9.8/dex2jar.sh
./test-dex/classes.dex
3.apktool
d test.apk test-res
下面列出自定义的编译脚本供参考:
#!/bin/bash
module_list="framework framework2 twframework services AccessControl AccuweatherPhone2013 AirMotionTryActually AlarmWidget AllShareCastPlayer AllshareControlShare AllshareFileShare AllshareFileShareClient AllshareFileShareServer AllshareMediaServer AllshareMediaShare AllSharePlay15 AnimatedScene ApplicationsProvider AssistantMenu AutomationTest_FB BackupRestoreConfirmation BadgeProvider BandService BasicDreams BCService BeautyFace BestFace Bluetooth BluetoothTest Blurb BrowserProviderProxy CapabilityManagerService CertInstaller ChatON_feature ChatONV_J ChocoEUKor Chrome CHS_J_Device_only ClipboardSaveService ClockPackage CloudAgent Collage_fhd ColorBlind Com2usPoker_ASGC com.sec.android.app.newmessage ContainerAgent ContainerEventsRelayManager ContextProvider CoolEUKor CSC DefaultContainerService DigitalClock21 DigitalClock DioDict3Service DirectConnect DirectShareManager Divx DrmProvider DroidSansSherifItalic Dropbox DropboxOOBE DSMForwarding DSMLawmo DualClockDigital Earth EasyFavoritesContactsWidget EasyLauncher EasySettings EdmSimPinService EdmSysScopeService EdmVpnServices ELMAgent EnterprisePermissions Episodes Eraser FaceLock FactoryCamera_FB FactoryKeystring_FB FactoryTest_FB FilterInstaller FilterProvider FlashBarService Flipboard FmmDM FmmDS FotaClient FusedLocation FWUpgrade GestureService GlanceView Gmail2 GmsCore GMS_Maps GoogleBackupTransport GoogleCalendarSyncAdapter GoogleContactsSyncAdapter GoogleFeedback GoogleLoginService GooglePartnerSetup GoogleSearchWidget GoogleServicesFramework GoogleTTS GroupPlay_20 HealthContentProvider Hearingdro HwModuleTest INDI_Server InputDevices InteractiveTutorial JobManager KeyChain KeyguardBackupRestore KeyguardWidget Kies kieswifi KikinSearch KNOXAgent LocalFOTA LogsProvider Magazines Match3VS MDMApp MediaUploader minimode-res MMAppFramework MobilePrint2 MobilePrintSvc_CUPS MobilePrintSvc_Epson MobilePrintSvc_HP MobilePrintSvc_Samsung MobileTrackerEngineTwo MtpApplication Music2 MusicFX MusicLiveShare MusicPlayerWT NetworkLocation NfcNci NfcTest NoiseField NotificationWidget OfficeSuite_Full_1.5_282 OmaCP OmaDrmPopup PackageInstaller PageBuddyNotiSvc2 PartnerBookmarksProvider PCWClientS Peel PhaseBeam PhoneErrService Phonesky PhotoRetouching_fhd PhotoTable PhrCloudService PicAction PickUpTutorial PlusOne PolarisViewer5 PopupuiReceiver Preconfig PreloadInstaller PrismBooks PrismStore PRUI ResourceManager ringtoneBR RoseEUKor SamsungApps_J_Only SamsungAppsUNA3 SamsungCamera2 SamsungGames SamsungIME SamsungLearning SamsungMusic SamsungOCR2 SamsungSans Samsungservice SamsungTTS SamsungVideo SamsungWidget_ProgramMonitor SBrowser SBrowserTry sCloudBackupApp sCloudBackupProvider sCloudDataRelay sCloudDataSync sCloudQuotaApp sCloudSyncCalendar sCloudSyncContacts sCloudSyncSBrowserBookmark sCloudSyncSBrowserTabs sCloudSyncSNote SCParser SecCalculator_3d SecCalendarProvider SecCalendar_SPen SecContacts SecContactsProvider SecDownloadProvider SecDownloadProviderUi SecEmail_J SecExchange SecFactoryPhoneTest SecGallery2013 SecHTMLViewer SecLauncher3 SecLiveWallpapersPicker SecLpp SecMediaProvider SecMms SecNoteMyFiles SecPhone SecSafetyAssurance SecSettings SecSettingsProvider SecSetupWizard2013 SecTelephonyProvider SecurityProvider SecVideoList SecVideoPlayer SecWalletManager SecWallpaperChooser SensorService serviceModeApp_FB ServiceModeApp_RIL SetDefaultBrowser SetDefaultLauncher SetupWizard SharedStorageBackup ShareShotService SharingAccessibilitySettings SHealth2 SimpleWidget SimServicePermission SmartBriefing4x2 SmartcardManager SmartcardService SMemo2 SNoteProvider SNS SphericalMosaic SPlannerAppWidget SPPPushClient_Prod Stk StoryAlbumWidget S_Translator_CSLi Street S-Voice_Android_phone_J SyncmlDM SyncmlDS SysScope SystemUI Tag Talk talkback TasksProvider TMServerApp TravelService TravelWidget TrimApp_phone_J TripAdvisor TwDVFSApp UltraCfg UserDictionaryProvider Velvet VoiceRecorder VoiceSearchStub VpnDialogs WeatherWidgetDaemon WebManual WfdBroker WlanTest wssyncmlnps YahoonewsPhone2013 YahoostockPhone2013 YosemitePHN YouTube"
framework_list="android.policy"
apk_list="com.htc.resources framework-htc-res framework-res"
module=""
odex=""
dex=""
res=""
sign=""
last_return=""
DST="icons"
LOG="log"
###########################################################
baksmali_internal(){
java -Xmx4096M -jar baksmali-1.4.2.jar -a 17 -c:abt-persistence.odex : access.control.odex : allshareJmDNS.odex : allshare.odex : am.odex : android.policy.odex : android.test.runner.odex : apache-xml.odex : bmgr.odex : bouncycastle.odex : bu.odex : com.android.future.usb.accessory.odex : com.android.location.provider.odex : com.android.nfc_extras.odex : com.broadcom.bt.odex : com.broadcom.nfc.odex : com.google.widevine.software.drm.odex : content.odex : core-junit.odex : core.odex : CustFeature.odex : ext.odex : framework2.odex : framework.odex : GlobalConfig.odex : ime.odex : input.odex : javax.obex.odex : kies_feature.odex : libvtmanagerjar.odex : minimode.odex : mmappframeworklib.odex : mms-common.odex : monkey.odex : multiwindow.odex : org.simalliance.openmobileapi.odex : pm.odex : requestsync.odex : sc.odex : scrollpause.odex : seccamera.odex : sec_edm.odex : secface.odex : sec_feature.odex : sechardware.odex : secmediarecorder.odex : secocsp.odex : sec_platform_library.odex : services.odex : settings.odex : smartfaceserviceapi.odex : smartfaceservice.odex : smatlib.odex : stayrotation.odex : svc.odex : svi.odex : sws.odex : telephony-common.odex : twframework.odex : uiautomator.odex : videowall.odex:SystemUI.odex -x $module.odex -o $odex
}
do_dex()
{
echo "Current module: $module"
if [ -d $module ];then
echo -e "$module exist.\n"
return;
fi
odex=$module-odex
echo "mkdir $odex"
java -jar baksmali-1.4.2.jar -a 17 -x $module.odex -o $odex
last_return="$?"
if [ "$last_return" -eq "1" ];then
echo "last_return 1: Failure."
#java -Xmx4096M -jar baksmali-1.4.2.jar -a 17 -c:abt-persistence.odex : access.control.odex : allshareJmDNS.odex : allshare.odex : am.odex : android.policy.odex : android.test.runner.odex : apache-xml.odex : bmgr.odex : bouncycastle.odex : bu.odex : com.android.future.usb.accessory.odex : com.android.location.provider.odex : com.android.nfc_extras.odex : com.broadcom.bt.odex : com.broadcom.nfc.odex : com.google.widevine.software.drm.odex : content.odex : core-junit.odex : core.odex : CustFeature.odex : ext.odex : framework2.odex : framework.odex : GlobalConfig.odex : ime.odex : input.odex : javax.obex.odex : kies_feature.odex : libvtmanagerjar.odex : minimode.odex : mmappframeworklib.odex : mms-common.odex : monkey.odex : multiwindow.odex : org.simalliance.openmobileapi.odex : pm.odex : requestsync.odex : sc.odex : scrollpause.odex : seccamera.odex : sec_edm.odex : secface.odex : sec_feature.odex : sechardware.odex : secmediarecorder.odex : secocsp.odex : sec_platform_library.odex : services.odex : settings.odex : smartfaceserviceapi.odex : smartfaceservice.odex : smatlib.odex : stayrotation.odex : svc.odex : svi.odex : sws.odex : telephony-common.odex : twframework.odex : uiautomator.odex : videowall.odex:SystemUI.odex -x $module.odex -o $odex
baksmali_internal
last_return="$?"
else
echo "last_return 1: Successful"
fi
if [ "$last_return" -eq "1" ];then
echo "last_return 2: Failure."
echo $module >> $LOG
rm -rf $odex
else
echo "last_return 2: Successful"
fi
dex=$module-dex
if [ "$last_return" -eq "0" ];then
echo "mkdir $dex"
mkdir $dex
java -jar smali-1.4.2.jar $odex/ -o $dex/classes.dex
if [ -f ./$dex/classes.dex ];then
./dex2jar-0.0.9.8/dex2jar.sh ./$dex/classes.dex
fi
fi
res=$module-res
if [ $module != "framework2" ];then
if [ $module == "framework" -o $module == "twframework" ];then
echo "mkdir $res"
./apktool d $module-res.apk $res
else
if [ -f $module.apk ];then
echo "mkdir $res"
./apktool d $module.apk $res
fi
fi
fi
rm -rf $module
mkdir $module
if [ -d $odex ];then
mv $odex $module
echo "mv $odex $module"
fi
if [ -d $dex ];then
mv $dex $module
echo "mv $dex $module"
fi
if [ -d $res ];then
mv $res $module
echo "mv $res $module"
fi
echo -e "Done.\n"
}
decode_api_internal()
{
echo "1 "
if [ -f $module.apk ];then
./apktool d $module.apk
if [ "$?" == "0" ];then
echo "2 "
mv $module/smali $module-odex
mv $module $module-res
mkdir $module
mv $module-odex $module
mv $module-res $module
mv $module.apk $module.zip
mkdir $module/$module-dex
unzip $module.zip -d $module/$module-dex
mv $module.zip ./$module.apk
if [ -f $module/$module-dex/classes.dex ];then
./dex2jar-0.0.9.8/dex2jar.sh $module/$module-dex/classes.dex
fi
else
echo "error,exit."
fi
else
echo "no $2.apk."
fi
}
decode_apk()
{
if [ -d $module ];then
echo "$module exist."
#rm -rf $module
#fi
else
decode_api_internal
fi
}
install_framework()
{
./apktool if framework-res.apk
#./apktool if com.htc.resources.apk
#./apktool if framework-htc-res.apk
if [ -f twframework-res.apk ];then
./apktool if twframework-res.apk
fi
}
echo -e "\nNow,please wait."
if [ "$1" == "list" -a "$#" -eq "1" ] ; then
echo -e "Module list: $module_list\n"
rm -f $LOG
install_framework
for module in $module_list; do
echo "$module"
if [ -f $module.odex ];then
do_dex
else
if [ -f $module.apk ];then
./apktool d $module.apk
if [ "$?" != "0" ];then
echo "error,exit."
else
mv $module/smali $module-odex
mv $module $module-res
mkdir $module
mv $module-odex $module
mv $module-res $module
mv $module.apk $module.zip
mkdir $module/$module-dex
unzip $module.zip -d $module/$module-dex
mv $module.zip ./$module.apk
if [ -f $module/$module-dex/classes.dex ];then
./dex2jar-0.0.9.8/dex2jar.sh $module/$module-dex/classes.dex
fi
fi
else
echo "no $2.apk."
fi
fi
#if [ $module == "AllshareControlShare" ] ; then
#break;
#fi
done
gedit $LOG &
elif [ "$1" == "framework-list" -a "$#" -eq "1" ] ; then
install_framework
for module in $framework_list; do
echo "$module"
done
elif [ "$1" == "apk-list" -a "$#" -eq "1" ] ; then
echo -e "Module list: $apk_list\n"
rm -f $LOG
install_framework
echo "11 "
for module in $apk_list; do
echo "22 "
decode_apk
done
gedit $LOG &
elif [ "$1" == "list" -a "$#" -eq "2" ] ; then
if [ "$2" == "clear" ];then
for module in $module_list; do
rm -rf $module
done
fi
elif [ "$1" == "single" -a "$#" -eq "2" ]; then
install_framework
module=$2
do_dex
elif [ "$1" == "single" -a "$#" -eq "3" ]; then
install_framework
if [ "$3" == "-r" ];then
rm -rf $2
module=$2
do_dex
fi
elif [ "$1" == "decode" ]; then
if [ -d $2 ];then
echo "$2 exist."
if [ "$3" == "-r" ];then
rm -rf $2
fi
fi
if [ -f $2.apk ];then
./apktool d $2.apk
if [ "$?" != "0" ];then
echo "error,exit."
fi
mv $2/smali $2-odex
mv $2 $2-res
mkdir $2
mv $2-odex $2
mv $2-res $2
mv $2.apk $2.zip
mkdir $2/$2-dex
unzip $2.zip -d $2/$2-dex
mv $2.zip ./$2.apk
if [ -f $2/$2-dex/classes.dex ];then
./dex2jar-0.0.9.8/dex2jar.sh $2/$2-dex/classes.dex
fi
else
echo "no $2.apk."
fi
elif [ "$1" == "sign" -a "$#" -eq "2" ]; then
if [ "$2" == "help" ]; then
echo "/build/target/product/security/:platform.pk8 platform.x509.pem
/out/host/linux-x86/framework/:signapk.jar
java -jar signapk.jar platform.x509.pem platform.pk8 xxx.apk xxx_signed.apk"
else
module=$2
if [ -d $module ];then
if [ -f $module/$2.apk ];then
# check whether need to sign
sign="$module/signapk"
rm -rf $sign
mkdir $sign
#cp $2.apk $module
java -jar signapk.jar platform.x509.pem platform.pk8 $module/$2.apk $sign/$2_signed.apk
else
echo "unknown $2.apk"
fi
else
if [ -f $2.apk ];then
# check whether need to sign
mkdir $module
sign="$module/signapk"
rm -rf $sign
mkdir $sign
cp $2.apk $module
java -jar signapk.jar platform.x509.pem platform.pk8 $module/$2.apk $sign/$2_signed.apk
else
echo "unknown $2.apk"
fi
fi
fi
elif [ "$1" == "copy" ];then
rm -rf $DST
mkdir $DST
for i in `find ./ -name "ic_launcher*.png"`
do
cp $i $DST
done
for i in `find ./ -name "*icon_*.png"`
do
cp $i $DST
done
mv $DST ~/Desktop
else
echo "Unknown Parameters.Do nothing."
fi
echo -e "All Done.\n"
#exit
#cd dex2jar-0.0.9.8