Git Product home page Git Product logo

apkutils's Introduction

apkutils

PyPI PyPI - Status PyPI - Python Version PyPI - Downloads PyPI - License

介绍

一个用于解析APK、Dex、AXML、ARSC、ELF的库。

安装教程

❯ pip install apkutils

❯ apkutils
Usage: apkutils [OPTIONS] COMMAND [ARGS]...

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  arsc      打印arsc
  certs     打印证书
  files     打印文件
  manifest  打印清单
  mtds      获取指定方法中的所有字符串
  strings   打印Dex中的字符串
  unzip     解压文件,默认显示zip文件
  xref      获取方法的引用方法

用法

from apkutils import APK

# NOTE 按需解析,这里仅仅解析清单,不解析dex、图标。
apk = APK.from_file(file_path).parse_resource()
manifest = apk.get_manifest()
apk.close()

# or 
with APK.from_file(file_path) as apk:
    apk.get_manifest()

请参考 examples 目录。

备注

1.3.0 开始,默认不解析清单、不解析图标、不解析Dex,而是按需解析。

感谢

apkutils's People

Contributors

kin9-0rz avatar martinmiglio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

apkutils's Issues

清单貌似无法解析

  01950132f634fb6095fb08325c542293
  132e7cf660ae5434ea70933edbb38e67
  1801d04f43ed4b15f24c925060233606
  42654eaf2260ce06cb728b79d9d79d5f
  5a9880a65c02049978065a9193ba83ac
  83bde58260b2cabe41db4112411f21fa
  8c69cc8e705da00f5a1c1e04616a99ef
  9f72c23b147d16affadf777a9af633c3
  cd9abd10a8590d86fca5a8a04a18c516

use pyinstaller import apkuilts fail

Failed to execute script 'APKAnalysis' due to unhandledexception: need to copy the

sdk/platforms/android-?/data/res/values/public.xml here
what is
sdk/platforms/android-?/data/res/values/public.xml

可能存在的侵犯开源协议

您的代码中用到了 https://github.com/Storyyeller/enjarify 项目,根据 Apache License 2.0,您必须在您的项目说明文件中加入此repo的地址(即:来源信息),并在您修改过的 https://github.com/kin9-0rz/apkutils/blob/master/apkutils/dex/dexparser.py 等文件中注明修改。
另外,axmlparser.py是来自您以前的项目 https://github.com/kin9-0rz/axmlparser ,本项目却使用了非 GPL-3.0的协议。尽管显然你不会举报自己侵权,但这样可能会给使用/二次开发本项目的人(比如我)带来潜在的侵权问题。或者说,我们可能无法肯定这部分代码应当以何种协议使用。

另,能写写docstring和type hint吗……没有这些会让人用的很难受

生成字符串索引

需要一个接口,获取所有方法及其包含的字符串 get_strings_refx

  1. 格式dict {mid:[strings]}
  2. 如果没有字符串,则不记录。

RuntimeError: File * is encrypted, password required for extraction

Traceback (most recent call last):
  File "D:\ProgramData\Miniconda3\Scripts\iave-script.py", line 11, in <module>
    load_entry_point('iave', 'console_scripts', 'iave')()
  File "d:\projects\iave\iave\__main__.py", line 71, in main
    iave.main(args)
  File "d:\projects\iave\iave\iave.py", line 1310, in main
    Statistics(apks).show()
  File "d:\projects\iave\iave\iave.py", line 56, in __init__
    self._process_manifest()
  File "d:\projects\iave\iave\iave.py", line 61, in _process_manifest
    manifest = apk_obj.get_manifest()
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\apk.py", line 86, in get_manifest
    self._init_manifest()
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\apk.py", line 106, in _init_manifest
    raise e
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\apk.py", line 94, in _init_manifest
    data = zf.read(ANDROID_MANIFEST)
  File "D:\ProgramData\Miniconda3\lib\zipfile.py", line 1314, in read
    with self.open(name, "r", pwd) as fp:
  File "D:\ProgramData\Miniconda3\lib\zipfile.py", line 1406, in open
    "required for extraction" % name)
RuntimeError: File 'AndroidManifest.xml' is encrypted, password required for extraction

估计是伪加密,zipfile会判断加密位。
5fb368d6f4dae0cda8c1735d5f3a99cc

IndexError: index out of range

0c856bbccab2a7fc7b477df68f3289d0
41b94ec1202fe6e06726362052374b6d

$ python -m apkutils.apk -s 41b94ec1202fe6e06726362052374b6d.apk
Warning, unexpected header size!
Warning, unexpected endianess tag!
Traceback (most recent call last):
  File "...\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "...\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "...\lib\site-packages\apkutils\apk.py", line 375, in <module>
    main(_args)
  File "...\lib\site-packages\apkutils\apk.py", line 357, in main
    for item in apk.get_strings():
  File "...\lib\site-packages\apkutils\apk.py", line 41, in get_strings
    self._init_strings()
  File "...\lib\site-packages\apkutils\apk.py", line 51, in _init_strings
    str_set.add(binascii.hexlify(dex_file.string(i)).decode())
  File "...\lib\site-packages\apkutils\dex\dexparser.py", line 300, in string
    stream.uleb128()  # ignore decoded length
  File "...\lib\site-packages\apkutils\dex\byteio.py", line 65, in uleb128
    return self._leb128()
  File "...\lib\site-packages\apkutils\dex\byteio.py", line 52, in _leb128
    while self.data[self.pos] >> 7:
IndexError: index out of range

Vulnerable OpenSSL included in cryptography wheels used in this library

Vulnerable OpenSSL included in cryptography wheels >= 0.8.1, < 39.0.1.

This package specifies cryptography = ">=35.0.0,<36.0.0"

As per dependabot:

pyca/cryptography's wheels include a statically linked copy of OpenSSL. The versions of OpenSSL included in cryptography 0.8.1-39.0.0 are vulnerable to a security issue. More details about the vulnerabilities themselves can be found in https://www.openssl.org/news/secadv/20221213.txt and https://www.openssl.org/news/secadv/20230207.txt.
If you are building cryptography source ("sdist") then you are responsible for upgrading your copy of OpenSSL. Only users installing from wheels built by the cryptography project (i.e., those distributed on PyPI) need to update their cryptography versions.

Parsing app package name, version etc.

Hi,
Thanks for your contribution to the community. I can't find any documentation for this script. Is there any way to retrieve package name and all other general info? If yes, then please update some examples.

Parse apk Launch Icon path

Thanks for great tool. (I'm in China ^_^)

Can you give some hint about how to get icon file from apk? I can see using this lib can get string from asar file, but how to do next.

No matching distribution found for apkutils

Any idea why I got this error on Ubuntu 16.04.

$ pip install apkutils
Collecting apkutils
  Could not find a version that satisfies the requirement apkutils (from versions: )
No matching distribution found for apkutils

And when I'm trying to install from the source I got this error:

$ pip install git+https://github.com/mikusjelly/apkutils.git
Collecting git+https://github.com/mikusjelly/apkutils.git
  Cloning https://github.com/mikusjelly/apkutils.git to /tmp/pip-req-build-Ogdj1H
Collecting pyelftools (from apkutils==0.5.2)
  Downloading https://files.pythonhosted.org/packages/fa/9a/0674cb1725196568bdbca98304f2efb17368b57af1a4bb3fc772c026f474/pyelftools-0.25.tar.gz (499kB)
    100% |████████████████████████████████| 501kB 6.7MB/s 
Collecting cigam (from apkutils==0.5.2)
  Could not find a version that satisfies the requirement cigam (from apkutils==0.5.2) (from versions: )
No matching distribution found for cigam (from apkutils==0.5.2)

parseBytecode AssertionError

aed7b989ab5898fee59ca39c287d1025

  File "... apkutils/__init__.py", line 71, in get_strings_refx
    self._init_strings_refx()
  File "... apkutils/__init__.py", line 36, in _init_strings_refx
    dexClass.parseData()
  File "... apkutils/dex/dexparser.py", line 243, in parseData
    self.data = ClassData(self.dex, self.data_off)
  File "... apkutils/dex/dexparser.py", line 198, in __init__
    self._parse(dex, dex.stream(offset))
  File "... apkutils/dex/dexparser.py", line 220, in _parse
    Method(dex, method_idx, stream.uleb128(), stream.uleb128()))
  File "... apkutils/dex/dexparser.py", line 188, in __init__
    self.code = CodeItem(dex, code_off) if code_off else None
  File "... apkutils/dex/dexparser.py", line 178, in __init__
    self.bytecode = parseBytecode(dex, insns_start_pos, insns, catch_addrs)
  File "... apkutils/dex/dalvik.py", line 203, in parseBytecode
    assert(0 not in catch_addrs)
AssertionError

StypePoolOffset parse error

0a5899ad02576cc557234cf748dd3818
141d30a60e48890b3d9244e07774cf5f
67ecdfbe69b37202b7541325bb1440f7
7d06e06970b9761d71fa8a31873421dc
ac8ec47603994f29bfdf949499602099
e1c89699ec7a6c0f6dacf1e323a67746
eb886cb29d5524cea0de74dfb9312fed
f4d603543501ab553954f825b2f325d2

get_asrc fail to parse

Hey!
I'm trying to get info from an apk but unfortunately I'm not able to read the asrc.

apk = APK(path)
asrc = apk.get_asrc()

Here is error:

  File "/home/me/aaa.py", line 29, in __init__
    x = self.apk.get_arsc()
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/__init__.py", line 224, in get_arsc
    self._init_arsc()
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/__init__.py", line 220, in _init_arsc
    raise e
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/__init__.py", line 218, in _init_arsc
    self.arsc = ARSCParser(data)
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/axml/arscparser.py", line 147, in __init__
    mKeyStrings = StringPoolChunk(self.buff)
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/axml/chunk.py", line 23, in __init__
    self.header_size, self.header = self.skipNullPadding(buff)
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/axml/chunk.py", line 92, in skipNullPadding
    header = readNext(buff)
  File "/home/me/.local/lib/python3.6/site-packages/apkutils/axml/chunk.py", line 83, in readNext
    header = unpack('<i', buff.read(4))[0]
struct.error: unpack requires a buffer of 4 bytes

This error doesn't come up for me with all apks.

I'm using apkutils 0.5.2 with python3.6
I'll very appreciate your support!

xml.parsers.expat.ExpatError: duplicate attribute

$ python -m apkutils.apk -m 312792279738e239c01d7a8636ca83bf.apk
Traceback (most recent call last):
  File "...\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "...\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "...\lib\site-packages\apkutils\apk.py", line 375, in <module>
    main(_args)
  File "...\lib\site-packages\apkutils\apk.py", line 354, in main
    print(json.dumps(apk.get_manifest(), indent=1))
  File "...\lib\site-packages\apkutils\apk.py", line 86, in get_manifest
    self._init_manifest()
  File "...\lib\site-packages\apkutils\apk.py", line 106, in _init_manifest
    raise e
  File "...\lib\site-packages\apkutils\apk.py", line 104, in _init_manifest
    raise e
  File "...\lib\site-packages\apkutils\apk.py", line 102, in _init_manifest
    raise e
  File "...\lib\site-packages\apkutils\apk.py", line 100, in _init_manifest
    axml.get_xml())['manifest']
  File "...\lib\site-packages\xmltodict.py", line 330, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: duplicate attribute: line 290, column 0

Have created a py2/3 compatible fork

https://github.com/zhangchunlin/apkutils
What I have done:

  • add cigam as external lib, because cigam is also only support py3
  • fix print in py2
  • change apkfile.py implementation, inherit from zipfile.ZipFile, and implementation 2 code because the ZipFile in py2 and py3 are so different
  • use six and future to make both 2 and 3 are compatible

Because the modification is too big, and I think you may not want to make it compatible with py2, so I did not raise PR with it.

Logo design contribution

Hallo
I am Md Masud Rana Want to make a logo for this project if you have any requirements or idea then let me know.Its totally free for any open source projects. Thank you

axml - IndexError: index out of range

$  python -m apkutils -m apks\4a004d48ed4aa6d9b46b177bc64f8fff.apk

Traceback (most recent call last):
  File "D:\ProgramData\Miniconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\ProgramData\Miniconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__main__.py", line 42, in <module>
    main(_args)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__main__.py", line 11, in main
    if apk.get_manifest():
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__init__.py", line 88, in get_manifest
    self._init_manifest()
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__init__.py", line 118, in _init_manifest
    raise e
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__init__.py", line 107, in _init_manifest
    raise e
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\__init__.py", line 103, in _init_manifest
    axml = AXML(data)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\axmlparser.py", line 360, in __init__
    self.parse()
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\axmlparser.py", line 376, in parse
    self.parser.get_prefix()) + self.parser.get_name()
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\axmlparser.py", line 228, in get_name
    return self.sb.getString(self.m_name)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\chunk.py", line 107, in getString
    self._cache[idx] = self.decode16(offset)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\chunk.py", line 126, in decode16
    str_len, skip = self.decodeLength(offset, 2)
  File "D:\ProgramData\Miniconda3\lib\site-packages\apkutils\axml\chunk.py", line 142, in decodeLength
    length = self.m_charbuff[offset]
IndexError: index out of range

正则匹配有问题

https://github.com/mikusjelly/apkutils/blob/52f0f4a15bcb3380e5043e22503adeb3e9e67a0d/apkutils/__init__.py#L89
遇到下面的AndroidManifest时,main_activity会匹配到aaa.bbb.Activity2而不是aaa.bbb.MainActivity

    <activity android:excludeFromRecents="true" android:icon="@mipmap/icf" android:label="Facebook" android:launchMode="3" android:name="aaa.bbb.Activity2" />
    <activity android:label="XXXX" android:launchMode="3" android:name="aaa.bbb.MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.