From 2bc933dcaa571a02051185a0908ec5ad52305fc6 Mon Sep 17 00:00:00 2001 From: Louis Granboulan Date: Wed, 9 Oct 2024 22:57:10 +0200 Subject: [PATCH] github action to compare with the output of readelf -h --- .github/workflows/tools.yml | 19 ++++++++++++++++++- examples/readelf.py | 28 +++++++++++++--------------- tests/examples_linux.sh | 10 ++++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 tests/examples_linux.sh diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 64f1635..b96ab16 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -9,7 +9,7 @@ on: branches: [ "master" ] jobs: - examples: + macos: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -26,3 +26,20 @@ jobs: run: | export PYTHONPATH=$PYTHONPATH:$(pwd) zsh ./tests/examples_macos.sh + linux: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-latest"] + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Comparison with readelf + run: | + export PYTHONPATH=$PYTHONPATH:$(pwd) + bash ./tests/examples_linux.sh diff --git a/examples/readelf.py b/examples/readelf.py index bed40e6..0002640 100755 --- a/examples/readelf.py +++ b/examples/readelf.py @@ -22,7 +22,7 @@ def display_headers(e): print("ELF Header:") import struct ident = struct.unpack('16B', e.Ehdr.ident) - print(" Magic: %s"%' '.join(['%02x'%_ for _ in ident])) + print(" Magic: %s "%' '.join(['%02x'%_ for _ in ident])) print(" Class: %s"%expand_code({ elf.ELFCLASS32: 'ELF32', elf.ELFCLASS64: 'ELF64', @@ -72,21 +72,19 @@ def display_headers(e): machine_code[elf.EM_IA_64] = 'Intel IA-64' machine_code[elf.EM_MIPS_X] = 'Stanford MIPS-X' machine_code[elf.EM_COLDFIRE] = 'Motorola Coldfire' + machine_code[elf.EM_X86_64] = 'Advanced Micro Devices X86-64' print(" Machine: %s"%expand_code(machine_code, e.Ehdr.machine)) - """ - TO BE CONTINUED - ("version","u32"), - ("entry","ptr"), - ("phoff","ptr"), - ("shoff","ptr"), - ("flags","u32"), - ("ehsize","u16"), - ("phentsize","u16"), - ("phnum","u16"), - ("shentsize","u16"), - ("shnum","u16"), - ("shstrndx","u16") ] - """ + print(" Version: %#x"%e.Ehdr.version) + print(" Entry point address: %#x"%e.Ehdr.entry) + print(" Start of program headers: %d (bytes into file)"%e.Ehdr.phoff) + print(" Start of section headers: %d (bytes into file)"%e.Ehdr.shoff) + print(" Flags: %#x"%e.Ehdr.flags) + print(" Size of this header: %d (bytes)"%e.Ehdr.ehsize) + print(" Size of program headers: %d (bytes)"%e.Ehdr.phentsize) + print(" Number of program headers: %d"%e.Ehdr.phnum) + print(" Size of section headers: %d (bytes)"%e.Ehdr.shentsize) + print(" Number of section headers: %d"%e.Ehdr.shnum) + print(" Section header string table index: %d"%e.Ehdr.shstrndx) def display_program_headers(e): # Output format similar to readelf -l diff --git a/tests/examples_linux.sh b/tests/examples_linux.sh new file mode 100644 index 0000000..b4815cf --- /dev/null +++ b/tests/examples_linux.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +options="-h -S -r -s --dyn-syms -d -l -g" +options="-h" +for option in $options; do +for file in /bin/sh; do +echo "=== readelf $option $file ===" +diff -c <(readelf $option $file) <(python ./examples/readelf.py $option $file 2>/dev/null) +done +done