diff --git a/bombast/__init__.py b/bombast/__init__.py index f74f92c..7f931c1 100644 --- a/bombast/__init__.py +++ b/bombast/__init__.py @@ -139,45 +139,3 @@ def configure(path): else: print('Warning: option "{}" is unused.'.format(option), file=sys.stderr) - -def main(): - parser = argparse.ArgumentParser(description='Obfuscate Python source code.') - parser.add_argument('infile', type=argparse.FileType('rb'), - default=sys.stdin, - help='input') - parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), - default='obfuscated.py', - help='output [default: obfuscated.py]') - parser.add_argument('--seed', type=int, default=0, - help='random seed [default: 0]') - parser.add_argument('--iters', type=int, default=1, - help='number of iterations [default: 1]') - parser.add_argument('--config', type=str, - help='configuration file [default: bombast.config]') - parser.add_argument('--show-translations', action='store_true', - help='print translations to stdout') - args = parser.parse_args() - configure(args.config) - - random.seed(args.seed) - root = ast.parse(args.infile.read()) - - # Choose renamings - preprocess = Preprocess() - preprocess.visit(root) - - bombast = Bombast(preprocess) - for _ in range(args.iters): - root = bombast.visit(root) - - # Postprocessing - root.body.sort(key=lambda x: not isinstance(x, ast.Import)) # move imports - ast.fix_missing_locations(root) # fix AST - - print(astunparse.unparse(root), file=args.outfile) - if args.show_translations: - for original, obfuscated in preprocess.mapping.items(): - print(original, '=', obfuscated) - -if __name__ == '__main__': - main() diff --git a/bombast/__main__.py b/bombast/__main__.py new file mode 100644 index 0000000..339c3bf --- /dev/null +++ b/bombast/__main__.py @@ -0,0 +1,43 @@ +from bombast import * + +def main(): + parser = argparse.ArgumentParser(description='Obfuscate Python source code.') + parser.add_argument('infile', type=argparse.FileType('rb'), + default=sys.stdin, + help='input') + parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), + default='obfuscated.py', + help='output [default: obfuscated.py]') + parser.add_argument('--seed', type=int, default=0, + help='random seed [default: 0]') + parser.add_argument('--iters', type=int, default=1, + help='number of iterations [default: 1]') + parser.add_argument('--config', type=str, + help='configuration file [default: bombast.config]') + parser.add_argument('--show-translations', action='store_true', + help='print translations to stdout') + args = parser.parse_args() + configure(args.config) + + random.seed(args.seed) + root = ast.parse(args.infile.read()) + + # Choose renamings + preprocess = Preprocess() + preprocess.visit(root) + + bombast = Bombast(preprocess) + for _ in range(args.iters): + root = bombast.visit(root) + + # Postprocessing + root.body.sort(key=lambda x: not isinstance(x, ast.Import)) # move imports + ast.fix_missing_locations(root) # fix AST + + print(astunparse.unparse(root), file=args.outfile) + if args.show_translations: + for original, obfuscated in preprocess.mapping.items(): + print(original, '=', obfuscated) + + +main() diff --git a/setup.py b/setup.py index 00e1c66..2ca5a5b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ install_requires=['astunparse'], entry_points={ 'console_scripts': [ - 'bombast=bombast.__init__:main', + 'bombast=bombast.__main__:main', ], } )