-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Convert most Bash scripts to Python * Port cmake/install-share to python * Some cleanup * Replaced install-share in cmake file with fully working python version * Attemp to fix compile error * Fix compile for older python version * Try calling python 3 instead * Make install-share.py executable Compilable decompiler version * Decompiler script now runs successfully until unpacking * Running until calling bin2llvmir now * [skip ci] Integrate @silverbacknet changes + some fixes * [skip ci] Use CmdRunner.run_cmd everywhere in retdec_decompiler Small fixes and cleanup Early out if an error occurs * [skip ci] Latest fixes add retdec_tests_runner.py * [skip ci] Check that options are correct + cleanup and fixes * [skip ci] Fixed various errors * Try to fix running install-share script * Should now work on every os * Fix compile error * Convert compile-yara to python * [skip ci] Make test runner more portable * [skip ci] Use correct code style * [skip ci] Decompiler script now runs successfully * Now generates the same output as the bash script * Try fixing Travis on macOS * Upgrade python instead * Test scripts in travis * Fix build * Fix path * Update build Small cleanup * Fix error in decompiler script * Try to debug failure reason Fix test runner Use Python 3.5 on ubuntu * Use newer Python version and fix some errors * [skip ci] Little cleanup to make the code more clear Don't parse_args twice * [skip ci] First version of reimplementing logging * [skip ci] Some fixes and cleanup * [skip ci] Print memory usage, print output from unpacker, match code convention and some other fixes * [skip ci] Fix crash when using cleanup option; fix crash when using color ida * [skip ci] Fix --backend-aggressive-opts argument * [skip ci] Fix error when file arch is followed by a comment * [skip ci] Match Bash script more closely * [skip ci] Fix a few comments * [skip ci] Add some comments * [skip ci] Add early type_extractor/gen_cstdlib_and_linux_jsons.py and type_extractor/gen_windows_and_windrivers_jsons.py version * Try Unit tests * Try to fix test * Use absolute path instead * [skip ci] Add check for python scripts * scripts/retdec_decompiler.py: use output if specified via -o option
- Loading branch information
1 parent
386abd5
commit 4de4f49
Showing
15 changed files
with
3,225 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Get RetDec share directory. | ||
""" | ||
import sys | ||
import hashlib | ||
import os | ||
import shutil | ||
import tarfile | ||
import urllib.request | ||
|
||
# Check arguments. | ||
if len(sys.argv) != 2: | ||
print('ERROR: Unexpected number of arguments.') | ||
sys.exit(1) | ||
|
||
############################################################################### | ||
|
||
version_filename = 'version.txt' | ||
arch_suffix = 'tar.xz' | ||
|
||
sha256hash_ref = 'b54ba07e2f28143c9afe34a9d5b4114fb61f3c1175b9807caced471fec82001e' | ||
version = '2018-02-08' | ||
|
||
############################################################################### | ||
|
||
arch_name = 'retdec-support' + '_' + version + '.' + arch_suffix | ||
|
||
# Get install path from script options. | ||
install_path = sys.argv[1] | ||
|
||
share_dir = os.path.join(install_path, 'share') | ||
share_retdec_dir = os.path.join(share_dir, 'retdec') | ||
support_dir = os.path.join(share_retdec_dir, 'support') | ||
|
||
arch_path = os.path.join(support_dir, arch_name) | ||
|
||
|
||
############################################################################### | ||
|
||
def cleanup(): | ||
if os.path.exists(support_dir): | ||
for n in os.listdir(support_dir): | ||
p = os.path.join(support_dir, n) | ||
if os.path.isdir(p): | ||
shutil.rmtree(p) | ||
else: | ||
os.unlink(p) | ||
|
||
|
||
# Share directory exists. | ||
if os.path.exists(support_dir): | ||
# Version file exists. | ||
if os.path.isfile(os.path.join(support_dir, version_filename)): | ||
with open(os.path.join(support_dir, version_filename)) as version_file: | ||
version_from_file = version_file.read().split('\n')[0] | ||
|
||
if version == version_from_file: | ||
print('%s already exists, version is ok' % support_dir) | ||
sys.exit(0) | ||
else: | ||
print('versions is not as expected -> replace with expected version') | ||
|
||
cleanup() | ||
|
||
# Make sure destination directory exists. | ||
os.makedirs(support_dir, exist_ok=True) | ||
|
||
# Download archive | ||
arch_url = 'https://github.com/avast-tl/retdec-support/releases/download/%s/%s' % (version, arch_name) | ||
print('Downloading archive from %s ...' % arch_url) | ||
|
||
try: | ||
urllib.request.urlretrieve(arch_url, arch_path) | ||
except (urllib.request.HTTPError, urllib.request.URLError): | ||
print('ERROR: download failed') | ||
cleanup() | ||
sys.exit(1) | ||
|
||
# Compute hash of the downloaded archive. | ||
print('Verfifying archive\'s checksum ...') | ||
|
||
sha256 = hashlib.sha256() | ||
with open(arch_path, 'rb') as f: | ||
try: | ||
sha256.update(f.read()) | ||
except IOError: | ||
print('ERROR: failed to compute the SHA-256 hash of the archive') | ||
cleanup() | ||
sys.exit(1) | ||
|
||
sha256hash = sha256.hexdigest() | ||
|
||
# Check that hash is ok. | ||
if sha256hash != sha256hash_ref: | ||
print('ERROR: downloaded archive is invalid (SHA-256 hash check failed)') | ||
cleanup() | ||
sys.exit(1) | ||
|
||
# Unpack archive. | ||
print('Unpacking archive ...') | ||
with tarfile.open(arch_path) as tar: | ||
try: | ||
tar.extractall(support_dir) | ||
except tarfile.ExtractError: | ||
print('ERROR: failed to unpack the archive') | ||
cleanup() | ||
sys.exit(1) | ||
|
||
# Remove archive. | ||
os.remove(arch_path) | ||
|
||
print('RetDec support directory downloaded OK') | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.