Skip to content

Commit

Permalink
github action to compare with the output of readelf -h
Browse files Browse the repository at this point in the history
  • Loading branch information
LRGH committed Oct 9, 2024
1 parent 73037e9 commit 2bc933d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches: [ "master" ]

jobs:
examples:
macos:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -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
28 changes: 13 additions & 15 deletions examples/readelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/examples_linux.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2bc933d

Please sign in to comment.