[Reproducible-commits] [debbindiff] 01/01: add test for PE assemblies and executables

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sun Jul 12 21:28:48 UTC 2015


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

dkg pushed a commit to branch master
in repository debbindiff.

commit 3d0af25e8d046b9ae08405cdbf243dc38ae543b4
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Sun Jul 12 17:10:13 2015 -0400

    add test for PE assemblies and executables
    
    This works at least for those assemblies generated by mono.  pedump
    does not currently provide useful output for PE binaries generated by
    i686-w64-mingw32-gcc, unfortunately.
    
    But this patch is a start that should help us express problems with
    mono builds more clearly at least.
---
 debbindiff/__init__.py             |   1 +
 debbindiff/comparators/__init__.py |   2 ++
 debbindiff/comparators/pe.py       |  34 ++++++++++++++++++++++++++++
 tests/comparators/test_pe.py       |  44 +++++++++++++++++++++++++++++++++++++
 tests/data/pe_expected_diff        |   9 ++++++++
 tests/data/test1.exe               | Bin 0 -> 3072 bytes
 tests/data/test2.exe               | Bin 0 -> 3072 bytes
 7 files changed, 90 insertions(+)

diff --git a/debbindiff/__init__.py b/debbindiff/__init__.py
index 596aaf1..be5c81b 100644
--- a/debbindiff/__init__.py
+++ b/debbindiff/__init__.py
@@ -50,6 +50,7 @@ class RequiredToolNotFound(Exception):
                 , 'objdump':    { 'debian': 'binutils-multiarch' }
                 , 'pdftk':      { 'debian': 'pdftk' }
                 , 'pdftotext':  { 'debian': 'poppler-utils' }
+                , 'pedump':     { 'debian': 'mono-utils' }
                 , 'readelf':    { 'debian': 'binutils-multiarch' }
                 , 'rpm2cpio':   { 'debian': 'rpm2cpio' }
                 , 'showttf':    { 'debian': 'fontforge-extras' }
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 8f79006..d45c273 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -41,6 +41,7 @@ from debbindiff.comparators.haskell import compare_hi_files
 from debbindiff.comparators.ipk import compare_ipk_files
 from debbindiff.comparators.iso9660 import compare_iso9660_files
 from debbindiff.comparators.pdf import compare_pdf_files
+from debbindiff.comparators.pe import compare_pe_files
 from debbindiff.comparators.png import compare_png_files
 try:
     from debbindiff.comparators.rpm import compare_rpm_files
@@ -110,6 +111,7 @@ COMPARATORS = [
     (r'^application/(x-font-ttf|vnd.ms-opentype)(;|$)', r'\.(ttf|otf)$', compare_ttf_files),
     (r'^image/png(;|$)', r'\.png$', compare_png_files),
     (r'^application/pdf(;|$)', r'\.pdf$', compare_pdf_files),
+    (r'^application/x-dosexec(;|$)', r'\.(exe|dll)$', compare_pe_files),
     (r'^text/plain; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
     (r'^application/xml; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
     (r'^application/postscript; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
diff --git a/debbindiff/comparators/pe.py b/debbindiff/comparators/pe.py
new file mode 100644
index 0000000..8d56c2f
--- /dev/null
+++ b/debbindiff/comparators/pe.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+#
+# debbindiff 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/>.
+
+from debbindiff import tool_required
+from debbindiff.comparators.utils import binary_fallback, returns_details, Command
+from debbindiff.difference import Difference
+
+
+class Pedump(Command):
+    @tool_required('pedump')
+    def cmdline(self):
+        return ['pedump', self.path]
+
+
+ at binary_fallback
+ at returns_details
+def compare_pe_files(path1, path2, source=None):
+    return [Difference.from_command(Pedump, path1, path2)]
diff --git a/tests/comparators/test_pe.py b/tests/comparators/test_pe.py
new file mode 100644
index 0000000..886f0cb
--- /dev/null
+++ b/tests/comparators/test_pe.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+#
+# debbindiff 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 shutil
+import pytest
+from debbindiff.comparators.pe import compare_pe_files
+
+# these were generated with:
+
+# echo 'public class Test { static public void Main () {} }' > test.cs
+# mcs -out:test1.exe test.cs ; sleep 2; mcs -out:test2.exe test.cs
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.exe') 
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.exe') 
+
+def test_no_differences():
+    difference = compare_pe_files(TEST_FILE1_PATH, TEST_FILE1_PATH)
+    assert difference is None
+
+ at pytest.fixture
+def differences():
+    return compare_pe_files(TEST_FILE1_PATH, TEST_FILE2_PATH).details
+
+def test_diff(differences):
+    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pe_expected_diff')).read()
+    assert differences[0].unified_diff == expected_diff
diff --git a/tests/data/pe_expected_diff b/tests/data/pe_expected_diff
new file mode 100644
index 0000000..72f3186
--- /dev/null
+++ b/tests/data/pe_expected_diff
@@ -0,0 +1,9 @@
+@@ -2,7 +2,7 @@
+ COFF Header:
+ 	                Machine: 0x014c
+ 	               Sections: 0x0003
+-	             Time stamp: 0x55a2d5bb
++	             Time stamp: 0x55a2d5bd
+ 	Pointer to Symbol Table: 0x00000000
+ 	   	   Symbol Count: 0x00000000
+ 	   Optional Header Size: 0x00e0
diff --git a/tests/data/test1.exe b/tests/data/test1.exe
new file mode 100755
index 0000000..f3ba0ff
Binary files /dev/null and b/tests/data/test1.exe differ
diff --git a/tests/data/test2.exe b/tests/data/test2.exe
new file mode 100755
index 0000000..0d2b0d0
Binary files /dev/null and b/tests/data/test2.exe differ

-- 
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