Skip to content

Commit

Permalink
unprotected file scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
nedlir committed Apr 21, 2022
1 parent 7ad223b commit a08ca53
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/officerbreaker/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class Controller {
private Image powerpointImage;
private Image progressOnGoing;
private Image progressFinished;

@FXML
private Text fileText;

@FXML
private Text invalidFileText;

@FXML
private ImageView progressBarBrowse;

Expand All @@ -60,19 +60,19 @@ public class Controller {
public void initialize() {
anchorPane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));

invalidFileText.setVisible(false);
invalidFileText.setVisible(false);
progressBarBrowse.setVisible(false);
progressBarRemove.setVisible(false);

try {
wordImage = new Image(getClass().getResourceAsStream("img/word.png"));

powerpointImage = new Image(getClass().getResourceAsStream("img/powerpoint.png"));

excelImage = new Image(getClass().getResourceAsStream("img/excel.png"));

progressOnGoing = new Image(getClass().getResourceAsStream("img/prog-bar-ongoing.gif"));

progressFinished = new Image(getClass().getResourceAsStream("img/prog-bar-complete.png"));

} catch (Exception e) {
Expand All @@ -84,14 +84,20 @@ public void initialize() {
void browsePressed(ActionEvent event) {

invalidFileText.setVisible(false);
progressBarRemove.setVisible(false);

progressBarBrowse.setVisible(true);
progressBarBrowse.setImage(progressOnGoing);

filePathText.setVisible(false);

try {
fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null);
filePath = file.toString();
fileName = file.getName();
filePathText.setVisible(true);
filePathText.setText(filePath);
fileType = getFileType();

Expand All @@ -106,6 +112,7 @@ void browsePressed(ActionEvent event) {

@FXML
void removePasswordPressed(ActionEvent event) {

if (file == null) {
return;
}
Expand All @@ -118,32 +125,32 @@ void removePasswordPressed(ActionEvent event) {
// show progress
progressBarRemove.setVisible(true);
progressBarRemove.setImage(progressOnGoing);

FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file

manipulator.extractFile(); // extract XML from file

XMLParser parser = new XMLParser(manipulator); // create new object to parse the XML

if (parser.isExistSecurityElement()) // if the file has a password
if (parser.isExistSecurityElement()) // if the file has a password protection as a read-only file
{
parser.removeElementOfSecurity(); // remove hash node from XML file

parser.writeToXMLFile(); // write to XML the change

manipulator.insertFile(); // write back to file

manipulator.removeXMLFile(); // cleans the xml extracted from origin file

fileText.setText(fileFinishedMessage());

progressBarRemove.setImage(progressFinished);
}
else // if there is no security element in the xml file, there is no read-only protection on it

} else // if there is no security element in the xml file, there is no read-only protection on it
{
manipulator.removeXMLFile(); // cleans the xml extracted from origin file
fileText.setText(notReadOnlyMessage());
}

manipulator.removeXMLFile(); // cleans the xml extracted from origin file

progressBarRemove.setImage(progressFinished);

} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -219,4 +226,9 @@ private String fileFinishedMessage() {
return messageOnScreen;
}

private String notReadOnlyMessage() {
String messageOnScreen = "Officer Breaker couldn't find any \"read-only\" restriction on the file. \n \nTry another file?";
return messageOnScreen;
}

}

0 comments on commit a08ca53

Please sign in to comment.