Skip to content

Commit

Permalink
acepting pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Manning committed Oct 28, 2016
2 parents e6ad356 + f2bdf27 commit 93811a6
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 40 deletions.
53 changes: 53 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -------------------------------------------------------------------
# AndroidXMLParser was created by Anthony Desnos and is taken from
# the Androguard Project.
# -------------------------------------------------------------------
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.
# If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------
# Contributors:
# -------------------------------------------------------------------
# Anthony Desnos <anthony [dot] desnos [at] gmail.com>
# Antitree <antitree [at] gmail.com>
# pee <pee@erkkila.org> spam this
# algorythm <algorythm [at] gmail /dot/ com>
# Jiejing Zhang <kzjeef [at] gmail /dot/ com> // for package to pip
# -------------------------------------------------------------------
# version: 0.0.2
# -------------------------------------------------------------------

Example:

1. convert apk binary manifest to string manifest.

import axmlparserpy.axmlprinter as axmlprinter

ap = axmlprinter.AXMLPrinter(open('example/binary/AndroidManifest.xml', 'rb').read())
buff = minidom.parseString(ap.getBuff()).toxml()
print(buff)

2. get apk information
import axmlparserpy.apk as apk
ap = apk.APK('_PATH_TO_APK')
print ap.get_package()
print ap.get_androidversion_name()


CHANGELOG

0.0.2
Make library python 3 compatible

0.0.1 (aka 0.01)
Initial release
10 changes: 5 additions & 5 deletions axmlparserpy/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ def get_libraries(self):
libraries = property(get_libraries)

def show(self):
print "FILES: ", self.get_files_types()
print("FILES: ", self.get_files_types())

print "ACTIVITIES: ", self.get_activities()
print "SERVICES: ", self.get_services()
print "RECEIVERS: ", self.get_receivers()
print "PROVIDERS: ", self.get_providers()
print("ACTIVITIES: ", self.get_activities())
print("SERVICES: ", self.get_services())
print("RECEIVERS: ", self.get_receivers())
print("PROVIDERS: ", self.get_providers())

18 changes: 9 additions & 9 deletions axmlparserpy/axmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

import bytecode
import axmlparserpy.bytecode

import stringblock
import typeconstants as tc
from stringblock import StringBlock
from bytecode import SV
import axmlparserpy.stringblock
import axmlparserpy.typeconstants as tc
from axmlparserpy.stringblock import StringBlock
from axmlparserpy.bytecode import SV

import StringIO
from io import StringIO
from struct import pack, unpack
from xml.dom import minidom

Expand All @@ -33,7 +33,7 @@ class AXMLParser:
def __init__(self, raw_buff):
self.reset()

self.buff = bytecode.BuffHandle(raw_buff)
self.buff = axmlparserpy.bytecode.BuffHandle(raw_buff)

self.buff.read(4)
self.buff.read(4)
Expand Down Expand Up @@ -89,7 +89,7 @@ def doNext(self):
if chunkSize < 8 or chunkSize%4 != 0:
raise("ooo")

for i in range(0, chunkSize/4-2):
for i in range(0, int(chunkSize/4-2)):
self.m_resourceIDs.append(SV('<L', self.buff.read(4)))

continue
Expand Down Expand Up @@ -217,7 +217,7 @@ def getAttributeCount(self):
if self.m_event != tc.START_TAG:
return -1

return len(self.m_attributes) / tc.ATTRIBUTE_LENGTH
return int(len(self.m_attributes) / tc.ATTRIBUTE_LENGTH)

def getAttributePrefix(self, index):
offset = self.getAttributeOffset(index)
Expand Down
15 changes: 7 additions & 8 deletions axmlparserpy/axmlprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

import bytecode
import axmlparserpy.bytecode

import typeconstants as tc
from axmlparser import AXMLParser
from bytecode import SV
import axmlparserpy.typeconstants as tc
from axmlparserpy.axmlparser import AXMLParser
from axmlparserpy.bytecode import SV

import StringIO
from io import StringIO
from struct import pack, unpack
from xml.dom import minidom
from xml.sax.saxutils import escape

from xml.sax import saxutils

class AXMLPrinter:
def __init__(self, raw_buff):
Expand Down Expand Up @@ -78,7 +77,7 @@ def getAttributeValue(self, index):

#print _type, _data
if _type == tc.TYPE_STRING:
return escape(self.axml.getAttributeValue(index), entities={'"': '&quot;'})
return saxutils.escape(self.axml.getAttributeValue(index), entities={'"': '&quot;'})

elif _type == tc.TYPE_ATTRIBUTE:
return "?%s%08X" % (self.getPackage(_data), _data)
Expand Down
2 changes: 1 addition & 1 deletion axmlparserpy/bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _Print(name, arg):
elif isinstance(arg, SVs):
buff += arg.get_value().__str__()

print buff
print(buff)

class SV:
"""SV is used to handle more easily a value"""
Expand Down
14 changes: 7 additions & 7 deletions axmlparserpy/stringblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

import bytecode
import axmlparserpy.bytecode

from bytecode import SV
from axmlparserpy.bytecode import SV

import StringIO
from io import StringIO
from struct import pack, unpack
from xml.dom import minidom

Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self, buff):
if (size % 4) != 0:
pass

for i in range(0, size / 4):
for i in range(0, int(size / 4)):
self.m_strings.append(SV('=L', buff.read(4)))

if self.stylesOffset.get_value() != 0:
Expand All @@ -86,7 +86,7 @@ def getRaw(self, idx):
while length > 0:
offset += 2
# Unicode character
data += unichr(self.getShort(self.m_strings, offset))
data += chr(self.getShort(self.m_strings, offset))

# FIXME
if data[-1] == "&":
Expand All @@ -97,8 +97,8 @@ def getRaw(self, idx):
return data

def getShort(self, array, offset):
value = array[offset / 4].get_value()
if ((offset % 4) / 2) == 0:
value = array[int(offset / 4)].get_value()
if (int((offset % 4)) / 2) == 0:
return value & 0xFFFF
else:
return value >> 16
Expand Down
3 changes: 2 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
from axmlparserpy.axmlprinter import AXMLPrinter

from axmlparserpy import axmlprinter
from xml.dom import minidom

def main():
Expand Down
22 changes: 13 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from setuptools import setup, find_packages
from setuptools import setup

version = "0.0.2"
setup(
name="AxmlParserPY",
version="0.0.2",
packages=["axmlparserpy"],
install_requires=[
],
description="Python support for extract information from android 'apk' package",
author='Anthony Desnos',
author_email='anthony.desnos@gmail.com',
url='https://github.com/kzjeef/AxmlParserPY.git',

setup(name="axmlparserpy",
version=version,
author="Bryan Bishop",
author_email="kanzure@gmail.com",
license="GPL",
description="Androguard-related tools for reverse engineering Android binary xml files (and others).",
packages=find_packages())
# ...
)

0 comments on commit 93811a6

Please sign in to comment.