Skip to content

Commit

Permalink
project: Introduces capstone as a new project to analyze (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
vulder authored Oct 8, 2024
1 parent b87a13c commit b5f490b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/experiment/test_workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_workload_config_param_token(self) -> None:
self.assertEqual(len(commands), 1)
command = commands[0]
args = command.command.rendered_args(project=project)
self.assertEquals(args, tuple(["-c"]))
self.assertEqual(args, tuple(["-c"]))

@run_in_test_environment(UnitTestFixtures.PAPER_CONFIGS)
def test_workload_commands_requires_patch(self) -> None:
Expand Down
7 changes: 4 additions & 3 deletions tests/utils/test_doc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ def test_generate_projects_overview_table(self) -> None:

self.assertEqual(
cleaned_first_row[0],
":class:`~varats.projects.c_projects.glibc.Glibc`"
":class:`~varats.projects.c_projects.capstone.Capstone`"
)
self.assertEqual(cleaned_first_row[1], "c_projects")
self.assertEqual(cleaned_first_row[2], "C Library")
self.assertEqual(cleaned_first_row[2], "Binary Analysis Framework")
self.assertEqual(cleaned_first_row[3], "")
self.assertEqual(
cleaned_first_row[4], "git://sourceware.org/git/glibc.git"
cleaned_first_row[4],
"https://github.com/capstone-engine/capstone.git"
)

def test_construct_feature_model_link(self) -> None:
Expand Down
7 changes: 4 additions & 3 deletions varats-core/varats/project/project_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ class ProjectDomains(Enum):
"""Defines a set of project domains."""
value: str

BINARY_ANALYSIS_FRAMEWORK = "Binary Analysis Framework"
CHAT_CLIENT = "Chat client"
CODEC = "Codec"
COMPRESSION = "Compression"
C_LIBRARY = "C Library"
CPP_LIBRARY = "C++ Library"
C_LIBRARY = "C Library"
DATABASE = "Database"
DATA_STRUCTURES = "Data structures"
DOCUMENTATION = "Documentation"
EDITOR = "Editor"
FILE_FORMAT = "File format"
HW_EMULATOR = "Hardware emulator"
HPC = "High Performance Applications"
HW_EMULATOR = "Hardware emulator"
PARSER = "Parser"
PLANNING = "Planning"
PROG_LANG = "Programming language"
PROTOCOL = "Protocol"
RENDERING = "Rendering"
SECURITY = "Security"
SOLVER = "Solver"
SIGNAL_PROCESSING = "Signal processing"
SOLVER = "Solver"
TEST = "Test project"
UNIX_TOOLS = "UNIX utils"
VERSION_CONTROL = "Version control"
Expand Down
77 changes: 77 additions & 0 deletions varats/varats/projects/c_projects/capstone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""Project file for capstone."""
import typing as tp

import benchbuild as bb
from benchbuild.utils.cmd import cmake
from plumbum import local

from varats.containers.containers import ImageBase, get_base_image
from varats.paper.paper_config import PaperConfigSpecificGit
from varats.project.project_domain import ProjectDomains
from varats.project.project_util import (
BinaryType,
ProjectBinaryWrapper,
RevisionBinaryMap,
get_local_project_repo,
verify_binaries,
)
from varats.project.varats_project import VProject
from varats.utils.git_util import ShortCommitHash


class Capstone(VProject):
"""Capstone is a disassembly framework with the target of becoming the
ultimate disasm engine for binary analysis and reversing in the security
community."""

NAME = 'capstone'
GROUP = 'c_projects'
DOMAIN = ProjectDomains.BINARY_ANALYSIS_FRAMEWORK

SOURCE = [
PaperConfigSpecificGit(
project_name='capstone',
remote="https://github.com/capstone-engine/capstone.git",
local="capstone",
refspec="origin/HEAD",
limit=None,
shallow=False
),
]

CONTAINER = get_base_image(ImageBase.DEBIAN_10
).run('apt', 'install', '-y', 'cmake')

@staticmethod
def binaries_for_revision(
revision: ShortCommitHash
) -> tp.List[ProjectBinaryWrapper]:
binary_map = RevisionBinaryMap(get_local_project_repo(Capstone.NAME))

binary_map.specify_binary('build/cstool', BinaryType.EXECUTABLE)

return binary_map[revision]

def run_tests(self) -> None:
pass

def compile(self) -> None:
"""Compile the project."""
capstone_version_source = local.path(self.source_of_primary)

c_compiler = bb.compiler.cc(self)
cxx_compiler = bb.compiler.cxx(self)
with local.cwd(capstone_version_source):
with local.env(CC=str(c_compiler), CXX=str(cxx_compiler)):

cmake_args = [
"-B",
"build",
"-DCMAKE_BUILD_TYPE=Release",
]

bb.watch(cmake)(*cmake_args)

bb.watch(cmake)("--build", "build")

verify_binaries(self)
1 change: 1 addition & 0 deletions varats/varats/tools/bb_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def update_projects(
'varats.projects.c_projects.busybox',
'varats.projects.c_projects.brotli',
'varats.projects.c_projects.bzip2',
'varats.projects.c_projects.capstone',
'varats.projects.c_projects.coreutils',
'varats.projects.c_projects.curl',
'varats.projects.c_projects.file',
Expand Down

0 comments on commit b5f490b

Please sign in to comment.