Patch for the broken `--config` option in `retdec-decompiler`
Project description
RetDec-Config-Patch
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, trypip3
.
Building the Package
One could also build the package from scratch. This is particularly useful for development and contributions.
- Clone the repository.
- If you are using VSCode, set up the devcontainer.
- If that doesn't work, follow the next few steps.
- Otherwise, go to step 6.
- Create a new virtual environment by running
python3 -m venv venv
. - Activate the virtual environment.
- Install Poetry in the virtual environment using
pip install poetry
.- Check that Poetry was successfully installed by running
poetry --version
.
- Check that Poetry was successfully installed by running
- 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.
- Locate the
/share/retdec
folder within the RetDec installation. - Save the existing
decompiler-config.json
somewhere. - Replace the
decompiler-config.json
there with the custom configuration file. - Run
retdec-decompiler
without specifying the--config
flag (since this does nothing). - Delete the
decompiler-config.json
file in the/share/retdec
folder (which is actually the custom configuration file). - 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.
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
Built Distribution
File details
Details for the file retdec_config_patch-0.2.2.tar.gz
.
File metadata
- Download URL: retdec_config_patch-0.2.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 747780310ef01e45b8374211279fed9cc6a0c2666e575951bf9d1834bb668004 |
|
MD5 | da7c2eec2bd80d948104ae79381de55f |
|
BLAKE2b-256 | d447f2f13e48ea573063c719a9575ba56d25ff1cee98434df0120b6a1bb09766 |
File details
Details for the file retdec_config_patch-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: retdec_config_patch-0.2.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64ab337520460d3dcc74f9fcae6e40c05fe9f86a6f1d18eab8cb15fffdc04e6 |
|
MD5 | 658d415ae057bb0d2d90ffe80ae86ad7 |
|
BLAKE2b-256 | 1c6edf7785d429e3f80f88e4b03337b299dd7ebd3a9ae80aea83e8c62f85fc3f |