Learning to Reverse DNNs from AI Programs Automatically

Simin Chen, Hamed Khanpour, Cong Liu, Wei Yang

Abstract

With the privatization deployment of DNNs on edge devices, the security of on-device DNNs has raised significant concern. To quantify the model leakage risk of on-device DNNs automatically, we propose NNReverse, the first learning-based method which can reverse DNNs from AI programs without domain knowledge. NNReverse trains a representation model to represent the semantics of binary code for DNN layers. By searching the most similar function in our database, NNReverse infers the layer type of a given function's binary code. To represent assembly instructions semantics precisely, NNReverse proposes a more fine-grained embedding model to represent the textual and structural-semantic of assembly functions.

Introduction

As Deep Neural Networks (DNNs) are increasingly deployed on edge devices for real-time inference, they are often shipped as compiled binary programs to protect intellectual property. However, these binaries are not immune to reverse engineering. Traditional model extraction attacks typically focus on "functionality attacks," where an adversary attempts to mimic a model's behavior by querying its API. In contrast, this work addresses the more severe "steal attack": reconstructing the exact architecture and parameters directly from the compiled binary file.

Reversing DNNs from binaries presents two primary challenges. First, the semantic complexity of modern DNNs, which may contain hundreds of layers, results in machine code that is nearly incomprehensible to human auditors. Second, cross-platform variance means that the same logical DNN operation (e.g., a convolution) will manifest as vastly different assembly instructions when compiled for different hardware architectures like Intel x86 or ARM.

The NNReverse Framework

To address these challenges, we introduce NNReverse, a learning-based framework designed to automatically reverse-engineer DNNs from compiled AI programs. The framework operates in two distinct phases: an offline knowledge-building phase and an online reconstruction phase.

The NNReverse framework consists of an offline step for building a kernel vector database and an online step for reversing the victim AI program.

In the Offline Phase, NNReverse constructs a database of "fingerprints" for common DNN kernels (e.g., Conv2d, Dense, ReLU). It trains a representation model to map these kernels into a high-dimensional vector space. In the Online Phase, a victim AI program is decompiled into assembly functions. These functions are then converted into vectors using the pre-trained model. By performing binary matching against the vector database, NNReverse identifies the layer types and subsequently reconstructs the entire model architecture and parameters.

Fine-Grained Representation Learning

The core innovation of NNReverse lies in its fine-grained embedding model, which captures both the textual and structural semantics of assembly functions. Unlike previous methods that treat instructions as simple tokens, NNReverse decomposes them to extract deeper meaning.

The fine-grained embedding model processes assembly functions through sequential and structural paths before fusing the features.

Textual and Structural Semantics

  1. Textual Semantics: Instructions are split into opcodes and operands. To handle the volatility of memory addresses and immediate values, a "blur strategy" is employed. This strategy replaces specific values with generic tokens (e.g., a large token for values exceeding a threshold), effectively mitigating Out-of-Vocabulary (OOV) issues and focusing the model on functional behavior.
  2. Structural Semantics: Recognizing that the logic of a mathematical operation is often reflected in its control flow, NNReverse represents assembly functions as Control Flow Graphs (CFGs). It utilizes the Weisfeiler-Lehman subgraph algorithm to capture the topology of these graphs, providing a structural signature that remains relatively stable across different platforms.

These two representations are fused into a single feature vector, allowing the model to distinguish between kernels that might look similar textually but differ structurally.

Experimental Evaluation

We evaluated NNReverse using a comprehensive dataset of over 80,000 assembly functions derived from popular open-source models (e.g., ResNet, VGG, BERT) compiled for four platforms: Android, Intel, ARM, and Aarch64.

Key Results

  • Identification Accuracy: NNReverse achieved F1 scores between 0.85 and 0.88 for vision models, significantly outperforming existing baselines like Asm2Vec.
  • Perfect Reconstruction: In case studies on ResNet-18, VGG-19, and MobileNet-V2, NNReverse achieved 100% reconstruction accuracy. The reversed models performed identically to the original source models.
  • Robustness: Sensitivity analysis demonstrated that the model's performance is stable across various embedding dimensions and context lengths, confirming its reliability for security auditing.

Conclusion

NNReverse demonstrates that the building blocks of DNNs are sufficiently enumerable and structurally distinct to be automatically reversed from binary code. While the framework is highly effective against standard compiled binaries, future work will explore its resilience against advanced code obfuscation and its adaptability to a wider variety of specialized AI compilers. This research highlights a critical security vulnerability in the current paradigm of on-device AI deployment.

Summary updated

Abstract

With the privatization deployment of DNNs on edge devices, the security of on-device DNNs has raised significant concern. To quantify the model leakage risk of on-device DNNs automatically, we propose NNReverse, the first learning-based method which can reverse DNNs from AI programs without domain knowledge. NNReverse trains a representation model to represent the semantics of binary code for DNN layers. By searching the most similar function in our database, NNReverse infers the layer type of a given function's binary code. To represent assembly instructions semantics precisely, NNReverse proposes a more fine-grained embedding model to represent the textual and structural-semantic of assembly functions.
BibTeX
@inproceedings{chen2022learning,
  author = {Simin Chen and Hamed Khanpour and Cong Liu and Wei Yang},
  title = {{Learning to Reverse DNNs from AI Programs Automatically}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2022},
  url = {https://openreview.net/forum?id=wWGNGOo0EZ},
}
Figure