From 0d07c540badfd5ac362f12dff8c60c426ca97973 Mon Sep 17 00:00:00 2001 From: Keke Ming Date: Tue, 24 Feb 2026 12:36:00 +0800 Subject: [PATCH] add python-capstone Signed-off-by: Keke Ming --- add-xprint-for-tests.patch | 47 +++++++++++++++++++++++++++++++++ python-capstone.spec | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 add-xprint-for-tests.patch create mode 100644 python-capstone.spec diff --git a/add-xprint-for-tests.patch b/add-xprint-for-tests.patch new file mode 100644 index 0000000..a77b6a7 --- /dev/null +++ b/add-xprint-for-tests.patch @@ -0,0 +1,47 @@ +diff --git a/a/tests/xprint.py b/a/tests/xprint.py +new file mode 100644 +index 0000000..70affac +--- a/tests/xprint.py ++++ b/tests/xprint.py +@@ -0,0 +1,41 @@ ++#!/usr/bin/env python ++# Capstone Python bindings, by Nguyen Anh Quynnh ++ ++from __future__ import print_function ++import sys ++_python3 = sys.version_info.major == 3 ++ ++ ++def to_hex(s, prefix_0x = True): ++ if _python3: ++ if prefix_0x: ++ return " ".join("0x{0:02x}".format(c) for c in s) # <-- Python 3 is OK ++ else: ++ return " ".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK ++ else: ++ if prefix_0x: ++ return " ".join("0x{0:02x}".format(ord(c)) for c in s) ++ else: ++ return " ".join("{0:02x}".format(ord(c)) for c in s) ++ ++def to_hex2(s): ++ if _python3: ++ r = "".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK ++ else: ++ r = "".join("{0:02x}".format(ord(c)) for c in s) ++ while r[0] == '0': r = r[1:] ++ return r ++ ++def to_x(s): ++ from struct import pack ++ if not s: return '0' ++ x = pack(">q", s) ++ while x[0] in ('\0', 0): x = x[1:] ++ return to_hex2(x) ++ ++def to_x_32(s): ++ from struct import pack ++ if not s: return '0' ++ x = pack(">i", s) ++ while x[0] in ('\0', 0): x = x[1:] ++ return to_hex2(x) diff --git a/python-capstone.spec b/python-capstone.spec new file mode 100644 index 0000000..b096f44 --- /dev/null +++ b/python-capstone.spec @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: (C) 2026 Institute of Software, Chinese Academy of Sciences (ISCAS) +# SPDX-FileCopyrightText: (C) 2026 openRuyi Project Contributors +# SPDX-FileContributor: Jvle +# +# SPDX-License-Identifier: MulanPSL-2.0 + +%global srcname capstone + +Name: python-%{srcname} +Version: 5.0.3 +Release: %autorelease +Summary: Python bindings for the Capstone disassembly framework +License: BSD +URL: http://www.capstone-engine.org/ +#!RemoteAsset +Source0: https://files.pythonhosted.org/packages/source/c/%{srcname}/%{srcname}-%{version}.tar.gz + +Patch0: add-xprint-for-tests.patch + +BuildRequires: python3-devel +BuildRequires: pyproject-rpm-macros +BuildRequires: python3dist(setuptools) +BuildRequires: python3dist(wheel) +Requires: capstone%{?_isa} + +BuildSystem: pyproject +BuildOption(install): -l %{srcname} + +Provides: python3-%{srcname} +%python_provide python3-%{srcname} + +%description +Python bindings for Capstone, a lightweight multi-platform, +multi-architecture disassembly framework. + +%generate_buildrequires +%pyproject_buildrequires + +%check +# 过滤掉 libcapstone,因为它是一个 C 库而非 Python 模块,无法直接 import +%pyproject_check_import -e "capstone.lib.libcapstone" +export PYTHONPATH=%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib} +cd tests +ls -la +%{__python3} test_all.py + + +%files -f %{pyproject_files} +%doc README.txt +%license LICENSE.TXT + +%changelog +%{?autochangelog} \ No newline at end of file