Skip to content

Commit d9694b7

Browse files
committed
Fixed security button and powershell command, fixed search bar (problem with unexpected details popup's)
1 parent d849f44 commit d9694b7

8 files changed

Lines changed: 234 additions & 15 deletions

File tree

HowToRun.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## 🖥️ Installation (2 clicks — for recruiters)
2+
3+
The application is distributed as a **standalone EXE** built with `jpackage`.
4+
5+
### ✔ Requirements
6+
Nothing except:
7+
- Windows 10/11
8+
- Local user profile
9+
- Windows PowerShell (built-in on Windows 10/11)
10+
11+
> **Java is bundled inside the EXE**.
12+
> You do NOT need to install Java.
13+
14+
### ✔ Running the app
15+
1. Download `SystemLogAnalyzer.rar`
16+
2. unpack it with winrar anywhere.
17+
3. Double-click on SystemLogAnalyzer.exe
18+
4. (Optional) If Security logs are selected → confirm Windows UAC popup
19+
20+
That's all.
21+
22+
## 📦 How it works
23+
24+
### 1. Choose:
25+
- directory for storing exported CSVs
26+
- directory for saving reports
27+
- log types (Application / System / Security)
28+
29+
### 2. The app:
30+
- runs PowerShell → exports CSV
31+
- parses records
32+
- loads them into a JavaFX table
33+
34+
### 3. You can:
35+
- filter
36+
- search
37+
- inspect details
38+
- refresh logs anytime
39+
40+
All without touching Event Viewer manually.

HowToRun_PL.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## 🖥️ Instalacja (2 kliknięcia — dla rekruterów)
2+
3+
Aplikacja jest dystrybuowana jako **samodzielny plik EXE** zbudowany przy użyciu `jpackage`.
4+
5+
### ✔ Wymagania
6+
Nic poza:
7+
- Windows 10/11
8+
- Lokalnym profilem użytkownika
9+
- Windows PowerShell (built-in on Windows 10/11)
10+
11+
> **Java jest dołączona do pliku EXE**.
12+
> NIE musisz instalować Javy.
13+
14+
### ✔ Uruchamianie aplikacji
15+
1. Pobierz `SystemLogAnalyzer.exe`
16+
2. Wypakuj program w dowolne miejsce
17+
3. Kliknij go dwukrotnie na SystemLogAnalyzer.exe
18+
4. (Opcjonalnie) Jeśli wybrano dzienniki zabezpieczeń → potwierdź wyskakujące okienko UAC systemu Windows
19+
20+
To wszystko.
21+
22+
## 📦 Jak to działa
23+
24+
### 1. Wybierz:
25+
- katalog do przechowywania wyeksportowanych plików CSV
26+
- katalog do zapisywania raportów
27+
- typy logów (Aplikacja/System/Zabezpieczenia)
28+
29+
### 2. Aplikacja:
30+
- uruchamia program PowerShell → eksportuje plik CSV
31+
- analizuje rekordy
32+
- ładuje je do tabeli JavaFX
33+
34+
### 3. Możesz:
35+
- filtrować
36+
- wyszukiwać
37+
- sprawdzać szczegóły
38+
- odświeżać logi w dowolnym momencie
39+
40+
Wszystko to bez ręcznego uruchamiania Podglądu zdarzeń.

pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<dependencies>
2020

21-
<!-- CZYSTY SPRING (bez Boot) -->
21+
<!-- Clear Spring -->
2222
<dependency>
2323
<groupId>org.springframework</groupId>
2424
<artifactId>spring-context</artifactId>
@@ -46,12 +46,19 @@
4646
<version>25-ea+1</version>
4747
</dependency>
4848

49+
<!-- JNA core + platform for elevating app to admin permissions -->
50+
<dependency>
51+
<groupId>net.java.dev.jna</groupId>
52+
<artifactId>jna</artifactId>
53+
<version>5.13.0</version>
54+
</dependency>
55+
4956
</dependencies>
5057

5158
<build>
5259
<plugins>
5360

54-
<!-- Kompilator Javy -->
61+
<!-- Java compilator -->
5562
<plugin>
5663
<groupId>org.apache.maven.plugins</groupId>
5764
<artifactId>maven-compiler-plugin</artifactId>
@@ -71,7 +78,7 @@
7178
</configuration>
7279
</plugin>
7380

74-
<!-- Wyłącz testy przy build -->
81+
<!-- mvn skip tests (because there is none . . . yet!)-->
7582
<plugin>
7683
<groupId>org.apache.maven.plugins</groupId>
7784
<artifactId>maven-surefire-plugin</artifactId>

src/main/java/com/project/system_log_analyzer/SystemLogAnalyzerApp.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
package com.project.system_log_analyzer;
22

33
import com.project.system_log_analyzer.config.SpringConfig;
4+
import com.project.system_log_analyzer.system.WindowsElevationManager;
45
import javafx.application.Application;
56
import javafx.fxml.FXMLLoader;
67
import javafx.scene.Parent;
78
import javafx.scene.Scene;
89
import javafx.stage.Stage;
910
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
1011

12+
import java.io.FileNotFoundException;
13+
import java.io.FileOutputStream;
14+
import java.io.PrintStream;
15+
1116
public class SystemLogAnalyzerApp extends Application {
1217

1318
private AnnotationConfigApplicationContext springContext;
1419

20+
private static Boolean elevatedFlag = false; // Admin permissions
21+
1522
@Override
1623
public void init() {
1724
springContext = new AnnotationConfigApplicationContext(SpringConfig.class);
25+
26+
// debug
27+
PrintStream out = null;
28+
try {
29+
out = new PrintStream(new FileOutputStream("app.log", true), true);
30+
} catch (FileNotFoundException e) {
31+
throw new RuntimeException(e);
32+
}
33+
System.setOut(out);
34+
System.setErr(out);
1835
}
1936

2037
@Override
2138
public void start(Stage primaryStage) throws Exception {
2239
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/WelcomeView.fxml"));
2340
loader.setControllerFactory(springContext::getBean);
2441

25-
Parent root = loader.load();
42+
boolean elevated = getParameters().getRaw().contains("--elevated");
43+
elevatedFlag = elevated; // Admin profile checker
44+
45+
System.out.println("ARGS = " + getParameters().getRaw()); // Admin permission check to debug file
46+
47+
com.project.system_log_analyzer.config.appConfig cfg = springContext.getBean(com.project.system_log_analyzer.config.appConfig.class);
2648

49+
if (elevated) {
50+
cfg.setCsvSecurity(true);
51+
}
52+
53+
try {
54+
cfg.setCsvSecurity(elevated);
55+
IO.println("Elevated mode: " + elevated);
56+
} catch (Exception e) {
57+
System.err.println("Could not set elevated flag in appConfig: " + e.getMessage());
58+
}
59+
60+
Parent root = loader.load();
2761
SpringConfig.APP_READY = true;
2862

2963
Scene scene = new Scene(root);
@@ -37,6 +71,10 @@ public void stop() {
3771
springContext.close();
3872
}
3973

74+
public static boolean isElevated() {
75+
return Boolean.TRUE.equals(elevatedFlag);
76+
}
77+
4078
public static void main(String[] args) {
4179
launch(args);
4280
}

src/main/java/com/project/system_log_analyzer/controller/MainWindowFXController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public void onRefreshClick() {
175175
refreshButton.setDisable(true);
176176
logTable.setDisable(true);
177177
loadingLabel.setText("Refreshing logs… Please wait. (Time of loading depends on number of logs)");
178+
logTable.getSelectionModel().clearSelection();
179+
logTable.getFocusModel().focus(-1); // Details unexpected pop-up || Fixed
180+
onClearFilters(); // Clear all filters
178181

179182
Task<List<LogEvent>> task = new Task<List<LogEvent>>() {
180183
@Override
@@ -222,6 +225,8 @@ protected List<LogEvent> call() throws Exception {
222225
}
223226
@FXML
224227
public void onSearchChanged() {
228+
logTable.getSelectionModel().clearSelection();
229+
logTable.getFocusModel().focus(-1); // Details unexpected pop-up || Fixed
225230
applyFilters();
226231
}
227232

src/main/java/com/project/system_log_analyzer/controller/WelcomeViewFXController.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.project.system_log_analyzer.controller;
22

3+
import com.project.system_log_analyzer.SystemLogAnalyzerApp;
34
import com.project.system_log_analyzer.config.ApplicationContextProvider;
45
import com.project.system_log_analyzer.config.appConfig;
6+
import com.project.system_log_analyzer.system.WindowsElevationManager;
7+
import javafx.application.Platform;
58
import javafx.event.ActionEvent;
69
import javafx.fxml.FXML;
710
import javafx.fxml.FXMLLoader;
@@ -34,6 +37,11 @@ public class WelcomeViewFXController {
3437
@FXML
3538
public void initialize() {
3639
System.out.println("Controller initialized, appConfig = " + appConfig);
40+
41+
if (appConfig.isCsvSecurity()) {
42+
securityButton.setSelected(true);
43+
securityLabel.setText("Admin permission granted!");
44+
}
3745
}
3846

3947

@@ -57,7 +65,7 @@ private void scan(ActionEvent event) throws IOException {
5765
ApplicationContext springContext = ApplicationContextProvider.getApplicationContext();
5866

5967
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/LoadingScreen.fxml"));
60-
loader.setControllerFactory(springContext::getBean); // Spring Boot starter by JavaFX !!IMPORTANT!!
68+
loader.setControllerFactory(springContext::getBean); // Spring starter by JavaFX !!IMPORTANT!!
6169
Parent root = loader.load();
6270

6371
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
@@ -103,17 +111,26 @@ private void systemButtonON(ActionEvent event) throws IOException {
103111

104112
@FXML
105113
private void securityButtonON(ActionEvent event) throws IOException {
114+
115+
if (SystemLogAnalyzerApp.isElevated()) { // Admin ckeck for Security Logs
116+
securityLabel.setText("Admin permission granted!");
117+
appConfig.setCsvSecurity(securityButton.isSelected());
118+
return;
119+
}
120+
106121
if (securityButton.isSelected()) {
107122
boolean proceed = askForSecurityPermission();
108123
if (!proceed) {
109124
securityButton.setSelected(false);
110-
securityLabel.setText("Admin permission required!");
111125
appConfig.setCsvSecurity(false);
126+
securityLabel.setText("Admin permission required!");
112127
return;
113-
} else {
114-
securityLabel.setText("Admin permission granted!");
115-
appConfig.setCsvSecurity(true);
116128
}
129+
130+
boolean relaunchStarted = WindowsElevationManager.relaunchAsAdmin("--elevated");
131+
132+
if (relaunchStarted) Platform.exit();
133+
117134
} else {
118135
appConfig.setCsvSecurity(false);
119136
securityLabel.setText("(Requires Admin Permission)");

src/main/java/com/project/system_log_analyzer/io/WindowsEventExporter.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Path exportToCsv(LogType type) { // Method responsible for exporting logs
7878
}
7979
}
8080

81-
public Path exportSecurityLogsAsAdmin() { // Method responsible for exporting Security logs with admin permissions
81+
public Path exportSecurityLogsAsAdmin() {
8282
try {
8383
String baseDir = config.getLogsDir() != null && !config.getLogsDir().isEmpty()
8484
? config.getLogsDir() : "logs/exported";
@@ -89,15 +89,30 @@ public Path exportSecurityLogsAsAdmin() { // Method responsible for exporting S
8989
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
9090
Path outputFile = Path.of(dir.getAbsolutePath(), "Security_" + timestamp + ".csv");
9191

92-
String powershellCommand =
93-
"Start-Process powershell -Verb RunAs -ArgumentList " +
94-
"\"Get-WinEvent -LogName Security | " +
92+
String ps =
93+
"Get-WinEvent -LogName Security -MaxEvents 15000 | " +
9594
"Select-Object TimeCreated, Id, LevelDisplayName, ProviderName, Message | " +
96-
"Export-Csv -Path '" + outputFile.toAbsolutePath() + "' -NoTypeInformation -Encoding UTF8\"";
95+
"Export-Csv -Path '" + outputFile.toAbsolutePath() +
96+
"' -NoTypeInformation -Encoding UTF8";
9797

98-
ProcessBuilder pb = new ProcessBuilder("Powershell.exe", "-Command", powershellCommand);
98+
99+
100+
List<String> cmd = new ArrayList<>();
101+
cmd.add("powershell.exe");
102+
cmd.add("-NoProfile");
103+
cmd.add("-ExecutionPolicy");
104+
cmd.add("Bypass");
105+
cmd.add("-Command");
106+
cmd.add(ps);
107+
108+
ProcessBuilder pb = new ProcessBuilder(cmd);
109+
pb.redirectErrorStream(true);
99110
Process process = pb.start();
100111

112+
try (BufferedReader out = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
113+
out.lines().forEach(System.out::println);
114+
}
115+
101116
int exit = process.waitFor();
102117

103118
if (exit == 0) {
@@ -114,6 +129,7 @@ public Path exportSecurityLogsAsAdmin() { // Method responsible for exporting S
114129
return null;
115130
}
116131

132+
117133
public List<Path> exportSelected() {
118134
List<Path> paths = new ArrayList<>();
119135

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.project.system_log_analyzer.system;
2+
3+
import com.sun.jna.Native;
4+
import com.sun.jna.Pointer;
5+
import com.sun.jna.WString;
6+
import com.sun.jna.win32.W32APIOptions;
7+
8+
import java.io.File;
9+
10+
public class WindowsElevationManager {
11+
12+
public interface Shell32 extends com.sun.jna.Library {
13+
Shell32 INSTANCE = Native.load("shell32", Shell32.class, W32APIOptions.DEFAULT_OPTIONS);
14+
15+
Pointer ShellExecuteW(
16+
Pointer hwnd,
17+
WString lpOperation,
18+
WString lpFile,
19+
WString lpParameters,
20+
WString lpDirectory,
21+
int nShowCmd
22+
);
23+
}
24+
25+
public static boolean relaunchAsAdmin(String params) {
26+
try {
27+
String exePath = new File(System.getProperty("user.dir"),
28+
"System_Log_Analyzer.exe").getAbsolutePath();
29+
30+
Pointer p = Shell32.INSTANCE.ShellExecuteW(
31+
null,
32+
new WString("runas"),
33+
new WString(exePath),
34+
params == null ? null : new WString(params),
35+
null,
36+
1
37+
);
38+
39+
long result = Pointer.nativeValue(p);
40+
return result > 32;
41+
42+
} catch (Throwable t) {
43+
t.printStackTrace();
44+
return false;
45+
}
46+
}
47+
48+
public static boolean isCurrentUserAdmin() {
49+
try {
50+
new java.io.File("C:\\Windows\\System32\\config\\systemprofile").list();
51+
return true;
52+
} catch (Throwable e) {
53+
return false;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)