Skip to content

Commit

Permalink
Rename CS_OPT_NO_BRANCH_OFFSET and corresponding flag to better name. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 authored Sep 25, 2024
1 parent 0c90fe1 commit 1014864
Show file tree
Hide file tree
Showing 1,165 changed files with 34,909 additions and 34,908 deletions.
8 changes: 4 additions & 4 deletions arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ void printAlignedLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
if (MCOperand_isImm(Op)) {
SStream_concat0(O, markup("<imm:"));
int64_t Offset = MCOperand_getImm(Op) * 4;
if (!MI->csh->PrintBranchImmNotAsAddress)
if (MI->csh->PrintBranchImmAsAddress)
printUInt64(O, (Address + Offset));
else {
printUInt64Bang(O, (Offset));
Expand All @@ -2045,7 +2045,7 @@ void printAdrLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
if (MCOperand_isImm(Op)) {
const int64_t Offset = MCOperand_getImm(Op);
SStream_concat0(O, markup("<imm:"));
if (!MI->csh->PrintBranchImmNotAsAddress)
if (MI->csh->PrintBranchImmAsAddress)
printUInt64(O, ((Address & -4) + Offset));
else {
printUInt64Bang(O, Offset);
Expand All @@ -2067,7 +2067,7 @@ void printAdrpLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
if (MCOperand_isImm(Op)) {
const int64_t Offset = MCOperand_getImm(Op) * 4096;
SStream_concat0(O, markup("<imm:"));
if (!MI->csh->PrintBranchImmNotAsAddress)
if (MI->csh->PrintBranchImmAsAddress)
printUInt64(O, ((Address & -4096) + Offset));
else {
printUInt64Bang(O, Offset);
Expand All @@ -2092,7 +2092,7 @@ void printAdrAdrpLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
Address = Address & -4096;
}
SStream_concat0(O, markup(">"));
if (!MI->csh->PrintBranchImmNotAsAddress)
if (MI->csh->PrintBranchImmAsAddress)
printUInt64(O, (Address + Offset));
else {
printUInt64Bang(O, Offset);
Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
void printOperandAddr(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
{
MCOperand *Op = MCInst_getOperand(MI, (OpNum));
if (!MCOperand_isImm(Op) || MI->csh->PrintBranchImmNotAsAddress ||
if (!MCOperand_isImm(Op) || !MI->csh->PrintBranchImmAsAddress ||
getUseMarkup()) {
printOperand(MI, OpNum, O);
return;
Expand Down
2 changes: 1 addition & 1 deletion arch/PowerPC/PPCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void printBranchOperand(MCInst *MI, uint64_t Address, unsigned OpNo, SStream *O)
((unsigned)MCOperand_getImm(MCInst_getOperand(MI, (OpNo)))
<< 2),
32);
if (!MI->csh->PrintBranchImmNotAsAddress) {
if (MI->csh->PrintBranchImmAsAddress) {
uint64_t Target = Address + Imm;
if (!IS_64BIT(MI->csh->mode))
Target &= 0xffffffff;
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
'CS_OPT_SKIPDATA_SETUP',
'CS_OPT_MNEMONIC',
'CS_OPT_UNSIGNED',
'CS_OPT_NO_BRANCH_OFFSET',
'CS_OPT_ONLY_OFFSET_BRANCH',

'CS_ERR_OK',
'CS_ERR_MEM',
Expand Down Expand Up @@ -388,7 +388,7 @@
CS_OPT_SKIPDATA_SETUP = 6 # Setup user-defined function for SKIPDATA option
CS_OPT_MNEMONIC = 7 # Customize instruction mnemonic
CS_OPT_UNSIGNED = 8 # Print immediate in unsigned form
CS_OPT_NO_BRANCH_OFFSET = 9 # ARM, prints branch immediates without offset.
CS_OPT_ONLY_OFFSET_BRANCH = 9 # ARM, prints branch immediates without offset.

# Capstone option value
CS_OPT_OFF = 0 # Turn OFF an option - default option of CS_OPT_DETAIL
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/cstest_py/src/cstest_py/cs_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"CS_OPT_SKIPDATA": {"type": cs.CS_OPT_SKIPDATA, "val": cs.CS_OPT_ON},
"CS_OPT_UNSIGNED": {"type": cs.CS_OPT_UNSIGNED, "val": cs.CS_OPT_ON},
"CS_OPT_NO_BRANCH_OFFSET": {
"type": cs.CS_OPT_NO_BRANCH_OFFSET,
"CS_OPT_ONLY_OFFSET_BRANCH": {
"type": cs.CS_OPT_ONLY_OFFSET_BRANCH,
"val": cs.CS_OPT_ON,
},
"CS_OPT_SYNTAX_DEFAULT": {
Expand Down
5 changes: 3 additions & 2 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
ud->mode = mode;
// by default, do not break instruction into details
ud->detail_opt = CS_OPT_OFF;
ud->PrintBranchImmAsAddress = true;

// default skipdata setup
ud->skipdata_setup.mnemonic = SKIPDATA_MNEM;
Expand Down Expand Up @@ -1110,8 +1111,8 @@ cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
return CS_ERR_OPTION;
}
break;
case CS_OPT_NO_BRANCH_OFFSET:
handle->PrintBranchImmNotAsAddress = value == CS_OPT_ON ? true : false;
case CS_OPT_ONLY_OFFSET_BRANCH:
handle->PrintBranchImmAsAddress = value == CS_OPT_ON ? false : true;
return CS_ERR_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion cs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct cs_struct {
cs_err errnum;
ARM_ITBlock ITBlock; // for Arm only
ARM_VPTBlock VPTBlock; // for ARM only
bool PrintBranchImmNotAsAddress;
bool PrintBranchImmAsAddress;
bool ShowVSRNumsAsVR;
cs_opt_value detail_opt, imm_unsigned;
int syntax; // asm syntax for simple printer such as ARM, Mips & PPC
Expand Down
2 changes: 1 addition & 1 deletion include/capstone/capstone.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ typedef enum cs_opt_type {
CS_OPT_SKIPDATA_SETUP, ///< Setup user-defined function for SKIPDATA option
CS_OPT_MNEMONIC, ///< Customize instruction mnemonic
CS_OPT_UNSIGNED, ///< print immediate operands in unsigned form
CS_OPT_NO_BRANCH_OFFSET, ///< ARM, PPC, AArch64, prints branch immediates without offset.
CS_OPT_ONLY_OFFSET_BRANCH, ///< ARM, PPC, AArch64: Don't add the branch immediate value to the PC.
} cs_opt_type;

/// Runtime option value (associated with option type above)
Expand Down
6 changes: 3 additions & 3 deletions suite/auto-sync/src/autosync/mcupdater.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
],
"PPC":
[
"CS_OPT_NO_BRANCH_OFFSET"
"CS_OPT_ONLY_OFFSET_BRANCH"
],
"ARM":
[
"CS_OPT_NO_BRANCH_OFFSET"
"CS_OPT_ONLY_OFFSET_BRANCH"
],
"AArch64":
[
"CS_OPT_NO_BRANCH_OFFSET"
"CS_OPT_ONLY_OFFSET_BRANCH"
]
},
"remove_options":
Expand Down
4 changes: 2 additions & 2 deletions suite/cstest/include/test_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ static const TestOptionMapEntry test_option_map[] = {
.opt = { .type = CS_OPT_SKIPDATA, .val = CS_OPT_ON } },
{ .str = "CS_OPT_UNSIGNED",
.opt = { .type = CS_OPT_UNSIGNED, .val = CS_OPT_ON } },
{ .str = "CS_OPT_NO_BRANCH_OFFSET",
.opt = { .type = CS_OPT_NO_BRANCH_OFFSET, .val = CS_OPT_ON } },
{ .str = "CS_OPT_ONLY_OFFSET_BRANCH",
.opt = { .type = CS_OPT_ONLY_OFFSET_BRANCH, .val = CS_OPT_ON } },
{ .str = "CS_OPT_SYNTAX_DEFAULT",
.opt = { .type = CS_OPT_SYNTAX, .val = CS_OPT_SYNTAX_DEFAULT } },
{ .str = "CS_OPT_SYNTAX_INTEL",
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/abs_32.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x20, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x21, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x21, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x23, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/abs_64.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x20, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x21, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x21, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x23, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/cnt_32.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x1c, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x1d, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x1d, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x1f, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/cnt_64.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x1c, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x1d, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x1d, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x1f, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/ctz_32.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x18, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x19, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x19, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x1b, 0xc0, 0x5a ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
8 changes: 4 additions & 4 deletions tests/MC/AArch64/CSSC/ctz_64.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0x00, 0x18, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0x55, 0x19, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xb7, 0x19, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xff, 0x1b, 0xc0, 0xda ]
arch: "CS_ARCH_AARCH64"
options: [ "CS_OPT_NO_BRANCH_OFFSET", "aarch64", "v9.4a" ]
options: [ "CS_OPT_ONLY_OFFSET_BRANCH", "aarch64", "v9.4a" ]
expected:
insns:
-
Expand Down
Loading

0 comments on commit 1014864

Please sign in to comment.