Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniDalvino committed Feb 21, 2021
1 parent 88b0fc3 commit 7e91049
Show file tree
Hide file tree
Showing 14 changed files with 3,946 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
build/
.vs/
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}",
"${workspaceFolder}/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

]
}
13 changes: 13 additions & 0 deletions .vscode/launch.vs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"projectTarget": "main.exe",
"name": "mydemo.exe with args",
"args": [
"-d mydll.dll -p notepad.exe"
]
}
]
}
75 changes: 75 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"**tq": "cpp",
"manfiest": "properties",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"filesystem": "cpp",
"xstring": "cpp",
"xtree": "cpp"
},
"C_Cpp.default.includePath": "C:/Users/ASD/Project/cplusplus/lib/vcpkg/installed/x86-windows/include/boost/"
}
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.18)
project("CommandLineInjector")

add_executable(main "src/main.cpp" "src/WinApiWrapper.cpp" "src/Util.cpp")
include_directories(main "include")
target_link_libraries(main "psapi.lib" "Wtsapi32.lib")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
set_property(TARGET main PROPERTY CXX_STANDARD 17)
set_property(TARGET main PROPERTY CXX_EXTENSIONS ON)


target_include_directories(main PUBLIC "include")
target_include_directories(main PUBLIC "C:/Users/ASD/Project/cplusplus/lib/vcpkg/installed/x64-windows/include") # set this as the vscode intelisense won't show the path unless I do this
target_compile_definitions(main PUBLIC "UNICODE")

if(NOT Boost_INCLUDE_DIR)
SET(Boost_INCLUDE_DIR "C:/Users/ASD/Project/cplusplus/lib/vcpkg/installed/x64-windows/include")
endif()
FIND_PACKAGE(Boost)
target_include_directories(main PUBLIC Boost_INCLUDE_DIR)

if (MSVC)
add_compile_options("/subsystem:console")
endif()
5 changes: 5 additions & 0 deletions include/Util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <vector>

template<typename T>
bool vector_include(std::vector<T> vec, T content);
67 changes: 67 additions & 0 deletions include/WinApiWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once
#include <vector>
#include <string>
#include <windows.h>
#include <filesystem>
#include <Psapi.h>
#include <Windows.h>
#include <WtsApi32.h>
#include <boost/foreach.hpp>
#include <codecvt>
#include <string>
#include <Psapi.h>
#include <functional>
#include <thread>

std::wstring utf8ToUtf16(std::string utf8Str);

std::string utf16ToUtf8(std::wstring utf16Str);

struct process
{
/**
* The exe name of the process
*/
std::wstring name;
DWORD pid;

process(DWORD pid, std::wstring name)
{
this->pid = pid;
this->name = name;
}

static std::vector<process> enumAllProcess();
};

/**
* Wait for a program to be opened syncronously
* @param toWatch the exe name of the program to wait to launch
* @return The PID of the program that opened
*/
DWORD waitForProgramLaunchSync(const std::wstring toWatch);

/**
* Wait for a program to be opened asyncronously
* @param toWatch the exe name of the program to wait to launch
* @param onLaunch an function to execute once the program find the program that launched
* @return An thread to scheduele the program watcher
*/
void waitForProgramLaunchAsync(const std::wstring toWatch, std::function<void(DWORD pid)> onLaunch);

enum class InjectDllReturnValue
{
AcessWindowHandleError,
MemAlocationError,
InjectionFail,
InjectionSucess,
InexistantDLL
};

/**
* Inject a DLL
* @param pid The process to inject the dll
* @param path The path of the dll
* @return Return false if there was a error while injecting
*/
InjectDllReturnValue InjectDll(DWORD pid, std::string Path);
Loading

0 comments on commit 7e91049

Please sign in to comment.