Commit 439b07db by Tobias

improve logging

1 parent 2a6459a0
......@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
public class BlockProcessor {
private final Payload payload;
private final List<String> messages = new ArrayList<>();
private final List<String> filePaths = new ArrayList<>();
......@@ -20,9 +21,7 @@ public class BlockProcessor {
}
public BlockProcessor processBlocks() {
payload.getBlocks().stream()
.map(block -> toBlockContainer(block))
.forEach(BlockContainer::processBlock);
payload.getBlocks().stream().map(block -> toBlockContainer(block)).forEach(BlockContainer::processBlock);
return this;
}
......@@ -43,7 +42,12 @@ public class BlockProcessor {
}
public String getExtractedMessage() {
return messages.get(0);
if (messages.isEmpty()) {
return null;
} else {
return messages.get(0);
}
}
public String getStatusText() {
......@@ -53,7 +57,7 @@ public class BlockProcessor {
}
return status;
}
private boolean thereWereProcessedFiles() {
return !filePaths.isEmpty();
}
......
......@@ -55,7 +55,9 @@ public class JPGF5
FileOutputStream outputStream = null;
//TODO: Move this saving functionality to ImageFormat.save()
try {
LOG.info("Saving jpg image to {}", outputPath);
outputStream = new FileOutputStream(outputPath);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
......
......@@ -56,7 +56,7 @@ public abstract class ImageFormat {
*/
public void load(File file)
throws SteganoImageException {
LOG.debug("Loading {} image from {}", getFileExtension(), file.getAbsolutePath());
LOG.info("Loading {} image from {}", getFileExtension(), file.getAbsolutePath());
this.file = file;
try {
setBufferedImage(ImageIO.read(file));
......
......@@ -19,8 +19,11 @@
// password switch
package org.stegosuite.image.jpgtemp.james;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.image.jpgtemp.net.f5.crypt.F5Random;
import org.stegosuite.image.jpgtemp.net.f5.crypt.Permutation;
import org.stegosuite.ui.cli.CliParser;
import java.awt.*;
import java.io.BufferedOutputStream;
......@@ -35,6 +38,8 @@ import java.io.OutputStream;
public class JpegEncoder
extends Frame {
private static final Logger LOG = LoggerFactory.getLogger(JpegEncoder.class);
Thread runner;
BufferedOutputStream outStream;
......@@ -174,8 +179,8 @@ public class JpegEncoder
}
final int coeff[] = new int[coeffCount];
System.out.println("DCT/quantisation starts");
System.out.println(this.imageWidth + " x " + this.imageHeight);
//LOG.debug("DCT/quantisation starts");
LOG.debug(this.imageWidth + " x " + this.imageHeight);
for (r = 0; r < MinBlockHeight; r++) {
for (c = 0; c < MinBlockWidth; c++) {
xpos = c * 8;
......@@ -243,7 +248,7 @@ public class JpegEncoder
}
}
}
System.out.println("got " + coeffCount + " DCT AC/DC coefficients");
// LOG.debug("got " + coeffCount + " DCT AC/DC coefficients");
int _changed = 0;
int _embedded = 0;
int _examined = 0;
......@@ -270,11 +275,11 @@ public class JpegEncoder
_expected = _large + (int) (0.49 * _one);
//
// System.out.println("zero="+_zero);
System.out.println("one=" + _one);
System.out.println("large=" + _large);
// LOG.debug("one=" + _one);
// LOG.debug("large=" + _large);
//
System.out.println("expected capacity: " + _expected + " bits");
System.out.println("expected capacity with");
LOG.debug("expected capacity: " + _expected + " bits");
// System.out.println("expected capacity with");
for (i = 1; i < 8; i++) {
int usable, changed, n;
n = (1 << i) - 1;
......@@ -290,18 +295,18 @@ public class JpegEncoder
break;
}
if (i == 1) {
System.out.print("default");
// LOG.debug("default");
} else {
System.out.print("(1, " + n + ", " + i + ")");
// LOG.debug("(1, " + n + ", " + i + ")");
}
System.out.println(" code: " + usable + " bytes (efficiency: " + usable * 8 / changed + "."
+ usable * 80 / changed % 10 + " bits per change)");
// LOG.debug(" code: " + usable + " bytes (efficiency: " + usable * 8 / changed + "."
// + usable * 80 / changed % 10 + " bits per change)");
}
// westfeld
if (this.embeddedData != null) {
// Now we embed the secret data in the permutated sequence.
System.out.println("Permutation starts");
// LOG.debug("Permutation starts");
final F5Random random = new F5Random(this.password.getBytes());
final Permutation permutation = new Permutation(coeffCount, random);
int nextBitToEmbed = 0;
......@@ -315,7 +320,7 @@ public class JpegEncoder
} catch (final Exception e) {
e.printStackTrace();
}
System.out.print("Embedding of " + (byteToEmbed * 8 + 32) + " bits (" + byteToEmbed + "+4 bytes) ");
// LOG.debug("Embedding of " + (byteToEmbed * 8 + 32) + " bits (" + byteToEmbed + "+4 bytes) ");
// We use the most significant byte for the 1 of n
// code, and reserve one extra bit for future use.
if (byteToEmbed > 0x007fffff) {
......@@ -343,10 +348,10 @@ public class JpegEncoder
this.n++;
break;
case 1:
System.out.println("using default code");
// LOG.debug("using default code");
break;
default:
System.out.println("using (1, " + this.n + ", " + k + ") code");
// LOG.debug("using (1, " + this.n + ", " + k + ") code");
}
byteToEmbed |= k << 24; // store k in the status word
// Since shuffling cannot hide the distribution, the
......@@ -441,7 +446,7 @@ public class JpegEncoder
if (j >= coeffCount) {
// in rare cases the estimated capacity is too
// small
System.out.println("Capacity exhausted.");
LOG.info("Capacity exhausted.");
break embeddingLoop;
}
shuffledIndex = permutation.getShuffled(j);
......@@ -534,14 +539,14 @@ public class JpegEncoder
}
}
if (_examined > 0) {
System.out.println(_examined + " coefficients examined");
// LOG.debug(_examined + " coefficients examined");
}
System.out.println(_changed + " coefficients changed (efficiency: " + _embedded / _changed + "."
+ _embedded * 10 / _changed % 10 + " bits per change)");
System.out.println(_thrown + " coefficients thrown (zeroed)");
System.out.println(_embedded + " bits (" + _embedded / 8 + " bytes) embedded");
// LOG.debug(_changed + " coefficients changed (efficiency: " + _embedded / _changed + "."
// + _embedded * 10 / _changed % 10 + " bits per change)");
// LOG.debug(_thrown + " coefficients thrown (zeroed)");
// LOG.debug(_embedded + " bits (" + _embedded / 8 + " bytes) embedded");
}
System.out.println("Starting Huffman Encoding.");
// LOG.debug("Starting Huffman Encoding.");
// Do the Huffman Encoding now.
shuffledIndex = 0;
for (r = 0; r < MinBlockHeight; r++) {
......@@ -711,7 +716,7 @@ public class JpegEncoder
try {
out.write(data, 0, 2);
} catch (final IOException e) {
System.out.println("IO Error: " + e.getMessage());
LOG.info("IO Error: " + e.getMessage());
}
}
......@@ -766,8 +771,8 @@ public class JpegEncoder
}
final int coeff[] = new int[coeffCount];
System.out.println("DCT/quantisation starts");
System.out.println(this.imageWidth + " x " + this.imageHeight);
// LOG.debug("DCT/quantisation starts");
// LOG.debug(this.imageWidth + " x " + this.imageHeight);
for (r = 0; r < MinBlockHeight; r++) {
for (c = 0; c < MinBlockWidth; c++) {
xpos = c * 8;
......@@ -835,7 +840,7 @@ public class JpegEncoder
}
}
}
System.out.println("got " + coeffCount + " DCT AC/DC coefficients");
// LOG.debug("got " + coeffCount + " DCT AC/DC coefficients");
int _changed = 0;
int _embedded = 0;
int _examined = 0;
......@@ -862,10 +867,10 @@ public class JpegEncoder
_expected = _large + (int) (0.49 * _one);
//
// System.out.println("zero="+_zero);
System.out.println("one=" + _one);
System.out.println("large=" + _large);
// LOG.debug("one=" + _one);
// LOG.debug("large=" + _large);
//
System.out.println("expected capacity: " + _expected + " bits");
// LOG.debug("expected capacity: " + _expected + " bits");
return (_expected / 8);
}
}
package org.stegosuite.image.jpgtemp.net.f5;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.image.embedding.jpg.JPGF5;
import org.stegosuite.image.jpgtemp.net.f5.crypt.F5Random;
import org.stegosuite.image.jpgtemp.net.f5.crypt.Permutation;
import org.stegosuite.image.jpgtemp.net.f5.ortega.HuffmanDecode;
......@@ -9,6 +12,8 @@ import java.io.*;
public class Extract {
private static final Logger LOG = LoggerFactory.getLogger(Extract.class);
private static File f; // carrier file
private static byte[] carrier; // carrier data
......@@ -30,12 +35,12 @@ public class Extract {
carrier = new byte[flength];
fis.read(carrier);
final HuffmanDecode hd = new HuffmanDecode(carrier);
System.out.println("Huffman decoding starts");
// LOG.debug("Huffman decoding starts");
coeff = hd.decode();
System.out.println("Permutation starts");
// LOG.debug("Permutation starts");
final F5Random random = new F5Random(password.getBytes());
final Permutation permutation = new Permutation(coeff.length, random);
System.out.println(coeff.length + " indices shuffled");
// LOG.debug(coeff.length + " indices shuffled");
int extractedByte = 0;
int availableExtractedBits = 0;
int extractedFileLength = 0;
......@@ -43,7 +48,7 @@ public class Extract {
int shuffledIndex = 0;
int extractedBit;
int i;
System.out.println("Extraction starts");
// LOG.debug("Extraction starts");
// extract length information
for (i = 0; availableExtractedBits < 32; i++) {
shuffledIndex = permutation.getShuffled(i);
......@@ -70,12 +75,12 @@ public class Extract {
k %= 32;
final int n = (1 << k) - 1;
extractedFileLength &= 0x007fffff;
System.out.println("Length of embedded file: " + extractedFileLength + " bytes");
// LOG.debug("Length of embedded file: " + extractedFileLength + " bytes");
availableExtractedBits = 0;
if (n > 0) {
int startOfN = i;
int hash;
System.out.println("(1, " + n + ", " + k + ") code used");
// LOG.debug("(1, " + n + ", " + k + ") code used");
extractingLoop: do {
// 1. read n places, and calculate k bits
hash = 0;
......@@ -122,7 +127,7 @@ public class Extract {
}
} while (true);
} else {
System.out.println("Default code used");
// LOG.debug("Default code used");
for (; i < coeff.length; i++) {
shuffledIndex = permutation.getShuffled(i);
if (shuffledIndex % 64 == 0) {
......@@ -152,8 +157,8 @@ public class Extract {
}
}
if (nBytesExtracted < extractedFileLength) {
System.out.println(
"Incomplete file: only " + nBytesExtracted + " of " + extractedFileLength + " bytes extracted");
// LOG.debug(
// "Incomplete file: only " + nBytesExtracted + " of " + extractedFileLength + " bytes extracted");
throw new SteganoKeyException();
}
}
......@@ -176,7 +181,7 @@ public class Extract {
continue;
}
if (args.length < i + 1) {
System.out.println("Missing parameter for switch " + args[i]);
LOG.debug("Missing parameter for switch " + args[i]);
usage();
return;
}
......@@ -185,7 +190,7 @@ public class Extract {
} else if (args[i].equals("-p")) {
password = args[i + 1];
} else {
System.out.println("Unknown switch " + args[i] + " ignored.");
LOG.debug("Unknown switch " + args[i] + " ignored.");
}
i++;
}
......@@ -200,10 +205,10 @@ public class Extract {
}
static void usage() {
System.out.println("java Extract [Options] \"image.jpg\"");
System.out.println("Options:");
System.out.println("\t-p password (default: abc123)");
System.out.println("\t-e extractedFileName (default: output.txt)");
System.out.println("\nAuthor: Andreas Westfeld, westfeld@inf.tu-dresden.de");
LOG.debug("java Extract [Options] \"image.jpg\"");
LOG.debug("Options:");
LOG.debug("\t-p password (default: abc123)");
LOG.debug("\t-e extractedFileName (default: output.txt)");
LOG.debug("\nAuthor: Andreas Westfeld, westfeld@inf.tu-dresden.de");
}
}
......@@ -30,7 +30,7 @@ public class Cli
return null;
}
}
public void embed(CommandLine cmd) {
String steganogramPath = getSteganogramPath(cmd);
if (steganogramPath == null)
......@@ -39,12 +39,12 @@ public class Cli
return;
pointFilter(cmd);
String message = cmd.getOptionValue("m");
if (message != null) {
presenter.addMessageToPayload(message);
}
String[] files = cmd.getOptionValues("f");
if (files != null) {
for (String string : files) {
......@@ -58,6 +58,7 @@ public class Cli
}
private void embed(String key) {
LOG.info("Embedding data...");
presenter.embed(key);
}
......@@ -74,6 +75,7 @@ public class Cli
}
private void extract(String key) {
LOG.info("Extracting data...");
presenter.extractUsing(key);
}
......@@ -137,7 +139,9 @@ public class Cli
public void extractingCompleted(String extractedMessage, List<String> filePaths, Visualizer visualizer,
ImageData imageData) {
LOG.info("Extracting completed");
LOG.info("Extracted message: {}", extractedMessage);
if (extractedMessage != null) {
LOG.info("Extracted message: {}", extractedMessage);
}
if (!filePaths.isEmpty()) {
for (String string : filePaths) {
LOG.info("Extracted file saved to {}", string);
......
......@@ -18,7 +18,7 @@ public class CliParser {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
options.addOption("v", "verbose", false, "show more information");
options.addOption("d", "debug", false, "show debug information");
options.addOption("e", "embed", false, "embed data into image");
options.addOption("x", "extract", false, "extract data from image");
options.addOption("m", "message", true, "message to embed");
......@@ -48,7 +48,7 @@ public class CliParser {
CommandLine line = parser.parse(options, args);
Cli cli = new Cli();
if (line.hasOption("v")) {
if (line.hasOption("d")) {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.DEBUG);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!