Skip to content

Commit 8170efd

Browse files
authored
Add support for ghost nops for x86-{32,64} ##arch
1 parent 97b71b8 commit 8170efd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

libr/arch/p/x86/plugin_cs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define r_anal_value_new() R_NEW0 (RAnalValue)
1010
#define ARCH_HAVE_READ 1
11+
#define GHOSTOPS 1
1112

1213
#if 0
1314
CYCLES:
@@ -3901,6 +3902,17 @@ static bool decode(RArchSession *as, RAnalOp *op, RArchDecodeMask mask) {
39013902

39023903
cs_insn *insn = NULL;
39033904
int n;
3905+
#if GHOSTOPS
3906+
if (op->size >= 2 && op->bytes[0] == 0x0f) {
3907+
ut8 b1 = op->bytes[1];
3908+
if (b1 == 0x1a || b1 == 0x1b) {
3909+
op->type = R_ANAL_OP_TYPE_NOP;
3910+
op->mnemonic = strdup ("nop2");
3911+
op->size = 2;
3912+
return true;
3913+
}
3914+
}
3915+
#endif
39043916

39053917
op->cycles = 1; // aprox
39063918
cs_option (handle, CS_OPT_DETAIL, CS_OPT_ON);
@@ -3920,7 +3932,7 @@ static bool decode(RArchSession *as, RAnalOp *op, RArchDecodeMask mask) {
39203932
n = cs_disasm (handle, (const ut8*)buf, len, addr, 1, &insn);
39213933
#endif
39223934
//XXX: capstone lcall seg:off workaround, remove when capstone will be fixed
3923-
if (n >= 1 && mode == CS_MODE_16 && !strncmp (insn->mnemonic, "lcall", 5)) {
3935+
if (n >= 1 && mode == CS_MODE_16 && r_str_startswith (insn->mnemonic, "lcall")) {
39243936
char *opstr = strdup (insn->op_str);
39253937
opstr = r_str_replace (opstr, ", ", ":", 0);
39263938
r_str_ncpy (insn->op_str, opstr, sizeof (insn->op_str));

libr/arch/p/x86_nz/nzasm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,6 +4946,7 @@ static const LookupTable oplookup[] = {
49464946
{ "mwait", 0, NULL, 0x0f01c9, 3},
49474947
{ "neg", 0, &opneg, 0},
49484948
{ "nop", 0, NULL, 0x90, 1},
4949+
{ "nop2", 0, NULL, 0x0f1a, 2},
49494950
{ "not", 0, &opnot, 0},
49504951
{ "or", 0, &opor, 0},
49514952
{ "out", 0, &opout, 0},

test/db/asm/x86_32

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,3 +2192,5 @@ a "dec DWORD PTR [esi+0x8]" ff4e08
21922192
a "dec DWORD PTR [esp]" ff0c24
21932193
a "dec DWORD PTR [esp+0x10]" ff4c2410
21942194
ad "bsr eax, dword [4]" 0fbd0504000000
2195+
ad "nop2" 0f1a
2196+
d "nop2" 0f1b

0 commit comments

Comments
 (0)