Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
0x11DFE committed Jun 14, 2021
1 parent 76d9085 commit 2b4bcfa
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Expand All @@ -7,3 +8,4 @@ cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# WTCPPoofer
Window Title Spoofer
CPP Window Title Spoofer

### Why?
No reason at all i just had needed it for a test and now i have nothing to do with it anymore so to save "you?" some time you can clone it.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.19)
project(WindowSpoofer)

set(CMAKE_CXX_STANDARD 20)

add_executable(WindowSpoofer main.cpp util.cpp inc.cpp)
7 changes: 7 additions & 0 deletions src/inc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>
#include <sstream>
#include <thread>
#include <Windows.h>
#include <psapi.h>

using namespace std;
55 changes: 55 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "util.cpp"

bool loop = false;
string processID;
string processWindowTitle;

void changeWindowTitle_loop() {
bool startOnce = true;

while (loop || startOnce) {
startOnce = false; // stop once started

HWND processHandle = Util::find_main_window(stoi(processID));
bool isChanged = SetWindowTextA(processHandle, processWindowTitle.c_str());
cout << (isChanged ? "+" : "."); // give some sort of information if the process is still active
}
}

int main(int argc, char **argv) {
SetConsoleTitle("WindowTitleSpoofer");

string loopYN;

if (argv[1] == nullptr || argv[2] == nullptr) {
cout << "Hey you can also launch using arguments. [argv[1] = processID, argv[2] = processWindowTitle]" << endl;

cout << "Process ID: ";
getline(cin, processID);

cout << "Window Title: ";
getline(cin, processWindowTitle);

loop:
cout << "Loop spoof [y, n]: ";
getline(cin, loopYN);
} else {
processID = argv[1];
processWindowTitle = argv[2];
loopYN = argv[3];
}

// Define loop status else ask again
if (loopYN != "y" && loopYN != "n") goto loop;
loop = loopYN == "y";

// Start background thread
thread(changeWindowTitle_loop).detach();

// If console resumed stop loop & program
cout << "Press a key to exit from the program." << endl;
cin.get();

loop = false;
exit(0);
}
36 changes: 36 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "inc.cpp"

class Util {
struct handle_data {
unsigned long process_id;
HWND window_handle;
};

static BOOL is_main_window(HWND handle) {
return GetWindow(handle, GW_OWNER) == (HWND) nullptr && IsWindowVisible(handle);
}

static BOOL CALLBACK enum_windows_callback(HWND handle, LPARAM lParam) {
handle_data &data = *(handle_data *) lParam;
unsigned long process_id = 0;
GetWindowThreadProcessId(handle, &process_id);
if (data.process_id != process_id || !is_main_window(handle)) return TRUE;

data.window_handle = handle;
return FALSE;
}

/***
* Enumerate windows from a process_id in order to get the process handle
* @param process_id
* @return HANDLE
*/
public:
static HWND find_main_window(unsigned long process_id) {
handle_data data{};
data.process_id = process_id;
data.window_handle = nullptr;
EnumWindows(enum_windows_callback, (LPARAM) &data);
return data.window_handle;
}
};

0 comments on commit 2b4bcfa

Please sign in to comment.