Code Action Network for Binary Function Scope Identification

Van Nguyen, Trung Le, Tue Le, Khanh Nguyen, Olivier Y. de Vel, Paul Montague, John C. Grundy, Dinh Phung

Abstract

Function identification is a fundamental prerequisite for binary analysis, yet it remains challenging due to compiler optimizations that create non-contiguous code blocks and internal data gaps. We present the Code Action Network (CAN), a novel deep learning framework that models function scope identification as a sequence of actions: Next Inclusion (NI), Next Exclusion (NE), and Function End (FE). By employing a bidirectional recurrent neural network (Bi-RNN), CAN leverages global context to accurately delineate function boundaries. Our evaluation on a large-scale dataset of 2,200 binaries demonstrates that CAN, particularly the instruction-level variant (CAN-M), significantly outperforms state-of-the-art tools like IDA Pro and ByteWeight, achieving F1 scores frequently exceeding 98% while offering substantial training efficiency.

Introduction

In cybersecurity and reverse engineering, analyzing "stripped" binaries—where symbol tables and source code are absent—is a common necessity for malware detection and vulnerability research. The first critical step in this process is function identification. However, modern compilers often optimize code in ways that make functions non-contiguous, interspersing code with jump tables, data, or padding instructions (e.g., nop).

Existing methods often struggle with Function Scope Identification: the precise determination of which instructions belong to which function. Traditional heuristic-based tools and even some early machine learning approaches often fail when faced with complex entry/exit patterns or non-contiguous blocks. If the scope is incorrectly defined, downstream analyses such as control-flow graph (CFG) construction become unreliable.

The Code Action Network (CAN) Framework

The Code Action Network (CAN) reimagines function identification by drawing inspiration from the logic of a Turing machine. It treats the binary as a "tape" and uses a neural network to determine the appropriate "action" for each unit (byte or instruction) encountered by a pointer.

Action State Logic

As the pointer moves through the binary, the network assigns one of three action states to each unit:

  1. NI (Next Inclusion): The current item belongs to the active function; the pointer moves to the next item.
  2. NE (Next Exclusion): The current item is a gap (data or padding) and does not belong to the function; the pointer skips it.
  3. FE (Function End): The current item is the final element of the function; the subsequent item marks the start of a new function.
The CAN framework: (Left) Mapping binary units to action states NI, NE, and FE to define function scopes. (Right) The bidirectional RNN architecture used to process these sequences.

Neural Architecture

The core of CAN is a Bidirectional Recurrent Neural Network (Bi-RNN) utilizing Long Short-Term Memory (LSTM) cells. The bidirectional nature is crucial; it allows the model to consider both preceding and succeeding code context when making a decision at any given point. This global perspective enables the network to recognize structural patterns that indicate function boundaries even in the presence of optimizations.

Implementation: CAN-B vs. CAN-M

The researchers developed two distinct versions of the network:

  • CAN-B (Byte-level): Operates directly on raw bytes. While highly portable, it suffers from long sequence lengths, making it slower to train and more susceptible to the vanishing gradient problem.
  • CAN-M (Instruction-level): Utilizes the Capstone disassembler to process machine instructions. By operating at the instruction level, CAN-M exploits semantic relationships between operations. This approach results in shorter sequences, making CAN-M 4x faster to train than CAN-B while achieving higher accuracy.

Evaluation and Results

CAN was evaluated against a massive benchmark of 2,200 binaries, including Linux utilities (compiled with gcc and icc at various optimization levels) and Windows open-source projects.

The results indicate that CAN consistently outperforms state-of-the-art baselines, including IDA Pro, ByteWeight, and Nucleus. On the critical task of identifying the entire function boundary (the start-end pair), CAN-M achieved F1 scores between 98% and 99% across different architectures (ELF x86, PE x86-64). Furthermore, CAN proved robust in handling functions with multiple entry and exit styles, a common failure point for heuristic-based tools.

Conclusion and Future Work

The Code Action Network demonstrates that treating binary analysis as a sequence of discrete actions is a powerful paradigm for function scope identification. By leveraging bidirectional context, CAN successfully navigates the complexities of modern compiler optimizations.

While highly effective, the current model assumes a lack of nested functions (which are statistically rare) and relies on accurate disassembly for its most efficient variant (CAN-M). Future research may explore Transformer-based architectures or specialized models for heavily obfuscated and malicious code where standard disassembly might fail.

Summary updated

BibTeX
@inproceedings{nguyen2020code,
  author = {Van Nguyen and Trung Le and Tue Le and Khanh Nguyen and Olivier Y. de Vel and Paul Montague and John C. Grundy and Dinh Phung},
  title = {{Code Action Network for Binary Function Scope Identification}},
  booktitle = {PAKDD},
  year = {2020},
  doi = {10.1007/978-3-030-47426-3\_55},
}
Figure