Skip to main content

RetDec-Config-Patch

PyPI - Python Version PyPI - Version PyPI - Downloads PyPI - License

Run Tests Publish Python Package

Patch for the broken --config option in RetDec.

The rationale for why this package exists is given below.

Installation

You can choose to install the patch from package or building from scratch. In either case, you will still need to activate the patch.

Installing from Package

The retdec-config-patch is available on PyPi. It is important to note that the package is to be installed system-wide so that the patch binary can be accessed across the whole system.

pip install retdec-config-patch

Troubleshooting:

  • If pip does not work, try pip3.

Building the Package

One could also build the package from scratch. This is particularly useful for development and contributions.

  1. Clone the repository.
  2. If you are using VSCode, set up the devcontainer.
    • If that doesn't work, follow the next few steps.
    • Otherwise, go to step 6.
  3. Create a new virtual environment by running python3 -m venv venv.
  4. Activate the virtual environment.
  5. Install Poetry in the virtual environment using pip install poetry.
    • Check that Poetry was successfully installed by running poetry --version.
  6. Install the dependencies by running poetry install.

Activating/Deactivating the Patch

Installing the package does not mean that the patch is active; you need to manually activate it.

Activating the Patch

To activate the patch, run

retdec-config-patch

This will perform the necessary checks before implementing the patch.

Once the patch is activated, you can use retdec-decompiler as per normal. The only difference is that the --config option works properly now.

If the patch is activated, a Using patched RetDec decompiler. message should appear before every run of retdec-decompiler. See the help message provided by RetDec by running

retdec-decompiler --help

Deactivating the Patch

If you want to deactivate the patch, run

undo-retdec-config-patch

Check that the patch was deactivated by running

retdec-decompiler

The Using patched RetDec decompiler. message should no longer appear.

License

The retdec-config-patch is licensed under the MIT license.

MIT License

Copyright (c) 2024 Ryan Kan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Appendix: Rationale

Why on earth does this package exist?

RetDec is a "retargetable machine-code decompiler based on LLVM". It is a very useful open-source project to help decompile binaries compiled using different architectures and on different platforms.

The trouble began when one notices that retdec-decompiler, the main program, offers a flag --config with the following help description.

        [--config] Specify JSON decompilation configuration file.

One would assume then that we could pass in a custom configuration file in order to adjust the decompilation process. For example, one can find an example configuration file in the RetDec repository. So one tries to create a custom configuration file, say my_config.json, which could contain

{
    "decompParams": {
        "verboseOut": false
    }
}

to disable verbose outputs, and then use this file in the retdec-decompiler by specifying the --config flag, i.e.

retdec-decompiler SOME_FILE --config my_config.json

However, this does not work at all. It appears as though RetDec ignores this configuration file and proceeds with running through all the steps of the decompilation.

So why does this happen?

It turns out that in retdec_decompiler.cpp, lines 995 to 1000, there is the following code,

    retdec::config::Config config;
    auto binpath = retdec::utils::getThisBinaryDirectoryPath();
    fs::path configPath(fs::canonical(binpath).parent_path());
    configPath.append("share");
    configPath.append("retdec");
    configPath.append("decompiler-config.json");

which explains why the configuration file that we specify is ignored — the code itself is hardcoded to use the default configuration file decompiler-config.json!

So, if we want to use our own configuration file, we need to perform the following steps.

  1. Locate the /share/retdec folder within the RetDec installation.
  2. Save the existing decompiler-config.json somewhere.
  3. Replace the decompiler-config.json there with the custom configuration file.
  4. Run retdec-decompiler without specifying the --config flag (since this does nothing).
  5. Delete the decompiler-config.json file in the /share/retdec folder (which is actually the custom configuration file).
  6. Copy over the original decompiler-config.json (which was saved in step 2) back into the /share/retdec folder.

These steps are what are performed by the patched retdec-decompiler executable provided by this package.

Metadata

Release files for retdec-config-patch 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retdec-config-patch 0.2.2
File Size Uploaded Provenance Actions
retdec_config_patch-0.2.2.tar.gz 12.3 kB Without provenance Details for retdec_config_patch-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for retdec-config-patch 0.2.2
File Interpreter ABI Platform Actions
retdec_config_patch-0.2.2-py3-none-any.whl Python 3 none any Details for retdec_config_patch-0.2.2-py3-none-any.whl

Total release size: 25.4 kB

Release files / retdec_config_patch-0.2.2.tar.gz

Download URL retdec_config_patch-0.2.2.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
747780310ef01e45b8374211279fed9cc6a0c2666e575951bf9d1834bb668004
BLAKE2b-256 checksum
How to use checksums
d447f2f13e48ea573063c719a9575ba56d25ff1cee98434df0120b6a1bb09766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / retdec_config_patch-0.2.2-py3-none-any.whl

Download URL retdec_config_patch-0.2.2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f64ab337520460d3dcc74f9fcae6e40c05fe9f86a6f1d18eab8cb15fffdc04e6
BLAKE2b-256 checksum
How to use checksums
1c6edf7785d429e3f80f88e4b03337b299dd7ebd3a9ae80aea83e8c62f85fc3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for retdec-config-patch 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page