Hex-Rays Blog: IDA Pro Tutorials & Reverse Engineering Tips

Recovering from Indirect Branch Obfuscation with Hex-Rays Microcode

Written by r3kapig | Nov 20, 2026

This article uses samples obfuscated with the Hikari-LLVM19 framework to present a recovery method for AArch64 indirect branch obfuscation. The method is not intended to handle all indirect branches. Different obfuscators may compute target addresses in entirely different ways, so the target resolver still needs to match the specific obfuscation semantics. However, once one or two successors can be reliably identified, the subsequent CFG completion, function range expansion, and microcode rewriting steps can be reused directly.

The indirect branch obfuscation in the samples used in this article has the following characteristics:

  • Machine-level branches use BR Xn.
  • Jump tables contain target addresses encrypted with a fixed offset.
  • Each indirect branch has one or two actual successors.

1. Background

1.1 Indirect Branch Obfuscation

Indirect branch obfuscation replaces explicit direct or conditional branches with a target-address calculation followed by a register-indirect branch. The original target is no longer encoded directly in the branch instruction. Instead, it is placed in a jump table and recovered at runtime using an index, an encrypted table entry, and an address adjustment.

A direct branch explicitly encodes its target address. When building the control-flow graph, IDA can read that address, create an edge between basic blocks, and continue analyzing code at the destination.

B       loc_1000 
B.EQ loc_2000

An indirect branch specifies only the register holding the target address. The actual destination depends on the value of X8 when execution reaches the branch.

BR      X8

The samples in this article first select an encrypted table entry based on a condition, then compute an address adjustment to recover the actual target:

CMP     W9, #0 
CSET W9, NE
LDR X8, [X20, W9, UXTW #3] ; Load the encrypted table entry
LDR W10, [X21] ; Load the encrypted key
EOR W10, W10, W11
NEG W10, W10
ADD X8, X8, W10, SXTW ; Apply the address adjustment
BR X8

The processor knows the value of X8 at runtime. But if IDA cannot statically determine the addresses that X8 may point to while building the CFG, it cannot create outgoing control-flow edges from this BR. The actual successors remain outside the current function, and Hex-Rays can generate microcode only for the incomplete function ranges. The result may be a function split into fragments, decompilation that ends prematurely, or pseudocode that still contains indirect branches.

Complete recovery therefore requires two steps:

  1. Resolve all actual successors of each BR.
  2. Feed those successors back into IDA to restore the complete function CFG.

1.2 Why Use Microcode?

A common approach to indirect branch obfuscation is to resolve the actual successors and then patch the binary directly. On AArch64, this works for most such obfuscation.

A branch with one successor is straightforward:

BR      X8

It can be replaced directly with:

B       target

For a branch with two successors, reordering instructions, removing the target-address calculations, and preserving unrelated instructions will usually allow a rewrite into:

B.cond  target_0 
B target_1

However, in some cases where indirect branch obfuscation is combined with control-flow flattening, patching the assembly directly becomes difficult.

The problem is more pronounced on x86. Its instructions have variable lengths, so indirect branches, direct branches, and conditional branches do not occupy the same number of bytes. Most arithmetic instructions also affect EFLAGS. Reusing the original flag condition that selects between two successors requires preserving the relationship between the definition and use of EFLAGS across intervening instructions. This often involves complex instruction reordering.

Microcode basic blocks are not constrained by machine instruction lengths or the original address layout. We therefore retain direct patching as a fast path for branches with one successor when it is safe, and use the IDA database and Hex-Rays microcode for branches with two successors that are unsuitable for an in-place rewrite.

2. Implementation

The target resolver in this article handles AArch64 BR instructions, but the overall process consists of three largely independent parts:

  1. Resolve the actual successors in Hex-Rays microcode.
  2. Complete the CFG and function ranges in the IDA database.
  3. Remove the synthetic switches used to complete the CFG when decompiling with F5.

The full process is shown below:

Indirect control-flow recovery process

2.1 Resolving the Actual Targets

We use forward abstract interpretation over a finite-set domain to analyze the entire function’s microcode at MMAT_PREOPTIMIZED and resolve one or two actual targets for each indirect branch.

Microcode at MMAT_PREOPTIMIZED retains the complete target-address calculation. At this stage, BR X8 typically appears as:

mov table_base, x8 
mov selector, w9
xds w9, x9
mov 8, x10
add x8, x9 * x10, x8
ldx [x8], x8 ; Encrypted table entry
mov encrypted_key, w10
xor w10, xor_key, w10
neg w10, w10
xds w10, x10
add x8, x10, x8 ; Recover the actual target
ijmp x8

This microcode does not directly reveal the final target. The interpreter walks through every microinstruction in each basic block, but implements state transitions only for the microcode operations used in the target-address calculation. Writes to registers, stack variables, or stack memory update the corresponding abstract state. Instructions that do not affect these states are skipped. If an unsupported instruction overwrites a tracked location, the old value for that location is discarded.

In these samples, Hikari extends the original branch’s Boolean condition to an integer and uses it as the index into a two-entry jump table. The index can therefore only be 0 or 1. At MMAT_PREOPTIMIZED, this Boolean value is commonly produced by a comparison instruction in the m_set* family, whose result the interpreter abstracts as {0, 1}.

Elsewhere, the same Boolean index may appear as an extraction of an integer’s least significant bit, such as and value, 1. Because the result contains only that bit, the index can still be conservatively represented as {0, 1} for this obfuscation, even if value is currently unknown.

This preserves both candidate table entries even when the current function ranges are incomplete or the condition’s inputs cannot yet be evaluated. It prevents the resolver from prematurely committing to a single successor based only on the currently visible state.

After propagation within each block, abstract states must also propagate between blocks along the CFG. For a basic block B, the entry and exit states satisfy:

Here, Predreached(B) denotes the predecessors already reached by the analysis. The join operator merges their candidate-value sets, and FB interprets the microinstructions in block B in order.

When handling loops, we must distinguish two cases:

  • A predecessor has not yet been reached.
  • A predecessor has been reached, but a value is unknown.

A back edge that has not yet been reached must not erase known values propagated from the entry path during the first iteration. The analysis should propagate the entry state first, then include the back edge’s state in the merge once that edge becomes reachable. This process repeats until the abstract states of all blocks stop changing.

At the fixed point, we read the abstract state of each m_ijmp target register. The one or two known addresses in that state form the complete successor set for the indirect branch.

2.2 Restoring the CFG and Function Ranges

Once the actual successors have been resolved, we must write the control-flow relationships back into the IDA database so the target code becomes part of the current function. The treatment depends on whether the indirect branch has one successor or two.

For a branch with one successor, the most direct approach on AArch64 is to patch:

BR X8

into:

B target

We then create a code reference. If the target code is not yet part of the current function, we also add its range to the function and trigger reanalysis.

This keeps the IDA database, the disassembly CFG, and the Hex-Rays microcode consistent. When microcode is generated again, the former indirect branch naturally becomes direct control flow, without requiring another synthetic structure.

For a branch with two successors, if the original location is unsuitable for an in-place rewrite using two machine instructions, we create a user-defined sparse switch at the BR instruction.

The synthetic switch simply tells IDA:

This indirect branch has two valid successors:  
target_0
target_1

There is no need to reconstruct the original selector at this stage. Immediately before BR X8, X8 already holds one of the two actual target addresses. We can therefore use X8 directly as the switch expression, with each target address serving as both the case value and the jump target:

switch expression: X8  

case target_0: goto target_0
case target_1: goto target_1

Once the synthetic switch has been saved, IDA can continue analyzing along both control-flow edges and incorporate the target basic blocks into the current function. Section 2.3 addresses the readability of the resulting pseudocode.

2.3 Restoring Structured Control Flow

The synthetic switch created in Section 2.2 completes the CFG. If left in place, however, it makes Hex-Rays produce a switch with only two cases and an awkward expression that obscures the original logic.

Pseudocode with the synthetic switch retained

After recovery, we therefore install a Hex-Rays hook. When the user presses F5, the hook finds the m_jtbl generated from the synthetic switch at MMAT_PREOPTIMIZED and replaces it with a regular conditional branch.

A Hex-Rays conditional branch has only one explicit target; its other target is represented by fallthrough. A microcode basic block can also have only one terminating instruction. We therefore cannot simply place a conditional branch followed by an m_goto at the end of the same block.

The resulting structure is:

Conditional branch and fallthrough through an intermediate block

The steps are:

  1. Identify the Boolean index from the reaching states of the whole function, then substitute 0 and 1 to determine the corresponding successors.
  2. Copy the Boolean condition to a Hex-Rays temporary register to preserve it during subsequent target-address calculations.
  3. Replace m_jtbl with m_jz.
  4. Insert an intermediate basic block after the current block.
  5. Add an m_goto to the other target in the intermediate block, update block types and predecessor/successor relationships, and ensure the conditional block’s succset[0] points to the immediately following fallthrough block.
  6. Invalidate the data-flow chains and call mba.verify(True) to check the microcode.

Once the synthetic switch has been replaced, subsequent Hex-Rays optimizations merge basic blocks, remove unreachable code, and perform structural analysis. The result can usually be expressed as natural if-else constructs, loops, or direct jumps.

Pseudocode after structured control flow is restored

Indirect control-flow recovery demonstration

Appendix

A. Sample Generation

The test samples use the IndirectBranch pass from Hikari-LLVM19 to obfuscate indirect control flow:

opt -load-pass-plugin=/path/to/libHikari.dylib \     
--passes='hikari(enable-indibran)' \
--indibran-enc-jump-target \
input.bc -o output.bc
  • enable-indibran enables indirect branch obfuscation, replacing direct LLVM IR branches with table lookups followed by indirectbr, which becomes BR Xn on AArch64.
  • indibran-enc-jump-target enables target address encryption: each table entry stores blockaddress plus a per-function offset, which is decrypted and subtracted at runtime to recover the target. For branches with one successor, the table index is also XOR-encoded with a random key; branches with two successors use the condition value, 0 or 1, to select an entry.

Other Hikari passes, such as control-flow flattening and bogus control flow, are disabled. This article focuses on the control-flow patterns produced by IndirectBranch and its target encryption.

B. Full Script

https://gist.github.com/GaoYuCan/c336d3964c1f8a7678290e50ad976c30

Download: hikari-indirect-branch-demo.zip

The archive contains the Python script, Keystone dependency, source code, and plain/obfuscated macOS arm64 binaries for the branch and AES examples.

Tested on IDA Pro 9.5 (build 261026), Hex-Rays 9.5.0.261026, and Keystone 0.9.2 on macOS arm64: recovery and rollback passed for 15 functions and 160 indirect branches, with no deprecation warnings.