mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
Adde CLI support for the fast Ackermann generator
This commit is contained in:
parent
45cdb9a3a5
commit
8f8cd483fd
1 changed files with 36 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#-*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Stéganô - Stéganô is a basic Python Steganography module.
|
# Stéganô - Stéganô is a basic Python Steganography module.
|
||||||
# Copyright (C) 2010-2017 Cédric Bonhomme - https://www.cedricbonhomme.org
|
# Copyright (C) 2010-2017 Cédric Bonhomme - https://www.cedricbonhomme.org
|
||||||
|
@ -40,58 +40,69 @@ import argparse
|
||||||
parser = argparse.ArgumentParser(prog='stegano-lsb-set')
|
parser = argparse.ArgumentParser(prog='stegano-lsb-set')
|
||||||
subparsers = parser.add_subparsers(help='sub-command help', dest='command')
|
subparsers = parser.add_subparsers(help='sub-command help', dest='command')
|
||||||
|
|
||||||
|
|
||||||
|
class ValidateGenerator(argparse.Action):
|
||||||
|
def __call__(self, parser, args, values, option_string=None):
|
||||||
|
valid_generators = [generator[0] for generator in inspect.getmembers(
|
||||||
|
generators, inspect.isfunction)]
|
||||||
|
# Verify that the generator is valid
|
||||||
|
generator = values[0]
|
||||||
|
if generator not in valid_generators:
|
||||||
|
raise ValueError("Unknown generator: %s" % generator)
|
||||||
|
# Set the generator_function arg of the parser
|
||||||
|
setattr(args, self.dest, values)
|
||||||
|
|
||||||
|
|
||||||
# Subparser: Hide
|
# Subparser: Hide
|
||||||
parser_hide = subparsers.add_parser('hide', help='hide help')
|
parser_hide = subparsers.add_parser('hide', help='hide help')
|
||||||
# Original image
|
# Original image
|
||||||
parser_hide.add_argument("-i", "--input", dest="input_image_file",
|
parser_hide.add_argument("-i", "--input", dest="input_image_file",
|
||||||
required=True, help="Input image file.")
|
required=True, help="Input image file.")
|
||||||
parser_hide.add_argument("-e", "--encoding", dest="encoding",
|
parser_hide.add_argument("-e", "--encoding", dest="encoding",
|
||||||
choices=tools.ENCODINGS.keys(), default='UTF-8',
|
choices=tools.ENCODINGS.keys(), default='UTF-8',
|
||||||
help="Specify the encoding of the message to hide." +
|
help="Specify the encoding of the message to hide." +
|
||||||
" UTF-8 (default) or UTF-32LE.")
|
" UTF-8 (default) or UTF-32LE.")
|
||||||
|
|
||||||
# Generator
|
# Generator
|
||||||
parser_hide.add_argument("-g", "--generator", dest="generator_function",
|
parser_hide.add_argument("-g", "--generator", dest="generator_function",
|
||||||
# choices=[generator[0] for generator in \
|
action=ValidateGenerator,
|
||||||
# inspect.getmembers(generators, inspect.isfunction)],
|
nargs='*', required=True, help="Generator (with optional arguments)")
|
||||||
nargs='*', required=True, help="Generator")
|
|
||||||
parser_hide.add_argument("-s", "--shift", dest="shift",
|
parser_hide.add_argument("-s", "--shift", dest="shift",
|
||||||
default=0, help="Shift for the generator")
|
default=0, help="Shift for the generator")
|
||||||
|
|
||||||
group_secret = parser_hide.add_mutually_exclusive_group(required=True)
|
group_secret = parser_hide.add_mutually_exclusive_group(required=True)
|
||||||
# Non binary secret message to hide
|
# Non binary secret message to hide
|
||||||
group_secret.add_argument("-m", dest="secret_message",
|
group_secret.add_argument("-m", dest="secret_message",
|
||||||
help="Your secret message to hide (non binary).")
|
help="Your secret message to hide (non binary).")
|
||||||
# Binary secret message to hide
|
# Binary secret message to hide
|
||||||
group_secret.add_argument("-f", dest="secret_file",
|
group_secret.add_argument("-f", dest="secret_file",
|
||||||
help="Your secret to hide (Text or any binary file).")
|
help="Your secret to hide (Text or any binary file).")
|
||||||
|
|
||||||
# Image containing the secret
|
# Image containing the secret
|
||||||
parser_hide.add_argument("-o", "--output", dest="output_image_file",
|
parser_hide.add_argument("-o", "--output", dest="output_image_file",
|
||||||
required=True, help="Output image containing the secret.")
|
required=True, help="Output image containing the secret.")
|
||||||
|
|
||||||
|
|
||||||
# Subparser: Reveal
|
# Subparser: Reveal
|
||||||
parser_reveal = subparsers.add_parser('reveal', help='reveal help')
|
parser_reveal = subparsers.add_parser('reveal', help='reveal help')
|
||||||
parser_reveal.add_argument("-i", "--input", dest="input_image_file",
|
parser_reveal.add_argument("-i", "--input", dest="input_image_file",
|
||||||
required=True, help="Input image file.")
|
required=True, help="Input image file.")
|
||||||
parser_reveal.add_argument("-e", "--encoding", dest="encoding",
|
parser_reveal.add_argument("-e", "--encoding", dest="encoding",
|
||||||
choices=tools.ENCODINGS.keys(), default='UTF-8',
|
choices=tools.ENCODINGS.keys(), default='UTF-8',
|
||||||
help="Specify the encoding of the message to reveal." +
|
help="Specify the encoding of the message to reveal." +
|
||||||
" UTF-8 (default) or UTF-32LE.")
|
" UTF-8 (default) or UTF-32LE.")
|
||||||
parser_reveal.add_argument("-g", "--generator", dest="generator_function",
|
parser_reveal.add_argument("-g", "--generator", dest="generator_function",
|
||||||
# choices=[generator[0] for generator in \
|
action=ValidateGenerator,
|
||||||
# inspect.getmembers(generators, inspect.isfunction)],
|
nargs='*', required=True, help="Generator (with optional arguments)")
|
||||||
nargs='*', required=True, help="Generator")
|
|
||||||
parser_reveal.add_argument("-s", "--shift", dest="shift",
|
parser_reveal.add_argument("-s", "--shift", dest="shift",
|
||||||
default=0, help="Shift for the generator")
|
default=0, help="Shift for the generator")
|
||||||
parser_reveal.add_argument("-o", dest="secret_binary",
|
parser_reveal.add_argument("-o", dest="secret_binary",
|
||||||
help="Output for the binary secret (Text or any binary file).")
|
help="Output for the binary secret (Text or any binary file).")
|
||||||
|
|
||||||
|
|
||||||
# Subparser: List generators
|
# Subparser: List generators
|
||||||
parser_list_generators = subparsers.add_parser('list-generators',
|
parser_list_generators = subparsers.add_parser('list-generators',
|
||||||
help='list-generators help')
|
help='list-generators help')
|
||||||
|
|
||||||
arguments = parser.parse_args()
|
arguments = parser.parse_args()
|
||||||
|
|
||||||
|
@ -105,11 +116,11 @@ if arguments.command != 'list-generators':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if (len(arguments.generator_function) > 1):
|
if (len(arguments.generator_function) > 1):
|
||||||
generator = getattr(generators, arguments.generator_function[0])\
|
generator = getattr(generators, arguments.generator_function[0])(
|
||||||
(*[int(e) for e in arguments.generator_function[1:]])
|
*[int(e) for e in arguments.generator_function[1:]])
|
||||||
else:
|
else:
|
||||||
generator = getattr(generators, arguments.generator_function[0])()
|
generator = getattr(generators, arguments.generator_function[0])()
|
||||||
|
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
print("Unknown generator: {}".format(arguments.generator_function))
|
print("Unknown generator: {}".format(arguments.generator_function))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue