add python-capstone

Signed-off-by: Keke Ming <ming.jvle@gmail.com>
This commit is contained in:
Keke Ming
2026-02-24 12:36:00 +08:00
commit 0d07c540ba
2 changed files with 100 additions and 0 deletions

View File

@@ -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 <aquynh@gmail.com>
+
+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)

53
python-capstone.spec Normal file
View File

@@ -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 <keke.oerv@isrc.iscas.ac.cn>
#
# 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}