Skip to content

Commit

Permalink
Pythonic Installer w/ Ghidra (#46)
Browse files Browse the repository at this point in the history
* Python Installer init

* remove old installer

* update paths for d2d

* bump versions since this breaks old versions

* updates to installer

* update readme
  • Loading branch information
mahaloz authored Oct 25, 2022
1 parent aa3d6dd commit 74ead62
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 226 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
*.egg-info
build*
*.pyc
*.gdb_history
*.gdb_history
decomp2dbg/decompilers
decomp2dbg/d2d.py
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE
include README.md
include d2d.py
recursive-include decompilers *.py *.json
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@ Currently supported in GDB with any additional plugin like [GEF](https://github.

[![Discord](https://img.shields.io/discord/900841083532087347?label=Discord&style=plastic)](https://discord.gg/wZSCeXnEvR)

## Install (script/fast)
The easiest and fastest way to install is using the `install.sh` script!
## Install
Install through pip, then use the built-in installer for decompilers:
```bash
./install.sh --ida /path/to/ida/plugins
pip3 install decomp2dbg && decomp2dbg --install
```

Make sure to define the correct option for your decompiler of choice. Use `--help` for more info!
Note: You may need to allow inbound connections on port 3662, or the port you use, for decomp2dbg to connect
to the decompiler.
This will open a prompt where you be asked to input the path to your decompiler of choice. For Ghidra installs,
you must follow the extra steps to enable extensions [here]().

> Note: If you are installing decomp2dbg with GEF or pwndbg it's important that in your ~/.gdbinit the
> decomp2dbg.py file is sourced after GEF or pwndbg.
**Note**: You may need to allow inbound connections on port 3662, or the port you use, for decomp2dbg to connect
to the decompiler. If you are installing decomp2dbg with GEF or pwndbg it's important that in your `~/.gdbinit` the
`d2d.py` file is sourced after GEF or pwndbg.

## Install (manual)
If you can't use the script (non-WSL Windows install for the decompiler), follow the steps below:
## Manual Install

Skip this if you were able to use the above install with no errors.
If you can't use the above built-in script (non-WSL Windows install for the decompiler), follow the steps below:

If you only need the decompiler side of things, copy the associated decompiler plugin to the
decompiler's plugin folder. Here is how you do it in IDA:

First, clone the repo:
```
git clone https://github.com/mahaloz/decomp2dbg.git
```

Copy all the files in `./decompilers/d2g_ida/` into your ida `plugins` folder:
```bash
cp -r ./decompilers/d2d_ida/* /path/to/ida/plugins/
Expand All @@ -39,7 +46,7 @@ cp -r ./decompilers/d2d_ida/* /path/to/ida/plugins/
If you also need to install the gdb side of things, use the line below:
```bash
pip3 install . && \
cp decomp2dbg.py ~/.decomp2dbg.py && echo "source ~/.decomp2dbg.py" >> ~/.gdbinit
cp d2d.py ~/.d2d.py && echo "source ~/.d2d.py" >> ~/.gdbinit
```

## Usage
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions decomp2dbg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from .clients.client import DecompilerClient
from .clients import GDBClient, GDBDecompilerClient
__version__ = "3.0.0"

try:
from .clients.client import DecompilerClient
from .clients import GDBClient, GDBDecompilerClient
except ImportError:
pass
30 changes: 30 additions & 0 deletions decomp2dbg/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import argparse

from .installer import Decomp2dbgInstaller


def main():
parser = argparse.ArgumentParser(
description="""
The decomp2dbg Command Line Util.
""",
epilog="""
Examples:
decomp2dbg --install
"""
)
parser.add_argument(
"--install", action="store_true", help="""
Install the decomp2dbg core to supported decompilers as plugins. This option will start an interactive
prompt asking for install paths for all supported decompilers. Each install path is optional and
will be skipped if not path is provided during install.
"""
)
args = parser.parse_args()

if args.install:
Decomp2dbgInstaller().install()


if __name__ == "__main__":
main()
90 changes: 90 additions & 0 deletions decomp2dbg/installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import textwrap
from urllib.request import urlretrieve

import pkg_resources
from pathlib import Path

from binsync.installer import Installer


class Decomp2dbgInstaller(Installer):
def __init__(self):
super(Decomp2dbgInstaller, self).__init__(targets=Installer.DECOMPILERS + ('gdb',))
self.plugins_path = Path(
pkg_resources.resource_filename("decomp2dbg", f"decompilers")
)

def display_prologue(self):
print(textwrap.dedent("""
__ ___ ____
____/ /__ _________ ____ ___ ____ |__ \ ____/ / /_ ____ _
/ __ / _ \/ ___/ __ \/ __ `__ \/ __ \__/ // __ / __ \/ __ `/
/ /_/ / __/ /__/ /_/ / / / / / / /_/ / __// /_/ / /_/ / /_/ /
\__,_/\___/\___/\____/_/ /_/ /_/ .___/____/\__,_/_.___/\__, /
/_/ /____/
Now installing decomp2dbg...
Please input decompiler/debugger install paths as prompted. Enter nothing to either use
the default install path if one exist, or to skip.
"""))

def install_gdb(self, path=None):
path = super().install_gdb(path=None)
if path is None:
return None

d2d_script_path_pkg = self.plugins_path.parent.joinpath("d2d.py")
with open(path, "r") as fp:
init_contents = fp.read()

write_str = f"source {str(d2d_script_path_pkg.absolute())}"
if write_str in init_contents:
self.warn("gdbinit already contains d2d source...")
return None

with open(path, "a") as fp:
fp.write(f"\n{write_str}\n")

return path

def install_ida(self, path=None):
ida_plugin_path = super().install_ida(path=path)
if ida_plugin_path is None:
return

src_d2d_ida_pkg = self.plugins_path.joinpath("d2d_ida").joinpath("d2d_ida")
src_d2d_ida_py = self.plugins_path.joinpath("d2d_ida").joinpath("d2d_ida.py")
dst_d2d_ida_pkg = ida_plugin_path.joinpath("d2d_ida")
dst_d2d_ida_py = ida_plugin_path.joinpath("d2d_ida.py")
self.link_or_copy(src_d2d_ida_pkg, dst_d2d_ida_pkg, is_dir=True)
self.link_or_copy(src_d2d_ida_py, dst_d2d_ida_py)
return dst_d2d_ida_pkg

def install_angr(self, path=None):
angr_plugin_path = super().install_angr(path=path)
if angr_plugin_path is None:
return None

src_d2d_angr_pkg = self.plugins_path.joinpath("d2d_angr")
dst_d2d_angr_pkg = angr_plugin_path.joinpath("d2d_angr")
self.link_or_copy(src_d2d_angr_pkg, dst_d2d_angr_pkg, is_dir=True)
return dst_d2d_angr_pkg

def install_ghidra(self, path=None):
ghidra_path = super().install_ghidra(path=path)
if ghidra_path is None:
return None

download_url = "https://github.com/mahaloz/decomp2dbg/releases/latest/download/d2d-ghidra-plugin.zip"
dst_path = ghidra_path.joinpath("d2d-ghidra-plugin.zip")
urlretrieve(download_url, dst_path)
return dst_path

def install_binja(self, path=None):
binja_plugin_path = super().install_binja(path=path)
if binja_plugin_path is None:
return None

src_path = self.plugins_path.joinpath("d2d_binja")
dst_path = binja_plugin_path.joinpath("d2d_binja")
self.link_or_copy(src_path, dst_path, is_dir=True)
return dst_path
192 changes: 0 additions & 192 deletions install.sh

This file was deleted.

Loading

0 comments on commit 74ead62

Please sign in to comment.