Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
spider2048 committed Dec 7, 2023
1 parent 2758f8e commit dbffabb
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ForceControlC/.vscode/c_cpp_properties.json
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
}
3 changes: 3 additions & 0 deletions ForceControlC/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"mesonbuild.configureOnOpen": false
}
15 changes: 15 additions & 0 deletions ForceControlC/README.md
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>
```
70 changes: 70 additions & 0 deletions ForceControlC/forcecontrolc.cpp
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;
}
}
7 changes: 7 additions & 0 deletions ForceControlC/meson.build
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)
5 changes: 5 additions & 0 deletions README.md
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.

0 comments on commit dbffabb

Please sign in to comment.