Compare commits

Author SHA1 Message Date
billow 8618b4051a Add binding for RzAnnotatedCode and RzCodeAnnotation headers 2025-10-01 03:01:38 +08:00
Khairul Azhar Kasmiran 318cfbc9b3 Cleanup inclusion of linux/limits.h (#80) 2025-03-16 14:53:25 +08:00
Khairul Azhar Kasmiran 05ce528bc2 ci: Upgrade to Ubuntu 24.04 (Noble) (#79)
* ci: Upgrade to Ubuntu 24.04 (Noble)
* Remove `pip3 --break-system-packages`
* Use `-include linux/limits.h` for Alpine build
2025-03-14 20:18:43 +08:00
Giovanni d9b84f46e7 Fix compilation (#77)
* Fix compilation due defines being redefined
* Add support for TypeKind.FUNCTIONNOPROTO
2025-02-18 15:40:17 +08:00
Anton Kochkov fe8468ea29 ci: use corresponding rizin branch 2024-12-21 20:44:59 +08:00
Anton Kochkov 4e324800d8 ci: use corresponding rizin branch (#75) 2024-12-21 20:11:59 +08:00
Anton Kochkov eecc6bb442 ci/mypy: disable unnecessary warning (#73) 2024-12-21 18:57:35 +08:00
Khairul Azhar Kasmiran b93006e24b Use / instead of \\ in CMAKE_PREFIX_PATH for Windows (#72) 2024-12-21 18:33:10 +08:00
wargio f1dbe864e6 Ensure argument name never matches the function name 2024-12-20 21:51:55 +08:00
wargio 1723f6e06e Revert "Fix wrong check on nonnull args which are inner not outer."
This reverts commit c527db8fcb.
2024-12-20 21:51:55 +08:00
wargio c527db8fcb Fix wrong check on nonnull args which are inner not outer. 2024-12-20 19:47:10 +08:00
Anton Kochkov 918136cbc2 ci: support pip3 for python 3.12 and later 2024-12-20 19:47:10 +08:00
Anton Kochkov 84a9542c9e ci: use macOS 14 as macOS 12 is deprecated 2024-12-20 19:47:10 +08:00
Anton Kochkov b47d3071c2 Update pypa/cibuildwheel to 2.22.0 2024-12-20 19:47:10 +08:00
Anton Kochkov 66f06da3cf Remove lastline from RzCons bindings 2024-12-20 19:47:10 +08:00
Anton Kochkov 8d233afef2 Remove SdbList as it was removed in Rizin (#64) 2024-05-22 22:48:05 +08:00
wargio 3fc9aedc2b Print filename when assert. 2024-05-22 20:35:27 +08:00
Khairul Azhar Kasmiran 046a905246 Uniquify artifact names (#63) 2024-04-19 19:03:47 +08:00
Khairul Azhar Kasmiran d00a7e9174 Use manylinux2014 base image instead (#62)
* Use `manylinux2014` base image instead
* Drop i686 support
2024-04-18 23:40:18 +08:00
Anton Kochkov 52d315929b Fix SWIG snippet example (#61) 2024-04-16 23:38:52 +08:00
pelijah 97d3a2d579 Add missing ht_* headers into cparser_header.py (#60) 2024-04-16 23:20:43 +08:00
Anton Kochkov 4d92885261 ci: update used pypa/cibuildwheel version (#59) 2024-04-16 20:57:16 +08:00
pelijah e106047c66 Add missing HT types to lint.py (#58) 2024-04-16 12:05:27 +03:00
wargio 23dcdda1b0 Revert "Format via black & fix lint check"
This reverts commit aa3340800e.
2024-04-16 11:39:00 +08:00
wargio aa3340800e Format via black & fix lint check 2024-04-16 11:36:06 +08:00
pelijah 438499c470 Add bindings for HtSP, HtSS, HtSU (#57) 2024-04-16 06:30:40 +08:00
Giovanni 1caa6237ee Merge pull request #55 from rizinorg/meson-wheel-option
Add meson option for wheel build
2024-03-15 22:32:29 +08:00
Khairul Azhar Kasmiran 70b2c55651 Add meson option for wheel build 2024-03-15 18:37:56 +08:00
Khairul Azhar Kasmiran 7da2b62917 Fix build fail due to missing rz_analysis_version (#52) 2024-03-11 19:46:09 +08:00
Khairul Azhar Kasmiran a33dca2316 Reformat according to black 24 (#51) 2024-03-10 18:23:05 +08:00
Khairul Azhar Kasmiran d5a3644dde Support user install of swig python module (#50) 2024-03-09 22:50:01 +08:00
Khairul Azhar Kasmiran 6da1edb1fe Fix missing rz_analysis_esil_inter_state_t key (#49) 2024-01-25 14:58:29 +08:00
Giovanni c001b1e7d2 Merge pull request #48 from rizinorg/meson-0.62.2
Bump minimum meson version to 0.62.2
2023-12-06 21:16:33 +08:00
Khairul Azhar Kasmiran 31a887b66d Bump minimum meson version to 0.62.2 2023-12-06 20:11:05 +08:00
Khairul Azhar Kasmiran 012c7073ae Use fetch-depth of 1 (#47) 2023-12-05 20:18:37 +08:00
Giovanni 1afe440947 Merge pull request #46 from rizinorg/ubuntu-default-llvm
Use default LLVM in Ubuntu build
2023-12-03 11:58:55 +08:00
Khairul Azhar Kasmiran 7cb3b801a1 Use gcc to compile 2023-12-03 10:54:06 +08:00
Khairul Azhar Kasmiran 23fe3cdf08 Use default LLVM in Ubuntu build 2023-12-03 10:27:18 +08:00
Khairul Azhar Kasmiran 98ec55469e Add build job ubuntu-llvm-15 (#44) 2023-12-02 22:27:01 +08:00
Khairul Azhar Kasmiran 39c4c75144 Revert "Fix Meson to 1.2.3 (#42)" (#43)
This reverts commit 5f60421e19.
2023-12-02 10:26:30 +08:00
Khairul Azhar Kasmiran 5f60421e19 Fix Meson to 1.2.3 (#42) 2023-11-21 21:27:40 +08:00
Khairul Azhar Kasmiran 4ea002e837 Fix CI images to ubuntu-22.04 and macos-12 (#41) 2023-11-18 22:59:09 +08:00
Khairul Azhar Kasmiran 673bdc320a Make CI job names shorter and more consistent (#40) 2023-11-15 19:01:17 +08:00
Khairul Azhar Kasmiran 601d3025c3 Fix Windows build (#39)
* Add quotation marks around `resource-dir`
* For redefinitions, check also `cursor.kind`
* wrap_type: For non-primitive types, wrap original type
2023-10-30 21:05:20 +08:00
Khairul Azhar Kasmiran b3d654aa08 Disable pylint too-many-arguments warning (#38) 2023-10-27 20:15:29 +08:00
Khairul Azhar Kasmiran 48d8602525 Fix build due to ht_*.h move and non-use of llvm-config (#37) 2023-10-26 23:00:27 +08:00
Anton Kochkov e0f4cb5cea Remove typelink remnants (#33) 2023-08-04 12:37:16 +08:00
Riccardo Schirone 19f9fad430 Fix CI builds (#29)
Change `apt` sources because manylinux_2_24 uses Debian Stretch and the repos are not available anymore
2023-08-02 17:18:07 +08:00
Riccardo Schirone 19b165c789 build: handle the cmake dependency too 2023-04-19 20:59:58 +02:00
Riccardo Schirone 5ab96866a1 Use default llvm/clang in cibw_before_all.sh 2023-04-19 17:26:25 +02:00
Riccardo Schirone b6df7168e1 Use llvm-15 and increase project version 2023-04-17 21:58:35 +02:00
wingdeans c09e93e06e Activate pybuffer typemaps by default
Rather than requiring typemap argument in add_function/add_method
2023-04-14 11:17:30 +02:00
Riccardo Schirone ab25a61ee7 Improve ci release (#25)
* Avoid duplicated workflows
* meson: do not use v prefix
* create sdist on linux
2023-03-07 21:14:39 +01:00
Riccardo Schirone 18bab79f2a Add RzAnalysisXRef class 2023-02-23 10:52:16 +01:00
Riccardo Schirone be13ad624e Disable broad-exception-raised message in pylint 2023-02-23 10:52:16 +01:00
Riccardo Schirone 7ba0eaafca Fix black style 2023-02-23 10:52:16 +01:00
Riccardo Schirone 336169bb07 Use the proper Rizin version for a given rz-binding release 2023-02-23 10:52:16 +01:00
Riccardo Schirone d1e5f15299 Automatically load py files in RZ_USER_PLUGINS/bindings (#23) 2023-01-24 09:35:34 +08:00
Riccardo Schirone dd453e7e21 Simplify meson.build (#22)
- Just depend on rz_core.
- Allow to compile plugin only
- Remove openssl dependencies, should come with rz_core if necessary
- Revert the MacOS fix because it was preventing the generation of the
  wheel as non-pure. Homebrew python is causing some problems here.
2023-01-19 08:29:58 +08:00
Riccardo Schirone a3a0037850 Remove plugin.pkgname because not used anymore (#20) 2023-01-16 21:36:16 +08:00
wingdeans e76a3a0978 Use rizin dev branch for CI 2023-01-15 09:44:36 -05:00
Riccardo Schirone 32d0813a3d Install the rizin plugin (#17) 2023-01-15 09:35:28 +08:00
Riccardo Schirone a86e691a73 Recompile bindings when .py files change (#16) 2023-01-15 09:11:40 +08:00
Riccardo Schirone 4ab8faf071 Remove RzMain as it does not exist anymore 2023-01-11 18:33:18 +01:00
Riccardo Schirone b67bdbd1bc build: fix compilation on MacOS due to python/meson bug 2023-01-11 18:33:18 +01:00
Riccardo Schirone 9195af393e Fix register_command argument handling and return value 2023-01-11 18:33:18 +01:00
Riccardo Schirone d950ade1f6 build: add project license and version and summary 2022-10-08 19:54:08 -04:00
wingdeans bebe9244ce Add PyPi CI
* Add PyPi upload CI job
* Install generated rizin.py script instead of rizin.cxx (bug)
* Use Rizin release build for cibuildwheel
2022-10-07 20:46:45 -04:00
27 changed files with 485 additions and 206 deletions

No files matched your search

+119 -18
View File
@@ -1,32 +1,133 @@
name: run-rz-bindgen
name: build
on:
push:
paths:
- 'src/**.py'
- 'src/**.pyi'
- 'src/**.i'
- 'meson.build'
- 'meson_options.txt'
workflow_dispatch:
workflow_call:
inputs:
external_call:
description: 'To distinguish workflow_call from regular push'
type: boolean
required: false
default: true
rizin_ref:
required: false
type: string
default: 'dev'
jobs:
run-bindgen:
name: Run bindgen
pypa-wheels:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-latest]
os: [ubuntu-24.04, windows-2019, macos-14]
steps:
- name: Install SWIG with Homebrew
if: matrix.os == 'macos-14' && matrix.enabled
run: brew install swig
- name: Checkout rz-bindgen
uses: actions/checkout@v4
# runned only from workflow_call
- name: Checkout rizin
if: ${{ inputs.external_call }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: ${{ inputs.rizin_ref }}
- name: Checkout rizin (stable)
if: ${{ !inputs.external_call && ((github.ref_name == 'stable') || (github.base_ref == 'stable')) }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: stable
- name: Checkout rizin (dev)
if: ${{ !inputs.external_call && ((github.ref_name != 'stable') && (github.base_ref != 'stable')) }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: dev
- name: Build rz-bindgen
uses: pypa/[email protected]
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: sdist-${{ matrix.os }}
path: dist/*.tar.gz
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: wheelhouse/*.whl
ubuntu-default-llvm:
runs-on: ubuntu-24.04
steps:
- name: Checkout rz-bindgen
uses: actions/checkout@v3
- name: Run rz-bindgen
uses: pypa/[email protected]
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/checkout@v4
with:
path: wheelhouse/*.whl
path: rz-bindgen
# runned only from workflow_call
- name: Checkout rizin
if: ${{ inputs.external_call }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: ${{ inputs.rizin_ref }}
- name: Checkout rizin (stable)
if: ${{ !inputs.external_call && ((github.ref_name == 'stable') || (github.base_ref == 'stable')) }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: stable
- name: Checkout rizin (dev)
if: ${{ !inputs.external_call && ((github.ref_name != 'stable') && (github.base_ref != 'stable')) }}
uses: actions/checkout@v4
with:
repository: rizinorg/rizin
path: rizin
ref: dev
- name: Install dependencies
run: |
sudo apt update
sudo apt-get --assume-yes install cmake swig pkg-config clang libclang-dev llvm wget unzip python3-wheel python3-setuptools build-essential python3-pip
sudo pip3 install meson ninja
- name: Install rizin
run: |
export PATH=$PATH:/usr/local/bin
meson setup --prefix=/usr --buildtype=release build && ninja -C build && sudo ninja -C build install
working-directory: rizin
- name: Build rz-bindgen
run: |
meson setup --prefix=/usr -Dplugin=enabled build
meson compile -C build
sudo meson install -C build
working-directory: rz-bindgen
- name: Test python lang plugin
run: rizin -qc "Ll" | grep "Python SWIG"
- name: Test rizin.py
run: |
echo "import rizin" > testimport.py
python3 testimport.py
+5 -5
View File
@@ -1,8 +1,8 @@
name: linting
name: lint
on: push
jobs:
licenses:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout rz-bindgen
uses: actions/checkout@v3
@@ -10,7 +10,7 @@ jobs:
uses: fsfe/reuse-action@v1
python:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout rz-bindgen
uses: actions/checkout@v3
@@ -19,7 +19,7 @@ jobs:
pip install mypy pyflakes pylint black
- name: Run mypy
run: |
mypy src/main.py
mypy --disable-error-code misc src/main.py
if: ${{ always() }}
- name: Run pyflakes
run: |
@@ -35,7 +35,7 @@ jobs:
if: ${{ always() }}
codeql:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
permissions:
security-events: write
steps:
+40
View File
@@ -0,0 +1,40 @@
name: release
on:
push:
tags:
- rizin-v*_*
workflow_dispatch:
jobs:
extract-rizin-version:
runs-on: ubuntu-24.04
outputs:
rizin_version: ${{ steps.extract_version.outputs.result }}
steps:
- id: extract_version
run: echo "result=$(echo ${{ github.ref }} | cut -d'_' -f1 | cut -d'-' -f2-)" >> "$GITHUB_OUTPUT"
build:
uses: ./.github/workflows/ci.yml
needs: [extract-rizin-version]
with:
rizin_ref: ${{ needs.extract-rizin-version.outputs.rizin_version }}
publish-pypi:
runs-on: ubuntu-24.04
needs: [build]
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: wheels
path: dist
- name: Download sdist
uses: actions/download-artifact@v3
with:
name: sdist
path: dist
- name: Publish wheels
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
+2 -2
View File
@@ -9,9 +9,9 @@ For usage information, see [the documentation](doc/README.md).
## Building python plugin
Requirements:
- rizin > 0.4.1 (needs commit [59b38e6](https://github.com/rizinorg/rizin/commit/59b38e6efaf00b9b9869e0ec5baba4f1b9605f37))
- meson
- meson >= 1.1.0
- ninja
- python >= 3.7
- python >= 3.10
- libclang
- SWIG
+38 -9
View File
@@ -4,23 +4,52 @@
set -ex
# Install deps
pip3 install meson ninja meson-python
pygt311=$(python3 -c 'import sys; print(0) if sys.version_info.minor > 11 else print(1)' 2>&1)
if [[ $pygt311 == '0' ]]; then
pip3 install --break-system-packages meson ninja meson-python build
else
pip3 install meson ninja meson-python build
fi
if command -v apt; then
apt update && apt install --assume-yes libclang-7-dev clang-7 llvm-7
if command -v brew; then
brew install --require-sha swig
elif command -v apt; then
set +e
grep VERSION_CODENAME=stretch /etc/os-release >/dev/null 2>/dev/null
if [[ $? == 0 ]] ; then
# Required because manylinux_2_24 uses Debian Stretch and the repos are not available anymore
echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list
echo "deb http://archive.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list
echo "Acquire::Check-Valid-Until no;" > /etc/apt/apt.conf.d/99no-check-valid-until
fi
set -e
apt update && apt install --assume-yes libclang-7-dev clang-7 llvm-7 sudo
elif command -v apk; then
apk update && apk add clang-dev
apk update && apk add clang-dev sudo
elif command -v yum; then
yum -y install llvm-toolset-7.0 llvm-toolset-7.0-llvm-devel sudo
# (CentOS 7) Uncomment following lines to see required paths in build log:
# yum -y install centos-release-scl
# source scl_source enable llvm-toolset-7.0 || true
fi
# Install rizin
git clone --depth 1 https://github.com/wingdeans/rizin.git -b header-types
pushd rizin
if [[ "$OSTYPE" =~ msys* ]]; then
meson setup --prefix='c:/rizin' --vsenv build
meson setup --buildtype=release --prefix='c:/rizin' --vsenv build
meson install -C build
else
meson setup --libdir=lib build
if [[ "$OSTYPE" =~ linux* ]]; then
export CFLAGS="-include linux/limits.h"
fi
meson setup --buildtype=release --libdir=lib build
sudo meson install -C build
fi
meson install -C build
popd
if command -v apt; then
if [ ! -e dist/*.tar.gz ] ; then
python3 -m build --sdist
fi
fi
+67 -35
View File
@@ -1,9 +1,12 @@
project('rz-bindgen', 'c', 'cpp',
version: 'v0.5.0dev',
license: 'LGPL3')
version: '0.6.0',
license: 'LGPL3',
meson_version: '>=0.62.2',
default_options: ['python.install_env=auto'])
pymod = import('python')
py = pymod.find_installation('python')
fs = import('fs')
py = pymod.find_installation()
clang_path = get_option('clang_path')
clang_args = get_option('clang_args')
@@ -16,9 +19,9 @@ target_sphinx = targets.contains('sphinx')
doxygen_path = get_option('doxygen_path')
if clang_path == ''
llvm = dependency('llvm', required: false)
if llvm.found()
clang_path = llvm.get_variable(configtool: 'libdir', default_value: 'none')
llvm_config = find_program('llvm-config', 'llvm-config-7', required: false)
if llvm_config.found()
clang_path = run_command(llvm_config, '--libdir', check: true).stdout().strip()
elif build_machine.system() == 'darwin'
clang_path = '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/'
elif build_machine.system() == 'windows'
@@ -28,12 +31,17 @@ if clang_path == ''
endif
endif
if not fs.exists(clang_path)
error('CLang path does not exist')
endif
rz_core = disabler()
if rizin_include_path == ''
rz_main = dependency('rz_main')
if rz_main.type_name() == 'pkgconfig'
rizin_include_path = rz_main.get_variable(pkgconfig: 'includedir') / 'librz'
elif rz_main.type_name() == 'cmake'
rizin_include_path = rz_main.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')[0]
rz_core = dependency('rz_core')
if rz_core.type_name() == 'pkgconfig'
rizin_include_path = rz_core.get_variable(pkgconfig: 'includedir') / 'librz'
elif rz_core.type_name() == 'cmake'
rizin_include_path = rz_core.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')[0]
endif
endif
@@ -41,7 +49,7 @@ if clang_args == ''
clang = find_program('clang', 'clang-7', required: false)
if clang.found()
clang_args += ' -resource-dir='
clang_args += run_command(clang, '-print-resource-dir', check: true).stdout().strip()
clang_args += '"' + run_command(clang, '-print-resource-dir', check: true).stdout().strip() + '"'
endif
if build_machine.system() == 'darwin'
clang_args += ' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
@@ -64,21 +72,43 @@ summary({
'Clang path': clang_path,
})
bindgen_outputs = custom_target(
'bindgen_outputs',
input: 'src' / 'main.py',
output: bindgen_output_names,
command: [
py, '@INPUT@',
'-o', '@OUTDIR@',
'--clang-path', clang_path,
'--clang-args', clang_args,
'--rizin-include-path', rizin_include_path,
'--targets', ','.join(targets)
] + (doxygen_path != '' ? ['--doxygen-path', doxygen_path] : [])
)
if target_swig or target_sphinx
src_files = files(
'src/binding_class.py',
'src/binding_director.py',
'src/binding_enum.py',
'src/binding_func.py',
'src/binding_generic.py',
'src/binding_generic_specializations.py',
'src/binding_typemap.py',
'src/bindings.py',
'src/cparser_header.py',
'src/cparser_types.py',
'src/generator_sphinx.py',
'src/generator_swig.py',
'src/lint.py',
'src/main.py',
'src/writer.py',
)
bindgen_outputs = custom_target(
'bindgen_outputs',
input: 'src' / 'main.py',
output: bindgen_output_names,
depend_files: src_files,
command: [
py, '@INPUT@',
'-o', '@OUTDIR@',
'--clang-path', clang_path,
'--clang-args', clang_args,
'--rizin-include-path', rizin_include_path,
'--targets', ','.join(targets)
] + (doxygen_path != '' ? ['--doxygen-path', doxygen_path] : [])
)
endif
if target_swig
wheel = get_option('wheel')
swig_output = custom_target(
'swig_output',
input: bindgen_outputs[swig_source_idx],
@@ -88,26 +118,28 @@ if target_swig
'-python', '-c++',
'-outdir', '@OUTDIR@', '@INPUT@'
],
install: true,
install_dir: [false, py.get_install_dir()]
install: wheel or host_machine.system() == 'windows',
install_dir: [py.get_install_dir(), false]
)
swig_py = swig_output[0]
swig_wrap = swig_output[1]
py.extension_module(
if not rz_core.found()
rz_core = dependency('rz_core')
endif
ext_mod = py.extension_module(
'_rizin',
swig_wrap,
dependencies: [
py.dependency(),
dependency('openssl', required: false),
dependency('rz_main')
rz_core,
],
include_directories: include_directories(
rizin_include_path,
rizin_include_path / 'sdb'
),
install: true
install: wheel or host_machine.system() == 'windows',
)
if host_machine.system() != 'windows'
meson.add_install_script('py_install.py', swig_py.full_path(), ext_mod.full_path())
endif
endif
if target_sphinx
+1
View File
@@ -4,5 +4,6 @@ option('rizin_include_path', type: 'string', value: '')
option('targets', type: 'array', choices: ['SWIG', 'sphinx'], value: ['SWIG'])
option('plugin', type: 'feature', value: 'disabled')
option('wheel', type: 'boolean', value: false, description: 'Set up for pypa wheel build')
option('doxygen_path', type: 'string', value: '')
+6 -1
View File
@@ -8,12 +8,17 @@ swig_runtime = custom_target(
]
)
rz_core_dep = dependency('rz_core')
rizin_plugdir = rz_core_dep.get_variable(pkgconfig: 'plugindir', cmake: 'rz_core_PLUGINDIR')
library(
'rz-bindings-plugin',
['plugin.c', swig_runtime],
dependencies: [
py.dependency(embed: true),
dependency('openssl', required: false),
dependency('rz_main')
rz_core_dep,
],
install: true,
install_dir: rizin_plugdir,
)
+25 -7
View File
@@ -2,7 +2,15 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <Python.h>
/**
* Some defines in rz_userconf.h are conflicting with the ones in python.h
**/
#undef HAVE_EXPLICIT_BZERO
#undef HAVE_SIGACTION
#undef HAVE_REALPATH
#include <rz_core.h>
#include <rz_util/rz_file.h>
#include <swig_runtime.h>
static PyObject *rizin_module = NULL;
@@ -28,6 +36,11 @@ static PyObject *rizin_module = NULL;
} \
return result;
static int rz_bindings_run_file(RzLang *lang, const char *filename) {
FILE *file = fopen(filename, "rb");
return PyRun_SimpleFile(file, filename) == 0;
}
static int rz_bindings_init(RzLang *lang) {
DEFER_SETUP;
@@ -69,12 +82,23 @@ static int rz_bindings_init(RzLang *lang) {
Py_INCREF(py_rz_core);
Py_INCREF(rizin_module);
char *globpath = rz_file_path_join(bindings_dir, "*.py");
RzList *files = rz_file_globsearch(globpath, 1);
RzListIter *it;
char *filename;
rz_list_foreach(files, it, filename) {
rz_bindings_run_file(lang, filename);
}
free(globpath);
rz_list_free(files);
DEFER_CLEANUP;
}
static int rz_bindings_fini(RzLang *lang) {
Py_XDECREF(rizin_module);
return Py_FinalizeEx();
return Py_FinalizeEx() == 0;
}
static int rz_bindings_prompt(RzLang *lang) {
@@ -153,11 +177,6 @@ static int rz_bindings_prompt(RzLang *lang) {
DEFER_CLEANUP;
}
static int rz_bindings_run_file(RzLang *lang, const char *filename) {
FILE *file = fopen(filename, "rb");
return PyRun_SimpleFile(file, filename) == 0;
}
RzLangPlugin rz_lang_plugin_bindings = {
.name = "python",
.desc = "Python SWIG bindings",
@@ -174,5 +193,4 @@ RzLibStruct rizin_plugin = {
.data = &rz_lang_plugin_bindings,
.version = RZ_VERSION,
.free = NULL,
.pkgname = "rz-bindings",
};
Executable
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""
SPDX-FileCopyrightText: 2024 kazarmy <[email protected]>
SPDX-License-Identifier: LGPL-3.0-only
"""
import os
import shutil
import sys
import sysconfig
def install_files(scheme):
for file in sys.argv[1:]:
if file.endswith(".py"):
dest_type = 'purelib'
elif file.endswith(".so"):
dest_type = 'platlib'
install_dir = sysconfig.get_path(dest_type, scheme)
shutil.copy(file, install_dir)
print(f"Installing {os.path.basename(file)} to {install_dir}")
try:
install_files(sysconfig.get_default_scheme())
except PermissionError:
print("Installing to user site-packages since normal site-packages is not writeable")
install_files(f"{os.name}_user")
+4 -2
View File
@@ -1,7 +1,9 @@
[MESSAGES CONTROL]
disable=too-many-instance-attributes,
too-few-public-methods,
too-few-public-methods,
too-many-branches,
too-many-return-statements,
too-many-locals,
fixme
too-many-arguments,
broad-exception-raised,
fixme
+19 -7
View File
@@ -1,22 +1,34 @@
[build-system]
requires = [
"meson==0.62.2",
"meson-python==0.7.0"
"meson>=0.62.2",
"meson-python>=0.7.0"
]
build-backend = "mesonpy"
[tool.meson-python.args]
setup = ['-Dwheel=true']
[tool.cibuildwheel]
build-verbosity = 3
before-all = "bash {project}/cibw_before_all.sh"
manylinux-x86_64-image = "manylinux_2_24"
manylinux-i686-image = "manylinux_2_24"
manylinux-x86_64-image = "manylinux2014"
skip = "pp*"
[tool.cibuildwheel.linux]
environment = { PATH="/opt/rh/llvm-toolset-7.0/root/usr/bin:/opt/rh/llvm-toolset-7.0/root/usr/sbin:$PATH", LD_LIBRARY_PATH="/opt/rh/llvm-toolset-7.0/root/usr/lib64:$LD_LIBRARY_PATH" }
archs = ["x86_64"]
[tool.cibuildwheel.windows]
environment = { CMAKE_PREFIX_PATH="C:\\rizin" }
environment = { CMAKE_PREFIX_PATH="C:/rizin" }
archs = ["AMD64"]
[tool.cibuildwheel.macos]
environment = { PATH="/opt/homebrew/bin:$PATH", MACOSX_DEPLOYMENT_TARGET="14.0" }
[project]
name = "rz-bindings"
version = "0.5.0"
requires-python = ">=3.8"
dynamic = [
'version',
]
requires-python = ">=3.9"
readme = "README.md"
+2 -4
View File
@@ -54,8 +54,7 @@ class Class:
typedef: str,
ignore_fields: Optional[Set[str]] = ...,
rename_fields: Optional[Dict[str, str]] = ...,
):
...
): ...
@overload
def __init__(
@@ -66,8 +65,7 @@ class Class:
struct: str,
ignore_fields: Optional[Set[str]] = ...,
rename_fields: Optional[Dict[str, str]] = ...,
):
...
): ...
def __init__(
self,
+2 -4
View File
@@ -46,12 +46,10 @@ class MacroEnum:
defines: OrderedDict[str, str]
@overload
def __init__(self, header: Header, *defines: str):
...
def __init__(self, header: Header, *defines: str): ...
@overload
def __init__(self, header: Header, *, prefix: str):
...
def __init__(self, header: Header, *, prefix: str): ...
def __init__(
self,
+2 -4
View File
@@ -28,8 +28,7 @@ class Func:
*,
default_args: Optional[Dict[str, str]] = ...,
typemaps: Optional[List[Typemap]] = ...,
):
...
): ...
@overload
def __init__(
@@ -39,8 +38,7 @@ class Func:
cfunc: "CFunc",
default_args: Optional[Dict[str, str]] = ...,
typemaps: Optional[List[Typemap]] = ...,
):
...
): ...
def __init__(
self,
+1
View File
@@ -2,6 +2,7 @@
SPDX-FileCopyrightText: 2022 wingdeans <[email protected]>
SPDX-License-Identifier: LGPL-3.0-only
"""
from typing import List, Dict, TYPE_CHECKING
from clang.cindex import Cursor, CursorKind
-14
View File
@@ -55,17 +55,3 @@ class Typemap:
f"Function {func.cfunc.cursor.spelling} did not match typemap `{self.args}`. "
f"Contents were: {args}"
)
buffer_len_typemap = Typemap(
"buffer_len",
[TypemapArg("unsigned char *", "buf"), TypemapArg("unsigned long long", "len")],
)
const_buffer_len_typemap = Typemap(
"const_buffer_len",
[
TypemapArg("const unsigned char *", "buf"),
TypemapArg("unsigned long long", "len"),
],
)
+61 -52
View File
@@ -12,7 +12,6 @@ from binding_class import Class
from binding_director import Director
from binding_enum import Enum, MacroEnum
from binding_generic import Generic
from binding_typemap import buffer_len_typemap, const_buffer_len_typemap
HeaderFunc = Callable[[Header], None]
threaded_headers: OrderedDict[str, HeaderFunc] = OrderedDict()
@@ -148,13 +147,11 @@ def bind_analysis(analysis_h: Header) -> None:
"""
RzAnalysis
"""
analysis_h.ignore("rz_analysis_version")
rz_analysis = Class(
analysis_h,
typedef="RzAnalysis",
ignore_fields={"leaddrs"},
rename_fields={"type_links": "_type_links"},
rename_fields={},
)
rz_analysis_function = Class(analysis_h, typedef="RzAnalysisFunction")
@@ -167,8 +164,16 @@ def bind_analysis(analysis_h: Header) -> None:
Class(analysis_h, typedef="RzAnalysisBlock")
Class(analysis_h, typedef="RzAnalysisEsil")
Class(analysis_h, typedef="RzAnalysisEsilInterState")
Class(analysis_h, typedef="RzAnalysisPlugin")
Class(
analysis_h,
typedef="RzAnalysisXRef",
rename_fields={"from": "from_addr", "to": "to_addr"},
)
Enum(analysis_h, typedef="RzAnalysisXRefType")
@threaded_header("rz_asm.h")
def bind_asm(asm_h: Header) -> None:
@@ -214,27 +219,7 @@ def bind_buf(buf_h: Header) -> None:
RzBuf
"""
rz_buf = Class(buf_h, typedef="RzBuffer")
# const ut8 *buffer, ut64 len
for name in [
"append_bytes",
"prepend_bytes",
"set_bytes",
"insert_bytes",
"write",
"write_at",
]:
rz_buf.add_method(
f"rz_buf_{name}",
rename=name,
typemaps=[const_buffer_len_typemap],
)
# ut8 *buffer, ut64 len
rz_buf.add_method("rz_buf_read", rename="read", typemaps=[buffer_len_typemap])
rz_buf.add_method("rz_buf_read_at", rename="read_at", typemaps=[buffer_len_typemap])
rz_buf.add_method("rz_buf_seek", rename="seek")
rz_buf.add_prefixed_methods("rz_buf_")
MacroEnum(buf_h, "RZ_BUF_SET", "RZ_BUF_CUR", "RZ_BUF_END")
@@ -273,7 +258,6 @@ def bind_cons(cons_h: Header) -> None:
typedef="RzCons",
ignore_fields={"term_raw", "term_buf"}, # struct termios
rename_fields={
"lastline": "_lastline",
"echo": "_echo",
"highlight": "_highlight",
"newline": "_newline",
@@ -343,6 +327,29 @@ def bind_core(core_h: Header) -> None:
Class(core_h, typedef="RzCoreFile")
@threaded_header("rz_util/rz_annotated_code.h")
def bind_annotated_code(annotated_code_h: Header) -> None:
"""
RzAnnotatedCode
"""
rz_code_annotation = Class(
annotated_code_h,
typedef="RzCodeAnnotation",
struct="rz_code_annotation_t",
)
rz_code_annotation.add_prefixed_methods("rz_annotation_")
rz_code_annotation.add_prefixed_funcs("rz_annotation_")
rz_annotated_code = Class(
annotated_code_h,
typedef="RzAnnotatedCode",
struct="rz_annotated_code_t",
)
rz_annotated_code.add_constructor("rz_annotated_code_new")
rz_annotated_code.add_destructor("rz_annotated_code_free")
rz_annotated_code.add_prefixed_methods("rz_annotated_code_")
rz_annotated_code.add_prefixed_funcs("rz_annotated_code_")
@threaded_header("rz_flag.h")
def bind_flag(flag_h: Header) -> None:
@@ -377,20 +384,6 @@ def bind_io(io_h: Header) -> None:
Class(io_h, typedef="RzIOPlugin")
@threaded_header("rz_main.h")
def bind_main(main_h: Header) -> None:
"""
RzMain
"""
main_h.ignore("rz_main_version")
rz_main = Class(main_h, typedef="RzMain")
rz_main.add_constructor("rz_main_new")
rz_main.add_destructor("rz_main_free")
rz_main.add_prefixed_methods("rz_main_")
rz_main.add_prefixed_funcs("rz_main_")
@threaded_header("rz_util/rz_num.h")
def bind_num(num_h: Header) -> None:
"""
@@ -445,15 +438,7 @@ def bind_sdb(sdb_h: Header) -> None:
Class(sdb_h, typedef="Sdb", ignore_fields={"db", "m"})
@threaded_header("sdb/ls.h")
def bind_ls(ls_h: Header) -> None:
"""
ls
"""
Class(ls_h, typedef="SdbList")
@threaded_header("sdb/ht_pp.h")
@threaded_header("rz_util/ht_pp.h")
def bind_ht_pp(ht_pp_h: Header) -> None:
"""
ht_pp
@@ -461,7 +446,7 @@ def bind_ht_pp(ht_pp_h: Header) -> None:
Class(ht_pp_h, typedef="HtPP")
@threaded_header("sdb/ht_pu.h")
@threaded_header("rz_util/ht_pu.h")
def bind_ht_pu(ht_pu_h: Header) -> None:
"""
ht_pu
@@ -469,7 +454,7 @@ def bind_ht_pu(ht_pu_h: Header) -> None:
Class(ht_pu_h, typedef="HtPU")
@threaded_header("sdb/ht_up.h")
@threaded_header("rz_util/ht_up.h")
def bind_ht_up(ht_up_h: Header) -> None:
"""
ht_up
@@ -477,9 +462,33 @@ def bind_ht_up(ht_up_h: Header) -> None:
Class(ht_up_h, typedef="HtUP")
@threaded_header("sdb/ht_uu.h")
@threaded_header("rz_util/ht_uu.h")
def bind_ht_uu(ht_uu_h: Header) -> None:
"""
ht_uu
"""
Class(ht_uu_h, typedef="HtUU")
@threaded_header("rz_util/ht_sp.h")
def bind_ht_sp(ht_sp_h: Header) -> None:
"""
ht_sp
"""
Class(ht_sp_h, typedef="HtSP")
@threaded_header("rz_util/ht_ss.h")
def bind_ht_ss(ht_ss_h: Header) -> None:
"""
ht_ss
"""
Class(ht_ss_h, typedef="HtSS")
@threaded_header("rz_util/ht_su.h")
def bind_ht_su(ht_su_h: Header) -> None:
"""
ht_su
"""
Class(ht_su_h, typedef="HtSU")
+2 -2
View File
@@ -2224,7 +2224,7 @@ class Type(Structure):
return result
assert self.kind == TypeKind.FUNCTIONPROTO
assert self.kind in (TypeKind.FUNCTIONPROTO, TypeKind.FUNCTIONNOPROTO)
return ArgumentsIterator(self)
@property
@@ -2320,7 +2320,7 @@ class Type(Structure):
def is_function_variadic(self):
"""Determine whether this function Type is a variadic function type."""
assert self.kind == TypeKind.FUNCTIONPROTO
assert self.kind in (TypeKind.FUNCTIONPROTO, TypeKind.FUNCTIONNOPROTO)
return conf.lib.clang_isFunctionTypeVariadic(self)
+2
View File
@@ -38,6 +38,7 @@ class TypeKind(Enum):
POINTER: TypeKind
CONSTANTARRAY: TypeKind
FUNCTIONPROTO: TypeKind
FUNCTIONNOPROTO: TypeKind
INCOMPLETEARRAY: TypeKind
RECORD: TypeKind
@@ -86,6 +87,7 @@ class Type:
class SourceLocation:
class File:
name: str
file: File
line: int
column: int
+14 -9
View File
@@ -12,6 +12,7 @@ from clang.cindex import TranslationUnit, Cursor, CursorKind
from cparser_types import CType, wrap_type
### Cursor wrappers ###
class AttrCursor:
"""
@@ -97,18 +98,20 @@ class HeaderBuilder:
assert rizin_include_path
filename = os.path.abspath(os.path.join(rizin_include_path, *name_segments))
# Fix sdb path if using source librz/include
if name_segments[0] == "sdb" and not os.path.exists(filename):
name_segments = ["..", "util", "sdb", "src"] + name_segments[1:]
filename = os.path.abspath(os.path.join(rizin_include_path, *name_segments))
assert os.path.exists(filename)
assert os.path.exists(filename), f"File {filename} does not exist"
self.filename = filename
# Parse ht_inc.h if importing SDB hashtable header
self.extra_filename = None
if name_segments[-1] in ["ht_pp.h", "ht_pu.h", "ht_up.h", "ht_uu.h"]:
if name_segments[-1] in [
"ht_pp.h",
"ht_pu.h",
"ht_up.h",
"ht_uu.h",
"ht_sp.h",
"ht_ss.h",
"ht_su.h",
]:
self.extra_filename = "ht_inc.h"
def translation_unit(self) -> TranslationUnit:
@@ -178,7 +181,9 @@ class Header:
continue
# Check for redefinitions
if name in self.cursor_kinds: # Redefinition
if (
name in self.cursor_kinds and cursor.kind == self.cursor_kinds[name]
): # Redefinition
prev = self.cursors[cursor.kind][name]
if cursor.kind == CursorKind.STRUCT_DECL:
assert prev.kind == CursorKind.STRUCT_DECL
+9 -6
View File
@@ -100,29 +100,32 @@ def wrap_type(type_: Type) -> CType:
"""
Wrap a type
"""
orig_type = type_
while type_.kind == TypeKind.ELABORATED:
type_ = type_.get_named_type()
# Complex types
if type_.kind == TypeKind.POINTER:
return CPointerType(type_, pointee=wrap_type(type_.get_pointee()))
return CPointerType(orig_type, pointee=wrap_type(type_.get_pointee()))
if type_.kind in [TypeKind.CONSTANTARRAY, TypeKind.INCOMPLETEARRAY]:
array_t = CArrayType(type_, element=wrap_type(type_.get_array_element_type()))
array_t = CArrayType(
orig_type, element=wrap_type(type_.get_array_element_type())
)
if type_.kind == TypeKind.CONSTANTARRAY:
array_t.element_count = type_.element_count
return array_t
if type_.kind == TypeKind.TYPEDEF:
return CTypedefType(
type_,
orig_type,
canonical=wrap_type(type_.get_canonical()),
cursor=type_.get_declaration(),
)
if type_.kind == TypeKind.FUNCTIONPROTO:
if type_.kind in (TypeKind.FUNCTIONPROTO, TypeKind.FUNCTIONNOPROTO):
return CFunctionType(
type_,
orig_type,
result=wrap_type(type_.get_result()),
args=[wrap_type(arg) for arg in type_.argument_types()],
)
@@ -132,7 +135,7 @@ def wrap_type(type_: Type) -> CType:
if decl_spelling.startswith("const "):
decl_spelling = decl_spelling[len("const ") :]
return CRecordType(type_, decl_spelling=decl_spelling)
return CRecordType(orig_type, decl_spelling=decl_spelling)
# Primitive types
if type_.kind in [
+5
View File
@@ -265,6 +265,11 @@ def write_func(writer: Writer, func: Func, name: str, kind: FuncKind) -> None:
if arg_name == "self":
arg_name = "_self"
# if function arg is the same as the function name
# we rename the argument
if arg_name == name:
arg_name += "_arg"
arg_decl = stringify_decl(
arg_name,
arg.ctype,
+12 -1
View File
@@ -23,6 +23,7 @@ and definitions. It also does this for Rizin annotations, such as RZ_OWN. This w
by defining the RZ_BINDINGS preprocessor flag, which sets the annotations to expand to
__attribute__((annotate)), which can be picked up by libclang.
"""
from typing import List, Dict, Set, TypedDict, Optional, cast
import os
@@ -163,7 +164,17 @@ def cursor_get_comment(cursor: Cursor, *, packed: bool = False) -> Optional[str]
warn(
f"Type comment at {stringify_location(cursor.location)} should not have pointer"
)
elif typeref_spelling in {"HtPP", "HtUP", "HtUU", "RBTree", "SdbList"}:
elif typeref_spelling in {
"HtPP",
"HtUP",
"HtUU",
"HtPU",
"HtSP",
"HtSS",
"HtSU",
"RBTree",
"SdbList",
}:
pass
else:
warn(
+4 -16
View File
@@ -21,22 +21,10 @@ void rizin_try_warn_deprecate(const char *name, const char *c_name) {
// Buffer typemaps
%include <pybuffer.i>
%define %buffer_len_activate(TYPE, SIZE)
%pybuffer_mutable_binary(TYPE, SIZE);
%enddef
%define %const_buffer_len_activate(TYPE, SIZE)
%pybuffer_binary(TYPE, SIZE);
%enddef
%define %buffer_len_deactivate(TYPE, SIZE)
%typemap(in) (TYPE, SIZE);
%enddef
%define %const_buffer_len_deactivate(TYPE, SIZE)
%typemap(in) (TYPE, SIZE);
%enddef
%pybuffer_mutable_binary(unsigned char *buf, unsigned long long len);
%pybuffer_binary(const unsigned char *buf, unsigned long long len);
%pybuffer_mutable_binary(unsigned char *buf, int len);
%pybuffer_binary(const unsigned char *buf, int len);
// CArrays
%include <carrays.i>
+15 -6
View File
@@ -4,11 +4,8 @@ def register_group(self, cmd, summary):
help_desc.summary = summary
self.rcmd.register_swig_command(cmd, None, None, help_desc)
import inspect
def register_command(self, cmd, fn):
import inspect
params = list(inspect.signature(fn).parameters.values())
core_arg = None
@@ -61,19 +58,31 @@ def register_command(self, cmd, fn):
if core_arg:
args[core_arg] = core
for i, param in enumerate(params):
arg = args_array[i + 1]
orig_arg = args_array[i + 1]
arg = orig_arg
if param.annotation == RzNumArg:
if not core.num.is_valid_input(arg):
raise ValueError(f"Could not convert '{orig_arg}' to RzNum value")
arg = core.num.math(arg)
elif param.annotation == int:
arg = int(arg)
try:
arg = int(arg)
except ValueError:
raise ValueError(f"Could not convert '{orig_arg}' to int") from e
elif param.annotation == RzFlagItem:
arg = core.flags.get(arg)
if arg is None:
raise ValueError(f"Could not find a flag named '{orig_arg}'")
elif param.annotation == RzAnalysisFunction:
arg = core.analysis.get_function_byname(arg)
if arg is None:
raise ValueError(f"Could not find a function named '{orig_arg}'")
args[param.name] = arg
return fn(**args)
except Exception as e:
print(e)
return False
director = wrapper()
director.__disown__()
+2 -2
View File
@@ -13,7 +13,7 @@ void register_swig_command(const char *str, CmdDirector *director,
} else {
char *dup = strdup(str);
dup[len - 1] = '\0';
parent = (RzCmdDesc *)ht_pp_find($self->ht_cmds, dup, NULL);
parent = (RzCmdDesc *)ht_sp_find($self->ht_cmds, dup, NULL);
free(dup);
}
@@ -21,7 +21,7 @@ void register_swig_command(const char *str, CmdDirector *director,
throw "Could not get parent RzCmdDesc";
}
RzCmdDesc *prev = (RzCmdDesc *)ht_pp_find($self->ht_cmds, str, NULL);
RzCmdDesc *prev = (RzCmdDesc *)ht_sp_find($self->ht_cmds, str, NULL);
std::string cmd(str);
if (prev) { // Update existing RzCmdDesc
auto it = SWIGCmds.find(cmd);