Commit 3cefb5e5c2289bfe1891379ddf15826e7ddb29e0

Authored by AlekseiP
1 parent f5aa7255

Endret main metode, laget kjøring med parameters

Showing 1 changed file with 71 additions and 7 deletions   Show diff stats
Oblig5/src/FileHashing.java
... ... @@ -22,6 +22,76 @@ import org.apache.commons.codec.digest.DigestUtils;
22 22  
23 23 public class FileHashing {
24 24  
  25 + public static String fileName = "hashfile.txt";
  26 + public static String fileName1;
  27 + public static String fileroot = "t";
  28 + public static boolean hParametr = false;
  29 + public static boolean rParametr = false;
  30 + public static boolean cParametr = false;
  31 + public static boolean fParametr = false;
  32 +
  33 + public static void main(String args[]) throws IOException {
  34 +
  35 + if (args.length < 1 || (args[0].equals("-help"))) {
  36 + System.out.println("You must either chek or hash operation");
  37 + System.out.println("Usage of the HachCheck: java HashCheck [OPTIONS] [FILES/DIRECTORIES]");
  38 + System.out.println(
  39 + "Options:/n -c check. Checks given files and/or files in directories against hashes in hash file");
  40 + System.out.println("-h hash. Scans given files and/or files in directories and saves their hashes");
  41 + System.out.println("-r recursive. If the directory is given all its folders will be scanned recursively");
  42 + System.out
  43 + .println("-f \"<hashfile>\" uses given hash file in operation instead of default HashCheck.hash ");
  44 + } else {
  45 +
  46 + for (int i = 0; i < args.length; i++) {
  47 + if (args[i].equals("-h")) {
  48 + hParametr = true;
  49 +
  50 + } else if (args[i].equals("-r")) {
  51 + rParametr = true;
  52 + }
  53 +
  54 + else if (args[i].equals("-f")) {
  55 + fParametr = true;
  56 + fileName1 = args[++i];
  57 + }
  58 +
  59 + else if (args[i].contains("C:\\")) {
  60 + fileroot = args[i];
  61 +
  62 + } else if (args[i].equals("-c")) {
  63 + cParametr = true;
  64 +
  65 +
  66 + }
  67 + }
  68 +
  69 + if (cParametr) {
  70 + File root;
  71 + root = new File(fileroot);
  72 + search(root);
  73 + }
  74 +
  75 + if (hParametr) {
  76 + File root;
  77 + root = new File(fileroot);
  78 + FileOutputStream newfile = new FileOutputStream(fileName);
  79 + newfile.close();
  80 + search(root);
  81 + signereHashFil();
  82 + System.out.println("Done");
  83 +
  84 +
  85 + }
  86 + if (fParametr) {
  87 +
  88 + System.out.println("Done");
  89 + }
  90 +
  91 + }
  92 + }
  93 +
  94 +
25 95 public static void search(File directory) throws FileNotFoundException{ // Recursively search for
26 96 // executables
27 97  
... ... @@ -179,12 +249,6 @@ infect(entry); // If executable, infect it
179 249 }
180 250 }
181 251  
182   - public static void main(String args[]) throws FileNotFoundException{
183   - File root;
184   - root = new File("t");
185   - search(root);
186   - signereHashFil();
187   - System.out.println("Done");
188   - }
  252 +
189 253  
190 254 }
... ...