diff --git a/compile-arch.sh b/compile-arch.sh new file mode 100755 index 0000000..27e1dcf --- /dev/null +++ b/compile-arch.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# Configuration +OUTPUT="hitmanLinux" +SOURCE="hitmanLinux.cpp" +REQUIRED_PACKAGES=( + "gcc" + "pkgconf" + "gtk3" + "libx11" + "libayatana-appindicator" +) + +# Compiler flags +CXXFLAGS=( + "-O2" # Optimization level 2 + "-Wall" # Enable all warnings + "-Wextra" # Enable extra warnings + "-std=c++11" # C++11 standard + "-fstack-protector-strong" # Stack protection + "-D_FORTIFY_SOURCE=2" # Additional security checks + "-static-libgcc" # Static linking of libgcc + "-static-libstdc++" # Static linking of libstdc++ +) + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Error handling +set -e # Exit on error + +# Print error message and exit +error() { + echo -e "${RED}Error: $1${NC}" >&2 + exit 1 +} + +# Print success message +success() { + echo -e "${GREEN}$1${NC}" +} + +# Print warning message +warning() { + echo -e "${YELLOW}Warning: $1${NC}" +} + +# Check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check and install required packages +check_and_install_packages() { + echo "Checking for required packages..." + + # Check if we're running on a Debian-based system + if ! command_exists pacman; then + error "This script requires pacman package manager. Please install packages manually." + fi + + # Check for sudo privileges + if ! command_exists sudo; then + error "sudo is required to install packages" + fi + + local missing_packages=() + for package in "${REQUIRED_PACKAGES[@]}"; do + if ! pacman -Qi "$package" &>/dev/null; then + missing_packages+=("$package") + else + success "$package is already installed." + fi + done + + # Install missing packages + if [ ${#missing_packages[@]} -ne 0 ]; then + echo "Installing missing packages: ${missing_packages[*]}" + sudo pacman -Sy --noconfirm "${missing_packages[@]}" || error "Failed to install packages" + fi +} + +# Compile source code +compile_source() { + echo "Compiling $SOURCE..." + + # Check if source file exists + [ -f "$SOURCE" ] || error "Source file $SOURCE not found" + + # Set PKG_CONFIG_PATH + export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH + + # Get GTK and X11 flags + local pkg_config_flags + pkg_config_flags=$(pkg-config --cflags --libs gtk+-3.0 x11 ayatana-appindicator3-0.1) || error "Failed to get package config flags" + + # Compile + g++ "${CXXFLAGS[@]}" "$SOURCE" -o "$OUTPUT" $pkg_config_flags || error "Compilation failed" + + # Make executable + chmod +x "$OUTPUT" || warning "Failed to make file executable" + + success "Compilation successful! Output file: $OUTPUT" +} + +# Cleanup function +cleanup() { + if [ $? -ne 0 ]; then + echo -e "\n${RED}Compilation failed!${NC}" + # Remove output file if it exists and compilation failed + [ -f "$OUTPUT" ] && rm "$OUTPUT" + fi +} + +# Main function +main() { + # Register cleanup function + trap cleanup EXIT + + echo "Starting compilation process..." + check_and_install_packages + compile_source + echo -e "\nBuild completed successfully!" +} + +# Run main function +main \ No newline at end of file diff --git a/compile.bat b/compile.bat index 35e7d17..a45e12b 100644 --- a/compile.bat +++ b/compile.bat @@ -1,5 +1,119 @@ @echo off -echo Compilation uses g++, make sure you have it installed! -@echo on -windres resources.rc -O coff -o resources.o -g++ -o ProcessHitman.exe hitman.cpp resources.o -mwindows \ No newline at end of file +setlocal enabledelayedexpansion + +:: Configuration +set "OUTPUT=ProcessHitman.exe" +set "SOURCE=hitman.cpp" +set "RESOURCE=resources.rc" +set "RESOURCE_OBJ=resources.o" + +:: Compiler flags +set "CXXFLAGS=-O2 -Wall -Wextra -std=c++11" +set "LINKFLAGS=-static -static-libgcc -static-libstdc++" +set "WINFLAGS=-mwindows -municode" + +:: Colors +set "RED=[91m" +set "GREEN=[92m" +set "YELLOW=[93m" +set "BLUE=[94m" +set "RESET=[0m" + +:: Title +title Process Hitman Build Script + +echo %BLUE%=================================%RESET% +echo %BLUE% Process Hitman Build Script %RESET% +echo %BLUE%=================================%RESET% +echo. + +:: Check for required tools +echo %BLUE%Checking required tools...%RESET% +where g++ >nul 2>&1 +if %ERRORLEVEL% neq 0 ( + echo %RED%Error: g++ not found! Please install MinGW-w64 and add it to PATH.%RESET% + echo %YELLOW%Download MinGW-w64 from: https://winlibs.com/%RESET% + goto :error +) + +where windres >nul 2>&1 +if %ERRORLEVEL% neq 0 ( + echo %RED%Error: windres not found! Please install MinGW-w64 and add it to PATH.%RESET% + goto :error +) + +:: Check if source files exist +echo %BLUE%Checking source files...%RESET% +if not exist "%SOURCE%" ( + echo %RED%Error: Source file %SOURCE% not found!%RESET% + goto :error +) + +if not exist "%RESOURCE%" ( + echo %RED%Error: Resource file %RESOURCE% not found!%RESET% + goto :error +) + +:: Clean previous build +echo %BLUE%Cleaning previous build...%RESET% +if exist "%OUTPUT%" ( + del "%OUTPUT%" 2>nul + if exist "%OUTPUT%" ( + echo %RED%Error: Could not delete previous build!%RESET% + goto :error + ) else ( + echo %GREEN%Previous build cleaned successfully.%RESET% + ) +) + +:: Compile resources +echo %BLUE%Compiling resources...%RESET% +windres "%RESOURCE%" -O coff -o "%RESOURCE_OBJ%" +if %ERRORLEVEL% neq 0 ( + echo %RED%Error: Failed to compile resources!%RESET% + goto :error +) +echo %GREEN%Resources compiled successfully.%RESET% + +:: Compile main program +echo %BLUE%Compiling main program...%RESET% +g++ %CXXFLAGS% %LINKFLAGS% %WINFLAGS% -o "%OUTPUT%" "%SOURCE%" "%RESOURCE_OBJ%" +if %ERRORLEVEL% neq 0 ( + echo %RED%Error: Compilation failed!%RESET% + goto :error +) + +:: Clean up resource object file +del "%RESOURCE_OBJ%" 2>nul + +:: Check if compilation was successful +if exist "%OUTPUT%" ( + echo %GREEN%Build completed successfully!%RESET% + echo %GREEN%Output file: %OUTPUT%%RESET% +) else ( + echo %RED%Error: Output file not created!%RESET% + goto :error +) + +:: Optional: Show file size +for %%A in ("%OUTPUT%") do ( + echo %BLUE%File size: %%~zA bytes%RESET% +) + +echo. +echo %BLUE%=================================%RESET% +echo %GREEN% Build Process Complete %RESET% +echo %BLUE%=================================%RESET% + +goto :end + +:error +echo. +echo %RED%=================================%RESET% +echo %RED% Build Process Failed %RESET% +echo %RED%=================================%RESET% +exit /b 1 + +:end +endlocal +pause diff --git a/compile.sh b/compile.sh old mode 100644 new mode 100755 index ca6a05f..c95299a --- a/compile.sh +++ b/compile.sh @@ -1,34 +1,131 @@ +#!/bin/bash + +# Configuration OUTPUT="hitmanLinux" SOURCE="hitmanLinux.cpp" +REQUIRED_PACKAGES=( + "g++" + "pkg-config" + "libgtk-3-dev" + "libx11-dev" + "libayatana-appindicator3-dev" +) + +# Compiler flags +CXXFLAGS=( + "-O2" # Optimization level 2 + "-Wall" # Enable all warnings + "-Wextra" # Enable extra warnings + "-std=c++11" # C++11 standard + "-fstack-protector-strong" # Stack protection + "-D_FORTIFY_SOURCE=2" # Additional security checks + "-static-libgcc" # Static linking of libgcc + "-static-libstdc++" # Static linking of libstdc++ +) + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Error handling +set -e # Exit on error + +# Print error message and exit +error() { + echo -e "${RED}Error: $1${NC}" >&2 + exit 1 +} -REQUIRED_PACKAGES=("g++" "pkg-config" "libgtk-3-dev" "libx11-dev" "libayatana-appindicator3-dev") +# Print success message +success() { + echo -e "${GREEN}$1${NC}" +} + +# Print warning message +warning() { + echo -e "${YELLOW}Warning: $1${NC}" +} + +# Check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} +# Check and install required packages check_and_install_packages() { echo "Checking for required packages..." - for PACKAGE in "${REQUIRED_PACKAGES[@]}"; do - if ! dpkg -s "$PACKAGE" &>/dev/null; then - echo "Missing package: $PACKAGE" - echo "Installing $PACKAGE..." - sudo apt update - sudo apt install -y "$PACKAGE" - if [ $? -ne 0 ]; then - echo "Failed to install $PACKAGE. Please check your package manager." - exit 1 - fi + + # Check if we're running on a Debian-based system + if ! command_exists apt-get; then + error "This script requires apt-get package manager. Please install packages manually." + fi + + # Check for sudo privileges + if ! command_exists sudo; then + error "sudo is required to install packages" + fi + + local missing_packages=() + for package in "${REQUIRED_PACKAGES[@]}"; do + if ! dpkg -s "$package" &>/dev/null; then + missing_packages+=("$package") else - echo "$PACKAGE is already installed." + success "$package is already installed." fi done + + # Install missing packages + if [ ${#missing_packages[@]} -ne 0 ]; then + echo "Installing missing packages: ${missing_packages[*]}" + sudo apt-get update || error "Failed to update package list" + sudo apt-get install -y "${missing_packages[@]}" || error "Failed to install packages" + fi } +# Compile source code compile_source() { + echo "Compiling $SOURCE..." + + # Check if source file exists + [ -f "$SOURCE" ] || error "Source file $SOURCE not found" + + # Set PKG_CONFIG_PATH export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH - g++ "$SOURCE" -o "$OUTPUT" $(pkg-config --cflags --libs gtk+-3.0 x11 ayatana-appindicator3-0.1) -std=c++11 + + # Get GTK and X11 flags + local pkg_config_flags + pkg_config_flags=$(pkg-config --cflags --libs gtk+-3.0 x11 ayatana-appindicator3-0.1) || error "Failed to get package config flags" + + # Compile + g++ "${CXXFLAGS[@]}" "$SOURCE" -o "$OUTPUT" $pkg_config_flags || error "Compilation failed" + + # Make executable + chmod +x "$OUTPUT" || warning "Failed to make file executable" + + success "Compilation successful! Output file: $OUTPUT" } +# Cleanup function +cleanup() { + if [ $? -ne 0 ]; then + echo -e "\n${RED}Compilation failed!${NC}" + # Remove output file if it exists and compilation failed + [ -f "$OUTPUT" ] && rm "$OUTPUT" + fi +} + +# Main function main() { + # Register cleanup function + trap cleanup EXIT + + echo "Starting compilation process..." check_and_install_packages compile_source + echo -e "\nBuild completed successfully!" } -main +# Run main function +main \ No newline at end of file diff --git a/hitmanLinux.cpp b/hitmanLinux.cpp index d8d1678..4e33e8e 100644 --- a/hitmanLinux.cpp +++ b/hitmanLinux.cpp @@ -15,10 +15,14 @@ #define CONFIG_FILE_PATH "/.config/process_hitman" bool hookEnabled = false; +bool isMainLoopRunning = false; GtkWidget *button, *checkbox1, *checkbox2, *checkbox3; -Display *display; +Display *display = nullptr; +GMainLoop *main_loop = nullptr; pid_t GetActiveWindowPID() { + if (!display) return 0; + Atom prop = XInternAtom(display, "_NET_WM_PID", True); Window window; int revert; @@ -53,7 +57,7 @@ void KillProcess(pid_t pid) { void ToggleHook(GtkButton *btn) { hookEnabled = !hookEnabled; - gtk_button_set_label(btn, hookEnabled ? "Disable Alt+F5" : "Enable Alt+F5"); + gtk_button_set_label(GTK_BUTTON(btn), hookEnabled ? "Disable Alt+F5" : "Enable Alt+F5"); } gboolean OnKeyPress() { @@ -90,7 +94,9 @@ void ShutdownFunction() { configFile.close(); } - gtk_main_quit(); + if (main_loop && g_main_loop_is_running(main_loop)) { + g_main_loop_quit(main_loop); + } } void LoadCheckboxStates() { @@ -137,41 +143,81 @@ void CreateUI(GtkWidget *window) { LoadCheckboxStates(); } +void CleanupResources() { + if (display) { + XCloseDisplay(display); + display = nullptr; + } + if (main_loop) { + g_main_loop_unref(main_loop); + main_loop = nullptr; + } +} + int main(int argc, char **argv) { - gtk_init(&argc, &argv); + // Initialize GTK + if (!gtk_init_check(&argc, &argv)) { + std::cerr << "Failed to initialize GTK!" << std::endl; + return 1; + } + + // Initialize X display display = XOpenDisplay(NULL); if (!display) { std::cerr << "Failed to open X display!" << std::endl; return 1; } + // Create main loop + main_loop = g_main_loop_new(NULL, FALSE); + if (!main_loop) { + std::cerr << "Failed to create main loop!" << std::endl; + CleanupResources(); + return 1; + } + + // Create main window GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Process Hitman"); gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); + // Connect destroy signal g_signal_connect(window, "destroy", G_CALLBACK(ShutdownFunction), NULL); + // Create UI CreateUI(window); gtk_widget_show_all(window); + // Set up X11 key binding KeyCode key_f5 = XKeysymToKeycode(display, XStringToKeysym("F5")); XGrabKey(display, key_f5, Mod1Mask, DefaultRootWindow(display), True, GrabModeAsync, GrabModeAsync); - while (true) { + // Event handling + GSource *x11_source = g_idle_source_new(); + g_source_set_callback(x11_source, []([[maybe_unused]]gpointer user_data) -> gboolean { + if (!display) return G_SOURCE_REMOVE; + while (XPending(display)) { XEvent event; XNextEvent(display, &event); if (event.type == KeyPress) { - if (event.xkey.keycode == key_f5 && (event.xkey.state & Mod1Mask)) { + if (event.xkey.keycode == XKeysymToKeycode(display, XStringToKeysym("F5")) && + (event.xkey.state & Mod1Mask)) { OnKeyPress(); } } } + return G_SOURCE_CONTINUE; + }, NULL, NULL); + g_source_attach(x11_source, g_main_loop_get_context(main_loop)); + g_source_unref(x11_source); - g_main_context_iteration(NULL, FALSE); - } + // Run main loop + g_main_loop_run(main_loop); - XCloseDisplay(display); + // Cleanup + CleanupResources(); + return 0; } \ No newline at end of file