Patch for the broken --config
option in RetDec.
The rationale for why this package exists is given below.
You can choose to install the patch from package or building from scratch. In either case, you will still need to activate the patch.
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
.
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
.
Installing the package does not mean that the patch is active; you need to manually activate it.
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
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.
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.
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.