Commit 06b47c1f authored by Rina Sergeeva's avatar Rina Sergeeva

merge with master

parents 095d8da3 9f76a6c8
package application.controller;
import application.dto.RecordMap;
import application.entity.Record;
import application.util.NotificationType;
import application.util.RecordLoader;
import com.jfoenix.controls.JFXTextArea;
import com.jfoenix.controls.JFXTextField;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.IOException;
public class FxAddSignatureController extends FxAdminController {
@FXML
private JFXTextArea body;
@FXML
private JFXTextArea preview;
@FXML
private JFXTextField name;
private String encode(ActionEvent event) {
return DigestUtils.md5Hex(body.getText());
}
public void generateSignature(ActionEvent event) throws IOException {
String encodedBody = encode(event);
JFXTextField extField = (JFXTextField) scene.lookup("#extension");
JFXTextField offsetField = (JFXTextField) scene.lookup("#offset");
JFXTextField prefaceField = (JFXTextField) scene.lookup("#preface");
if (!offsetField.getText().matches("\\d+-\\d+")) {
setFocusColor(offsetField, true);
notificate("Malformed input!", NotificationType.ERROR);
return;
} else {
setFocusColor(offsetField, false);
}
String signature = prefaceField.getText()
+ ":" + encodedBody
+ ":" + 10
+ ":" + 20
+ ":" + 30
+ ":" + extField.getText()
+ ":" + name.getText();
preview.setText(signature);
notificate("Signature created", NotificationType.SUCCESS);
Record newRecord = Record.getInstance(signature);
RecordMap map = RecordMap.getInstance();
map.addRecord(newRecord.getPreface(), newRecord);
RecordLoader.unloadRecord();
}
}
package application.controller;
import application.dto.RecordMap;
import application.entity.Record;
import application.util.FilePreparer;
import application.util.FileSearcher;
import application.util.NotificationType;
import application.util.RecordLoader;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextArea;
import com.jfoenix.controls.JFXTextField;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Control;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.paint.Color;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.stream.Collectors;
public class FxAdminController extends FxController {
private Parent parent;
private Scene scene;
private Stage window;
protected Parent parent;
protected Scene scene;
protected Stage window;
private boolean isPE = false;
private FileSearcher fileSearcher;
@FXML
private Label filesFound;
private final DirectoryChooser directoryChooser = new DirectoryChooser();
@FXML
private void updateFilesFoundLabel(int total) {
filesFound.setText(String.valueOf(total));
}
public void loadAddSignature(ActionEvent event) throws IOException {
deselectHyperLink(event);
loadUI(event, "templates/av_add_signature.fxml");
......@@ -75,19 +86,12 @@ public class FxAdminController extends FxController {
setStageAndScene(event);
}
private void deselectHyperLink(ActionEvent event) {
protected void deselectHyperLink(ActionEvent event) {
Hyperlink hyperlink = (Hyperlink) event.getSource();
hyperlink.setVisited(false);
}
private String encode(ActionEvent event) {
JFXButton button = (JFXButton) event.getSource();
scene = button.getScene();
JFXTextArea body = (JFXTextArea) scene.lookup("#body");
return DigestUtils.md5Hex(body.getText());
}
private void setFocusColor(Control control, boolean malformed) {
protected void setFocusColor(Control control, boolean malformed) {
if (control instanceof JFXTextField) {
JFXTextField textField = (JFXTextField) control;
if (malformed) {
......@@ -100,39 +104,6 @@ public class FxAdminController extends FxController {
}
}
public void generateSignature(ActionEvent event) throws IOException {
String encodedBody = encode(event);
JFXTextArea preview = (JFXTextArea) scene.lookup("#preview");
JFXTextField nameField = (JFXTextField) scene.lookup("#name");
JFXTextField extField = (JFXTextField) scene.lookup("#extension");
JFXTextField offsetField = (JFXTextField) scene.lookup("#offset");
JFXTextField prefaceField = (JFXTextField) scene.lookup("#preface");
if (!offsetField.getText().matches("\\d+-\\d+")) {
setFocusColor(offsetField, true);
notificate("Malformed input!", NotificationType.ERROR);
return;
} else {
setFocusColor(offsetField, false);
}
String signature = prefaceField.getText()
+ ":" + encodedBody
+ ":" + 10
+ ":" + 20
+ ":" + 30
+ ":" + extField.getText()
+ ":" + nameField.getText();
preview.setText(signature);
notificate("Signature created", NotificationType.SUCCESS);
Record newRecord = Record.getInstance(signature);
RecordMap map = RecordMap.getInstance();
map.addRecord(newRecord.getPreface(), newRecord);
RecordLoader.unloadRecord();
}
public void clear(ActionEvent event) {
Hyperlink button = (Hyperlink) event.getSource();
scene = button.getScene();
......@@ -140,22 +111,6 @@ public class FxAdminController extends FxController {
dirpathNameField.setText(null);
}
public void loadDatabase(ActionEvent event) throws IOException, URISyntaxException {
JFXButton button = (JFXButton) event.getSource();
scene = button.getScene();
ListView<String> list = (ListView<String>) scene.lookup("#list");
RecordMap map = RecordLoader.loadRecords();
List<String> signatures = new ArrayList<>();
for (Record s : map.getRecords().values()) {
signatures.add(s.toString());
}
ObservableList<String> items = FXCollections.observableArrayList(signatures);
list.setItems(items);
}
public void browse(ActionEvent event) {
deselectHyperLink(event);
Hyperlink button = (Hyperlink) event.getSource();
......@@ -172,6 +127,10 @@ public class FxAdminController extends FxController {
}
}
public void filterPe(ActionEvent event) {
isPE = !isPE;
}
public void prepareFiles(ActionEvent event) {
JFXButton button = (JFXButton) event.getSource();
scene = button.getScene();
......@@ -184,18 +143,49 @@ public class FxAdminController extends FxController {
}
File root = new File(dirpathNameField.getText());
Timer timer = new Timer("Label Files Found Timer");
if (root.exists()) {
FileSearcher fileSearcher = FileSearcher.getInstance();
fileSearcher = FileSearcher.getInstance();
Thread fileSearcherThread = new Thread(() -> {
List<File> files = fileSearcher.prepareFiles(root);
List<String> filesItems = files.stream().map(file -> file.toString()).collect(Collectors.toList());
ObservableList<String> items = FXCollections.observableArrayList(filesItems);
preparedFilesList.setItems(items);
List<File> peFiles;
if (isPE) {
peFiles = new ArrayList<>();
for (File file : files) {
if (FilePreparer.isPE(file))
peFiles.add(file);
}
files.clear();
files.addAll(peFiles);
}
Platform.runLater(() -> {
List<String> filesItems = files.stream().map(File::toString).collect(Collectors.toList());
ObservableList<String> items = FXCollections.observableArrayList(filesItems);
preparedFilesList.setItems(items);
timer.cancel();
});
});
fileSearcherThread.setName("File Searcher");
fileSearcherThread.setDaemon(true);
fileSearcherThread.start();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> {
updateFilesFoundLabel(fileSearcher.getTotal());
});
}
}, 0, 250);
} else {
notificate("Invalid dirpath!", NotificationType.ERROR);
}
}
}
}
\ No newline at end of file
package application.controller;
import application.dto.RecordMap;
import application.entity.Record;
import application.util.RecordLoader;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
public class FxLoadDbController extends FxAdminController {
@FXML
private ListView database;
public void loadDatabase(ActionEvent event) throws IOException, URISyntaxException {
RecordMap map = RecordLoader.loadRecords();
List<String> signatures = new ArrayList<>();
for (Record s : map.getRecords().values()) {
signatures.add(s.toString());
}
ObservableList<String> items = FXCollections.observableArrayList(signatures);
database.setItems(items);
}
}
package application.util;
import java.io.*;
public class FilePreparer {
public static boolean isPE(File file) {
try (InputStream is = new FileInputStream(file)) {
// take e_lfanew value on 3C offset that contains PE address
// extra 4 bytes stand for DWORD data type
int e_lfanew = Integer.parseInt("3C", 16) + 4;
byte[] pe = new byte[e_lfanew];
if (is.read(pe, 0, e_lfanew) < 64)
return false;
// take DWORD (4bytes) of e_lfanew value
StringBuilder sb = new StringBuilder();
sb.append((char) pe[0]);
sb.append((char) pe[1]);
if (!sb.toString().equals("MZ"))
return false;
sb.setLength(0);
// TODO neg arr size ex
for (int i = e_lfanew - 1; i != e_lfanew - 1 - 4; i--) {
sb.append(String.format("%02X", pe[i]));
}
// convert from HEX to dec offset of PE header
int peOffset = Integer.parseInt(sb.toString(), 16);
// bytes left to read in order to get to PE header
int offsetToPe = peOffset - e_lfanew;
// read 'em
byte[] signature = new byte[offsetToPe];
is.read(signature, 0, offsetToPe);
// and finally get PE signature
byte[] pe_header = new byte[2];
is.read(pe_header, 0, 2);
sb.setLength(0);
for (byte p : pe_header) {
sb.append((char) p);
}
if (sb.toString().equals("PE"))
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
return false;
}
return false;
}
}
......@@ -12,14 +12,14 @@ public class FileSearcher {
private int filesFound;
public List<File> prepareFiles(File root) {
public List<File> prepareFiles(File root) {
filesFound = 0;
// monitor = new FileMonitor();
// monitor.start();
// monitor.registerDir(root);
monitor = new FileMonitor();
monitor.start();
monitor.registerDir(root);
List<File> foundedFiles = scanDirectory(root);
foundedFiles.addAll(monitoredFiles);
// monitor.stopMonitoring();
monitor.stopMonitoring();
return foundedFiles;
}
......
......@@ -14,7 +14,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="1024.0" styleClass="parent" stylesheets="@../styles/av.css" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.FxAdminController">
<AnchorPane prefHeight="600.0" prefWidth="1024.0" styleClass="parent" stylesheets="@../styles/av.css" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.FxAddSignatureController">
<VBox alignment="TOP_CENTER" prefHeight="600.0" prefWidth="300.0" styleClass="sidebar" stylesheets="@../styles/uv.css">
<Label prefHeight="75.0" prefWidth="300.0" style="-fx-background-color: #00A2D3;" text="Admin Panel" textFill="WHITE">
<padding>
......
......@@ -13,7 +13,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="1024.0" styleClass="parent" stylesheets="@../styles/av.css" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.FxAdminController">
<AnchorPane prefHeight="600.0" prefWidth="1024.0" styleClass="parent" stylesheets="@../styles/av.css" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.FxLoadDbController">
<VBox alignment="TOP_CENTER" prefHeight="600.0" prefWidth="300.0" styleClass="sidebar" stylesheets="@../styles/uv.css">
<Label prefHeight="75.0" prefWidth="300.0" style="-fx-background-color: #00A2D3;" text="Admin Panel" textFill="WHITE">
<padding>
......@@ -132,7 +132,7 @@
<Font name="Calibri Light" size="16.0" />
</font>
</JFXButton>
<JFXListView fx:id="list" layoutX="14.0" layoutY="14.0" prefHeight="212.0" prefWidth="518.0" />
<JFXListView fx:id="database" layoutX="14.0" layoutY="14.0" prefHeight="212.0" prefWidth="518.0" />
</Pane>
</VBox>
</AnchorPane>
......@@ -3,6 +3,7 @@
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXListView?>
<?import com.jfoenix.controls.JFXTextField?>
<?import com.jfoenix.controls.JFXToggleButton?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Hyperlink?>
......@@ -163,7 +164,7 @@
<Font name="Calibri Light" size="20.0" />
</font>
</Label>
<Label layoutX="659.0" layoutY="494.0" text="0">
<Label fx:id="filesFound" layoutX="659.0" layoutY="494.0" text="0">
<font>
<Font name="Calibri Light" size="20.0" />
</font>
......@@ -184,6 +185,7 @@
<Font name="Calibri Light" size="22.0" />
</font>
</Label>
<JFXToggleButton layoutX="598.0" layoutY="387.0" mnemonicParsing="false" onAction="#filterPe" text="PE" />
</children>
</Pane>
</VBox>
......
......@@ -58,6 +58,24 @@
<Font name="Calibri Light Italic" size="19.0" />
</font>
</Label>
<VBox prefHeight="150.0" prefWidth="724.0">
<children>
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #f9f9f9;">
<children>
<Label layoutX="50.0" layoutY="38.0" text="Your device is being protected">
<font>
<Font name="Calibri Light" size="32.0" />
</font>
</Label>
<Label layoutX="50.0" layoutY="98.0" text="Last health scan: 04/04/2019">
<font>
<Font name="Calibri Light" size="19.0" />
</font>
</Label>
</children>
</Pane>
</children>
</VBox>
</children>
</Pane>
</children>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment