Skip to content

Commit

Permalink
[FEATURE] Resolve more arguments for Arm64 disasm
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jul 14, 2024
1 parent 13ccbab commit 20b0649
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion disasm/Disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using namespace pe_bear;
using namespace minidis;

const int Disasm::MAX_ARG_NUM = 2;
const int Disasm::MAX_ARG_NUM = 3;

void pe_bear::resetCond(cond_buf &buf)
{
Expand Down
30 changes: 16 additions & 14 deletions disasm/PeDisasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ offset_t PeDisasm::getArgRVA(int index, int argNum, bool &isOk) const
offset_t PeDisasm::getTargetVA(int index, bool &isOk) const
{
offset_t targetAddr = INVALID_ADDR;
for (int i = 0; i <= MAX_ARG_NUM; i++ ) {
for (int i = 0; i <= getMaxArgNum(); i++ ) {
targetAddr = getArgVA(index, i, isOk);
if (targetAddr != INVALID_ADDR) break;
}
Expand Down Expand Up @@ -211,19 +211,21 @@ bool PeDisasm::isCallToRet(int index) const
using namespace minidis;

if (!m_PE) return false;

const mnem_type mnem = this->getMnemType(index);
if (mnem != MT_CALL) return false;
//is pointer to RET?
static const BYTE OP_RET = 0xc3;

bool isOk = false;
uint64_t raw = this->getTargetRaw(index, isOk);
if (raw == INVALID_ADDR || !isOk) return false;

BYTE *cntnt = m_PE->getContent();
if (cntnt[raw] == OP_RET) {
return true;

if (this->m_arch == Executable::ARCH_INTEL) {
const mnem_type mnem = this->getMnemType(index);
if (mnem != MT_CALL) return false;
//is pointer to RET?
static const BYTE OP_RET = 0xc3;

bool isOk = false;
uint64_t raw = this->getTargetRaw(index, isOk);
if (raw == INVALID_ADDR || !isOk) return false;

BYTE *cntnt = m_PE->getContent();
if (cntnt[raw] == OP_RET) {
return true;
}
}
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion disasm/cdis/CDisasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace pe_bear {
class CDisasm : public Disasm
{
public:
//const static int MAX_ARG_NUM;

CDisasm();
~CDisasm();
Expand Down Expand Up @@ -120,6 +119,17 @@ class CDisasm : public Disasm
virtual bool isAddrOperand(int index) const;

bool isFollowable(const int y) const;

int getMaxArgNum() const
{
if (this->m_arch == Executable::ARCH_INTEL) {
return 2;
}
if (this->m_arch == Executable::ARCH_ARM) {
return 3;
}
return 2;
}

protected:
size_t _chunksCount() const { return this->m_table.size(); }
Expand Down
10 changes: 3 additions & 7 deletions pe-bear/DisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,17 +884,13 @@ QVariant DisasmModel::getHint(const QModelIndex &index) const

bool DisasmModel::isClickable(const QModelIndex &index) const
{
bool isValid = false;
if (index.isValid() == false) return false;

int y = index.row();
return myDisasm.isFollowable(y);
if (!index.isValid()) return false;
return myDisasm.isFollowable(index.row());
}

uint32_t DisasmModel::getCurrentChunkSize(const QModelIndex &index) const
{
bool isValid = false;
if (index.isValid() == false) return 0;
if (!index.isValid()) return 0;
return myDisasm.getChunkSize(index.row());
}

Expand Down

0 comments on commit 20b0649

Please sign in to comment.