Skip to main content

A tool for reverse engineering React Native bytecode files, including disassembly and decompilation facilities

Project description

hermes-dec is a reverse-engineering tool which can be used for disassembling and decompiling React Native files compiled into the Hermes VM bytecode (HBC) format.

For a wider presentation of its purpose, please see our presentation blog post.

Background

The Hermes VM for React Native was announced by Facebook on the 12 July 2019. The initial release of Hermes was version 0.1.0 (bytecode version 59), Github tags 0.0.1 to 0.0.3 correspond to pre-public release.

However, Hermes is the default compilation target for React Native on Android only since React Native 0.70 (released on 5 September 2022), as explained here.

Before that, and since React Native 0.60.2, the Hermes VM was an opt-in feature. Hermes for iOS is supported since version 0.64 of React Native (released on the 12 March 2021).

React Native is used by a wide variety of significant mobile applications, as exposed on the React Native showcase page.

A variety of technical documentation regarding the Hermes VM, which is published as an open-source project under the BSD license, including various design documents in the Markdown format, which can be read on Github as well as on Facebook's website for React documentation.

In Android applications released under the .APK format, the Hermes bytecode (HBC) file is usually located at:

$ file assets/index.android.bundle
assets/index.android.bundle: Hermes JavaScript bytecode, version 84

On non-Hermes based setups of React Native, this file usually contains minified/Webpacked JavaScript code.

Installation

The application itself only relies on the Python 3.x standard library for now.

You can install the tool through the following commands:

uv tool install git+https://github.com/P1sec/hermes-dec
# Or with pipx:
pipx install git+https://github.com/P1sec/hermes-dec

Certain internal development utilities may however require to install libclang for Python:

sudo apt install python3-clang-12

Usage

If you didn't install the tool system-wide using the command above, you can also download the source using this command and find the same utilities at the root:

$ git clone git@github.com:P1sec/hermes-dec.git
$ cd hermes-dec/

For an Android application, you should extract the Hermes bundle file from the .APK file through using your favorite unzipping tool (an .APK file is a renamed .ZIP archive):

$ 7z x my_application.apk
$ cd my_application

And check the type of the assets/index.android.bundle React Native bundle file which, in the case of a React Native-based application, should be either a plain-text minified JavaScript bundle file or an Hermes bytecode file:

$ file assets/index.android.bundle
assets/index.android.bundle: Hermes JavaScript bytecode, version 84

If the concerned file is indeed an Hermes JavaScript bytecode file, you may then decode most of its file headers using the following utility (which output may not be stable over time):

hbc-file-parser assets/index.android.bundle

You may then disassemble the contents of the React Native bytecode file to the /tmp/my_output_file.hasm output file using the following command (leave out the second parameter in order to send the disassembled content to the standard output):

hbc-disassembler assets/index.android.bundle /tmp/my_output_file.hasm

And perform the decompilation to pseudo-code (which is not valid JavaScript yet as it does not retranscribe loop/conditional structures) using the following command:

hbc-decompiler assets/index.android.bundle /tmp/my_output_file.js

Extra documentation

You can find auto-generated documentation for the Hermes VM opcodes here.

This is an useful tool to understand the generated assembly code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hermes_dec-0.1.0.tar.gz (60.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hermes_dec-0.1.0-py3-none-any.whl (138.3 kB view details)

Uploaded Python 3

File details

Details for the file hermes_dec-0.1.0.tar.gz.

File metadata

  • Download URL: hermes_dec-0.1.0.tar.gz
  • Upload date:
  • Size: 60.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hermes_dec-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c6c1ed86ec57a1a6cc5ac686b2f8e78c5400b044761194a5b101a1fa6c0a402
MD5 9e3cbbac5cf658bf4470c2c24dfe533f
BLAKE2b-256 bc720c49fd309c5964a374dafcc96fd2221dbc41db4f8f1384b66f4ce96fcf8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hermes_dec-0.1.0.tar.gz:

Publisher: python-publish.yml on P1sec/hermes-dec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hermes_dec-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hermes_dec-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 138.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hermes_dec-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e5cc7ae3df57f7f8a92d5db858f0371a0c6c6edcaf339b86cab8c27afdadc15
MD5 76a99b84361d30ee717b3577b7b98e36
BLAKE2b-256 d78f929f761c48ecbba3a6359938d44f08ac2cc60da7297d43f3dfafc74b2e52

See more details on using hashes here.

Provenance

The following attestation bundles were made for hermes_dec-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on P1sec/hermes-dec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page