Merge commit '3621a6c08002c6b3e5b6f91bb0e20d8372613160' into dev

This commit is contained in:
Simone
2025-01-07 15:08:55 +00:00
1521 changed files with 323443 additions and 365407 deletions

View File

@@ -0,0 +1,2 @@
*.deb
*.txt

View File

@@ -0,0 +1,68 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Andrew Quijano
# Contact: andrewquijano92@gmail.com
ARG VERSION=""
# Run in the root of the repo
# docker build -f ./packages/deb/Dockerfile -t packager .
FROM debian:bookworm-slim
# Install necessary tools for packaging
RUN apt-get -qq update && \
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \
fakeroot dpkg-dev dos2unix cmake
# Copy project files into the container
RUN mkdir /capstone
COPY . /capstone
WORKDIR /capstone/
# Using cmake, see BUILDING.md file
# For debug build change "Release" to "Debug"
ARG VERSION
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1 -DPROJECT_VERSION=${VERSION} -DCMAKE_INSTALL_PREFIX=/usr
RUN cmake --build build
# List files before cmake install
# RUN find / -type f > /before-install.txt
# Make directories as needed
RUN mkdir -p /package-root/usr/include/capstone/
RUN mkdir -p /package-root/usr/lib/pkgconfig/
RUN mkdir -p /package-root/usr/bin/
RUN mkdir -p /package-root/usr/share/doc/libcapstone-dev
# Run cmake install
RUN cmake --install build --prefix /package-root/usr/
# List files after cmake install
# RUN find / -type f > /after-install.txt
# Create DEBIAN directory and control file
COPY ./packages/deb/control /package-root/DEBIAN/control
# Copy documentation over
COPY ./LICENSES/ /package-root/usr/share/doc/libcapstone-dev/LICENSES/
COPY ./ChangeLog /package-root/usr/share/doc/libcapstone-dev
COPY ./CREDITS.TXT /package-root/usr/share/doc/libcapstone-dev
COPY ./README.md /package-root/usr/share/doc/libcapstone-dev
COPY ./SPONSORS.TXT /package-root/usr/share/doc/libcapstone-dev
# Generate MD5 checksums for all files and save to DEBIAN/md5sums
RUN cd /package-root && \
find . -type f ! -path './DEBIAN/*' -exec md5sum {} + | sed 's| \./| |' > /package-root/DEBIAN/md5sums
# Update control file with the correct information
ARG VERSION
RUN INSTALLED_SIZE=$(du -sk /package-root | cut -f1) && \
sed -i "s/^Installed-Size:.*/Installed-Size: ${INSTALLED_SIZE}/" /package-root/DEBIAN/control
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control
# Add triggers script to run ldconfig after installation
COPY ./packages/deb/triggers /package-root/DEBIAN/triggers
# Build the package
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev_${VERSION}_amd64.deb
# The user can now extract the .deb file from the container with something like
# docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"

View File

@@ -0,0 +1,26 @@
# Capstone Docker packaging
This assumes your working directory is in the `packages/deb/` directory.
To build a Debian package for Capstone, run the script, where `<tag-name>` is going to be the version
attached to both the `capstone.pc` file and the Debian package itself. The version is expected to be compliant with Debian versioning (a major/minor/patch), e. g. `5.0.4`. Debian versions can also support values to indicate pre-release, e. g. `6.0.0-Alpha1`.
**Note**: if a value such as `6.0.0-Alpha1` is provided, the major/minor/patch number is extracted for `capstone.pc`, which would have version `6.0.0`, but the Debian package would have the full version name on the control file.
**Note**: Currently the package is hard coded to the `amd64` architecture. Independently on what machine you built it. Also see [issue #2537](https://github.com/capstone-engine/capstone/issues/2537).
```bash
./setup.sh <tag-name>
```
The output Debian file would be in the form `libcapstone-dev_<tag-version>_amd64.deb`, as to match what would be expected in a standard Debian library package.
To confirm the necessary libraries and `capstone.pc` is filled correctly, there exists a `check_capstone.sh` script to confirm `libcapstone-dev` was built correctly.
If you want to check the contents of the Debian package, use the following:
```bash
# Check the DEBIAN/ folder
dpkg-deb -e libcapstone-dev_<tag-version>_amd64.deb ./unpacked
# Check the content of the package, EXCEPT the DEBIAN/ folder
dpkg-deb -x libcapstone-dev_<tag-version>_amd64.deb ./unpacked
```

View File

@@ -0,0 +1,50 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Andrew Quijano
# Contact: andrewquijano92@gmail.com
#!/bin/bash
set -eu
# Usage: ./check_capstone_pc.sh <path_to_deb_file>
DEB_FILE=$1
# Check if the deb file exists
if [[ ! -f "$DEB_FILE" ]]; then
echo "Debian package file not found!"
exit 1
fi
# Create a temporary directory to extract the deb file
TEMP_DIR=$(mktemp -d)
# Extract the deb file
dpkg-deb -x "$DEB_FILE" "$TEMP_DIR"
# Check if the capstone.pc file exists
CAPSTONE_PC="$TEMP_DIR/usr/lib/x86_64-linux-gnu/pkgconfig/capstone.pc"
if [[ ! -f "$CAPSTONE_PC" ]]; then
echo "capstone.pc file not found in the package!"
rm -rf "$TEMP_DIR"
exit 1
fi
# Check if libcapstone.a is included in the package
LIBCAPSTONE_A="$TEMP_DIR/usr/lib/x86_64-linux-gnu/libcapstone.a"
if [[ ! -f "$LIBCAPSTONE_A" ]]; then
echo "libcapstone.a not found in the package!"
rm -rf "$TEMP_DIR"
exit 1
fi
# Check if libcapstone.so is included in the package
LIBCAPSTONE_SO="$TEMP_DIR/usr/lib/x86_64-linux-gnu/libcapstone.so"
if [[ ! -f "$LIBCAPSTONE_SO" ]]; then
echo "libcapstone.so not found in the package!"
rm -rf "$TEMP_DIR"
exit 1
fi
echo "libcapstone-dev.deb file is correct."
rm -rf "$TEMP_DIR"
exit 0

25
external/capstone/packages/deb/control vendored Normal file
View File

@@ -0,0 +1,25 @@
Package: libcapstone-dev
Source: capstone
Version: <version-placeholder>
Architecture: amd64
Maintainer: Rot127 <unisono@quyllur.org>
Original-Maintainer: Debian Security Tools <team+pkg-security@tracker.debian.org>
Installed-Size: <size-in-kb>
Depends: libc6 (>= 2.2.5)
Section: libdevel
Priority: optional
Multi-Arch: same
Homepage: https://www.capstone-engine.org/
Description: lightweight multi-architecture disassembly framework - devel files
Capstone is a lightweight multi-platform, multi-architecture disassembly
framework. These are the development headers and libraries.
Features:
- Support hardware architectures: AArch64, ARM, Alpha, BPF, EVM, HPPA, LongArch, M680X, M68K, MOS65XX, Mips, PowerPC, RISCV, SH, Sparc, SystemZ, TMS320C64x, TriCore, WASM, x86, XCore, Xtensa.
- Clean/simple/lightweight/intuitive architecture-neutral API.
- Provide details on disassembled instructions (called "decomposer" by some
others).
- Provide some semantics of the disassembled instruction, such as list of
implicit registers read & written.
- Thread-safe by design.
- Special support for embedding into firmware or OS kernel.
- Distributed under the open source BSD license.

57
external/capstone/packages/deb/setup.sh vendored Executable file
View File

@@ -0,0 +1,57 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Andrew Quijano
# Contact: andrewquijano92@gmail.com
# !/bin/bash
set -eu
# Function to get the current Ubuntu version
get_os_version() {
lsb_release -i -s 2>/dev/null
}
# Check if the script is running in the ./packages/deb folder
if [[ $(basename "$PWD") != "deb" ]]; then
echo "ERROR: Script must be run from the ./deb directory"
exit 1
fi
OS_VERSION=$(get_os_version)
if [[ "$OS_VERSION" != "Ubuntu" && "$OS_VERSION" != "Debian" ]]; then
echo "ERROR: OS is not Ubuntu or Debian and unsupported"
exit 1
fi
# Get the version number as an input
# Check if version argument is provided
if [[ $# -ne 1 ]]; then
echo "ERROR: Version argument is required"
exit 1
fi
# Get the version number as an input
version=$1
# Remove leading 'v' if present, e. g. v1.5.1 -> 1.5.1
if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
version=${version:1}
fi
# Check if the version follows the format for Debian Packages
if [[ ! "$version" =~ ^[0-9]+(.[0-9]+)*(-[A-Za-z0-9]+)?$ ]]; then
echo "ERROR: Version must be in a valid Debian package format"
exit 1
fi
# Now build the packager container from that
pushd ../../
docker build -f ./packages/deb/Dockerfile -t packager --build-arg VERSION="${version}" .
popd
# Copy deb file out of container to host
docker run --rm -v $(pwd):/out packager bash -c "cp /*.deb /out"
# Check which files existed before and after 'make install' was executed.
# docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out"
# docker run --rm -v $(pwd):/out packager bash -c "cp /after-install.txt /out"
# diff before-install.txt after-install.txt

View File

@@ -0,0 +1,2 @@
# Trigger ldconfig after install
activate-noawait ldconfig