我使用过的Linux命令之unzip - 解压zip文件

我使用过的Linux命令之unzip - 解压zip文件

本文链接:http://codingstandards.iteye.com/blog/792040    (转载请注明出处)

用途说明

zip文件是一种常用的压缩文件格式,WinZip、WinRar等压缩软件都支持zip文件格式,就连java的jar包也是zip格式的,Firefox插件xpi文件也是zip格式的。Linux在zip文件上的支持也是很周到的,它提供了zip、unzip和zcat等命令来支持。本文的主题是讲一下使用unzip命令来解压zip格式的压缩文件。当我们需要把Windows上的很多文件(比如一个目录中的所有文件)上传到Linux时,可以先把这些文件打包到一个zip文件中,然后再上传,再在Linux下利用unzip进行解压,这比一个一个上传好得多。

常用参数

在linux下解压zip文件,最简单的方式就是unzip命令直接跟上要解压的zip文件。

unzip <zip-file>

上面的用法是把文件解压到当前目录下,如果要把文件解压到指定的目录下,需要用到-d参数。

unzip -d <dst-dir> <zip-file>

解压的时候,有时候不想覆盖已经存在的文件,那么可以加上-n参数。

unzip -n <zip-file>

unzip -n -d <dst-dir> <zip-file>

有时候,我们只想看一下zip压缩包中包含哪些文件,就可以使用-l参数。

unzip -l <zip-file>

我们在使用WinZip或WinRar的时候,它显示的文件列表还包含压缩比率,unzip命令使用-v命令也可以看到这些信息。

unzip -v <zip-file>

我们经常会碰到这种情况,从网上下载的zip文件可能不完整,在使用WinZip或WinRar打开的时候,会报错,unzip提供了-t参数来检查zip文件是否损坏。

unzip -t <zip-file>

使用示例

示例一 解压tinyxml开发包

tinyxml是一个解析XML的C++开发包,它小巧玲珑,简单易用。

[root@rhel55 c++]# ls tinyxml_2_6_1.zip -l
-rw-r--r-- 1 root root 296068 10-22 14:25 tinyxml_2_6_1.zip
[root@rhel55 c++]# unzip tinyxml_2_6_1.zip
Archive:  tinyxml_2_6_1.zip
   creating: tinyxml/
  inflating: tinyxml/changes.txt    
   creating: tinyxml/docs/
  inflating: tinyxml/docs/annotated.html 
  inflating: tinyxml/docs/classes.html 
  inflating: tinyxml/docs/classTiXmlAttribute-members.html 
  inflating: tinyxml/docs/classTiXmlAttribute.html 
  inflating: tinyxml/docs/classTiXmlAttribute.png 
  inflating: tinyxml/docs/classTiXmlBase-members.html 
  inflating: tinyxml/docs/classTiXmlBase.html 
  inflating: tinyxml/docs/classTiXmlBase.png 
  inflating: tinyxml/docs/classTiXmlComment-members.html 
  inflating: tinyxml/docs/classTiXmlComment.html 
 extracting: tinyxml/docs/classTiXmlComment.png 
  inflating: tinyxml/docs/classTiXmlDeclaration-members.html 
  inflating: tinyxml/docs/classTiXmlDeclaration.html 
 extracting: tinyxml/docs/classTiXmlDeclaration.png 
  inflating: tinyxml/docs/classTiXmlDocument-members.html 
  inflating: tinyxml/docs/classTiXmlDocument.html 
  inflating: tinyxml/docs/classTiXmlDocument.png 
  inflating: tinyxml/docs/classTiXmlElement-members.html 
  inflating: tinyxml/docs/classTiXmlElement.html 
  inflating: tinyxml/docs/classTiXmlElement.png 
  inflating: tinyxml/docs/classTiXmlHandle-members.html 
  inflating: tinyxml/docs/classTiXmlHandle.html 
  inflating: tinyxml/docs/classTiXmlNode-members.html 
  inflating: tinyxml/docs/classTiXmlNode.html 
  inflating: tinyxml/docs/classTiXmlNode.png 
  inflating: tinyxml/docs/classTiXmlPrinter-members.html 
  inflating: tinyxml/docs/classTiXmlPrinter.html 
  inflating: tinyxml/docs/classTiXmlPrinter.png 
  inflating: tinyxml/docs/classTiXmlText-members.html 
  inflating: tinyxml/docs/classTiXmlText.html 
 extracting: tinyxml/docs/classTiXmlText.png 
  inflating: tinyxml/docs/classTiXmlUnknown-members.html 
  inflating: tinyxml/docs/classTiXmlUnknown.html 
  inflating: tinyxml/docs/classTiXmlUnknown.png 
  inflating: tinyxml/docs/classTiXmlVisitor-members.html 
  inflating: tinyxml/docs/classTiXmlVisitor.html 
  inflating: tinyxml/docs/classTiXmlVisitor.png 
  inflating: tinyxml/docs/deprecated.html 
  inflating: tinyxml/docs/doxygen.css 
  inflating: tinyxml/docs/doxygen.png 
  inflating: tinyxml/docs/files.html 
  inflating: tinyxml/docs/functions.html 
  inflating: tinyxml/docs/functions_0x63.html 
  inflating: tinyxml/docs/functions_0x64.html 
  inflating: tinyxml/docs/functions_0x65.html 
  inflating: tinyxml/docs/functions_0x66.html 
  inflating: tinyxml/docs/functions_0x67.html 
  inflating: tinyxml/docs/functions_0x69.html 
  inflating: tinyxml/docs/functions_0x6c.html 
  inflating: tinyxml/docs/functions_0x6e.html 
  inflating: tinyxml/docs/functions_0x6f.html 
  inflating: tinyxml/docs/functions_0x70.html 
  inflating: tinyxml/docs/functions_0x71.html 
  inflating: tinyxml/docs/functions_0x72.html 
  inflating: tinyxml/docs/functions_0x73.html 
  inflating: tinyxml/docs/functions_0x74.html 
  inflating: tinyxml/docs/functions_0x75.html 
  inflating: tinyxml/docs/functions_0x76.html 
  inflating: tinyxml/docs/functions_enum.html 
  inflating: tinyxml/docs/functions_func.html 
  inflating: tinyxml/docs/functions_func_0x63.html 
  inflating: tinyxml/docs/functions_func_0x64.html 
  inflating: tinyxml/docs/functions_func_0x65.html 
  inflating: tinyxml/docs/functions_func_0x66.html 
  inflating: tinyxml/docs/functions_func_0x67.html 
  inflating: tinyxml/docs/functions_func_0x69.html 
  inflating: tinyxml/docs/functions_func_0x6c.html 
  inflating: tinyxml/docs/functions_func_0x6e.html 
  inflating: tinyxml/docs/functions_func_0x70.html 
  inflating: tinyxml/docs/functions_func_0x71.html 
  inflating: tinyxml/docs/functions_func_0x72.html 
  inflating: tinyxml/docs/functions_func_0x73.html 
  inflating: tinyxml/docs/functions_func_0x74.html 
  inflating: tinyxml/docs/functions_func_0x75.html 
  inflating: tinyxml/docs/functions_func_0x76.html 
  inflating: tinyxml/docs/functions_rela.html 
  inflating: tinyxml/docs/functions_vars.html 
  inflating: tinyxml/docs/hierarchy.html 
  inflating: tinyxml/docs/index.html 
  inflating: tinyxml/docs/pages.html 
  inflating: tinyxml/docs/tab_b.gif 
  inflating: tinyxml/docs/tab_l.gif 
  inflating: tinyxml/docs/tab_r.gif 
  inflating: tinyxml/docs/tabs.css  
  inflating: tinyxml/docs/tinystr_8h_source.html 
  inflating: tinyxml/docs/tinyxml_8h_source.html 
  inflating: tinyxml/docs/tutorial0.html 
  inflating: tinyxml/echo.dsp       
  inflating: tinyxml/Makefile       
  inflating: tinyxml/readme.txt     
  inflating: tinyxml/tinystr.cpp    
  inflating: tinyxml/tinystr.h      
  inflating: tinyxml/tinyxml.cpp    
  inflating: tinyxml/tinyxml.dsw    
  inflating: tinyxml/tinyxml.h      
  inflating: tinyxml/tinyxml.sln    
  inflating: tinyxml/tinyxml_lib.dsp 
  inflating: tinyxml/tinyxml_lib.vcproj 
  inflating: tinyxml/tinyxmlerror.cpp 
  inflating: tinyxml/tinyxmlparser.cpp 
  inflating: tinyxml/tinyxmlSTL.dsp 
  inflating: tinyxml/tinyxmlSTL.vcproj 
  inflating: tinyxml/tinyXmlTest.dsp 
  inflating: tinyxml/tinyXmlTest.vcproj 
  inflating: tinyxml/tinyXmlTestSTL.dsp 
  inflating: tinyxml/tinyXmlTestSTL.vcproj 
  inflating: tinyxml/utf8test.gif   
  inflating: tinyxml/utf8test.xml   
  inflating: tinyxml/utf8testverify.xml 
  inflating: tinyxml/xmltest.cpp    

[root@rhel55 c++]#

示例二 解压tinyxml开发包到/opt/devtools目录

/opt目录常用来存放用户软件的目录,比如我们通常把oracle数据库安装在/opt目录。

这里我们把tinyxml开发包解压到/opt/devtools目录下,其中devtools子目录并不存在,执行该命令时候,这个目录自动创建了。

[root@rhel55 c++]# unzip -d /opt/devtools tinyxml_2_6_1.zip
Archive:  tinyxml_2_6_1.zip
   creating: /opt/devtools/tinyxml/
  inflating: /opt/devtools/tinyxml/changes.txt 
   creating: /opt/devtools/tinyxml/docs/
  inflating: /opt/devtools/tinyxml/docs/annotated.html 
  inflating: /opt/devtools/tinyxml/docs/classes.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlAttribute-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlAttribute.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlAttribute.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlBase-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlBase.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlBase.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlComment-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlComment.html 
 extracting: /opt/devtools/tinyxml/docs/classTiXmlComment.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlDeclaration-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlDeclaration.html 
 extracting: /opt/devtools/tinyxml/docs/classTiXmlDeclaration.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlDocument-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlDocument.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlDocument.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlElement-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlElement.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlElement.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlHandle-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlHandle.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlNode-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlNode.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlNode.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlPrinter-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlPrinter.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlPrinter.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlText-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlText.html 
 extracting: /opt/devtools/tinyxml/docs/classTiXmlText.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlUnknown-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlUnknown.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlUnknown.png 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlVisitor-members.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlVisitor.html 
  inflating: /opt/devtools/tinyxml/docs/classTiXmlVisitor.png 
  inflating: /opt/devtools/tinyxml/docs/deprecated.html 
  inflating: /opt/devtools/tinyxml/docs/doxygen.css 
  inflating: /opt/devtools/tinyxml/docs/doxygen.png 
  inflating: /opt/devtools/tinyxml/docs/files.html 
  inflating: /opt/devtools/tinyxml/docs/functions.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x63.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x64.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x65.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x66.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x67.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x69.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x6c.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x6e.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x6f.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x70.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x71.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x72.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x73.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x74.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x75.html 
  inflating: /opt/devtools/tinyxml/docs/functions_0x76.html 
  inflating: /opt/devtools/tinyxml/docs/functions_enum.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x63.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x64.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x65.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x66.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x67.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x69.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x6c.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x6e.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x70.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x71.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x72.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x73.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x74.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x75.html 
  inflating: /opt/devtools/tinyxml/docs/functions_func_0x76.html 
  inflating: /opt/devtools/tinyxml/docs/functions_rela.html 
  inflating: /opt/devtools/tinyxml/docs/functions_vars.html 
  inflating: /opt/devtools/tinyxml/docs/hierarchy.html 
  inflating: /opt/devtools/tinyxml/docs/index.html 
  inflating: /opt/devtools/tinyxml/docs/pages.html 
  inflating: /opt/devtools/tinyxml/docs/tab_b.gif 
  inflating: /opt/devtools/tinyxml/docs/tab_l.gif 
  inflating: /opt/devtools/tinyxml/docs/tab_r.gif 
  inflating: /opt/devtools/tinyxml/docs/tabs.css 
  inflating: /opt/devtools/tinyxml/docs/tinystr_8h_source.html 
  inflating: /opt/devtools/tinyxml/docs/tinyxml_8h_source.html 
  inflating: /opt/devtools/tinyxml/docs/tutorial0.html 
  inflating: /opt/devtools/tinyxml/echo.dsp 
  inflating: /opt/devtools/tinyxml/Makefile 
  inflating: /opt/devtools/tinyxml/readme.txt 
  inflating: /opt/devtools/tinyxml/tinystr.cpp 
  inflating: /opt/devtools/tinyxml/tinystr.h 
  inflating: /opt/devtools/tinyxml/tinyxml.cpp 
  inflating: /opt/devtools/tinyxml/tinyxml.dsw 
  inflating: /opt/devtools/tinyxml/tinyxml.h 
  inflating: /opt/devtools/tinyxml/tinyxml.sln 
  inflating: /opt/devtools/tinyxml/tinyxml_lib.dsp 
  inflating: /opt/devtools/tinyxml/tinyxml_lib.vcproj 
  inflating: /opt/devtools/tinyxml/tinyxmlerror.cpp 
  inflating: /opt/devtools/tinyxml/tinyxmlparser.cpp 
  inflating: /opt/devtools/tinyxml/tinyxmlSTL.dsp 
  inflating: /opt/devtools/tinyxml/tinyxmlSTL.vcproj 
  inflating: /opt/devtools/tinyxml/tinyXmlTest.dsp 
  inflating: /opt/devtools/tinyxml/tinyXmlTest.vcproj 
  inflating: /opt/devtools/tinyxml/tinyXmlTestSTL.dsp 
  inflating: /opt/devtools/tinyxml/tinyXmlTestSTL.vcproj 
  inflating: /opt/devtools/tinyxml/utf8test.gif 
  inflating: /opt/devtools/tinyxml/utf8test.xml 
  inflating: /opt/devtools/tinyxml/utf8testverify.xml 
  inflating: /opt/devtools/tinyxml/xmltest.cpp 
[root@rhel55 c++]#

 

示例三 解压文件,不覆盖已经存在的文件

[root@rhel55 c++]# unzip -n -d /opt/devtools tinyxml_2_6_1.zip
Archive:  tinyxml_2_6_1.zip
[root@rhel55 c++]#

示例四 查看zip文件中包含的文件列表

[root@rhel55 c++]# unzip -l tinyxml_2_6_1.zip
Archive:  tinyxml_2_6_1.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  03-23-10 13:16   tinyxml/
    14898  03-23-10 13:16   tinyxml/changes.txt
        0  03-23-10 13:16   tinyxml/docs/
     3796  03-23-10 13:16   tinyxml/docs/annotated.html
     2809  03-23-10 13:16   tinyxml/docs/classes.html
     8304  03-23-10 13:16   tinyxml/docs/classTiXmlAttribute-members.html
    15523  03-23-10 13:16   tinyxml/docs/classTiXmlAttribute.html
      401  03-23-10 13:16   tinyxml/docs/classTiXmlAttribute.png
     3890  03-23-10 13:16   tinyxml/docs/classTiXmlBase-members.html
    16033  03-23-10 13:16   tinyxml/docs/classTiXmlBase.html
     1470  03-23-10 13:16   tinyxml/docs/classTiXmlBase.png
    19288  03-23-10 13:16   tinyxml/docs/classTiXmlComment-members.html
     7737  03-23-10 13:16   tinyxml/docs/classTiXmlComment.html
      518  03-23-10 13:16   tinyxml/docs/classTiXmlComment.png
    20501  03-23-10 13:16   tinyxml/docs/classTiXmlDeclaration-members.html
    10823  03-23-10 13:16   tinyxml/docs/classTiXmlDeclaration.html
      557  03-23-10 13:16   tinyxml/docs/classTiXmlDeclaration.png
    24057  03-23-10 13:16   tinyxml/docs/classTiXmlDocument-members.html
    30742  03-23-10 13:16   tinyxml/docs/classTiXmlDocument.html
      535  03-23-10 13:16   tinyxml/docs/classTiXmlDocument.png
    23787  03-23-10 13:16   tinyxml/docs/classTiXmlElement-members.html
    30888  03-23-10 13:16   tinyxml/docs/classTiXmlElement.html
      514  03-23-10 13:16   tinyxml/docs/classTiXmlElement.png
     5695  03-23-10 13:16   tinyxml/docs/classTiXmlHandle-members.html
    25214  03-23-10 13:16   tinyxml/docs/classTiXmlHandle.html
    18771  03-23-10 13:16   tinyxml/docs/classTiXmlNode-members.html
    60709  03-23-10 13:16   tinyxml/docs/classTiXmlNode.html
     1303  03-23-10 13:16   tinyxml/docs/classTiXmlNode.png
     5515  03-23-10 13:16   tinyxml/docs/classTiXmlPrinter-members.html
    14684  03-23-10 13:16   tinyxml/docs/classTiXmlPrinter.html
      380  03-23-10 13:16   tinyxml/docs/classTiXmlPrinter.png
    19711  03-23-10 13:16   tinyxml/docs/classTiXmlText-members.html
    10566  03-23-10 13:16   tinyxml/docs/classTiXmlText.html
      485  03-23-10 13:16   tinyxml/docs/classTiXmlText.png
    18804  03-23-10 13:16   tinyxml/docs/classTiXmlUnknown-members.html
     7013  03-23-10 13:16   tinyxml/docs/classTiXmlUnknown.html
      521  03-23-10 13:16   tinyxml/docs/classTiXmlUnknown.png
     3643  03-23-10 13:16   tinyxml/docs/classTiXmlVisitor-members.html
     8524  03-23-10 13:16   tinyxml/docs/classTiXmlVisitor.html
      386  03-23-10 13:16   tinyxml/docs/classTiXmlVisitor.png
     2622  03-23-10 13:16   tinyxml/docs/deprecated.html
     7131  03-23-10 13:16   tinyxml/docs/doxygen.css
     1281  03-23-10 13:16   tinyxml/docs/doxygen.png
     1548  03-23-10 13:16   tinyxml/docs/files.html
     4052  03-23-10 13:16   tinyxml/docs/functions.html
     4729  03-23-10 13:16   tinyxml/docs/functions_0x63.html
     3362  03-23-10 13:16   tinyxml/docs/functions_0x64.html
     4191  03-23-10 13:16   tinyxml/docs/functions_0x65.html
     4063  03-23-10 13:16   tinyxml/docs/functions_0x66.html
     3584  03-23-10 13:16   tinyxml/docs/functions_0x67.html
     4078  03-23-10 13:16   tinyxml/docs/functions_0x69.html
     3828  03-23-10 13:16   tinyxml/docs/functions_0x6c.html
     4046  03-23-10 13:16   tinyxml/docs/functions_0x6e.html
     3473  03-23-10 13:16   tinyxml/docs/functions_0x6f.html
     4600  03-23-10 13:16   tinyxml/docs/functions_0x70.html
     4139  03-23-10 13:16   tinyxml/docs/functions_0x71.html
     3823  03-23-10 13:16   tinyxml/docs/functions_0x72.html
     5492  03-23-10 13:16   tinyxml/docs/functions_0x73.html
     6167  03-23-10 13:16   tinyxml/docs/functions_0x74.html
     3462  03-23-10 13:16   tinyxml/docs/functions_0x75.html
     5012  03-23-10 13:16   tinyxml/docs/functions_0x76.html
     1932  03-23-10 13:16   tinyxml/docs/functions_enum.html
     3977  03-23-10 13:16   tinyxml/docs/functions_func.html
     4654  03-23-10 13:16   tinyxml/docs/functions_func_0x63.html
     3287  03-23-10 13:16   tinyxml/docs/functions_func_0x64.html
     4116  03-23-10 13:16   tinyxml/docs/functions_func_0x65.html
     3988  03-23-10 13:16   tinyxml/docs/functions_func_0x66.html
     3509  03-23-10 13:16   tinyxml/docs/functions_func_0x67.html
     4003  03-23-10 13:16   tinyxml/docs/functions_func_0x69.html
     3753  03-23-10 13:16   tinyxml/docs/functions_func_0x6c.html
     3861  03-23-10 13:16   tinyxml/docs/functions_func_0x6e.html
     4525  03-23-10 13:16   tinyxml/docs/functions_func_0x70.html
     4064  03-23-10 13:16   tinyxml/docs/functions_func_0x71.html
     3748  03-23-10 13:16   tinyxml/docs/functions_func_0x72.html
     5417  03-23-10 13:16   tinyxml/docs/functions_func_0x73.html
     6092  03-23-10 13:16   tinyxml/docs/functions_func_0x74.html
     3277  03-23-10 13:16   tinyxml/docs/functions_func_0x75.html
     4937  03-23-10 13:16   tinyxml/docs/functions_func_0x76.html
     2063  03-23-10 13:16   tinyxml/docs/functions_rela.html
     1929  03-23-10 13:16   tinyxml/docs/functions_vars.html
     2343  03-23-10 13:16   tinyxml/docs/hierarchy.html
    24431  03-23-10 13:16   tinyxml/docs/index.html
     1215  03-23-10 13:16   tinyxml/docs/pages.html
       35  03-23-10 13:16   tinyxml/docs/tab_b.gif
      706  03-23-10 13:16   tinyxml/docs/tab_l.gif
     2585  03-23-10 13:16   tinyxml/docs/tab_r.gif
     1844  03-23-10 13:16   tinyxml/docs/tabs.css
    28921  03-23-10 13:16   tinyxml/docs/tinystr_8h_source.html
   203302  03-23-10 13:16   tinyxml/docs/tinyxml_8h_source.html
    23226  03-23-10 13:16   tinyxml/docs/tutorial0.html
     4457  03-23-10 13:16   tinyxml/echo.dsp
     3502  03-23-10 13:16   tinyxml/Makefile
    19831  03-23-10 13:16   tinyxml/readme.txt
     2602  03-23-10 13:16   tinyxml/tinystr.cpp
     8783  03-23-10 13:16   tinyxml/tinystr.h
    36435  03-23-10 13:16   tinyxml/tinyxml.cpp
     1315  03-23-10 13:16   tinyxml/tinyxml.dsw
    64316  03-23-10 13:16   tinyxml/tinyxml.h
     2535  03-23-10 13:16   tinyxml/tinyxml.sln
     3475  03-23-10 13:16   tinyxml/tinyxml_lib.dsp
     5676  03-23-10 13:16   tinyxml/tinyxml_lib.vcproj
     1780  03-23-10 13:16   tinyxml/tinyxmlerror.cpp
    37193  03-23-10 13:16   tinyxml/tinyxmlparser.cpp
     3518  03-23-10 13:16   tinyxml/tinyxmlSTL.dsp
     5656  03-23-10 13:16   tinyxml/tinyxmlSTL.vcproj
     4189  03-23-10 13:16   tinyxml/tinyXmlTest.dsp
     5336  03-23-10 13:16   tinyxml/tinyXmlTest.vcproj
     4453  03-23-10 13:16   tinyxml/tinyXmlTestSTL.dsp
     5447  03-23-10 13:16   tinyxml/tinyXmlTestSTL.vcproj
    14812  03-23-10 13:16   tinyxml/utf8test.gif
      690  03-23-10 13:16   tinyxml/utf8test.xml
      692  03-23-10 13:16   tinyxml/utf8testverify.xml
    41492  03-23-10 13:16   tinyxml/xmltest.cpp
 --------                   -------
  1163603                   113 files
[root@rhel55 c++]#

 

示例五 显示更详细的文件信息列表,包括压缩比率等

[root@rhel55 c++]# unzip -v tinyxml_2_6_1.zip
Archive:  tinyxml_2_6_1.zip
 Length   Method    Size  Ratio   Date   Time   CRC-32    Name
--------  ------  ------- -----   ----   ----   ------    ----
       0  Stored        0   0%  03-23-10 13:16  00000000  tinyxml/
   14898  Defl:X     6510  56%  03-23-10 13:16  32a9eb00  tinyxml/changes.txt
       0  Stored        0   0%  03-23-10 13:16  00000000  tinyxml/docs/
    3796  Defl:X     1116  71%  03-23-10 13:16  4bd0b7b5  tinyxml/docs/annotated.html
    2809  Defl:X      847  70%  03-23-10 13:16  f63675f5  tinyxml/docs/classes.html
    8304  Defl:X     1784  79%  03-23-10 13:16  6221073d  tinyxml/docs/classTiXmlAttribute-members.html
   15523  Defl:X     3172  80%  03-23-10 13:16  0c474e09  tinyxml/docs/classTiXmlAttribute.html
     401  Defl:X      400   0%  03-23-10 13:16  8c97bdf8  tinyxml/docs/classTiXmlAttribute.png
    3890  Defl:X     1154  70%  03-23-10 13:16  d184de48  tinyxml/docs/classTiXmlBase-members.html
   16033  Defl:X     3879  76%  03-23-10 13:16  1984decc  tinyxml/docs/classTiXmlBase.html
    1470  Defl:X     1438   2%  03-23-10 13:16  3899f54a  tinyxml/docs/classTiXmlBase.png
   19288  Defl:X     3223  83%  03-23-10 13:16  aef8fe13  tinyxml/docs/classTiXmlComment-members.html
    7737  Defl:X     2100  73%  03-23-10 13:16  1dad3de2  tinyxml/docs/classTiXmlComment.html
     518  Stored      518   0%  03-23-10 13:16  f89010b1  tinyxml/docs/classTiXmlComment.png
   20501  Defl:X     3385  84%  03-23-10 13:16  0d6b321b  tinyxml/docs/classTiXmlDeclaration-members.html
   10823  Defl:X     2633  76%  03-23-10 13:16  e282761f  tinyxml/docs/classTiXmlDeclaration.html
     557  Stored      557   0%  03-23-10 13:16  a84cb341  tinyxml/docs/classTiXmlDeclaration.png
   24057  Defl:X     3881  84%  03-23-10 13:16  444474ce  tinyxml/docs/classTiXmlDocument-members.html
   30742  Defl:X     5233  83%  03-23-10 13:16  b686e382  tinyxml/docs/classTiXmlDocument.html
     535  Defl:X      527   2%  03-23-10 13:16  e805b493  tinyxml/docs/classTiXmlDocument.png
   23787  Defl:X     3811  84%  03-23-10 13:16  d500f7d3  tinyxml/docs/classTiXmlElement-members.html
   30888  Defl:X     4771  85%  03-23-10 13:16  85cf72b3  tinyxml/docs/classTiXmlElement.html
     514  Defl:X      488   5%  03-23-10 13:16  c63d39ed  tinyxml/docs/classTiXmlElement.png
    5695  Defl:X     1285  77%  03-23-10 13:16  c79878e4  tinyxml/docs/classTiXmlHandle-members.html
   25214  Defl:X     3737  85%  03-23-10 13:16  ab50ac54  tinyxml/docs/classTiXmlHandle.html
   18771  Defl:X     3147  83%  03-23-10 13:16  1f9f07b9  tinyxml/docs/classTiXmlNode-members.html
   60709  Defl:X     8578  86%  03-23-10 13:16  5079c120  tinyxml/docs/classTiXmlNode.html
    1303  Defl:X     1245   5%  03-23-10 13:16  cd1dc9f5  tinyxml/docs/classTiXmlNode.png
    5515  Defl:X     1313  76%  03-23-10 13:16  37f34eb0  tinyxml/docs/classTiXmlPrinter-members.html
   14684  Defl:X     3041  79%  03-23-10 13:16  6f2a49a7  tinyxml/docs/classTiXmlPrinter.html
     380  Defl:X      377   1%  03-23-10 13:16  277c06d3  tinyxml/docs/classTiXmlPrinter.png
   19711  Defl:X     3302  83%  03-23-10 13:16  b5d7be0e  tinyxml/docs/classTiXmlText-members.html
   10566  Defl:X     2689  75%  03-23-10 13:16  53bcfa73  tinyxml/docs/classTiXmlText.html
     485  Stored      485   0%  03-23-10 13:16  6e78480b  tinyxml/docs/classTiXmlText.png
   18804  Defl:X     3163  83%  03-23-10 13:16  b5da9c89  tinyxml/docs/classTiXmlUnknown-members.html
    7013  Defl:X     2107  70%  03-23-10 13:16  9b4816cc  tinyxml/docs/classTiXmlUnknown.html
     521  Defl:X      520   0%  03-23-10 13:16  84b4f6b9  tinyxml/docs/classTiXmlUnknown.png
    3643  Defl:X     1018  72%  03-23-10 13:16  89443ea5  tinyxml/docs/classTiXmlVisitor-members.html
    8524  Defl:X     2180  74%  03-23-10 13:16  b8f1d221  tinyxml/docs/classTiXmlVisitor.html
     386  Defl:X      385   0%  03-23-10 13:16  a25913cb  tinyxml/docs/classTiXmlVisitor.png
    2622  Defl:X      970  63%  03-23-10 13:16  d26502e1  tinyxml/docs/deprecated.html
    7131  Defl:X     2058  71%  03-23-10 13:16  3f275ea9  tinyxml/docs/doxygen.css
    1281  Defl:X     1208   6%  03-23-10 13:16  61f5966b  tinyxml/docs/doxygen.png
    1548  Defl:X      656  58%  03-23-10 13:16  37e5e107  tinyxml/docs/files.html
    4052  Defl:X     1173  71%  03-23-10 13:16  efac1257  tinyxml/docs/functions.html
    4729  Defl:X     1398  70%  03-23-10 13:16  9c56c519  tinyxml/docs/functions_0x63.html
    3362  Defl:X      929  72%  03-23-10 13:16  8f96a8a8  tinyxml/docs/functions_0x64.html
    4191  Defl:X     1169  72%  03-23-10 13:16  e0e89f57  tinyxml/docs/functions_0x65.html
    4063  Defl:X     1153  72%  03-23-10 13:16  67a42520  tinyxml/docs/functions_0x66.html
    3584  Defl:X     1011  72%  03-23-10 13:16  76fd776f  tinyxml/docs/functions_0x67.html
    4078  Defl:X     1170  71%  03-23-10 13:16  44e00503  tinyxml/docs/functions_0x69.html
    3828  Defl:X     1093  71%  03-23-10 13:16  f830b80d  tinyxml/docs/functions_0x6c.html
    4046  Defl:X     1136  72%  03-23-10 13:16  9565bb3f  tinyxml/docs/functions_0x6e.html
    3473  Defl:X      959  72%  03-23-10 13:16  489db97e  tinyxml/docs/functions_0x6f.html
    4600  Defl:X     1340  71%  03-23-10 13:16  c970597f  tinyxml/docs/functions_0x70.html
    4139  Defl:X     1139  73%  03-23-10 13:16  3249d80a  tinyxml/docs/functions_0x71.html
    3823  Defl:X     1088  72%  03-23-10 13:16  e4f5c05e  tinyxml/docs/functions_0x72.html
    5492  Defl:X     1565  72%  03-23-10 13:16  c4041eb1  tinyxml/docs/functions_0x73.html
    6167  Defl:X     1742  72%  03-23-10 13:16  f2e5d279  tinyxml/docs/functions_0x74.html
    3462  Defl:X      967  72%  03-23-10 13:16  1c9b85b1  tinyxml/docs/functions_0x75.html
    5012  Defl:X     1417  72%  03-23-10 13:16  474ff720  tinyxml/docs/functions_0x76.html
    1932  Defl:X      695  64%  03-23-10 13:16  17f18324  tinyxml/docs/functions_enum.html
    3977  Defl:X     1121  72%  03-23-10 13:16  2c91ef74  tinyxml/docs/functions_func.html
    4654  Defl:X     1343  71%  03-23-10 13:16  351531b3  tinyxml/docs/functions_func_0x63.html
    3287  Defl:X      872  74%  03-23-10 13:16  d8829ae3  tinyxml/docs/functions_func_0x64.html
    4116  Defl:X     1118  73%  03-23-10 13:16  68896775  tinyxml/docs/functions_func_0x65.html
    3988  Defl:X     1099  72%  03-23-10 13:16  2eeb5fdf  tinyxml/docs/functions_func_0x66.html
    3509  Defl:X      962  73%  03-23-10 13:16  8548d1af  tinyxml/docs/functions_func_0x67.html
    4003  Defl:X     1117  72%  03-23-10 13:16  aecae710  tinyxml/docs/functions_func_0x69.html
    3753  Defl:X     1041  72%  03-23-10 13:16  34eee051  tinyxml/docs/functions_func_0x6c.html
    3861  Defl:X     1053  73%  03-23-10 13:16  d3850bd8  tinyxml/docs/functions_func_0x6e.html
    4525  Defl:X     1288  72%  03-23-10 13:16  d215c72b  tinyxml/docs/functions_func_0x70.html
    4064  Defl:X     1085  73%  03-23-10 13:16  97d683c4  tinyxml/docs/functions_func_0x71.html
    3748  Defl:X     1035  72%  03-23-10 13:16  76b9a0f1  tinyxml/docs/functions_func_0x72.html
    5417  Defl:X     1513  72%  03-23-10 13:16  5be71089  tinyxml/docs/functions_func_0x73.html
    6092  Defl:X     1687  72%  03-23-10 13:16  18798f4c  tinyxml/docs/functions_func_0x74.html
    3277  Defl:X      864  74%  03-23-10 13:16  ac6292bd  tinyxml/docs/functions_func_0x75.html
    4937  Defl:X     1361  72%  03-23-10 13:16  2d50c7fc  tinyxml/docs/functions_func_0x76.html
    2063  Defl:X      744  64%  03-23-10 13:16  9144fcfe  tinyxml/docs/functions_rela.html
    1929  Defl:X      699  64%  03-23-10 13:16  181b3b44  tinyxml/docs/functions_vars.html
    2343  Defl:X      770  67%  03-23-10 13:16  2a9a3b46  tinyxml/docs/hierarchy.html
   24431  Defl:X     8844  64%  03-23-10 13:16  8d8338ce  tinyxml/docs/index.html
    1215  Defl:X      579  52%  03-23-10 13:16  13b766be  tinyxml/docs/pages.html
      35  Defl:X       33   6%  03-23-10 13:16  423d30cb  tinyxml/docs/tab_b.gif
     706  Defl:X      701   1%  03-23-10 13:16  f40065a7  tinyxml/docs/tab_l.gif
    2585  Defl:X     2573   1%  03-23-10 13:16  e25bca26  tinyxml/docs/tab_r.gif
    1844  Defl:X      614  67%  03-23-10 13:16  d5ca0949  tinyxml/docs/tabs.css
   28921  Defl:X     5996  79%  03-23-10 13:16  6f4e2aaa  tinyxml/docs/tinystr_8h_source.html
  203302  Defl:X    27378  87%  03-23-10 13:16  d45b3393  tinyxml/docs/tinyxml_8h_source.html
   23226  Defl:X     6479  72%  03-23-10 13:16  60f240f7  tinyxml/docs/tutorial0.html
    4457  Defl:X     1034  77%  03-23-10 13:16  f7d161c6  tinyxml/echo.dsp
    3502  Defl:X      927  74%  03-23-10 13:16  f4c914ab  tinyxml/Makefile
   19831  Defl:X     8023  60%  03-23-10 13:16  2de10ec5  tinyxml/readme.txt
    2602  Defl:X     1049  60%  03-23-10 13:16  c6eefc0b  tinyxml/tinystr.cpp
    8783  Defl:X     3014  66%  03-23-10 13:16  a12eaf4d  tinyxml/tinystr.h
   36435  Defl:X     7838  79%  03-23-10 13:16  d5ee9686  tinyxml/tinyxml.cpp
    1315  Defl:X      289  78%  03-23-10 13:16  ff190c78  tinyxml/tinyxml.dsw
   64316  Defl:X    16285  75%  03-23-10 13:16  3c44527b  tinyxml/tinyxml.h
    2535  Defl:X      576  77%  03-23-10 13:16  fa79f489  tinyxml/tinyxml.sln
    3475  Defl:X     1001  71%  03-23-10 13:16  e4f79816  tinyxml/tinyxml_lib.dsp
    5676  Defl:X     1172  79%  03-23-10 13:16  1d839803  tinyxml/tinyxml_lib.vcproj
    1780  Defl:X      911  49%  03-23-10 13:16  5f74e68a  tinyxml/tinyxmlerror.cpp
   37193  Defl:X     9915  73%  03-23-10 13:16  026ceb3d  tinyxml/tinyxmlparser.cpp
    3518  Defl:X      981  72%  03-23-10 13:16  9997529a  tinyxml/tinyxmlSTL.dsp
    5656  Defl:X     1134  80%  03-23-10 13:16  c9d38a10  tinyxml/tinyxmlSTL.vcproj
    4189  Defl:X     1022  76%  03-23-10 13:16  e3220707  tinyxml/tinyXmlTest.dsp
    5336  Defl:X     1233  77%  03-23-10 13:16  5c16b425  tinyxml/tinyXmlTest.vcproj
    4453  Defl:X     1058  76%  03-23-10 13:16  eae3e727  tinyxml/tinyXmlTestSTL.dsp
    5447  Defl:X     1251  77%  03-23-10 13:16  874e8072  tinyxml/tinyXmlTestSTL.vcproj
   14812  Defl:X    14778   0%  03-23-10 13:16  fbc32be6  tinyxml/utf8test.gif
     690  Defl:X      437  37%  03-23-10 13:16  07f6f1c1  tinyxml/utf8test.xml
     692  Defl:X      435  37%  03-23-10 13:16  12b9019f  tinyxml/utf8testverify.xml
   41492  Defl:X    10283  75%  03-23-10 13:16  6053a3ef  tinyxml/xmltest.cpp
--------          -------  ---                            -------
 1163603           274650  76%                            113 files
[root@rhel55 c++]#

问题思考

暂无。

相关资料

【1】Linux自由空间 unzip命令,linux下解压zip

 

返回 我使用过的Linux命令系列总目录

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
https://github.com/iBotPeaches/Apktool Introduction Basic First lets take a lesson into apk files. apks are nothing more than a zip file containing resources and compiled java. If you were to simply unzip an apk like so, you would be left with files such as classes.dex and resources.arsc. $ unzip testapp.apk Archive: testapp.apk inflating: AndroidManifest.xml inflating: classes.dex extracting: res/drawable-hdpi/ic_launcher.png inflating: res/xml/literals.xml inflating: res/xml/references.xml extracting: resources.arsc However, at this point you have simply inflated compiled sources. If you tried to view AndroidManifest.xml. You'd be left viewing this. P4F0\fnversionCodeversionNameandroid*http://schemas.android.com/apk/res/androidpackageplatformBuildVersionCodeplatformBuildVersionNamemanifestbrut.apktool.testapp1.021APKTOOL Obviously, editing or viewing a compiled file is next to impossible. That is where Apktool comes into play. $ apktool d testapp.apk I: Using Apktool 2.0.0 on testapp.apk I: Loading resource table... I: Decoding AndroidManifest.xml with resources... I: Loading resource table from file: 1.apk I: Regular manifest package... I: Decoding file-resources... I: Decoding values */* XMLs... I: Baksmaling classes.dex... I: Copying assets and libs... $ Viewing AndroidManifest.xml again results in something much more human readable <?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="brut.apktool.testapp" platformBuildVersionCode="21" platformBuildVersionName="APKTOOL"/> In addition to XMLs, resources such as 9 patch images, layouts, strings and much more are correctly decoded to source form. Decoding The decode option on Apktool can be invoked either from d or decode like shown below. $ apktool d foo.jar // decodes foo.jar to foo.jar.out folder $ apktool decode foo.jar // decodes foo.jar to foo.jar.out folder $ apktool d bar.apk // decodes bar.apk to bar folder $ apktool decode bar.apk // decodes bar.apk to bar folder $ apktool d bar.apk -o baz // decodes bar.apk to baz folder Building The build option can be invoked either from b or build like shown below $ apktool b foo.jar.out // builds foo.jar.out folder into foo.jar.out/dist/foo.jar file $ apktool build foo.jar.out // builds foo.jar.out folder into foo.jar.out/dist/foo.jar file $ apktool b bar // builds bar folder into bar/dist/bar.apk file $ apktool b . // builds current directory into ./dist $ apktool b bar -o new_bar.apk // builds bar folder into new_bar.apk $ apktool b bar.apk // WRONG: brut.androlib.AndrolibException: brut.directory.PathNotExist: apktool.yml // Must use folder, not apk/jar file InfoIn order to run a rebuilt application. You must resign the application. Android documentation can help with this. Frameworks Frameworks can be installed either from if or install-framework, in addition two parameters -p, --frame-path <dir> - Store framework files into <dir> -t, --tag <tag> - Tag frameworks using <tag> Allow for a finer control over how the files are named and how they are stored. $ apktool if framework-res.apk I: Framework installed to: 1.apk // pkgId of framework-res.apk determines number (which is 0x01) $ apktool if com.htc.resources.apk I: Framework installed to: 2.apk // pkgId of com.htc.resources is 0x02 $ apktool if com.htc.resources.apk -t htc I: Framework installed to: 2-htc.apk // pkgId-tag.apk $ apktool if framework-res.apk -p foo/bar I: Framework installed to: foo/bar/1.apk $ apktool if framework-res.apk -t baz -p foo/bar I: Framework installed to: foo/bar/1-baz.apk Migration Instructions v2.1.1 -> v2.2.0 Run the following commands to migrate your framework directory Apktool will work fine without running these commands, this will just cleanup abandoned files unix - mkdir -p ~/.local/share; mv ~/apktool ~/.local/share windows - move %USERPROFILE%\apktool %USERPROFILE%\AppData\Local v2.0.1 -> v2.0.2 Update apktool to v2.0.2 Remove framework file $HOME/apktool/framework/1.apk due to internal API update (Android Marshmallow) v1.5.x -> v2.0.0 Java 1.7 is required Update apktool to v2.0.0 aapt is now included inside the apktool binary. It's not required to maintain your own aapt install under $PATH. (However, features like -a / --aapt are still used and can override the internal aapt) The addition of aapt replaces the need for separate aapt download packages. Helper Scripts may be found here Remove framework $HOME/apktool/framework/1.apk Eagle eyed users will notice resources are now decoded before sources now. This is because we need to know the API version via the manifest for decoding the sources Parameter Changes Smali/baksmali 2.0 are included. This is a big change from 1.4.2. Please read the smali updates here for more information -o / --output is now used for the output of apk/directory -t / --tag is required for tagging framework files -advance / --advanced will launch advance parameters and information on the usage output -m / --match-original is a new feature for apk analysis. This retains the apk is nearly original format, but will make rebuild more than likely not work due to ignoring the changes that newer aapt requires After [d]ecode, there will be new folders (original / unknown) in the decoded apk folder original = META-INF folder / AndroidManifest.xml, which are needed to retain the signature of apks to prevent needing to resign. Used with -c / --copy-original on [b]uild unknown = Files / folders that are not part of the standard AOSP build procedure. These files will be injected back into the rebuilt APK. apktool.yml collects more information than last version SdkInfo - Used to repopulate the sdk information in AndroidManifest.xml since newer aapt requires version information to be passed via parameter packageInfo - Used to help support Android 4.2 renamed manifest feature. Automatically detects differences between resource and manifest and performs automatic --rename-manifest-package on [b]uild versionInfo - Used to repopulate the version information in AndroidManifest.xml since newer aapt requires version information to be passed via parameter compressionType - Used to determine the compression that resources.arsc had on the original apk in order to replicate during [b]uild unknownFiles - Used to record name/location of non-standard files in an apk in order to place correctly on rebuilt apk sharedLibrary - Used to help support Android 5 shared library feature by automatically detecting shared libraries and using --shared-lib on [b]uild Examples of new usage in 2.0 vs 1.5.x Old (Apktool 1.5.x) New (Apktool 2.0.x) apktool if framework-res.apk tag apktool if framework-res.apk -t tag apktool d framework-res.apk output apktool d framework.res.apk -o output apktool b output new.apk apktool b output -o new.apk v1.4.x -> v1.5.1 Update apktool to v1.5.1 Update aapt manually or use package r05-ibot via downloading Mac, Windows or Linux Remove framework file $HOME/apktool/framework/1.apk Intermediate Framework Files As you probably know, Android apps utilize code and resources that are found on the Android OS itself. These are known as framework resources and Apktool relies on these to properly decode and build apks. Every Apktool release contains internally the most up to date AOSP framework at the time of the release. This allows you to decode and build most apks without a problem. However, manufacturers add their own framework files in addition to the regular AOSP ones. To use apktool against these manufacturer apks you must first install the manufacturer framework files. Example Lets say you want to decode HtcContacts.apk from an HTC device. If you try you will get an error message. $ apktool d HtcContacts.apk I: Loading resource table... I: Decoding resources... I: Loading resource table from file: 1.apk W: Could not decode attr value, using undecoded value instead: ns=android, name=drawable W: Could not decode attr value, using undecoded value instead: ns=android, name=icon Can't find framework resources for package of id: 2. You must install proper framework files, see project website for more info. We must get HTC framework resources before decoding this apk. We pull com.htc.resources.apk from our device and install it $ apktool if com.htc.resources.apk I: Framework installed to: 2.apk Now we will try this decode again. $ apktool d HtcContacts.apk I: Loading resource table... I: Decoding resources... I: Loading resource table from file: /home/brutall/apktool/framework/1.apk I: Loading resource table from file: /home/brutall/apktool/framework/2.apk I: Copying assets and libs... As you can see. Apktool leveraged both 1.apk and 2.apk framework files in order to properly decode this application. Finding Frameworks For the most part any apk in /system/framework on a device will be a framework file. On some devices they might reside in /data/system-framework and even cleverly hidden in /system/app or /system/priv-app. They are usually named with the naming of "resources", "res" or "framework". Example HTC has a framework called com.htc.resources.apk, LG has one called lge-res.apk After you find a framework file you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number that the framework is named during install corresponds to the pkgId of the application. These values should range from 1 to 9. Any APK that installs itself as 127 is 0x7F which is an internal pkgId. Internal Frameworks Apktool comes with an internal framework like mentioned above. This file is copied to $HOME/apktool/framework/1.apk during use. Warning Apktool has no knowledge of what version of framework resides there. It will assume its up to date, so delete the file during Apktool upgrades Managing framework files Frameworks are stored in $HOME/apktool/framework for Windows and Unix systems. Mac OS X has a slightly different folder location of $HOME/Library/apktool/framework. If these directories are not available it will default to java.io.tmpdir which is usually /tmp. This is a volatile directory so it would make sense to take advantage of the parameter --frame-path to select an alternative folder for framework files. Note Apktool has no control over the frameworks once installed, but you are free to manage these files on your own. Tagging framework files Frameworks are stored in the naming convention of: <id>-<tag>.apk. They are identified by pkgId and optionally custom tag. Usually tagging frameworks isn't necessary, but if you work on apps from many different devices and they have incompatible frameworks, you will need some way to easily switch between them. You could tag frameworks by: $ apktool if com.htc.resources.apk -t hero I: Framework installed to: /home/brutall/apktool/framework/2-hero.apk $ apktool if com.htc.resources.apk -t desire I: Framework installed to: /home/brutall/apktool/framework/2-desire.apk Then: $ apktool d HtcContacts.apk -t hero I: Loading resource table... I: Decoding resources... I: Loading resource table from file: /home/brutall/apktool/framework/1.apk I: Loading resource table from file: /home/brutall/apktool/framework/2-hero.apk I: Copying assets and libs... $ apktool d HtcContacts.apk -t desire I: Loading resource table... I: Decoding resources... I: Loading resource table from file: /home/brutall/apktool/framework/1.apk I: Loading resource table from file: /home/brutall/apktool/framework/2-desire.apk I: Copying assets and libs... You don't have to select a tag when building apk - apktool automatically uses the same tag, as when decoding. Smali Debugging Warning SmaliDebugging has been marked as deprecated in 2.0.3, and removed in 2.1. Please check SmaliIdea for a debugger. Apktool makes possible to debug smali code step by step, watch variables, set breakpoints, etc. General information Generally we need several things to run Java debugging session: debugger server (usually Java VM) debugger client (usually IDE like IntelliJ, Eclipse or Netbeans) client must have sources of debugged application server must have binaries compiled with debugging symbols referencing these sources sources must be java files with at least package and class definitions, to properly connect them with debugging symbols In our particular situation we have: server: Monitor (Previously DDMS), part of Android SDK, standard for debugging Android applications - explained here client: any JPDA client - most of decent IDEs have support for this protocol. sources: smali code modified by apktool to satisfy above requirements (".java" extension, class declaration, etc.). Apktool modifies them when decoding apk in debug mode. binaries: when building apk in debug mode, apktool removes original symbols and adds new, which are referencing smali code (line numbers, registers/variables, etc.) Info To successfully run debug sessions, the apk must be both decoded and built in debug mode. Decoding with debug decodes the application differently to allow the debug rebuild option to inject lines allowing the debugger to identify variables and types.-d / --debug General instructions Above information is enough to debug smali code using apktool, but if you aren't familiar with DDMS and Java debugging, then you probably still don't know how to do it. Below are simple instructions for doing it using IntelliJ or Netbeans. Decode apk in debug mode: $ apktool d -d -o out app.apk Build new apk in debug mode: $ apktool b -d out Sign, install and run new apk. Follow sub-instructions below depending on IDE. IntelliJ (Android Studio) instructions In IntelliJ add new Java Module Project selecting the "out" directory as project location and the "smali" subdirectory as content root dir. Run Monitor (Android SDK /tools folder), find your application on a list and click it. Note port information in last column - it should be something like "86xx / 8700". In IntelliJ: Debug -> Edit Configurations. Since this is a new project, you will have to create a Debugger. Create a Remote Debugger, with the settings on "Attach" and setting the Port to 8700 (Or whatever Monitor said). The rest of fields should be ok, click "Ok". Start the debugging session. You will see some info in a log and debugging buttons will show up in top panel. Set breakpoint. You must select line with some instruction, you can't set breakpoint on lines starting with ".", ":" or "#". Trigger some action in application. If you run at breakpoint, then thread should stop and you will be able to debug step by step, watch variables, etc. Netbeans instructions In Netbeans add new Java Project with Existing Sources, select "out" directory as project root and "smali" subdirectory as sources dir. Run DDMS, find your application on a list and click it. Note port information in last column - it should be something like "86xx / 8700". In Netbeans: Debug -> Attach Debugger -> select JPDA and set Port to 8700 (or whatever you saw in previous step). Rest of fields should be ok, click "Ok". Debugging session should start: you will see some info in a log and debugging buttons will show up in top panel. Set breakpoint. You must select line with some instruction, you can't set breakpoint on lines starting with ".", ":" or "#". Trigger some action in application. If you run at breakpoint, then thread should stop and you will be able to debug step by step, watch variables, etc. Limitations/Issues Because IDE doesn't have full sources, it doesn't know about class members and such. Variables watching works because most of data could be read from memory (objects in Java know about their types), but if for example, you watch an object and it has some nulled member, then you won't see, what type this member is. 9Patch Images Docs exist for the mysterious 9patch images here and there. (Read these first). These docs though are meant for developers and lack information for those who work with already compiled 3rd party applications. There you can find information how to create them, but no information about how they actually work. I will try and explain it here. The official docs miss one point that 9patch images come in two forms: source & compiled. source - You know this one. You find it in the source of an application or freely available online. These are images with a black border around them. compiled - The mysterious form found in apk files. There are no borders and the 9patch data is written into a binary chunk called npTc. You can't see or modify it easily, but Android OS can as its quicker to read. There are problems related to the above two points. You can't move 9patch images between both types without a conversion. If you try and unpack 9patch images from an apk and use it in the source of another, you will get errors during build. Also vice versa, you cannot take source 9patch images directly into an apk. 9patch binary chunk isn't recognized by modern image processing tools. So modifying the compiled image will more than likely break the npTc chunk, thus breaking the image on the device. The only solution to this problem is to easily convert between these two types. The encoder (which takes source to compiled) is built into the aapt tool and is automatically used during build. This means we only need to build a decoder which has been in apktool since v1.3.0 and is automatically ran on all 9patch images during decode. So if you want to modify 9patch images, don't do it directly. Use apktool to decode the application (including the 9patch images) and then modify the images. At that point when you build the application back, the source 9patch images will be compiled. Other FAQ What about the -j switch shown from the original YouTube videos? Read Issue 199. In short - it doesn't exist. Is it possible to run apktool on a device? Sadly not. There are some incompatibilities with SnakeYAML, java.nio and aapt Where can I download sources of apktool? From our Github or Bitbucket project. Resulting apk file is much smaller than original! Is there something missing? There are a couple of reasons that might cause this. Apktool builds unsigned apks. This means an entire directory META-INF is missing. New aapt binary. Newer versions of apktool contain a newer aapt which optimizes images differently. These points might have contributed to a smaller than normal apk There is no META-INF dir in resulting apk. Is this ok? Yes. META-INF contains apk signatures. After modifying the apk it is no longer signed. You can use -c / --copy-original to retain these signatures. However, using -c uses the original AndroidManifest.xml file, so changes to it will be lost. What do you call "magic apks"? For some reason there are apks that are built using modified build tools. These apks don't work on a regular AOSP Android build, but usually are accompanied by a modified system that can read these modified apks. Apktool cannot handle these apks, therefore they are "magic". Could I integrate apktool into my own tool? Could I modify apktool sources? Do I have to credit you? Actually the Apache License, which apktool uses, answers all these questions. Yes you can redistribute and/or modify apktool without my permission. However, if you do it would be nice to add our contributors (brut.all, iBotPeaches and JesusFreke) into your credits but it's not required. Where does apktool store its framework files? unix - $HOME/.local/share/apktool mac - $HOME/Library/apktool windows - $HOME/AppData/Local/apktool Options Utility Options that can be executed at any time. -version, --version Outputs current version. (Ex: 1.5.2) -v, --verbose Verbose output. Must be first parameter -q, --quiet Quiet output. Must be first parameter -advance, --advanced Advance usage output Decode These are all the options when decoding an apk. --api <API> The numeric api-level of the smali files to generate (defaults to targetSdkVersion) -b, --no-debug-info Prevents baksmali from writing out debug info (.local, .param, .line, etc). Preferred to use if you are comparing smali from the same APK of different versions. The line numbers and debug will change among versions, which can make DIFF reports a pain. -f, --force Force delete destination directory. Use when trying to decode to a folder that already exists --keep-broken-res - Advanced If there is an error like "Invalid Config Flags Detected. Dropping Resources...". This means that APK has a different structure then Apktool can handle. This might be a newer Android version or a random APK that doesn't match standards. Running this will allow the decode, but then you have to manually fix the folders with -ERR in them. -m, --match-original - Used for analysis Matches files closest as possible to original, but prevents rebuild. -o, --output <DIR> The name of the folder that apk gets written to -p, --frame-path <DIR> The folder location where framework files should be stored/read from -r, --no-res This will prevent the decompile of resources. This keeps the resources.arsc intact without any decode. If only editing Java (smali) then this is the recommend for faster decompile & rebuild -s, --no-src This will prevent the disassemble of the dex files. This keeps the apk classes.dex file and simply moves it during build. If your only editing the resources. This is recommended for faster decompile & rebuild -t, --frame-tag <TAG> Uses framework files tagged via <TAG> Rebuild These are all the options when building an apk. -a, --aapt <FILE> Loads aapt from the specified file location, instead of relying on path. Falls back to $PATH loading, if no file found -c, --copy-original - Will still require signature resign post API18 Copies original AndroidManifest.xml and META-INF folder into built apk -d, --debug Adds debuggable="true" to AndroidManifest file. -f, --force-all Overwrites existing files during build, reassembling the resources.arsc file and classes.dex file -o, --output <FILE> The name and location of the apk that gets written -p, --frame-path <DIR> The location where framework files are loaded from

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值