​[AndroidAPP]APK反编译与重新打包

2017年12月02日 Android 13条评论 阅读3689次
[AndroidAPP]APK反编译与重新打包的那些事


一、工具 & 环境 准备

工于利其事,必先利其器。先上工具:

1、apktool

1、apktool

 作用:
 将apk文件解压,得到资源文件(AndroidManifest.xml清单文件、layout布局、string等xml资源文件)
 这个工具的解压,和一般电脑上的解压工具不一样,解压工具出来的APK得到的资源文件是二进制文件,我们是无法读懂的。
 
 下载地址:
 https://bitbucket.org/iBotPeaches/apktool/downloads/</span><br />   下载后得到apktool_2.3.0.jar文件(目前最新版本是2017年9月21日发布的2.3.0),并命名为apktool.jar(配合下面脚本使用)。另外还需要一个脚本执行文件
  https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/osx/apktool</span><br />   保存到文件apktool,并sudo chmod +x apktool 即可
  确保apktool文件和上面下载重命名为apktool.jar放到同一个目录下。
  apktool是否要放到环境变量这个就看个人需要了,再次不再敖述。

2、dex2jar
 作用:
 将apk中的classes.dex文件转换成jar文件。
 
 下载地址:
 https://sourceforge.net/projects/dex2jar/</span><br />
 下载后要对dex2jar.sh增加可执行权限。
 chmod +x dex2jar.sh

3、jd-gui
 作用:
 将jar包还原为java文件。
 说明下,非Android专用,只要是jar包,一般用这个均可以还原为java文件

 下载地址:
 http://jd.benow.ca</span><br />

二、Android 对APK进行反编译

工具准备好之后,接下来就是反编译的过程了。

0、原始APK文件:/Users/jileniao/Documents/decompile-apk/TestDemoDecompile.apk

1、使用apktool工具

cd /Users/jileniao/Documents/decompile-apk/
apktool d TestDemoDecompile.apk



更多使用方法,可以随时apktool -help查阅。

执行后,会在decompile-apk目录下,生成apk同名的文件夹TestDemoDecompile。

进入TestDemoDecompile文件夹:


decompile-apk-apktool b.png


这就是我们熟悉的Android源码工程目录结构了。
打开AndroidManifest.xml看看吧,已经不是二进制代码了,其他布局文件资源文件也是同样。

其中注意smali文件夹,里面目录和src文件夹下java源码目录相同,里面都是以.smali结尾的文件。
smali语言是Davlik的寄存器语言,语法上和汇编语言相似,Dalvik VM与JVM的最大的区别之一就是Dalvik VM是基于寄存器的。基于寄存器的意思是,在smali里的所有操作都必须经过寄存器来进行。

2、针对上面的smali文件,虽然有固定的语法格式,但读起来还是比较困难的,我们还是希望能直接读的java代码。
  
  使用dex2jar工具。执行下面命令

  cd /Users/jileniao/Documents/decompile-apk/
  d2j-dex2jar.sh TestDemoDecompile.apk



  执行后,会在d2j-dex2jar.sh目录下,生成apk同名+-dex2jar的jar文件。TestDemoDecompile-dex2jar.jar

  另外,属于步骤1的另外一种情况,有些apktool版本反编译出来的某个版本的apk文件含有的classes.dex的,或直接用解压工具解压apk也会得到classes.dex。
  这个classes.dex是Java代码编译得到的Dalvik VM能直接执行的文件。
  此时,针对classes.dex文件,也要执行dex2jar命令得到jar文件了

3、使用jd-gui还原java源码

有了jar文件,就是使用jd-gui了,如其名,这是个窗口工具,通过file open...便可以直接打包上面步骤2中生成的jar文件了。

  此时,终于有了守得云开见月明的感觉。完完整整清清楚楚的java文件已经呈现在眼前了。


三、Android 对APK进行反编译文件进行某些修改后,重新打包回APK,或叫二次打包

1、二次打包,还是使用apktool工具

 继续沿用上面步骤中的路径,我反编译后的目录是/Users/jileniao/Documents/decompile-apk/,一些修改也要在这里进行的。

 apktool b /Users/jileniao/Documents/decompile-apk



 命令执行结果,会在decompile-apk目录下生成dist和build文件夹
 其中build文件夹是编译过程中临时文件,dist中的apk就是本次打包后的apk了。

2、是不是迫不及待地想要安装apk试试了,此时直接安装apk后会有下面的错误。

 Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

见文知意,原来是没有经过签名的apk,此时就要对apk进行签名了。

签名,就要有签名文件,可以使用keystore命令生成一个签名文件

keytool -genkey -v -keystore decompile-apk -alias decompile-apk -keyalg RSA -validity 20000 -keystore ./decompile-apk.keystore 



该命令执行后,会有一系列诸如用户名、组织名、市、省、国家、密码等问题,按照提示回答后确认即可。

该命令将在当前文件夹下生成名为decompile-apk.keystore、别名decompile-apk、签名算法为RSA、有效期20000天的签名文件。


3、有了上一步的签名证书,可以给apk签名了。

jarsigner -verbose -keystore /Users/jileniao/Documents/decompile-apk/decompile-apk.keystore -signedjar /Users/jileniao/Documents/decompile-apk/TestDemoDecompile_signed.apk /Users/jileniao/Documents/decompile-apk/dist/TestDemoDecompile.apk decompile-apk




4、安装到手机确认

卸载之前的apk,重新安装二次打包后的apk,打开apk。命令如下:

adb uninstall net.jileniao.decompileapk
adb install /Users/jileniao/Documents/decompile-apk/decompile-apk.keystore -signedjar /Users/jileniao/Documents/decompile-apk/TestDemoDecompile_signed.apk
adb shell am start -n net.jileniao.decompileapk/net.jileniao.decompileapk.MainActivity





至此,已经完成了对APK从反编译,到重新打包回APK并签名,安装到手机的全过程。

反编译(逆向工程)仅限用于技术交流,禁止用户商业盈利目的。

分享本文至:

WRITTEN BY

avatar
本文标签:apk反编译
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

13 条评论

  1. <a href="http://www.airdirectairways.net/nike-free-3.0-v5-distance-blu-zone-chaussuresf">nike free 3.0 v5 distance blu zone</a> <a href="http://www.allinforchrist.net/nike-zoom-structure-20-femminile-verde-grigio-chaussuresa">nike zoom structure 20 femminile verde grigio</a> <a href="http://www.allproinspections.net/kyrie-3-jaune-toe-music-butya">kyrie 3 jaune toe music</a> <a href="http://www.americanparkinsonla.net/asics-gel-kinsei-2-hommes-chaussures-noir-butyc">asics gel kinsei 2 hommes chaussures noir</a> <a href="http://www.amicsdelball.net/nike-dunk-negro-glitter-scarpeg">nike dunk negro glitter</a> <a href="http://www.amishcraftedgazebos.net/air-jordan-5-sort-varsity-r%C3%B8d-chaussuresc">air jordan 5 sort varsity r酶d</a>
    puffyp http://www.puffyp.net/

  2. <a href="http://www.flushnhunt.com/nike-air-max-hyperfuse-naranja-gris-zapatosk">nike air max hyperfuse naranja gris</a> <a href="http://www.evelpa.com/adidas-neo-campus-naranja-gris-zapatosp">adidas neo campus naranja gris</a> <a href="http://www.taaliminfos.com/ladies-north-face-denali-northfaceh">ladies north face denali</a> <a href="http://www.cacikvideo.com/herren-nike-roshe-run-blum%C3%A4nner-orangen-rosa-schuhej">herren nike roshe run blum盲nner orangen rosa</a> <a href="http://www.grossavind.com/bl%C3%A5-guld-nike-shox-skoh">bl氓 guld nike shox</a> <a href="http://www.boltsfans.com/nike-air-max-lunar-1-femmes-argent-vert-chaussuresh">nike air max lunar 1 femmes argent vert</a>
    maplebeyond http://www.maplebeyond.com/

  3. avatar ventarium

    <a href="http://www.drtruth.net/yeezy-750-boost-triple-svart-scarpec">yeezy 750 boost triple svart</a> <a href="http://www.drybulkintelligence.net/hommes-nike-huarache-ultra-tout-rose-schuhee">hommes nike huarache ultra tout rose</a> <a href="http://www.dsicomposer.net/air-jordan-future-gamma-bleu-keyboard-scarpef">air jordan future gamma bleu keyboard</a> <a href="http://www.duckbeachmovie.net/nike-free-run-4.0-v3-hommes-gris-tile-scarpeg">nike free run 4.0 v3 hommes gris tile</a> <a href="http://www.dynamicbook.net/nike-free-3.0-v5-mennns-marinen-kurpesa">nike free 3.0 v5 mennns marinen</a> <a href="http://www.earlylearninggroup.net/air-max-90-bon-march%C3%A9-australia-schuhee">air max 90 bon march茅 australia</a>
    ventarium http://www.ventarium.net/

  4. avatar squigglecase

    <a href="http://www.candacebenson.com/yeezy-350-boost-alle-schwarz-items-butyf">yeezy 350 boost alle schwarz items</a> <a href="http://www.kodakid.com/air-jordan-14-bleu-sport-scarpec">air jordan 14 bleu sport</a> <a href="http://www.brantfordpark.com/roshe-run-bleu-electric-vert-chaussuresf">roshe run bleu electric vert</a> <a href="http://www.landsmanbook.com/adidas-projoator-powerswerve-jr-butya">adidas projoator powerswerve jr</a> <a href="http://www.moviestellar.com/nike-free-3.0-v5-fusion-rojo-eye-schuhea">nike free 3.0 v5 fusion rojo eye</a> <a href="http://www.djprofi.com/nike-air-huarache-wei%C3%9F-gelb-schuhec">nike air huarache wei脽 gelb</a>
    squigglecase http://www.squigglecase.com/

  5. avatar mccrarycabins

    <a href="http://www.candacebenson.com/nike-air-max-2015-kinder-gr%C3%BCn-wei%C3%9F-schuhed">nike air max 2015 kinder gr眉n wei脽</a> <a href="http://www.kodakid.com/air-jordan-future-gold-grau-kurpesb">air jordan future gold grau</a> <a href="http://www.brantfordpark.com/adidas-prougeator-absolion-fg-blanc-kurpesa">adidas prougeator absolion fg blanc</a> <a href="http://www.landsmanbook.com/nike-roshe-two-hvit-gr%C3%A5-obuvb">nike roshe two hvit gr氓</a> <a href="http://www.moviestellar.com/nike-zoom-winflo-2-brun-hvid-kurpesa">nike zoom winflo 2 brun hvid</a> <a href="http://www.djprofi.com/air-jordan-12-retro-negro-varsity-rojo-blanco-lines-butyd">air jordan 12 retro negro varsity rojo blanco lines</a>
    mccrarycabins http://www.mccrarycabins.com/

  6. avatar intellalegal

    <a href="http://www.egyptmaritime.com/nike-roshe-run-dynamic-flywire-qs-nero-scarpeh">nike roshe run dynamic flywire qs nero</a> <a href="http://www.erstube.com/hat-creek-burger-georgetown-hath">hat creek burger georgetown</a> <a href="http://www.thecardplayer.com/nike-roshe-run-hyp-gris-noir-chaussuresh">nike roshe run hyp gris noir</a> <a href="http://www.theweedaddict.com/femmes-nike-free-gris-rose-chaussuresj">femmes nike free gris rose</a> <a href="http://www.thecampingman.com/nike-zoom-pegasus-31-dam%C3%A4nner-himmelblau-schwarz-schuhej">nike zoom pegasus 31 dam盲nner himmelblau schwarz</a> <a href="http://www.otuzbircek.com/neon-gul-air-max-thea-skop">neon gul air max thea</a>
    intellalegal http://www.intellalegal.com/

  7. avatar fetison

    <a href="http://www.georgesherry.com/air-jordan-retro-12-kinder-gr%C3%BCn-obuvc">air jordan retro 12 kinder gr眉n</a> <a href="http://www.jenalgroup.com/indians-30-tyler-naquin-grey-flexbase-authentic-collection-2016-world-series-bound-stitched-mlb-jersey-nflw">indians 30 tyler naquin grey flexbase authentic collection 2016 world series bound stitched mlb jersey</a> <a href="http://www.badacamshotel.com/kirk-cousins-8-washington-redskins-jersey-nflv">kirk cousins 8 washington redskins jersey</a> <a href="http://www.compressmyjs.com/air-jordan-5-retro-black-grape-austin-mahone-skog">air jordan 5 retro black grape austin mahone</a> <a href="http://www.fetison.com/jordan-5-black-university-blue-skob">jordan 5 black university blue</a> <a href="http://www.neffloot.com/oakland-university-new-era-ncaa-2-tone-59fifty-cap-black-gold-hatd">oakland university new era ncaa 2 tone 59fifty cap black gold</a>
    fetison http://www.fetison.com/

  8. avatar tuartonline

    <a href="http://www.tryautolikes.com/mens-nike-new-york-jets-30-rashard-robinson-white-vapor-untouchable-elite-player-nfl-jersey-nflx">mens nike new york jets 30 rashard robinson white vapor untouchable elite player nfl jersey</a> <a href="http://www.zgzllc.com/nike-dunk-lux-high-sherpa-sp-triple-schwarz-obuvd">nike dunk lux high sherpa sp triple schwarz</a> <a href="http://www.bigbigk.com/kvinders-nike-air-max-tn-gr%C3%B8n-lilla-scarpec">kvinders nike air max tn gr酶n lilla</a> <a href="http://www.bluerosegear.com/asics-asics-gel-kayano-20-gr%C3%B8nn-brun-kurpesb">asics asics gel kayano 20 gr酶nn brun</a> <a href="http://www.burayagidin.com/yankees-51-bernie-williams-green-salute-to-service-stitched-mlb-jersey-nflr">yankees 51 bernie williams green salute to service stitched mlb jersey</a> <a href="http://www.distisoft.com/nike-air-presto-4d-naranja-marr%C3%B3n-butyg">nike air presto 4d naranja marr贸n</a>
    tuartonline http://www.tuartonline.com/

  9. avatar addaxia

    <a href="http://www.lasdamas.net/kvinders-nike-air-max-1-bl%C3%A5-hvid-obuvc">kvinders nike air max 1 bl氓 hvid</a> <a href="http://www.lavoilebleue.net/kvinders-air-jordan-retro-7-r%C3%B8d-gr%C3%B8n-kurpese">kvinders air jordan retro 7 r酶d gr酶n</a> <a href="http://www.lifechurchindy.net/nike-mercurialx-finale-marr%C3%B3n-negro-kurpesa">nike mercurialx finale marr贸n negro</a> <a href="http://www.lincei.net/salomon-xt-wings-3-lila-grau-chaussuresb">salomon xt wings 3 lila grau</a> <a href="http://www.litpower.net/nike-hyperdunk-2014-caqui-obuve">nike hyperdunk 2014 caqui</a> <a href="http://www.lngstation.net/nike-air-max-1-mid-fb-hvit-chaussuresa">nike air max 1 mid fb hvit</a>
    addaxia http://www.addaxia.net/

  10. avatar nutraxtractor

    <a href="http://www.printonlypros.com/nike-mens-brandon-mebane-limited-navy-blue-jersey-los-angeles-chargers-nfl-92-player-name-number-tank-top-nfls">nike mens brandon mebane limited navy blue jersey los angeles chargers nfl 92 player name number tank top</a> <a href="http://www.sklroofing.com/adidas-stan-smith-rot-grau-scarpeg">adidas stan smith rot grau</a> <a href="http://www.ammampart.com/nike-air-max-2016-gr%C3%A5-gr%C3%B8nn-lantern-obuvd">nike air max 2016 gr氓 gr酶nn lantern</a> <a href="http://www.bandqlocal.com/nike-air-huarache-svart-brun-scarpea">nike air huarache svart brun</a> <a href="http://www.cathmanuel.com/jordan-12-blanc-taxi-schuheb">jordan 12 blanc taxi</a> <a href="http://www.dailysewansew.com/adidas-golden-knights-81-jonathan-marchessault-purple-authentic-fights-cancer-stitched-nhl-jersey-nflr">adidas golden knights 81 jonathan marchessault purple authentic fights cancer stitched nhl jersey</a>
    nutraxtractor http://www.nutraxtractor.com/

  11. avatar alpigap

    <a href="http://www.divorcecpas.com/adidas-superstar-argent-orange-butyf">adidas superstar argent orange</a> <a href="http://www.donhowsuccess.com/polo-ralph-lauren-v-neck-sweater-m%C3%A6nd-polou">polo ralph lauren v neck sweater m忙nd</a> <a href="http://www.emtekmakina.com/nike-flyknit-roshe-run-blu-oro-chaussuresf">nike flyknit roshe run blu oro</a> <a href="http://www.kokismith.com/nike-sb-lunar-stefan-janoski-scarpe-scarpef">nike sb lunar stefan janoski scarpe</a> <a href="http://www.luftsepp.com/miami-heat-alternate-jersey-nfls">miami heat alternate jersey</a> <a href="http://www.rimsanmakine.com/hommes-ralph-lauren-royal-bleu-cotton-hoodie-polot">hommes ralph lauren royal bleu cotton hoodie</a>
    alpigap http://www.alpigap.com/

  12. avatar pbco924y

    <a href="http://www.sjkrsnkj.com/nike-shox-navina-svart-butya">nike shox navina svart</a> <a href="http://www.uw756gei.com/nike-lebron-12-sort-lyser%C3%B8d-bl%C3%A5-butyc">nike lebron 12 sort lyser酶d bl氓</a> <a href="http://www.kfpcbsi0.com/nike-roshe-ld-1000-dark-marina-militare-scarpeg">nike roshe ld 1000 dark marina militare</a> <a href="http://www.gojfx342.com/kobe-9-rouge-and-bleu-chaussuresb">kobe 9 rouge and bleu</a> <a href="http://www.6k6gzmtk.com/nike-kd-vii-big-enfants-argent-butya">nike kd vii big enfants argent</a> <a href="http://www.4o249gfo.com/nike-air-huarache-hommes-vente-yard-schuhee">nike air huarache hommes vente yard</a>
    [url=http://www.pbco924y.com/]pbco924y[/url]

  13. avatar caryongpum

    <a href="http://www.floornhome.com/bon-march%C3%A9-nike-free-femmes-jaune-runningc">bon march茅 nike free femmes jaune</a> <a href="http://www.juniorensea.com/nike-air-max-90-triple-black-all-black-runninge">nike air max 90 triple black all black</a> <a href="http://www.jlredcross.com/michael-kors-md-messenger-bag-mkr">michael kors md messenger bag</a> <a href="http://www.synexiemobile.com/orange-pink-mens-adidas-zx-700-shoes-sportse">orange pink mens adidas zx 700 shoes</a> <a href="http://www.minruteguide.com/nike-limited-mens-pittsburgh-steelers-84-antonio-brown-80th-anniversary-throwback-nfl-jersey-89.99-nflv">nike limited mens pittsburgh steelers 84 antonio brown 80th anniversary throwback nfl jersey 89.99</a> <a href="http://www.emigunindia.com/air-max-hyperfuse-90-price-shoesg">air max hyperfuse 90 price</a>
    caryongpum http://www.caryongpum.com/

欢迎留言




用户登录

sitemap