Commit 3d0af25e authored by Daniel Kahn Gillmor's avatar Daniel Kahn Gillmor

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.
parent 71e673b1
......@@ -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' }
......
......@@ -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),
......
# -*- coding: utf-8 -*-
#
# debbindiff: highlight differences between two builds of Debian packages
#
# Copyright © 2015 Daniel Kahn Gillmor <dkg@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]
@binary_fallback
@returns_details
def compare_pe_files(path1, path2, source=None):
return [Difference.from_command(Pedump, path1, path2)]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# debbindiff: highlight differences between two builds of Debian packages
#
# Copyright © 2015 Daniel Kahn Gillmor <dkg@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
@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
@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment