.ipa or .hbc files) to detect vulnerable npm packages by matching bytecode fingerprints against the Hedis database.
Prerequisites
Before analyzing an app, ensure you have:- Built the Hedis decompiler (
go build -o hermes-decompiler .) - Set up MongoDB connection (see Configuration)
- Built the fingerprint database (see Building Database)
- Obtained an
.ipafile or extracted.hbcbundle from a React Native app
Extracting Hermes Bytecode
From IPA Files
React Native iOS apps bundle Hermes bytecode in the.app bundle within the .ipa archive:
From Android APK Files
For Android apps, the bytecode is typically in theassets directory:
Analysis Modes
Basic Analysis
Analyze an HBC file with exact hash matching:- Disassembles the HBC file
- Extracts function fingerprints (structural, content IR1, content IR2)
- Queries the MongoDB database for exact hash matches
- Reports matched packages with version and React Native version
Fuzzy Matching Analysis
Enable fuzzy matching to detect packages even when bytecode differs slightly due to different optimization levels or minor version differences:-f/--fuzzy-matching— Enable Levenshtein distance-based fuzzy matching-c/--confidence-threshold— Minimum similarity score (0.0–1.0, default: 0.8)
- Compares raw IR strings (not just hashes) for functions ≥30 characters
- Uses length-based pre-filtering (±20% tolerance) for performance
- Calculates Levenshtein similarity for candidate matches
- Reports matches above the confidence threshold
Performance tuning for fuzzy matching
Performance tuning for fuzzy matching
Fuzzy matching is computationally expensive. Adjust these flags for large bundles:
--max-fuzzy-docs— Limit documents checked per IR string (default: 5000)--length-tolerance— Tighten length pre-filter (default: 0.2 = ±20%)
Specific Package Analysis
Compare a known package’s bytecode against an app bundle to verify inclusion:- Extracts fingerprints from both files
- Computes exact hash matches
- Runs fuzzy IR comparison for non-matching functions
- Outputs detailed match statistics to
results.txt
results.txt):
Understanding Results
Hash Types
Hedis uses three complementary fingerprint types per function (frompkg/hbc/types/functionobject.go:ToIR):
-
Structural Hash — SHA256 of instruction bigrams (opcode sequences)
- Captures control flow patterns
- Most stable across builds
-
Content IR1 Hash — SHA256 of non-identifier string literals
- Detects string constants (error messages, URLs, etc.)
- Uses trigram shingling for fuzzy matching
-
Content IR2 Hash — SHA256 of identifiers and object references
- Captures variable/function names
- More fragile (affected by minification)
Baseline Filtering
The analyzer automatically filters out React Native framework functions using thebaselines_v3 collection. Only application and third-party package functions are reported.
Troubleshooting
Error: failed to parse HBC file
Error: failed to parse HBC file
Cause: The file is not a valid Hermes bytecode file or uses an unsupported version.Solution:
- Verify the magic number:
hexdump -C file.hbc | head -n 1 - Check supported versions: v61–v96 (see Opcode Generation)
- If the version is newer, generate opcodes for that version
MONGO_CONNECTION_STRING is not set
MONGO_CONNECTION_STRING is not set
Cause: Environment variables not loaded.Solution:
Create a
.env file in go/hermes-decompiler/ with MongoDB configuration:No hash matches found
No hash matches found
Possible causes:
- Database is empty — run the pipeline to build fingerprints
- App uses a React Native version not in your database
- App’s Hermes compiler settings differ significantly from your baselines
- Check database contents:
mongosh hedis --eval 'db.hashes.countDocuments()' - Try fuzzy matching:
-f -c 0.75 - Build database for the app’s RN version
Fuzzy matching is too slow
Fuzzy matching is too slow
Solution:
- Reduce
--max-fuzzy-docsto 1000–2000 - Increase
--confidence-thresholdto 0.9 - Tighten
--length-toleranceto 0.1 - Use exact matching first, then fuzzy only for unmatched functions
Advanced Usage
Batch Analysis
Analyze multiple apps and aggregate results:Integration with CI/CD
Run Hedis analysis as part of your build pipeline to detect supply chain risks:Exporting Results
Save analysis results to a file for further processing:Next Steps
- Learn how to build the fingerprint database
- Understand configuration options
- Add support for new Hermes versions