Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add r2dec #1

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,27 @@ RUN pip install /mdec-base /mdec-snowman \
&& rm -rf /mdec-base /mdec-snowman

CMD ["python3", "-m", "mdecsnowman"]

#
# r2dec
#
FROM base as r2dec

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -qy build-essential cmake git

RUN cd /root \
&& git clone https://github.com/radareorg/radare2 \
&& cd radare2 \
&& ./sys/install.sh \
&& r2pm init \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& r2pm -ci r2dec

COPY common/mdec-base /mdec-base
COPY r2dec/mdec-r2dec /mdec-r2dec
RUN pip install /mdec-base /mdec-r2dec \
&& rm -rf /mdec-base /mdec-r2dec

CMD ["python3", "-m", "mdecr2dec"]
1 change: 1 addition & 0 deletions backend/r2dec/mdec-r2dec/mdecr2dec/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .service import R2decService
6 changes: 6 additions & 0 deletions backend/r2dec/mdec-r2dec/mdecr2dec/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from mdecr2dec import R2decService
from mdecbase import mdec_main


if __name__ == '__main__':
mdec_main(R2decService)
34 changes: 34 additions & 0 deletions backend/r2dec/mdec-r2dec/mdecr2dec/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import traceback
import r2pipe
import subprocess

from mdecbase import Service

class R2decService(Service):
"""
r2dec as a service
"""

def decompile(self, path: str) -> str:
"""
Decompile all the function in the binary located at `path`.
"""
r2 = r2pipe.open(path, flags=['-e bin.cache=true'])
r2.cmd('a'*6)
funcs = [func['name'] for func in r2.cmdj('aflj')]

out = []

for func in funcs:
try:
dec = r2.cmd(f'pdd @{func}')
out.append(dec)
except:
out.append(f'/* Decompilation of {func} failed:\n{traceback.format_exc()}\n*/')


return '\n'.join(out)

def version(self) -> str:
return subprocess.run(['/usr/local/bin/r2', '-v'], stdout=subprocess.PIPE).stdout.splitlines()[0].split()[1].decode('utf-8', 'ignore')

13 changes: 13 additions & 0 deletions backend/r2dec/mdec-r2dec/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3
from setuptools import setup

__version__ = '0.0.1'


setup(name='mdec-r2dec',
version=__version__,
description='mdec-r2dec',
packages=['mdecr2dec'],
install_requires=['mdec-base', 'r2pipe'],
python_requires='>=3.8'
)
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ services:
context: backend
target: snowman

r2dec:
build:
context: backend
target: r2dec

volumes:
nginx_logs:
8 changes: 8 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,13 @@ http {
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
}

location ~ ^/r2dec/(.*)$ {
set $service_host http://r2dec:8000;
limit_except GET HEAD POST { deny all; }
proxy_pass $service_host/$1;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}
9 changes: 8 additions & 1 deletion frontend/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ <h1><a href="https://github.com/mborgerson/mdec">mdec</a></h1>
Snowman
</a>
</li>
<li>
<a href="#" class="dropdown-item service-checkbox-link" for="r2dec-checkbox">
<input class="form-check-input service-checkbox" type="checkbox" data-value="r2dec" value="" id="r2dec-checkbox">
r2dec
</a>
</li>
</ul>
</div>
</div>
Expand All @@ -153,6 +159,7 @@ <h1><a href="https://github.com/mborgerson/mdec">mdec</a></h1>
<div class="editor-col" id="reko-col"><h3>Reko</h3><div class="version" id="reko-version"></div><div class="editor" id="reko-editor"></div></div>
<div class="editor-col" id="retdec-col"><h3>RetDec</h3><div class="version" id="retdec-version"></div><div class="editor" id="retdec-editor"></div></div>
<div class="editor-col" id="snowman-col"><h3>Snowman</h3><div class="version" id="snowman-version"></div><div class="editor" id="snowman-editor"></div></div>
<div class="editor-col" id="r2dec-col"><h3>r2dec</h3><div class="version" id="r2dec-version"></div><div class="editor" id="r2dec-editor"></div></div>
</div>

</div>
Expand All @@ -166,7 +173,7 @@ <h1><a href="https://github.com/mborgerson/mdec">mdec</a></h1>

<script type="text/javascript">

var services = ['angr', 'binja', 'ghidra', 'hexrays', 'reko', 'retdec', 'snowman'];
var services = ['angr', 'binja', 'ghidra', 'hexrays', 'reko', 'retdec', 'snowman', 'r2dec'];
var editors = {};
var version_boxes = {};
var options = [];
Expand Down