[Reproducible-commits] [diffoscope] 01/03: Add comparator for Android dex files
Reiner Herrmann
reiner at reiner-h.de
Sat Nov 21 18:38:56 UTC 2015
This is an automated email from the git hooks/post-receive script.
deki-guest pushed a commit to branch master
in repository diffoscope.
commit 7ab0e4317bf19ede85afef2e6786f2f71a95170f
Author: Reiner Herrmann <reiner at reiner-h.de>
Date: Tue Oct 27 12:23:34 2015 +0100
Add comparator for Android dex files
---
diffoscope/__init__.py | 1 +
diffoscope/comparators/__init__.py | 2 ++
diffoscope/comparators/dex.py | 66 ++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 46ea5db..a493abb 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -40,6 +40,7 @@ class RequiredToolNotFound(Exception):
, 'cmp': { 'debian': 'diffutils' }
, 'cpio': { 'debian': 'cpio' }
, 'diff': { 'debian': 'diffutils' }
+ , 'enjarify': { 'debian': 'enjarify' }
, 'file': { 'debian': 'file' }
, 'find': { 'debian': 'findutils' }
, 'getfacl': { 'debian': 'acl' }
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 4c111b9..efa85c7 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -44,6 +44,7 @@ except ImportError as ex:
raise
from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile
from diffoscope.comparators.device import Device
+from diffoscope.comparators.dex import DexFile
from diffoscope.comparators.directory import Directory, compare_directories
from diffoscope.comparators.elf import ElfFile, StaticLibFile
from diffoscope.comparators.fonts import TtfFile
@@ -129,6 +130,7 @@ FILE_CLASSES = (
CbfsFile,
CpioFile,
DebFile,
+ DexFile,
ElfFile,
StaticLibFile,
Sqlite3Database,
diff --git a/diffoscope/comparators/dex.py b/diffoscope/comparators/dex.py
new file mode 100644
index 0000000..003adaa
--- /dev/null
+++ b/diffoscope/comparators/dex.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Reiner Herrmann <reiner at reiner-h.de>
+#
+# diffoscope 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.
+#
+# diffoscope 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 diffoscope. If not, see <http://www.gnu.org/licenses/>.
+
+import re
+import os.path
+import subprocess
+from diffoscope import logger, tool_required
+from diffoscope.comparators.binary import File, needs_content
+from diffoscope.comparators.utils import Archive, get_compressed_content_name
+from diffoscope.difference import Difference
+
+
+class DexContainer(Archive):
+ @property
+ def path(self):
+ return self._path
+
+ def open_archive(self, path):
+ self._path = path
+ return self
+
+ def close_archive(self):
+ self._path = None
+
+ def get_members(self):
+ return {'dex-content': self.get_member(self.get_member_names()[0])}
+
+ def get_member_names(self):
+ return [get_compressed_content_name(self.path, '.dex') + '.jar']
+
+ @tool_required('enjarify')
+ def extract(self, member_name, dest_dir):
+ dest_path = os.path.join(dest_dir, member_name)
+ logger.debug('dex extracting to %s', dest_path)
+ subprocess.check_call(['enjarify', '-o', dest_path, self.path],
+ shell=False, stderr=None, stdout=subprocess.PIPE)
+ return dest_path
+
+class DexFile(File):
+ RE_FILE_TYPE = re.compile(r'^Dalvik dex file .*\b')
+
+ @staticmethod
+ def recognizes(file):
+ return DexFile.RE_FILE_TYPE.match(file.magic_file_type)
+
+ @needs_content
+ def compare_details(self, other, source=None):
+ with DexContainer(self).open() as my_container, \
+ DexContainer(other).open() as other_container:
+ return my_container.compare(other_container)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list