diff --git a/.gitignore b/.gitignore index b651fdd..a852dd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ db.txt h-db.txt -customdb.txt \ No newline at end of file +customdb.txt +log.txt \ No newline at end of file diff --git a/README.md b/README.md index 9a1b9f3..816699b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # nodejs-hash-antivirus Simple antivirus written in node.js. Uses md5 hashes. +
+If you get any errors(Which you most likely will) please make a issue and send the log.txt file found in the same folder as the program
+
+ # Usage
 Use "npm run" to run the main program.
diff --git a/log.js b/log.js
new file mode 100644
index 0000000..f52f52a
--- /dev/null
+++ b/log.js
@@ -0,0 +1,52 @@
+import exp from 'constants';
+import * as fs from 'fs';
+
+var currentTime = "nAn";
+
+export function newSession() {
+    getTime();
+    fs.appendFileSync('log.txt', '\r\n')
+    fs.appendFileSync('log.txt', "New session started at: " + currentTime + '\r\n')
+    fs.appendFileSync('log.txt', '\r\n')
+}
+
+export function AXlog(msg) {
+    getTime();
+    console.log(msg)
+    fs.appendFileSync('log.txt', "[" + currentTime + "] " + msg + '\r\n')
+}
+
+export function AXlogColor(param1, msg) {
+    getTime();
+    console.log(param1, msg)
+    fs.appendFileSync('log.txt', "[" + currentTime + "] " + msg + '\r\n')
+}
+
+function getTime() {
+    let date_time = new Date();
+
+    // get current date
+    // adjust 0 before single digit date
+    let date = ("0" + date_time.getDate()).slice(-2);
+
+    // get current month
+    let month = ("0" + (date_time.getMonth() + 1)).slice(-2);
+
+    // get current year
+    let year = date_time.getFullYear();
+
+    // get current hours
+    let hours = date_time.getHours();
+
+    // get current minutes
+    let minutes = date_time.getMinutes();
+
+    // get current seconds
+    let seconds = date_time.getSeconds();
+
+    // prints date in YYYY-MM-DD format
+    //console.log(year + "-" + month + "-" + date);
+
+    // prints date & time in YYYY-MM-DD HH:MM:SS format
+    currentTime = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
+}
\ No newline at end of file
diff --git a/main.js b/main.js
index 40c0955..47bc221 100644
--- a/main.js
+++ b/main.js
@@ -1,6 +1,14 @@
-var prompt = require("prompt-sync")({ sigint: true });
-var fs = require('fs');
-var crypto = require('crypto');
+//var prompt = require("prompt-sync")({ sigint: true });
+//var fs = require('fs');
+//var crypto = require('crypto');
+
+import promptSync from 'prompt-sync';
+import {AXlog, newSession, AXlogColor} from './log.js';
+import * as fs from 'fs';
+import * as crypto from 'crypto';
+
+
+const prompt = promptSync({ sigint: true });
 
 // Variables
 var isdetected = false;
@@ -13,18 +21,20 @@ function delay(milliseconds) {
     });
 }
 //Credits
-console.log('\x1b[32m%s\x1b[0m', "███╗   ███╗ █████╗ ██████╗ ███████╗    ██████╗ ██╗   ██╗    ██████╗  ██████╗  ██████╗ ███████╗██████╗ ███████╗██╗   ██╗")
-console.log('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝    ██╔══██╗╚██╗ ██╔╝    ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║   ██║")
-console.log('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║  ██║█████╗      ██████╔╝ ╚████╔╝     ██████╔╝██║   ██║██║   ██║█████╗  ██║  ██║█████╗  ██║   ██║")
-console.log('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║  ██║██╔══╝      ██╔══██╗  ╚██╔╝      ██╔══██╗██║   ██║██║   ██║██╔══╝  ██║  ██║██╔══╝  ╚██╗ ██╔╝")
-console.log('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║  ██║██████╔╝███████╗    ██████╔╝   ██║       ██████╔╝╚██████╔╝╚██████╔╝██║     ██████╔╝███████╗ ╚████╔╝ ")
-console.log('\x1b[32m%s\x1b[0m', "╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝ ╚══════╝    ╚═════╝    ╚═╝       ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝     ╚═════╝ ╚══════╝  ╚═══╝  ")
-console.log('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
-console.log()
+AXlogColor('\x1b[32m%s\x1b[0m', "███╗   ███╗ █████╗ ██████╗ ███████╗    ██████╗ ██╗   ██╗    ██████╗  ██████╗  ██████╗ ███████╗██████╗ ███████╗██╗   ██╗")
+AXlogColor('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝    ██╔══██╗╚██╗ ██╔╝    ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║   ██║")
+AXlogColor('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║  ██║█████╗      ██████╔╝ ╚████╔╝     ██████╔╝██║   ██║██║   ██║█████╗  ██║  ██║█████╗  ██║   ██║")
+AXlogColor('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║  ██║██╔══╝      ██╔══██╗  ╚██╔╝      ██╔══██╗██║   ██║██║   ██║██╔══╝  ██║  ██║██╔══╝  ╚██╗ ██╔╝")
+AXlogColor('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║  ██║██████╔╝███████╗    ██████╔╝   ██║       ██████╔╝╚██████╔╝╚██████╔╝██║     ██████╔╝███████╗ ╚████╔╝ ")
+AXlogColor('\x1b[32m%s\x1b[0m', "╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝ ╚══════╝    ╚═════╝    ╚═╝       ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝     ╚═════╝ ╚══════╝  ╚═══╝  ")
+AXlogColor('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
+AXlog()
+
+newSession();
 
 //Ask user what database to use.
-console.log("What database should be used?")
-console.log("[1] Virus database")
+AXlog("What database should be used?")
+AXlog("[1] Virus database")
 const databasetouse = prompt("");
 if (databasetouse == 1) {
     databasetouse2 = "db.txt"
@@ -34,31 +44,31 @@ if (databasetouse == 69) {
 }
 
 // Load database
-console.log("Loading database...")
+AXlog("Loading database...")
 var database0 = fs.readFileSync(databasetouse2).toString().split("\n");
 var database = database0.toString().toUpperCase();
-console.log ("Database loaded!")
+AXlog ("Database loaded!")
 // Ask user what file they should scan
 const filetoscan = prompt("Enter path of file to be scanned: ");
-console.log("Obtaining hash...")
+AXlog("Obtaining hash...")
 const buff = fs.readFileSync(filetoscan);
 var outputdata0 = crypto.createHash("md5").update(buff).digest("hex");
 var outputdata = outputdata0.toString().toUpperCase();
-console.log("Hash: " + outputdata)
+AXlog("Hash: " + outputdata)
 // Check if database contains output data
-console.log("Checking if the hash matches the database...")
+AXlog("Checking if the hash matches the database...")
 if (database.includes(outputdata)) {
     isdetected = true;
-    console.log("The file IS a virus.");
+    AXlog("The file IS a virus.");
 } else {
     isdetected = false;
-    console.log("The file is NOT a virus.");
+    AXlog("The file is NOT a virus.");
 }
 
 
 /*async function printout() {
     await delay(100);
     if (isdetected == true) {
-        console.log("")
+        AXlog("")
     }
 }*/
\ No newline at end of file
diff --git a/package.json b/package.json
index f0c6b12..42567c9 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
   "version": "1.0.0",
   "description": "simple js virus scanner",
   "main": "main.js",
+  "type": "module",
   "scripts": {
     "update": "node update.js",
     "custom": "node dbcreator.js",
diff --git a/update.js b/update.js
index 2788ea6..c8a1d89 100644
--- a/update.js
+++ b/update.js
@@ -1,15 +1,16 @@
-var prompt = require("prompt-sync")({ sigint: true });
-var fs = require('fs');
-const http = require('http');
-const https = require('https');
+import promptSync from 'prompt-sync';
+import * as fs from 'fs';
+import * as http from 'http';
+import * as https from 'https';
+
+
+const prompt = promptSync({ sigint: true });
 
 console.log("This will update the database.")
 console.log("Do you wish to proceed? Y/N")
 const useragree = prompt("");
 if (useragree == "Y") {
     console.log("Deleting old files")
-    fs.unlinkSync("h-db.txt")
-    fs.unlinkSync("db.txt")
     console.log("Downloading new files")
     //download first database
     const db69 = fs.createWriteStream("h-db.txt");
@@ -31,5 +32,5 @@ if (useragree == "Y") {
         });
     });
 } else {
-    exit()
+    console.log("Exiting")
 }
\ No newline at end of file