Skip to content

Commit

Permalink
Fix packet recognition of first and jump target packets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Sep 22, 2023
1 parent 9b9e840 commit 16d421e
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions librz/analysis/arch/hexagon/hexagon_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ static inline bool pkt_at_addr_is_emu_ready(const HexPkt *pkt, const ut32 addr)
}

/**
* \brief Returns the IL operation of the instruction at \p addr. This will always be NOP().
* \brief Returns the IL operation of the instruction at \p addr. This will always be EMPTY().
* Except for last instructions in a packet. Those will always return the complete IL operation
* of the packet or NULL if one instruction was not implemented or an error occurred.
*
* \param addr Address of the requested IL operation.
* \param get_pkt_op If true, it returns the IL operation of the whole packet at \p addr.
* It will return NOP() if there is no packet which starts at \p addr.
* It will return EMPTY() if there is no packet which starts at \p addr.
* If false, the bahvior is as documented above.
* \return RzILOpEffect* Sequence of operations to emulate the packet.
*/
Expand All @@ -363,30 +363,24 @@ RZ_IPI RzILOpEffect *hex_get_il_op(const ut32 addr, const bool get_pkt_op) {
RZ_LOG_WARN("Packet was NULL although it should have been disassembled at this point.\n");
return NULL;
}
if (!get_pkt_op) {
HexInsnContainer *hic = hex_get_hic_at_addr(state, addr);
if (state->just_init || might_has_jumped) {
// Assume that the instruction at the address the VM was initialized is the first instruction.
// Also make it valid if a jump let to this packet.
p->is_valid = true;
hic->pkt_info.first_insn = true;
state->just_init = false;
might_has_jumped = false;
}

if (!hic->pkt_info.last_insn) {
// Only at the last instruction we execute all il ops of the packet.
return NOP();
}
HexInsnContainer *hic = hex_get_hic_at_addr(state, addr);
if (state->just_init || might_has_jumped) {
// Assume that the instruction at the address the VM was initialized is the first instruction.
// Also make it valid if a jump let to this packet.
p->is_valid = true;
hic->pkt_info.first_insn = true;
state->just_init = false;
might_has_jumped = false;
}

if (!(get_pkt_op && pkt_at_addr_is_emu_ready(p, addr)) || !pkt_at_addr_is_emu_ready(p, p->pkt_addr)) {
return NOP();
if (!get_pkt_op && !hic->pkt_info.last_insn) {
// Only at the last instruction we execute all il ops of the packet.
return EMPTY();
}

if (!p->is_valid && !might_has_jumped) {
RZ_LOG_WARN("Attempt to execute invalid packet at 0x%" PFMT32x "\n", addr);
return NULL;
if (!(get_pkt_op && pkt_at_addr_is_emu_ready(p, addr)) || !pkt_at_addr_is_emu_ready(p, p->pkt_addr)) {
// Invalid packet, EMPTY()
return EMPTY();
}

if (!rz_vector_empty(p->il_ops)) {
Expand Down

0 comments on commit 16d421e

Please sign in to comment.