Commit a2e4561d by Tobias

Started working on CLI

1 parent b37649fb
......@@ -121,6 +121,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<profiles>
......
package org.stegosuite;
import org.slf4j.LoggerFactory;
import org.stegosuite.ui.cli.CliParser;
import org.stegosuite.ui.gui.Gui;
import ch.qos.logback.classic.Level;
......@@ -13,8 +14,8 @@ public class Stegosuite {
root.setLevel(Level.INFO);
if (args.length == 0) {
new Gui(null);
// } else if (args[0].startsWith("-")) {
// new Cli(args);
} else if (args[0].startsWith("-")) {
new CliParser(args);
} else {
new Gui(args[0]);
}
......
/*package org.stegosuite.ui.cli;
import com.beust.jcommander.Parameter;
public class Arguments {
@Parameter(names = { "-h", "--help" }, help = true, description = "Displays this message.")
private boolean help = false;
@Parameter(names = { "-V", "--verbose" }, description = "Show more information.")
private boolean verbose = false;
@Parameter(names = {
"--disable-noise-detection" }, description = "Disables the automatic exclusion of homogeneous areas in the image.")
private boolean disableNoiseDetection = false;
@Parameter(names = "-e", description = "Embed data into image")
private boolean embed = false;
@Parameter(names = "-x", description = "Extract data from image")
private boolean extract = false;
@Parameter(names = "-i", description = "Image for embedding/extracting")
private String steganogramPath;
@Parameter(names = "-k", description = "Secret key used for encrytion and embedding/extracting")
private String secretkey;
@Parameter(names = { "-m", "--embedMessage" }, description = "Message to embed")
private String message = "This is the default secret message";
@Parameter(names = { "-f", "--embedFile" }, description = "File to embed")
private String filePath;
boolean isDisableNoiseDetection() {
return disableNoiseDetection;
}
boolean isHelp() {
return help;
}
boolean isVerbose() {
return verbose;
}
boolean isEmbed() {
return embed;
}
boolean isExtract() {
return extract;
}
String getSteganogramPath() {
return steganogramPath;
}
String getFilePath() {
return filePath;
}
String getSecretKey() {
return secretkey;
}
String getMessage() {
return message;
}
}*/
/*package org.stegosuite.ui.cli;
package org.stegosuite.ui.cli;
import java.io.File;
import java.io.IOException;
......@@ -6,10 +6,10 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import org.apache.commons.cli.CommandLine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.image.format.ImageFormat;
import org.stegosuite.image.util.FileUtils;
import org.stegosuite.model.exception.SteganoEmbedException;
import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
......@@ -19,53 +19,22 @@ import org.stegosuite.model.payload.block.FileBlock;
import org.stegosuite.model.payload.block.MessageBlock;
import org.stegosuite.ui.gui.embedding.Embedding;
import org.stegosuite.ui.gui.embedding.EmbeddingFactory;
import com.beust.jcommander.JCommander;
import ch.qos.logback.classic.Level;
import org.stegosuite.util.FileUtils;
public class Cli {
private String[] args;
private Arguments arguments;
private static final Logger LOG = LoggerFactory.getLogger(Cli.class);
public Cli(String[] s) {
args = s;
parseCli();
}
private void parseCli() {
arguments = new Arguments();
JCommander jCommander = new JCommander(arguments, args);
jCommander.setProgramName("stegosuite");
if (arguments.isVerbose()) {
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.DEBUG);
}
if (arguments.isEmbed()) {
embed();
} else if (arguments.isExtract()) {
extract();
} else if (arguments.isHelp()) {
jCommander.usage();
return;
}
}
private void embed() {
String steganogramPath = arguments.getSteganogramPath();
String filePath = arguments.getFilePath();
public void embed(CommandLine cmd) {
String steganogramPath = cmd.getOptionValue("e");
String message = cmd.getOptionValue("m");
String key = cmd.getOptionValue("k");
Payload payload = new Payload();
payload.getBlocks().add(new MessageBlock(arguments.getMessage()));
if (filePath != null) {
payload.getBlocks().add(new FileBlock(filePath));
}
payload.getBlocks().add(new MessageBlock(message));
payload.setSteganoPassword(arguments.getSecretKey());
payload.setEncryptionPassword(arguments.getSecretKey());
payload.setSteganoPassword(key);
payload.setEncryptionPassword(key);
File steganogramFile = new File(steganogramPath);
String extension = FileUtils.getFileExtension(steganogramPath);
......@@ -78,9 +47,6 @@ public class Cli {
Embedding embedding = EmbeddingFactory.getEmbedding(image);
embedding.setPointFilter(1);
if (arguments.isDisableNoiseDetection()) {
embedding.setPointFilter(0);
}
try {
image.load(steganogramFile);
......@@ -99,32 +65,31 @@ public class Cli {
}
}
private void extract() {
String filePath = arguments.getSteganogramPath();
public void extract(CommandLine cmd) {
String steganogramPath = cmd.getOptionValue("x");
String key = cmd.getOptionValue("k");
Payload payload = new Payload();
payload.setSteganoPassword(arguments.getSecretKey());
payload.setEncryptionPassword(arguments.getSecretKey());
payload.setSteganoPassword(key);
payload.setEncryptionPassword(key);
String extension = FileUtils.getFileExtension(filePath);
String extension = FileUtils.getFileExtension(steganogramPath);
ImageFormat image = ImageFormat.newInstance(extension);
if (image == null) {
LOG.error("Error: Currently only gif and bmp file types are supported.");
String supportedFormats = String.join(", ", ImageFormat.getRegisteredImageExtensions().keySet());
LOG.error("Error: Currently only these file types are supported: {}", supportedFormats);
return;
}
File file = new File(filePath);
File file = new File(steganogramPath);
try {
image.load(file);
Embedding embedding = EmbeddingFactory.getEmbedding(image);
embedding.setPointFilter(1);
if (arguments.isDisableNoiseDetection()) {
embedding.setPointFilter(0);
}
embedding.extract(payload, (embeddingMethod) -> {
for (Block block : payload.getBlocks()) {
if (block.getIdentifier() == FileBlock.IDENTIFIER) {
String outPath = FileUtils.changeFileName(filePath, ((FileBlock) block).getFileName());
String outPath = FileUtils.changeFileName(steganogramPath, ((FileBlock) block).getFileName());
LOG.debug("Outputpath: {}", outPath);
try {
Files.write(Paths.get(outPath), ((FileBlock) block).getFileContent(),
......@@ -143,4 +108,4 @@ public class Cli {
e.printStackTrace();
}
}
}*/
}
package org.stegosuite.ui.cli;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
public class CliParser {
private String[] args = null;
private static final Logger LOG = LoggerFactory.getLogger(CliParser.class);
public CliParser(String[] s) {
args = s;
parse();
}
private void parse() {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
options.addOption("v", "verbose", true, "show more information");
options.addOption("e", "embed", true, "embed data into image");
options.addOption("x", "extract", true, "extract data from image");
options.addOption("m", "message", true, "message to embed");
options.addOption("k", "key", true, "secret key used for encrytion and hiding");
options.addOption("f", "file", true, "file to embed"); // TODO
options.addOption("c", "capacity", true, "shows the maximum amount of data which can be embededded"); // TODO
options.addOption("f", "file", true, "file to embed");
options.addOption("h", "help", false, "displays this help message");
Option stegokey = Option.builder().hasArg().longOpt("stegokey")
.desc("the secret stego key used for hiding the content").build();
Option cryptokey = Option.builder().hasArg().longOpt("encryptionkey")
.desc("the secret key used for encryption of the content").build();
Option noNoise = Option.builder().longOpt("disable-noise-detection")
.desc("disables the automatic avoidance of homogeneous areas").build();
Option extractPath = Option.builder().longOpt("extraction-path").desc("the folder to store extracted files")
.build();
options.addOption(stegokey); // TODO
options.addOption(cryptokey); // TODO
options.addOption(noNoise); // TODO
options.addOption(extractPath); // TODO
try {
CommandLine line = parser.parse(options, args);
Cli cli = new Cli();
if (line.hasOption("v")) {
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.DEBUG);
}
if (line.hasOption("e")) {
cli.embed(line);
} else if (line.hasOption("x")) {
cli.extract(line);
} else if (line.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("stegosuite", options);
}
} catch (ParseException exp) {
LOG.error("Unexpected exception:" + exp.getMessage());
}
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!