Skip to content

Commit

Permalink
Update ASMARM error
Browse files Browse the repository at this point in the history
  • Loading branch information
TerraWilly committed Aug 12, 2024
1 parent 994acef commit 73b4048
Showing 1 changed file with 78 additions and 34 deletions.
112 changes: 78 additions & 34 deletions plugins/patching/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,27 +657,45 @@ class AsmARM(KeystoneAssembler):
def __init__(self, inf):

# ARM64
if inf.is_64bit():
arch = keystone.KS_ARCH_ARM64

if inf.is_be():
mode = keystone.KS_MODE_BIG_ENDIAN
else:
mode = keystone.KS_MODE_LITTLE_ENDIAN
if ida_pro.IDA_SDK_VERSION < 900:
if inf.is_64bit():
arch = keystone.KS_ARCH_ARM64

# AArch64 does not use THUMB
self._ks_thumb = None
if inf.is_be():
mode = keystone.KS_MODE_BIG_ENDIAN
else:
mode = keystone.KS_MODE_LITTLE_ENDIAN

# ARM
# AArch64 does not use THUMB
self._ks_thumb = None
else:
arch = keystone.KS_ARCH_ARM
if ida_ida.inf_is_64bit():
arch = keystone.KS_ARCH_ARM64

if inf.is_be():
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_BIG_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_BIG_ENDIAN)
if ida_ida.inf_is_be():
mode = keystone.KS_MODE_BIG_ENDIAN
else:
mode = keystone.KS_MODE_LITTLE_ENDIAN

# AArch64 does not use THUMB
self._ks_thumb = None
# ARM
else:
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_LITTLE_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_LITTLE_ENDIAN)
arch = keystone.KS_ARCH_ARM
if ida_pro.IDA_SDK_VERSION < 900:
if inf.is_be():
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_BIG_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_BIG_ENDIAN)
else:
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_LITTLE_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_LITTLE_ENDIAN)
else:
if ida_ida.inf_is_be():
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_BIG_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_BIG_ENDIAN)
else:
mode = keystone.KS_MODE_ARM | keystone.KS_MODE_LITTLE_ENDIAN
self._ks_thumb = keystone.Ks(arch, keystone.KS_MODE_THUMB | keystone.KS_MODE_LITTLE_ENDIAN)

# initialize keystone-based assembler
super(AsmARM, self).__init__(arch, mode)
Expand Down Expand Up @@ -823,11 +841,16 @@ class AsmPPC(KeystoneAssembler):
def __init__(self, inf):
arch = keystone.KS_ARCH_PPC

if inf.is_64bit():
mode = keystone.KS_MODE_PPC64
if ida_pro.IDA_SDK_VERSION < 900:
if inf.is_64bit():
mode = keystone.KS_MODE_PPC64
else:
mode = keystone.KS_MODE_PPC32
else:
mode = keystone.KS_MODE_PPC32

if ida_ida.inf_is_64bit():
mode = keystone.KS_MODE_PPC64
else:
mode = keystone.KS_MODE_PPC32
# TODO: keystone does not support Little Endian mode for PPC?
#if arch_name == 'ppc':
# mode += keystone.KS_MODE_BIG_ENDIAN
Expand All @@ -844,16 +867,27 @@ class AsmMIPS(KeystoneAssembler):
def __init__(self, inf):
arch = keystone.KS_ARCH_MIPS

if inf.is_64bit():
mode = keystone.KS_MODE_MIPS64
else:
mode = keystone.KS_MODE_MIPS32
if ida_pro.IDA_SDK_VERSION < 900:

if inf.is_64bit():
mode = keystone.KS_MODE_MIPS64
else:
mode = keystone.KS_MODE_MIPS32

if inf.is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
if inf.is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_ENDIAN
if ida_ida.inf_is_64bit():
mode = keystone.KS_MODE_MIPS64
else:
mode = keystone.KS_MODE_MIPS32

if ida_ida.inf_is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_ENDIAN
# initialize keystone-based assembler
super(AsmMIPS, self).__init__(arch, mode)

Expand All @@ -866,16 +900,26 @@ class AsmSPARC(KeystoneAssembler):
def __init__(self, inf):
arch = keystone.KS_ARCH_SPARC

if inf.is_64bit():
mode = keystone.KS_MODE_SPARC64
else:
mode = keystone.KS_MODE_SPARC32
if ida_pro.IDA_SDK_VERSION < 900:
if inf.is_64bit():
mode = keystone.KS_MODE_SPARC64
else:
mode = keystone.KS_MODE_SPARC32

if inf.is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
if inf.is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_ENDIAN
if ida_ida.inf_is_64bit():
mode = keystone.KS_MODE_SPARC64
else:
mode = keystone.KS_MODE_SPARC32

if ida_ida.inf_is_be():
mode |= keystone.KS_MODE_BIG_ENDIAN
else:
mode |= keystone.KS_MODE_LITTLE_
# initialize keystone-based assembler
super(AsmSPARC, self).__init__(arch, mode)

Expand Down

0 comments on commit 73b4048

Please sign in to comment.