Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aarch64 decompilation #533

Merged
merged 112 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
25fbdbe
Capstone2llvmirtool default basic modes for architectures
MatejKastak Sep 6, 2018
7b92167
Base for the ARM64 translator
MatejKastak Sep 10, 2018
7007ead
Fix the cs_reg_name
MatejKastak Sep 11, 2018
952def8
Add ARM64 support for capstone dependency
MatejKastak Sep 11, 2018
8a79401
Temporary solution to call translate function
MatejKastak Sep 11, 2018
446820d
Status register and program counter added to environment
MatejKastak Sep 11, 2018
94f6426
Methods store/load registers/operands skeletons + add instruction
MatejKastak Sep 11, 2018
623aef9
Store instruction base
MatejKastak Sep 12, 2018
32781de
Operand shifts ported from ARM and MOV instruction tranlation
MatejKastak Sep 13, 2018
5edc4ba
Arm64 - tests ported from Arm
MatejKastak Sep 15, 2018
8caa63e
Basic MOV tests
MatejKastak Sep 16, 2018
649d74d
Test for STR instruction and test header comments
MatejKastak Sep 20, 2018
928f3e3
STP instruction + tests, pc in new enum, get op addr function
MatejKastak Sep 20, 2018
bf88c1e
LDR + STR, LDR tests from ARM, LDP stub
MatejKastak Sep 21, 2018
8916e12
Implemented parent register handling
MatejKastak Sep 22, 2018
9b62769
LLVM data layout modified for ARM64
MatejKastak Sep 22, 2018
372f896
Removed useless debug output
MatejKastak Sep 23, 2018
d369bfb
getCarryRegister for ARM64 fixed
MatejKastak Sep 23, 2018
8631ae7
Store register ZEXT_TRUNC, 32bit tests baseline + tests
MatejKastak Sep 23, 2018
7626662
Zero extension tests for ADD and MOV 32bit variants
MatejKastak Sep 23, 2018
58381bb
Implemented BL instruction
MatejKastak Sep 23, 2018
f0f9195
Implemented RET instruction
MatejKastak Sep 23, 2018
8af607c
Implemented LDP instruction
MatejKastak Sep 23, 2018
ed53e67
Implemeneted ADRP instruction
MatejKastak Sep 24, 2018
8c24571
enable arm64 in decompiler.py and add arm64 architecture
MatejKastak Sep 26, 2018
69b78f7
Arm64 ABI implementation
MatejKastak Sep 26, 2018
f04458b
Arm64 decoder ported from Arm
MatejKastak Sep 26, 2018
f225f0c
Arm64 imm operand shifts should not update flags by default.
MatejKastak Sep 27, 2018
f884890
Operand register extension generator + 64bit variant extension tests
MatejKastak Sep 27, 2018
8ed7de9
Arm64 Zero/Sign extension 32bit variant tests
MatejKastak Sep 28, 2018
4c90fca
Implemented SUB instruction
MatejKastak Sep 28, 2018
f1da674
Implemented BR instruction
MatejKastak Sep 28, 2018
e551941
Arm64 syscall id register is X8
MatejKastak Sep 28, 2018
118eada
Specified call and return instruction ID for implemented instruction
MatejKastak Sep 28, 2018
da65a75
Merge branch 'master' into arm-prep
MatejKastak Jan 31, 2019
d7bc4c3
Fixed compilation after merge
MatejKastak Jan 31, 2019
51645be
Generate pseudoasm instruction when translation routine is not found
MatejKastak Jan 31, 2019
8000ed7
Check preconditions in implemented arm64 instructions
MatejKastak Jan 31, 2019
d5f6296
Changed register generation to match other modules.
MatejKastak Jan 31, 2019
81e47e2
LDR instruction all 3 formats + tests
MatejKastak Feb 2, 2019
65d54ef
Binaries can now be decompiled
MatejKastak Feb 3, 2019
a370232
Generate condition codes for conditional instructions.
MatejKastak Feb 6, 2019
16e0725
ARM64: strb, strh instructions + tests
MatejKastak Feb 6, 2019
41add94
Arm64: conditional and unconditional branch instruction + tests
MatejKastak Feb 6, 2019
f4332ba
Arm64: Instruction ret can have optional register operand + test
MatejKastak Feb 6, 2019
732e021
Arm64: BLR instruction + test
MatejKastak Feb 6, 2019
c55d1d4
Arm64: CBNZ, CBZ instruction + test
MatejKastak Feb 7, 2019
29d4f88
Arm64: TBNZ, TBZ implementation + tests
MatejKastak Feb 7, 2019
6cf11dd
Arm64: LDR different size variants, sign/zero extend + tests
MatejKastak Feb 7, 2019
e84259e
Arm64: LDPSW instruction + tests
MatejKastak Feb 8, 2019
ece1754
Arm64: ADC instruction + tests
MatejKastak Feb 8, 2019
950f92f
Arm64: ADCS 32bit tests for flags
MatejKastak Feb 8, 2019
aa58cf0
Arm64: ADR, ADRP instruction + tests
MatejKastak Feb 9, 2019
52c8932
Arm64: AND, ANDS instruction + tests
MatejKastak Feb 9, 2019
00b2b83
Arm64: ASR instruction + tests
MatejKastak Feb 9, 2019
c9046df
Arm64: LSL, LSR, ROR instructions + tests
MatejKastak Feb 9, 2019
e66c51a
Arm64: SUB, SBC flags + tests
MatejKastak Feb 9, 2019
8832ed1
Arm64: CMP, CMN instructions + tests
MatejKastak Feb 9, 2019
a0e1ff2
Arm64: CSEL instruction + tests
MatejKastak Feb 10, 2019
d689563
Arm64: CSET, CSETM instruction + tests
MatejKastak Feb 10, 2019
e4261a8
Arm64: MUL instruction + tests
MatejKastak Feb 11, 2019
fe17869
Arm64: MADD instruction + tests
MatejKastak Feb 11, 2019
293615a
Arm64: MSUB instruction + tests
MatejKastak Feb 11, 2019
9454975
Arm64: MNEG instruction + tests
MatejKastak Feb 11, 2019
81f9c83
Arm64: NEG, NEGS instruction + tests
MatejKastak Feb 11, 2019
62a7b9b
Arm64: NGC, NGCS initial implementation + tests
MatejKastak Feb 11, 2019
72bad32
Merge branch 'master' of https://github.com/avast-tl/retdec into arm-…
MatejKastak Feb 13, 2019
f8b029f
Arm64: SDIV, UDIV instruction + tests
MatejKastak Feb 14, 2019
d145dc6
Arm64: Fix correct semantics for SBC and NEG instructions
MatejKastak Feb 15, 2019
2f45d2d
Arm64: SMADDL, UMADDL instruction + tests
MatejKastak Feb 15, 2019
3a666ed
Arm64: UMSUBL, SMSUBL instruction + tests
MatejKastak Feb 15, 2019
3684a9b
Arm64: SMNEG, UMNEG instruction + tests
MatejKastak Feb 15, 2019
7a87054
Arm64: UMULL, SMULL, UMULH, SMULH instruction + tests
MatejKastak Feb 16, 2019
48772de
Arm64: Conditional select operation instruction + tests
MatejKastak Feb 16, 2019
f410655
Arm64: CINC, CINV, CNEG tests
MatejKastak Feb 17, 2019
18045b9
Arm64: EON, EOR instruction + tests
MatejKastak Feb 18, 2019
1f7f82c
Arm64: ORN, ORR instruction + tests
MatejKastak Feb 19, 2019
22a3f14
Arm64: TST instruction + tests
MatejKastak Feb 19, 2019
6455608
Arm64: EXTR instruction + tests
MatejKastak Feb 19, 2019
a89a677
Arm64: Extend instructions + tests
MatejKastak Feb 20, 2019
96c944d
Arm64: CCMN, CCMP instruction + tests
MatejKastak Feb 21, 2019
b268133
Arm64: NOP instruction + tests
MatejKastak Feb 22, 2019
b6b2fa9
Arm64: REV, RBIT, CLZ instructions + tests
MatejKastak Feb 22, 2019
7dc1287
Arm64: BIC instruction + tests
MatejKastak Feb 22, 2019
f1dc1e3
Arm64: Unpriviledged loads/stores instructions + tests
MatejKastak Feb 23, 2019
cde4008
Arm64: Load/Store exclusive instructions + tests
MatejKastak Feb 23, 2019
9833fbe
ARM64: LDAXR instruction variants + tests
MatejKastak Feb 24, 2019
3590595
Arm64: LDAR instruction variants + tests
MatejKastak Feb 24, 2019
4d4ed83
Arm64, llvmir-emul: don't lower bitreverse intrinsic
MatejKastak Feb 27, 2019
23bcf77
Arm64: FP environment + basic unary and binary operations + tests
MatejKastak Feb 28, 2019
881876c
Arm64: FMIN, FMINNM, FMAX, FMAXNM instruction + tests
MatejKastak Feb 28, 2019
35b2d35
Arm64: FCMP, FCCMP, FCVT, {U, S}CVTF instructions + tests
MatejKastak Mar 1, 2019
d980328
Arm64: FCVTZS, FCVTZU instructions + tests
MatejKastak Mar 1, 2019
7b88475
Arm64, bin2llvmir: Decoder should not analyse stack.
MatejKastak Mar 1, 2019
309baeb
Merge branch 'master' into arm-prep
MatejKastak Mar 3, 2019
bac43b4
Arm64: MOVK instruction + tests
MatejKastak Mar 5, 2019
b8b28ec
Arm64: MOVN instructions + tests
MatejKastak Mar 5, 2019
affd7d3
Merge master with arm-prep
MatejKastak Mar 6, 2019
e9b2866
Architecture: Change arm architectures to account for arm64
MatejKastak Mar 7, 2019
c5f421f
Architecture: Removed the wrong architecture types
MatejKastak Mar 7, 2019
dbbb137
Arm64: XZR loads zero and discards result when written
MatejKastak Mar 9, 2019
2a5e865
Arm64: STR and LDR instructions now determine correct register size
MatejKastak Mar 9, 2019
275d44e
Arm64: Syscall optimalization and detection
MatejKastak Mar 13, 2019
f64fba4
Arm64: MOVI instructions + tests, Vector and half register
MatejKastak Mar 16, 2019
5012585
Arm64: STR and LDR tests
MatejKastak Mar 16, 2019
891db78
Arm64: Removed zero division semantics from llvmir
MatejKastak Mar 21, 2019
b56101e
Merge branch 'master' into arm-prep
MatejKastak Mar 22, 2019
2ee7c91
Arm64: FMOV instruction with immediate values
MatejKastak Mar 22, 2019
3c6b0d3
Revert "Arm64, bin2llvmir: Decoder should not analyse stack."
MatejKastak Mar 22, 2019
52ac3c8
Merge branch 'master' into arm-prep
MatejKastak Mar 26, 2019
e92523d
Arm64: Simplified and documented some code
MatejKastak Mar 27, 2019
aa97f92
Arm64: Fixed documentation build
MatejKastak Mar 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/capstone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ ExternalProject_Add(capstone-project
-DCAPSTONE_X86_ATT_DISABLE=OFF
# Enabled architectures.
-DCAPSTONE_ARM_SUPPORT=ON
-DCAPSTONE_ARM64_SUPPORT=ON
-DCAPSTONE_MIPS_SUPPORT=ON
-DCAPSTONE_PPC_SUPPORT=ON
-DCAPSTONE_X86_SUPPORT=ON
# Disabled architectures.
-DCAPSTONE_ARM64_SUPPORT=OFF
-DCAPSTONE_M68K_SUPPORT=OFF
-DCAPSTONE_SPARC_SUPPORT=OFF
-DCAPSTONE_SYSZ_SUPPORT=OFF
Expand Down
9 changes: 9 additions & 0 deletions include/retdec/bin2llvmir/optimizations/decoder/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ class Decoder : public llvm::ModulePass
void patternsPseudoCall_arm(llvm::CallInst*& call, AsmInstruction& pAi);
cs_mode determineMode_arm(cs_insn* insn, utils::Address& target);

// ARM64 specific.
//
private:
std::size_t decodeJumpTargetDryRun_arm64(
const JumpTarget& jt,
ByteData bytes,
bool strict = false);
void patternsPseudoCall_arm64(llvm::CallInst*& call, AsmInstruction& pAi);

// MIPS specific.
//
private:
Expand Down
4 changes: 4 additions & 0 deletions include/retdec/bin2llvmir/optimizations/syscalls/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class SyscallFixer : public llvm::ModulePass
bool runArm_linux_32();
bool runArm_linux_32(AsmInstruction ai);

bool runArm64();
bool runArm64_linux_64();
bool runArm64_linux_64(AsmInstruction ai);

bool runMips();
bool runMips_linux();
bool runMips_linux(AsmInstruction ai);
Expand Down
35 changes: 35 additions & 0 deletions include/retdec/capstone2llvmir/arm64/arm64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file include/retdec/capstone2llvmir/arm64/arm64.h
* @brief ARM64 specialization of translator's abstract public interface.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_H
#define RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_H

#include "retdec/capstone2llvmir/arm64/arm64_defs.h"
#include "retdec/capstone2llvmir/capstone2llvmir.h"

namespace retdec {
namespace capstone2llvmir {

/**
* ARM64 specialization of translator's abstract public interface.
*/
class Capstone2LlvmIrTranslatorArm64 : virtual public Capstone2LlvmIrTranslator
{
public:
virtual ~Capstone2LlvmIrTranslatorArm64() {};

public:
/**
* @return Capstone register that is parent to the specified Capstone
* register @p r. Register can be its own parent.
*/
virtual uint32_t getParentRegister(uint32_t r) const = 0;
};

} // namespace capstone2llvmir
} // namespace retdec

#endif /* RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_H */
21 changes: 21 additions & 0 deletions include/retdec/capstone2llvmir/arm64/arm64_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file include/retdec/capstone2llvmir/arm64/arm64_defs.h
* @brief Additional (on top of Capstone) definitions for ARM64 translator.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_DEFS_H
#define RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_DEFS_H

#include <capstone/arm64.h>

enum arm64_reg_cpsr_flags
{
ARM64_REG_CPSR_N = ARM64_REG_ENDING + 1,
ARM64_REG_CPSR_Z,
ARM64_REG_CPSR_C,
ARM64_REG_CPSR_V,
ARM64_REG_PC,
};

#endif /* RETDEC_CAPSTONE2LLVMIR_ARM64_ARM64_DEFS_H */
1 change: 1 addition & 0 deletions include/retdec/capstone2llvmir/capstone2llvmir.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// These are additions to capstone - include them all here.
#include "retdec/capstone2llvmir/arm/arm_defs.h"
#include "retdec/capstone2llvmir/arm64/arm64_defs.h"
#include "retdec/capstone2llvmir/mips/mips_defs.h"
#include "retdec/capstone2llvmir/powerpc/powerpc_defs.h"
#include "retdec/capstone2llvmir/x86/x86_defs.h"
Expand Down
7 changes: 5 additions & 2 deletions include/retdec/config/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class Architecture
bool isPic32() const;
bool isMipsOrPic32() const;
bool isArm() const;
bool isArm32() const;
bool isArm64() const;
bool isThumb() const;
bool isArmOrThumb() const;
bool isArm32OrThumb() const;
bool isX86() const;
bool isX86_16() const;
bool isX86_32() const;
Expand All @@ -51,6 +52,8 @@ class Architecture
void setIsPic32();
void setIsArm();
void setIsThumb();
void setIsArm32();
void setIsArm64();
void setIsX86();
void setIsPpc();
void setIsEndianLittle();
Expand Down Expand Up @@ -84,7 +87,6 @@ class Architecture
MIPS,
PIC32,
ARM,
THUMB,
X86,
PPC,
};
Expand All @@ -97,6 +99,7 @@ class Architecture
private:
std::string _name;
unsigned _bitSize = 32;
bool _thumbFlag = false;
eEndian _endian = E_UNKNOWN;
eArch _arch = eArch::UNKNOWN;
};
Expand Down
13 changes: 8 additions & 5 deletions scripts/retdec-decompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def parse_args(args):
parser.add_argument('-a', '--arch',
dest='arch',
metavar='ARCH',
choices=['mips', 'pic32', 'arm', 'thumb', 'powerpc', 'x86', 'x86-64'],
help='Specify target architecture [mips|pic32|arm|thumb|powerpc|x86|x86-64].'
choices=['mips', 'pic32', 'arm', 'thumb', 'arm64', 'powerpc', 'x86', 'x86-64'],
help='Specify target architecture [mips|pic32|arm|thumb|arm64|powerpc|x86|x86-64].'
' Required if it cannot be autodetected from the input (e.g. raw mode, Intel HEX).')

parser.add_argument('-e', '--endian',
Expand Down Expand Up @@ -882,7 +882,10 @@ def decompile(self):
arch_full = arch_full.lower()

# Strip comments in parentheses and all trailing whitespace
self.arch = arch_full.split(' ')[0]
if 'aarch64' in arch_full:
self.arch = 'arm64'
else:
self.arch = arch_full.split(' ')[0]

# Get object file format.
self.format, _, _ = CmdRunner.run_cmd([config.CONFIGTOOL, self.config_file, '--read', '--format'], buffer_output=True)
Expand All @@ -905,7 +908,7 @@ def decompile(self):

ords_dir = ''
# Check whether the correct target architecture was specified.
if self.arch in ['arm', 'thumb']:
if self.arch in ['arm', 'thumb', 'arm64']:
ords_dir = config.ARM_ORDS_DIR
elif self.arch in ['x86', 'x86-64']:
ords_dir = config.X86_ORDS_DIR
Expand All @@ -917,7 +920,7 @@ def decompile(self):

self._cleanup()
utils.print_error('Unsupported target architecture \'%s\'. Supported architectures: '
'Intel x86, Intel x86-64, ARM, ARM + Thumb, MIPS, PIC32, PowerPC.' % self.arch)
'Intel x86, Intel x86-64, ARM, ARM + Thumb, ARM64, MIPS, PIC32, PowerPC.' % self.arch)
return 1

# Check file class (e.g. 'ELF32', 'ELF64'). At present, we can only decompile 32-bit files.
Expand Down
2 changes: 2 additions & 0 deletions src/bin2llvmir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(BIN2LLVMIR_SOURCES
optimizations/cond_branch_opt/cond_branch_opt.cpp
optimizations/constants/constants.cpp
optimizations/decoder/arm.cpp
optimizations/decoder/arm64.cpp
optimizations/decoder/bbs.cpp
optimizations/decoder/decoder_ranges.cpp
optimizations/decoder/decoder_init.cpp
Expand Down Expand Up @@ -65,6 +66,7 @@ set(BIN2LLVMIR_SOURCES
optimizations/stack_pointer_ops/stack_pointer_ops.cpp
optimizations/value_protect/value_protect.cpp
optimizations/syscalls/arm.cpp
optimizations/syscalls/arm64.cpp
optimizations/syscalls/mips.cpp
optimizations/syscalls/syscalls.cpp
optimizations/syscalls/x86.cpp
Expand Down
111 changes: 111 additions & 0 deletions src/bin2llvmir/optimizations/decoder/arm64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @file src/bin2llvmir/optimizations/decoder/arm64.cpp
* @brief Decoding methods specific to ARM64 architecture.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include "retdec/bin2llvmir/optimizations/decoder/decoder.h"
#include "retdec/bin2llvmir/utils/capstone.h"
#include "retdec/utils/string.h"

using namespace retdec::utils;
using namespace retdec::capstone2llvmir;
using namespace llvm;

namespace retdec {
namespace bin2llvmir {

bool insnWrittesPcArm64(csh& ce, cs_insn* insn)
{
// Aarch64 reference manual states:
// Software cannot write directly to the PC. It can only
// be updated on a branch, exception entry or exception return.

// Set of instructions that can modify PC
const std::set<unsigned int> branch_instructions = {
ARM64_INS_B,
ARM64_INS_CBNZ,
ARM64_INS_CBZ,
ARM64_INS_TBNZ,
ARM64_INS_TBZ,
ARM64_INS_BL,
ARM64_INS_BLR,
ARM64_INS_BR,
ARM64_INS_RET,
ARM64_INS_ERET,
};

return (branch_instructions.count(insn->id) != 0);
}

bool looksLikeArm64FunctionStart(cs_insn* insn)
{
// Create stack frame 'stp x29, x30, [sp, -48]!'
return insn->id == ARM64_INS_STP;
}

std::size_t Decoder::decodeJumpTargetDryRun_arm64(
const JumpTarget& jt,
ByteData bytes,
bool strict)
{

if (strict)
{
return true;
}

static csh ce = _c2l->getCapstoneEngine();

uint64_t addr = jt.getAddress();
std::size_t nops = 0;
bool first = true;
// bytes.first -> Code
// bytes.second -> Code size
// addr -> Address of first instruction
while (cs_disasm_iter(ce, &bytes.first, &bytes.second, &addr, _dryCsInsn))
{

if (strict && first && !looksLikeArm64FunctionStart(_dryCsInsn))
{
return true;
}

if (jt.getType() == JumpTarget::eType::LEFTOVER
&& (first || nops > 0)
&& _abi->isNopInstruction(_dryCsInsn))
{
nops += _dryCsInsn->size;
}
else if (jt.getType() == JumpTarget::eType::LEFTOVER
&& nops > 0)
{
return nops;
}

if (_c2l->isControlFlowInstruction(*_dryCsInsn)
|| insnWrittesPcArm64(ce, _dryCsInsn))
{
return false;
}

first = false;
}

if (nops > 0)
{
return nops;
}

// There is a BB right after, that is not a function start.
//
if (getBasicBlockAtAddress(addr) && getFunctionAtAddress(addr) == nullptr)
{
return false;
}

return true;
}

} // namespace bin2llvmir
} // namespace retdec
12 changes: 8 additions & 4 deletions src/bin2llvmir/optimizations/decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,14 @@ std::size_t Decoder::decodeJumpTargetDryRun(
{
return decodeJumpTargetDryRun_x86(jt, bytes, strict);
}
else if (_config->getConfig().architecture.isArmOrThumb())
else if (_config->getConfig().architecture.isArm32OrThumb())
{
return decodeJumpTargetDryRun_arm(jt, bytes, strict);
}
else if (_config->getConfig().architecture.isArm64())
{
return decodeJumpTargetDryRun_arm64(jt, bytes, strict);
}
else if (_config->getConfig().architecture.isMipsOrPic32())
{
return decodeJumpTargetDryRun_mips(jt, bytes, strict);
Expand All @@ -400,7 +404,7 @@ std::size_t Decoder::decodeJumpTargetDryRun(

cs_mode Decoder::determineMode(cs_insn* insn, utils::Address& target)
{
if (_config->getConfig().architecture.isArmOrThumb())
if (_config->getConfig().architecture.isArm32OrThumb())
{
return determineMode_arm(insn, target);
}
Expand Down Expand Up @@ -472,7 +476,7 @@ bool Decoder::getJumpTargetsFromInstruction(
CallInst*& pCall = tr.branchCall;
auto nextAddr = addr + tr.size;

if (_config->getConfig().architecture.isArmOrThumb())
if (_config->getConfig().architecture.isArm32OrThumb())
{
AsmInstruction ai(tr.llvmInsn);
patternsPseudoCall_arm(pCall, ai);
Expand Down Expand Up @@ -1554,7 +1558,7 @@ void Decoder::finalizePseudoCalls()
// TODO: what about other possible LR stores? e.g. see
// patternsPseudoCall_arm().
//
if (_config->getConfig().architecture.isArmOrThumb()
if (_config->getConfig().architecture.isArm32OrThumb()
&& icf)
if (auto* st = dyn_cast<StoreInst>(i))
{
Expand Down
10 changes: 8 additions & 2 deletions src/bin2llvmir/optimizations/decoder/decoder_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ void Decoder::initTranslator()
case 32: basicMode = CS_MODE_32; break;
}
}
else if (a.isArmOrThumb()
else if (a.isArm32OrThumb()
&& a.getBitSize() == 32)
{
arch = CS_ARCH_ARM;
basicMode = CS_MODE_ARM; // We start with ARM mode even for THUMB.
}
else if (a.isArm64())
{
arch = CS_ARCH_ARM64;
basicMode = CS_MODE_ARM;
}
else
{
throw std::runtime_error("Unsupported architecture.");
Expand Down Expand Up @@ -188,7 +193,8 @@ void Decoder::initRanges()

auto& arch = _config->getConfig().architecture;
unsigned a = 0;
a = arch.isArmOrThumb() ? 2 : a;
a = arch.isArm32OrThumb() ? 2 : a;
a = arch.isArm64() ? 4 : a;
a = arch.isMipsOrPic32() ? 4 : a;
a = arch.isPpc() ? 4 : a;
_ranges.setArchitectureInstructionAlignment(a);
Expand Down
6 changes: 5 additions & 1 deletion src/bin2llvmir/optimizations/decoder/ir_modifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ llvm::GlobalVariable* Decoder::getCallReturnObject()
{
return _abi->getRegister(PPC_REG_R3);
}
else if (_config->getConfig().architecture.isArmOrThumb())
else if (_config->getConfig().architecture.isArm32OrThumb())
{
return _abi->getRegister(ARM_REG_R0);
}
else if (_config->getConfig().architecture.isArm64())
{
return _config->getLlvmRegister("r0");
}

assert(false);
return nullptr;
Expand Down
Loading