diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d79fc21 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include ducktoolkit/languages *.json \ No newline at end of file diff --git a/ducktoolkit/__init__.py b/ducktoolkit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/common.py b/ducktoolkit/common.py similarity index 86% rename from common.py rename to ducktoolkit/common.py index b8d72a7..4acfc7c 100644 --- a/common.py +++ b/ducktoolkit/common.py @@ -1,3 +1,5 @@ +import os + encoder_command_keys = [ "DELAY", "SPACE", @@ -120,3 +122,11 @@ "STOP", "POWER" ] + +def list_languages(): + languages = [] + lang_dir = os.path.join(os.path.dirname(__file__), 'languages') + for filename in os.listdir(lang_dir): + if filename.endswith('.json'): + languages.append(filename) + return languages \ No newline at end of file diff --git a/decoder.py b/ducktoolkit/decoder.py similarity index 88% rename from decoder.py rename to ducktoolkit/decoder.py index fa9404c..802dddb 100644 --- a/decoder.py +++ b/ducktoolkit/decoder.py @@ -5,7 +5,8 @@ def decode_script(duck_lang, ducky_bin): - language_dict = os.path.join('languages', '{0}.json'.format(duck_lang)) + lang_dir = os.path.join(os.path.dirname(__file__), 'languages') + language_dict = os.path.join(lang_dir, '{0}.json'.format(duck_lang)) lang_file = json.load(open(language_dict)) ducky_hex = ducky_bin.encode('hex') decoded_bin = "" diff --git a/encoder.py b/ducktoolkit/encoder.py similarity index 96% rename from encoder.py rename to ducktoolkit/encoder.py index 2886918..3e95e50 100644 --- a/encoder.py +++ b/ducktoolkit/encoder.py @@ -94,7 +94,8 @@ def parse_text(duck_text, lang_file): def encode_script(duck_text, duck_lang): - language_dict = os.path.join('languages', '{0}.json'.format(duck_lang)) + lang_dir = os.path.join(os.path.dirname(__file__), 'languages') + language_dict = os.path.join(lang_dir, '{0}.json'.format(duck_lang)) lang_file = json.load(open(language_dict)) try: diff --git a/ducktoolkit/languages/__init__.py b/ducktoolkit/languages/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/languages/gb.json b/ducktoolkit/languages/gb.json similarity index 100% rename from languages/gb.json rename to ducktoolkit/languages/gb.json diff --git a/languages/us.json b/ducktoolkit/languages/us.json similarity index 100% rename from languages/us.json rename to ducktoolkit/languages/us.json diff --git a/ducktools.py b/ducktools.py index 5e36e67..dbb447f 100644 --- a/ducktools.py +++ b/ducktools.py @@ -1,24 +1,16 @@ #!/usr/bin/env python -import os import sys from optparse import OptionParser -import encoder -import decoder +from ducktoolkit import encoder, decoder +from ducktoolkit.common import list_languages __description__ = 'Ducky Tools' __author__ = 'Kevin Breen, James Hall, https://ducktoolkit.com' -__version__ = '0.1' +__version__ = '0.2' __date__ = '25/08/2016' -def list_languages(): - languages = [] - for filename in os.listdir('languages'): - languages.append(filename) - return languages - - if __name__ == "__main__": parser = OptionParser(usage='usage: %prog [options] inputfile outputfile\n' + __description__, version='%prog ' + __version__) @@ -41,12 +33,16 @@ def list_languages(): if not language: print "[!] You need to specify a supported language" + parser.print_help() + sys.exit() if "{0}.json".format(language) not in list_languages(): print "[!] Language {0} is not supported at this time.".format(language) print "[+] Supported Languages" for lang in list_languages(): print " [-] {0}".format(lang.split('.')[0]) + parser.print_help() + sys.exit() if options.encode: diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..39f6f93 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +from setuptools import setup, find_packages + +setup( + name='ducktoolkit', + version='0.2', + author='Kevin Breen, James Hall', + author_email='pip@ducktoolkit.com', + description="USB Rubber Ducky Toolkit", + url='https://ducktoolkit.com', + license='GNU V3', + zip_safe=False, + packages=find_packages(), + include_package_data=True, + scripts=['ducktools.py'], + package_data={'': ['*.json', 'README.md, LICENSE']}, +)