Skip to content

Commit

Permalink
Add copy of meta-programming macros for capstone-sys build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Dec 17, 2023
1 parent 3374a00 commit 156765b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions librz/analysis/arch/arm/arm_cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <rz_analysis.h>
#include <capstone/capstone.h>
#include "../../asm/arch/arm/aarch64_meta_macros.h"

RZ_IPI int rz_arm_cs_analysis_op_32_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, bool thumb);
RZ_IPI int rz_arm_cs_analysis_op_64_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn);
Expand Down
63 changes: 63 additions & 0 deletions librz/asm/arch/arm/aarch64_meta_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: 2023 Rot127 <[email protected]>
// SPDX-License-Identifier: LGPL-3.0-only

#ifndef AARCH64_META_MACROS_H
#define AARCH64_META_MACROS_H

#ifdef USE_SYS_CAPSTONE

/// Macro for meta programming.
/// Meant for projects using Capstone and need to support multiple
/// versions of it.
/// These macros replace several instances of the old "ARM64" with
/// the new "AArch64" name depending on the CS version.
#if CS_NEXT_VERSION < 6
#define CS_AARCH64(x) ARM64##x
#else
#define CS_AARCH64(x) AArch64##x
#endif

#if CS_NEXT_VERSION < 6
#define CS_AARCH64pre(x) x##ARM64
#else
#define CS_AARCH64pre(x) x##AARCH64
#endif

#if CS_NEXT_VERSION < 6
#define CS_AARCH64CC(x) ARM64_CC##x
#else
#define CS_AARCH64CC(x) AArch64CC##x
#endif

#if CS_NEXT_VERSION < 6
#define CS_AARCH64_VL_(x) ARM64_VAS_##x
#else
#define CS_AARCH64_VL_(x) AArch64Layout_VL_##x
#endif

#if CS_NEXT_VERSION < 6
#define CS_aarch64(x) arm64##x
#else
#define CS_aarch64(x) aarch64##x
#endif

#if CS_NEXT_VERSION < 6
#define CS_aarch64_op() cs_arm64_op
#define CS_aarch64_reg() arm64_reg
#define CS_aarch64_cc() arm64_cc
#define CS_cs_aarch64() cs_arm64
#define CS_aarch64_extender() arm64_extender
#define CS_aarch64_shifter() arm64_shifter
#define CS_aarch64_vas() arm64_vas
#else
#define CS_aarch64_op() cs_aarch64_op
#define CS_aarch64_reg() aarch64_reg
#define CS_aarch64_cc() AArch64CC_CondCode
#define CS_cs_aarch64() cs_aarch64
#define CS_aarch64_extender() aarch64_extender
#define CS_aarch64_shifter() aarch64_shifter
#define CS_aarch64_vas() AArch64Layout_VectorLayout
#endif

#endif // USE_SYS_CAPSTONE
#endif // AARCH64_META_MACROS_H
1 change: 1 addition & 0 deletions librz/asm/arch/arm/asm-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define _INCLUDE_ARMASS_H_

#include <rz_types_base.h>
#include "../arch/arm/aarch64_meta_macros.h"

int armass_assemble(const char *str, ut64 off, int thumb);

Expand Down
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ if not capstone_dep.found()
error('Wrong capstone version selected. Please use one of the supported versions.')
endif
capstone_dep = capstone_proj.get_variable('capstone_dep')
else
# Package managers CS version has no meta programming macros for AArch64 -> ARM64 renaming
# (because it is outdated).
# With this define we includeour copy of those macros.
add_project_arguments(['-DUSE_SYS_CAPSTONE'], language: 'c')
endif

# handle magic library
Expand Down

0 comments on commit 156765b

Please sign in to comment.