Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Technique:Identifying machine-learning models in applications

From ReverseEngineering.wiki
Technique
On this wiki Facts · Code · Notes · Topics

How to tell which ML runtime and model file an application embeds from magic bytes, file layout, library names and exports, with links to the format pages.

By file

Evidence Format
ASCII GGUF at offset 0 Format:GGUF (llama.cpp, ggml)
TFL3 at offset 4 Format:TensorFlow Lite model
uint64 N then { at byte 8, N small Format:safetensors
ZIP (PK) with data.pkl, version, byteorder Format:PyTorch model archive
Protobuf starting 08 <small ir_version> with producer_name and graph Format:ONNX model
Protobuf starting 08 <specificationVersion>; or a .mlmodelc folder Format:Core ML model

Protobuf formats have no magic: decode with the .proto of the format (Format:Protocol Buffers wire format) and check that fields 1, 2, 7 and 8 of ModelProto make sense.

By library

  • Library:ONNX Runtime: onnxruntime.dll / libonnxruntime.so, export OrtGetApiBase, version string 1.x.y.
  • TensorFlow Lite / LiteRT: libtensorflowlite, libtensorflowlite_jni.so on Android (Unverified names), TFLite version string.
  • llama.cpp/ggml: libllama, ggml*.dll or .so, strings starting with general.architecture and gguf.
  • Core ML: Apple frameworks, no library shipped in the app.

Steps

  1. List files by magic, not by extension (model files often have custom extensions or are packed in an asset archive or APK/IPA).
  2. Read the version fields (ir_version/opset, TFLite schema version, GGUF version) to know which runtime version can load it.
  3. Dump tensor names, shapes and dtypes from the header: all of these formats put them in a header or graph that can be read without the weights.
  4. Never load untrusted pickle-based files.

Encrypted or custom-wrapped models usually keep the runtime unchanged: hook the loader call (for example the buffer given to the ONNX Runtime CreateSessionFromArray slot, Unverified) rather than breaking the wrapper.

Quick magic table

Recognition by the first bytes, each from source (see the format pages): GGUF = Format:GGUF; bytes 4-7 TFL3 = Format:TensorFlow Lite model; 93 4E 55 4D 50 59 = Format:NumPy NPY and NPZ (.npz is a ZIP of .npy); PK\x03\x04 with data.pkl and data/0 members = Format:PyTorch model archive; first line 7767517 (or int32 DD 85 76 00) = Format:NCNN model; a FlatBuffer with root Net and no identifier, extension .mnn = Format:MNN model; a folder with Manifest.json and Data/ = .mlpackage (Format:Core ML model). Keras .h5 files are Format:HDF5 (signature 89 48 44 46 0D 0A 1A 0A, which can also sit at offset 512, 1024, 2048...) and .keras files are ZIPs. Unverified: the Keras part was not read from the Keras sources.