[Reproducible-commits] [debbindiff] 07/10: Add support for comparing ELF

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Sep 29 22:35:20 UTC 2014


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository debbindiff.

commit 5f863487ca83c4873e245951dbebdbd9302623b1
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Tue Sep 30 00:19:15 2014 +0200

    Add support for comparing ELF
---
 debbindiff/comparators/__init__.py |  2 ++
 debbindiff/comparators/elf.py      | 49 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index a2940a4..f7c9ddc 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -26,6 +26,7 @@ from debbindiff.comparators.binary import compare_binary_files
 from debbindiff.comparators.bzip2 import compare_bzip2_files
 from debbindiff.comparators.changes import compare_changes_files
 from debbindiff.comparators.deb import compare_deb_files
+from debbindiff.comparators.elf import compare_elf_files
 from debbindiff.comparators.gzip import compare_gzip_files
 from debbindiff.comparators.haskell import compare_hi_files
 from debbindiff.comparators.text import compare_text_files
@@ -61,6 +62,7 @@ COMPARATORS = [
         (r'^application/x-debian-package(;|$)', r'\.deb$',     compare_deb_files),
         (r'^application/x-gzip(;|$)',           r'\.gz$',      compare_gzip_files),
         (r'^application/x-bzip2(;|$)',          r'\.bzip2$',   compare_bzip2_files),
+        (r'^application/x-executable(;|$)',     None,          compare_elf_files),
     ]
 
 def compare_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/elf.py b/debbindiff/comparators/elf.py
new file mode 100644
index 0000000..ec8247b
--- /dev/null
+++ b/debbindiff/comparators/elf.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2014 Jérémy Bobbio <lunar at debian.org>
+#
+# debdindiff 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.
+#
+# debbindiff 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 debbindiff.  If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+import subprocess
+from debbindiff.comparators.utils import binary_fallback
+from debbindiff.difference import Difference
+
+def readelf_all(path):
+    return subprocess.check_output(['readelf', '--all', path], shell=False)
+
+def readelf_debug_dump(path):
+    return subprocess.check_output(['readelf', '--debug-dump', path], shell=False)
+
+def objdump_disassemble(path):
+    return subprocess.check_output(['objdump', '--disassemble', path], shell=False)
+
+ at binary_fallback
+def compare_elf_files(path1, path2, source=None):
+    differences = []
+    all1 = readelf_all(path1)
+    all2 = readelf_all(path2)
+    if all1 != all2:
+        differences.append(Difference(all1.splitlines(1), all2.splitlines(1), path1, path2, source='readelf --all'))
+    debug_dump1 = readelf_debug_dump(path1)
+    debug_dump2 = readelf_debug_dump(path2)
+    if debug_dump1 != debug_dump2:
+        differences.append(Difference(debug_dump1.splitlines(1), debug_dump2.splitlines(1), path1, path2, source='readelf --debug-dump'))
+    objdump1 = objdump_disassemble(path1)
+    objdump2 = objdump_disassemble(path2)
+    if objdump1 != objdump2:
+        differences.append(Difference(objdump1.splitlines(1), objdump2.splitlines(1), path1, path2, source='objdump --dissamble'))
+    return differences

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git



More information about the Reproducible-commits mailing list