-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2758f8e
commit dbffabb
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"${workspaceFolder}/**" | ||
], | ||
"defines": [ | ||
"_DEBUG", | ||
"UNICODE", | ||
"_UNICODE" | ||
], | ||
"compilerPath": "D:\\msys64\\mingw64\\bin\\gcc.exe", | ||
"intelliSenseMode": "windows-gcc-x64", | ||
"compileCommands": "${workspaceFolder}/build/compile_commands.json" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mesonbuild.configureOnOpen": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ForceControlC | ||
|
||
> Sp1d3R | 2023 | ||
## Usage | ||
|
||
```bash | ||
$ python simulate.py # (Example) | ||
<handle Ctrl-C events and never stop> | ||
``` | ||
|
||
```bash | ||
$ .\ForceControlC python simulate.py | ||
<terminate python on Ctrl-C> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <sstream> | ||
#include <cstdlib> | ||
#include <Windows.h> | ||
|
||
PROCESS_INFORMATION pi; | ||
void terminate_child_process(); | ||
void spawn_process(const std::string& command_line); | ||
BOOL WINAPI ctrl_handler(DWORD fdwCtrlType); | ||
|
||
int main(int argc, char** argv) { | ||
SetConsoleCtrlHandler(ctrl_handler, TRUE); | ||
|
||
std::stringstream ss; | ||
for (int i=1; i<argc; ++i) { | ||
ss << argv[i] << " "; | ||
} | ||
|
||
spawn_process(ss.str()); | ||
} | ||
|
||
void spawn_process(const std::string& command_line) { | ||
memset(&pi, 0, sizeof(PROCESS_INFORMATION)); | ||
|
||
STARTUPINFOA si; | ||
memset(&si, 0, sizeof(STARTUPINFOA)); | ||
|
||
bool ret = CreateProcessA( | ||
nullptr, | ||
const_cast<char*>(command_line.c_str()), | ||
nullptr, | ||
nullptr, | ||
false, | ||
0, | ||
nullptr, | ||
nullptr, | ||
&si, | ||
&pi | ||
); | ||
|
||
if (!ret) { | ||
std::cerr << "[-] Creating process failed." << std::endl; | ||
return; | ||
} | ||
|
||
WaitForSingleObject(pi.hProcess, INFINITE); | ||
|
||
DWORD exit{}; | ||
GetExitCodeProcess(pi.hProcess, &exit); | ||
TerminateProcess(GetCurrentProcess(), exit); | ||
} | ||
|
||
void terminate_child_process() { | ||
std::cout << "[+] Quitting ..." << std::endl; | ||
if (pi.hThread) { | ||
TerminateProcess(pi.hProcess, 777); | ||
} | ||
} | ||
|
||
|
||
BOOL WINAPI ctrl_handler(DWORD fdwCtrlType) { | ||
switch (fdwCtrlType) { | ||
case CTRL_C_EVENT: | ||
terminate_child_process(); | ||
return TRUE; | ||
default: return FALSE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
project('ForceControlC', 'cpp', | ||
version : '0.1', | ||
default_options : ['warning_level=3', 'cpp_std=c++14']) | ||
|
||
executable('ForceControlC', | ||
'forcecontrolc.cpp', | ||
install : true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Utilities | ||
|
||
> Sp1d3R | 2023 | ||
A collection of utilities to make lives easier. |