Skip to content

Commit 1b7cbd9

Browse files
authored
Merge branch 'main' into refactor-binexport-launching
2 parents 6968eba + 4e047af commit 1b7cbd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+341
-54
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/data/** filter=lfs diff=lfs merge=lfs -text

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
groups:
11+
python:
12+
patterns:
13+
- "*"
14+
schedule:
15+
interval: "daily"
16+
17+
- package-ecosystem: "github-actions"
18+
directory: "/"
19+
groups:
20+
python:
21+
patterns:
22+
- "*"
23+
schedule:
24+
interval: "daily"

.github/workflows/release.yml

100755100644
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-python@v4
13+
- uses: actions/checkout@v6
14+
- uses: actions/setup-python@v6
1515
with:
1616
python-version: '3.10'
1717
- name: Install dependencies
1818
run: pip install build
1919
- name: Build wheel and sdist
2020
run: python -m build
21-
- uses: actions/upload-artifact@v4
21+
- uses: actions/upload-artifact@v5
2222
with:
2323
name: artifact
2424
path: |
@@ -29,20 +29,20 @@ jobs:
2929
needs: build_wheel_and_sdist
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/download-artifact@v4
32+
- uses: actions/download-artifact@v6
3333
with:
3434
# unpacks default artifact into dist/
3535
# if `name: artifact` is omitted, the action will create extra parent dir
3636
name: artifact
3737
path: dist
3838

3939
- name: Publish a Python distribution to PyPI
40-
uses: pypa/gh-action-pypi-publish@v1.8.2
40+
uses: pypa/gh-action-pypi-publish@v1.13.0
4141
with:
4242
password: ${{ secrets.PYPI_DEPLOY_TOKEN }}
4343

4444
- name: Upload Python packages for release notes
45-
uses: softprops/action-gh-release@v0.1.15
45+
uses: softprops/action-gh-release@v2.5.0
4646
with:
4747
files: |
4848
dist/*

.github/workflows/testing.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
testing:
11+
name: Run tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v6
16+
with:
17+
lfs: true
18+
- uses: actions/setup-python@v6
19+
with:
20+
python-version: |
21+
3.11
22+
3.12
23+
3.10
24+
25+
- name: Install dependencies
26+
run: pip install .[dev]
27+
28+
- name: Running pytest
29+
run: tox run -- -s
30+
31+
- name: Generate coverage
32+
run: tox run -e py310-coverage -- -s --cov-report=term
33+
34+
- uses: actions/upload-artifact@v5
35+
with:
36+
name: coverage
37+
path: ./htmlcov

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ build/
88
dist/
99
*.egg-info/
1010
/venv/
11+
.tox/
12+
.coverage
13+
htmlcov/

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python-binexport"
7-
version = "0.3.6"
7+
version = "0.4.0"
88
description = "Python wrapper to manipulate binexport files (protobuf)"
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
authors = [{ name = "Quarkslab", email = "diffing@quarkslab.com" }]
1111
license = {text = "AGPL-3.0"}
12-
requires-python = ">=3.9"
12+
requires-python = ">=3.10"
1313
dependencies = [
1414
"python-magic; os_name!='nt'",
1515
"python-magic-bin; os_name=='nt'",
@@ -34,6 +34,9 @@ Documentation = "https://quarkslab.github.io/diffing-portal/exporter/binexport.h
3434
[project.scripts]
3535
binexporter = 'binexport.__main__:main'
3636

37+
[project.optional-dependencies]
38+
dev = ["tox"]
39+
3740
[tool.black]
3841
line-length = 100
3942
target-version = ['py310']

src/binexport/basic_block.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ def function(self) -> FunctionBinExport:
8888
"""
8989
return self._function()
9090

91+
@cached_property
92+
def contiguous_ranges(self) -> list[tuple[Addr, bytes]]:
93+
"""
94+
The contiguous ranges of instructions contained in this basic block. That identifies
95+
the *real* basic blocks, as BinExport's basic blocks do not necessarily represent a
96+
contiguous block of instructions.
97+
98+
:return: List of tuples (begin address, bytes), each of them representing a contiguous
99+
block of instructions.
100+
"""
101+
102+
ranges = []
103+
104+
# Ranges are in fact the true basic blocks but BinExport
105+
# doesn't have the same basic block semantic and merge multiple basic blocks into one.
106+
# For example: BB_1 -- unconditional_jmp --> BB_2
107+
# might be merged into a single basic block so the edge gets lost.
108+
for rng in self.pb_bb.instruction_index:
109+
rng_bytes = b""
110+
rng_addr = None
111+
for idx in instruction_index_range(rng):
112+
rng_bytes += self.program.proto.instruction[idx].raw_bytes
113+
114+
# The first instruction determines the basic block address
115+
if rng_addr is None:
116+
rng_addr = get_instruction_address(self.program.proto, idx)
117+
ranges.append((rng_addr, rng_bytes))
118+
119+
return ranges
120+
91121
@cached_property
92122
def instructions(self) -> dict[Addr, InstructionBinExport]:
93123
"""

src/binexport/instruction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(
3636
self._idx = i_idx
3737
self.data_refs: set[Addr] = self.program.data_refs[self._idx] #: Data references address
3838
self.bytes = self.pb_instr.raw_bytes #: bytes of the instruction (opcodes)
39+
self.disasm = f"{self.mnemonic} {', '.join(str(o) for o in self.operands)}"
3940

4041
def __hash__(self) -> int:
4142
return hash(self.addr)

0 commit comments

Comments
 (0)