Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a functional Debian Package for Capstone v5 #2569

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

AndrewQuijano
Copy link
Contributor

@AndrewQuijano AndrewQuijano commented Dec 5, 2024

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

This is based on continuing work, I hope to create at least a functional Debian Package for Capstonev5 used within PANDA. I updated the control file to be much more detailed to align for eventual future publishing to Debian Repositories.

Fixes completed:

  • Architecture in the control file was incorrectly set to all.
  • As you already said, the package should be installed into /usr/.
  • The generated package misses the dependency information.
  • The package name was not according to the Debian standard.
  • Hash sums missing

Since this is a Debian binary package control file, I only need to follow this guidance
https://www.debian.org/doc/debian-policy/ch-controlfields.html#debian-binary-package-control-files-debian-control

...

Test plan

  1. Use the check_capstone.sh to confirm files are at expected locations.
  2. Will use the generated package within an integration test for PANDA. PANDA uses capstone in its integration tests, will attach PR when merged

...

Closing issues
Would just be progress on packaging goal.

References on past work:
#2543
#2521

I think based on the quality of the work, this should close #2537. The next work would be just to send this to Debian, but it seems like it has everything Debian could want, based on what I see from the current old packages.
...

@AndrewQuijano AndrewQuijano force-pushed the debian-v5 branch 2 times, most recently from 00673b2 to 3af3d27 Compare December 5, 2024 03:11
@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 5, 2024

Evidence of new Control File

image

md5sum evidence
image

Sanity check with gcc package on apt
image

@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 5, 2024

Based on libcapstone-dev for version 4.0.1, I see this. Based on this, I need

Other fixes:

  • Copying documentation into the Debian package
  • We should use /usr/lib/x86_64-linux-gnu instead of /usr/lib
  • capstone.pc has correct prefix and correct version, also archs= removed from capstone.pc.in if it isn't used.
  • Set the version in your CI/CD pipeline and pass it to CMake using -D option for project version, just to keep everything consistent
# Check if VERSION is provided externally, otherwise default to 5.0.3
if(NOT DEFINED PROJECT_VERSION)
    set(PROJECT_VERSION "5.0.3")
endif()
project(capstone VERSION ${PROJECT_VERSION})

libcapstone4.deb

andrew@DESKTOP-82KSFL5:~$ ls -alR extracted-libcapstone4/ > libcapstone4.txt
andrew@DESKTOP-82KSFL5:~$ cat libcapstone4.txt
extracted-libcapstone4/:
total 12
drwxr-xr-x  3 andrew andrew 4096 Dec 25  2021 .
drwxr-x--- 37 andrew andrew 4096 Dec  4 22:54 ..
drwxr-xr-x  4 andrew andrew 4096 Dec 25  2021 usr

extracted-libcapstone4/usr:
total 16
drwxr-xr-x 4 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 lib
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 share

extracted-libcapstone4/usr/lib:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 4 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 2 andrew andrew 4096 Dec 25  2021 x86_64-linux-gnu

extracted-libcapstone4/usr/lib/x86_64-linux-gnu:
total 6456
drwxr-xr-x 2 andrew andrew    4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew    4096 Dec 25  2021 ..
-rw-r--r-- 1 andrew andrew 6601776 Dec 25  2021 libcapstone.so.4

extracted-libcapstone4/usr/share:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 4 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 doc

extracted-libcapstone4/usr/share/doc:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 2 andrew andrew 4096 Dec 25  2021 libcapstone4

extracted-libcapstone4/usr/share/doc/libcapstone4:
total 20
drwxr-xr-x 2 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
-rw-r--r-- 1 andrew andrew 1284 Dec 25  2021 changelog.Debian.gz
-rw-r--r-- 1 andrew andrew 5629 Dec  8  2020 copyright

libcapstone-dev.deb v4.0.2 (note, this does require libcapstone4)

image

andrew@DESKTOP-82KSFL5:~$ ls -alR extracted-libcapstone-dev/ > output.txt
andrew@DESKTOP-82KSFL5:~$ cat output.txt
extracted-libcapstone-dev/:
total 12
drwxr-xr-x  3 andrew andrew 4096 Dec 25  2021 .
drwxr-x--- 36 andrew andrew 4096 Dec  4 22:44 ..
drwxr-xr-x  5 andrew andrew 4096 Dec 25  2021 usr

extracted-libcapstone-dev/usr:
total 20
drwxr-xr-x 5 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 include
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 lib
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 share

extracted-libcapstone-dev/usr/include:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 5 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 2 andrew andrew 4096 Dec 25  2021 capstone

extracted-libcapstone-dev/usr/include/capstone:
total 272
drwxr-xr-x 2 andrew andrew  4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew  4096 Dec 25  2021 ..
-rw-r--r-- 1 andrew andrew 18795 Dec 25  2021 arm.h
-rw-r--r-- 1 andrew andrew 28542 Dec 25  2021 arm64.h
-rw-r--r-- 1 andrew andrew 29509 Dec 25  2021 capstone.h
-rw-r--r-- 1 andrew andrew  4386 Dec 25  2021 evm.h
-rw-r--r-- 1 andrew andrew 12320 Dec 25  2021 m680x.h
-rw-r--r-- 1 andrew andrew 13855 Dec 25  2021 m68k.h
-rw-r--r-- 1 andrew andrew 17047 Dec 25  2021 mips.h
-rw-r--r-- 1 andrew andrew  4010 Dec 25  2021 platform.h
-rw-r--r-- 1 andrew andrew 25638 Dec 25  2021 ppc.h
-rw-r--r-- 1 andrew andrew 11297 Dec 25  2021 sparc.h
-rw-r--r-- 1 andrew andrew 14335 Dec 25  2021 systemz.h
-rw-r--r-- 1 andrew andrew  8262 Dec 25  2021 tms320c64x.h
-rw-r--r-- 1 andrew andrew 42841 Dec 25  2021 x86.h
-rw-r--r-- 1 andrew andrew  4919 Dec 25  2021 xcore.h

extracted-libcapstone-dev/usr/lib:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 5 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 3 andrew andrew 4096 Dec  4 22:33 x86_64-linux-gnu

extracted-libcapstone-dev/usr/lib/x86_64-linux-gnu:
total 7804
drwxr-xr-x 3 andrew andrew    4096 Dec  4 22:33 .
drwxr-xr-x 3 andrew andrew    4096 Dec 25  2021 ..
-rw-r--r-- 1 andrew andrew 7978074 Dec 25  2021 libcapstone.a
lrwxrwxrwx 1 andrew andrew      16 Dec 25  2021 libcapstone.so -> libcapstone.so.4
drwxr-xr-x 2 andrew andrew    4096 Dec 25  2021 pkgconfig

extracted-libcapstone-dev/usr/lib/x86_64-linux-gnu/pkgconfig:
total 12
drwxr-xr-x 2 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec  4 22:33 ..
-rw-r--r-- 1 andrew andrew  222 Dec 25  2021 capstone.pc

extracted-libcapstone-dev/usr/share:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 5 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 doc

extracted-libcapstone-dev/usr/share/doc:
total 12
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
drwxr-xr-x 2 andrew andrew 4096 Dec  4 22:33 libcapstone-dev

extracted-libcapstone-dev/usr/share/doc/libcapstone-dev:
total 36
drwxr-xr-x 2 andrew andrew 4096 Dec  4 22:33 .
drwxr-xr-x 3 andrew andrew 4096 Dec 25  2021 ..
-rw-r--r-- 1 andrew andrew 2658 May  8  2020 CREDITS.TXT
-rw-r--r-- 1 andrew andrew 2234 May  8  2020 HACK.TXT
-rw-r--r-- 1 andrew andrew 2167 May  8  2020 README.md
-rw-r--r-- 1 andrew andrew  856 May  8  2020 SPONSORS.TXT
-rw-r--r-- 1 andrew andrew  427 May  8  2020 TODO
lrwxrwxrwx 1 andrew andrew   35 Dec 25  2021 changelog.Debian.gz -> ../libcapstone4/changelog.Debian.gz
-rw-r--r-- 1 andrew andrew 5629 Dec  8  2020 copyright

Current version

extracted-libcapstone-dev/:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:43 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 usr

extracted-libcapstone-dev/usr:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 bin
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 include
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 lib

extracted-libcapstone-dev/usr/bin:
total 9388
drwxrwxrwx 1 andrew andrew    4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew    4096 Dec  4 22:40 ..
-rwxrwxrwx 1 andrew andrew 9612152 Dec  4 22:40 cstool

extracted-libcapstone-dev/usr/include:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 capstone

extracted-libcapstone-dev/usr/include/capstone:
total 448
drwxrwxrwx 1 andrew andrew  4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew  4096 Dec  4 22:40 ..
-rwxrwxrwx 1 andrew andrew 20872 Nov 28 13:28 arm.h
-rwxrwxrwx 1 andrew andrew 86980 Nov 28 13:28 arm64.h
-rwxrwxrwx 1 andrew andrew  4308 Nov 28 13:28 bpf.h
-rwxrwxrwx 1 andrew andrew 34412 Nov 28 13:28 capstone.h
-rwxrwxrwx 1 andrew andrew  4574 Nov 28 13:27 evm.h
-rwxrwxrwx 1 andrew andrew 12857 Nov 28 13:28 m680x.h
-rwxrwxrwx 1 andrew andrew 14468 Nov 28 13:28 m68k.h
-rwxrwxrwx 1 andrew andrew 18000 Nov 28 13:28 mips.h
-rwxrwxrwx 1 andrew andrew  5991 Nov 28 13:28 mos65xx.h
-rwxrwxrwx 1 andrew andrew  4132 Nov 28 13:27 platform.h
-rwxrwxrwx 1 andrew andrew 40378 Nov 28 13:28 ppc.h
-rwxrwxrwx 1 andrew andrew 13799 Nov 28 13:28 riscv.h
-rwxrwxrwx 1 andrew andrew  8238 Nov 28 13:28 sh.h
-rwxrwxrwx 1 andrew andrew 11817 Nov 28 13:28 sparc.h
-rwxrwxrwx 1 andrew andrew 47232 Nov 28 13:28 systemz.h
-rwxrwxrwx 1 andrew andrew  8621 Nov 28 13:27 tms320c64x.h
-rwxrwxrwx 1 andrew andrew 13257 Nov 28 13:28 tricore.h
-rwxrwxrwx 1 andrew andrew  6441 Nov 28 13:27 wasm.h
-rwxrwxrwx 1 andrew andrew 45041 Nov 28 13:28 x86.h
-rwxrwxrwx 1 andrew andrew  5154 Nov 28 13:27 xcore.h

extracted-libcapstone-dev/usr/lib:
total 10704
drwxrwxrwx 1 andrew andrew     4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew     4096 Dec  4 22:40 ..
drwxrwxrwx 1 andrew andrew     4096 Dec  4 22:40 cmake
-rwxrwxrwx 1 andrew andrew 10958532 Dec  4 22:39 libcapstone.a
drwxrwxrwx 1 andrew andrew     4096 Dec  4 22:40 pkgconfig

extracted-libcapstone-dev/usr/lib/cmake:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 capstone

extracted-libcapstone-dev/usr/lib/cmake/capstone:
total 16
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 ..
-rwxrwxrwx 1 andrew andrew 2878 Dec  4 22:39 capstone-config-version.cmake
-rwxrwxrwx 1 andrew andrew 1072 Dec  4 22:39 capstone-config.cmake
-rwxrwxrwx 1 andrew andrew 1315 Dec  4 22:39 capstone-targets-release.cmake
-rwxrwxrwx 1 andrew andrew 4047 Dec  4 22:39 capstone-targets.cmake

extracted-libcapstone-dev/usr/lib/pkgconfig:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 .
drwxrwxrwx 1 andrew andrew 4096 Dec  4 22:40 ..
-rwxrwxrwx 1 andrew andrew  301 Dec  4 22:40 capstone.pc

image

@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 6, 2024

Showing proof of new changes to new Debian file @Rot127

extracted/:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:56 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 usr

extracted/usr:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 lib
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 share

extracted/usr/lib:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 pkgconfig
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 x86_64-linux-gnu

extracted/usr/lib/pkgconfig:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 ..

extracted/usr/lib/x86_64-linux-gnu:
total 20124
drwxrwxrwx 1 andrew andrew     4096 Dec  5 19:42 .
drwxrwxrwx 1 andrew andrew     4096 Dec  5 19:23 ..
-rwxrwxrwx 1 andrew andrew 10989740 Dec  5 19:23 libcapstone.a
lrwxrwxrwx 1 andrew andrew       16 Dec  5 19:23 libcapstone.so -> libcapstone.so.6
lrwxrwxrwx 1 andrew andrew       20 Dec  5 19:23 libcapstone.so.6 -> libcapstone.so.6.0.0
-rwxrwxrwx 1 andrew andrew  9610296 Dec  5 19:23 libcapstone.so.6.0.0
drwxrwxrwx 1 andrew andrew     4096 Dec  5 19:23 pkgconfig

extracted/usr/lib/x86_64-linux-gnu/pkgconfig:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 ..
-rwxrwxrwx 1 andrew andrew  305 Dec  5 19:23 capstone.pc

extracted/usr/share:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 doc

extracted/usr/share/doc:
total 0
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 ..
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 libcapstone-dev

extracted/usr/share/doc/libcapstone-dev:
total 16
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:42 .
drwxrwxrwx 1 andrew andrew 4096 Dec  5 19:23 ..
-rwxrwxrwx 1 andrew andrew  3144 Dec  5 20:10 CREDITS.TXT
-rwxrwxrwx 1 andrew andrew 36243 Dec  5 20:10 ChangeLog
-rwxrwxrwx 1 andrew andrew  3998 Dec  5 20:10 HACK.TXT
-rwxrwxrwx 1 andrew andrew  1687 Dec  5 20:10 LICENSE.TXT
-rwxrwxrwx 1 andrew andrew  2549 Dec  5 20:10 README.md
-rwxrwxrwx 1 andrew andrew     0 Dec  5 20:10 RELEASE_NOTES
-rwxrwxrwx 1 andrew andrew   637 Dec  5 20:10 SPONSORS.TXT

capstone.pc can correctly get the Project Version from CMakeLists.txt, which can now be dynamically updated via CI/CD, and can handle pre-release versions by parsing out major.minor.patch

image

Yes, I am aware there is a blank /usr/lib/pkgconfig library, but this is a very minor issue, as I think based on this draft, I have a pretty functional package working now.

Here is the control file
image

And I created a release with the package
https://github.com/AndrewQuijano/capstone/releases/tag/6.0.0-Alpha5

I'm going to now attempt testing this with PANDA shortly with this PR

panda-re/panda#1558

@AndrewQuijano AndrewQuijano force-pushed the debian-v5 branch 2 times, most recently from 7a62be2 to b156163 Compare December 6, 2024 01:27
@AndrewQuijano AndrewQuijano force-pushed the debian-v5 branch 2 times, most recently from 0a02a08 to 888b695 Compare December 6, 2024 01:36
@AndrewQuijano AndrewQuijano changed the title [DO NOT MERGE] Creating a functional Debian Package for Capstone v5 Creating a functional Debian Package for Capstone v5 Dec 6, 2024
Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks better now!

Please add your copyright to all files in SPDX format:

// SPDX-FileCopyrightText: 2024 AndrewQuijano <your-mail>
// SPDX-License-Identifier: <License you like this under. Default is BSD-3>

packages/deb/control Show resolved Hide resolved
packages/deb/control Outdated Show resolved Hide resolved
packages/deb/control Outdated Show resolved Hide resolved
packages/deb/control Outdated Show resolved Hide resolved
packages/deb/control Outdated Show resolved Hide resolved
packages/deb/README.md Outdated Show resolved Hide resolved
@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 7, 2024

@Rot127 I just made the changes, actually, could you merge into v5 and create version '5.0.4'? I can confirm, when I install the Debian package, and use ldconfig, it does look correct showing the link to libcapstone, so I am pretty confident it works. The fact that this new Debian package looks a lot more like the packages in apt further solidifies my confidence this does work as intended.

Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, lgtm. Just those three little things.

could you merge into v5 and create version '5.0.4'?

@kabeor has to merge and do the release. I don't have the privileges to do so.

packages/deb/Dockerfile Show resolved Hide resolved
packages/deb/control Outdated Show resolved Hide resolved
packages/deb/control Show resolved Hide resolved
@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 8, 2024

@kabeor @Rot127 Please also merge #2579 too, I replicated all the changes to next branch from here too

@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 10, 2024

Finally able to test Debian Package dynamically with PANDA, but please create the new release, I'd rather PANDA pull the Debian package from capstone than my fork.

panda-re/panda#1562

@AndrewQuijano
Copy link
Contributor Author

AndrewQuijano commented Dec 10, 2024

@kabeor The PANDA integration test completed correctly, please merge both PRs for Debian Package on v5/v6 and create 5.0.4 release, I'm hoping to get my PR into PANDA done before the Christmas break

@XVilka
Copy link
Contributor

XVilka commented Dec 15, 2024

@kabeor and this pair of PRs please

Copy link
Member

@kabeor kabeor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@kabeor kabeor merged commit ea42c28 into capstone-engine:v5 Dec 17, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants