Skip to content

Commit 95b3992

Browse files
author
ViniDalvino
committed
Added feature to unload module
1 parent b6f9d8c commit 95b3992

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2+
Version 2, December 2004
3+
4+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5+
6+
Everyone is permitted to copy and distribute verbatim or modified
7+
copies of this license document, and changing it is allowed as long
8+
as the name is changed.
9+
10+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12+
13+
0. You just DO WHAT THE FUCK YOU WANT TO.

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![License: WTFPL](https://img.shields.io/badge/License-WTFPL-brightgreen.svg)](http://www.wtfpl.net/about/)
12
# command-line-dll-injector
23
An command line utility made for injecting Dll
34

@@ -17,14 +18,14 @@ The program fully respect the CLI Guidelines which mean that the program will b
1718

1819
# Command line argument
1920

20-
| **Argument** | **Description** | **Example** |
21-
|:------------------:|-------------------------------------------------------------------------------------------|----------------------|
22-
| `-h [ --help ]` | Produce a help message | |
23-
| `-d [ --dll ] arg` | Specify the dll to launch | `--dll cheat.dll` |
24-
| `-e [ --exe ] arg` | Specify the program name to inject | `--exe MGSV.exe` |
25-
| `-w [ --watch ]` | Wait for the specified to be opened before injecting | `-w -p game.exe` |
26-
| `--delay arg` | Wait a amount of time before injecting(in seconds) | `--delay 1.5` |
27-
| `-u [ --unload ]` | Unload the dll that is going to be injected if it's already present in the process memory | |
21+
| **Argument** | **Description** | **Example** |
22+
|:------------------:|-----------------------------------------------------------------------------------------------------------|-------------------|
23+
| `-h [ --help ]` | Produce a help message | |
24+
| `-d [ --dll ] arg` | Specify the dll to launch | `--dll cheat.dll` |
25+
| `-e [ --exe ] arg` | Specify the program name to inject | `--exe MGSV.exe` |
26+
| `-w [ --watch ]` | Wait for the specified to be opened before injecting | `-w -p game.exe` |
27+
| `--delay arg` | Wait a amount of time before injecting(in seconds) | `--delay 1.5` |
28+
| `-u [ --unload ]` | Unload the dll that is going to be injected if it's already present in the process memory (not added yet) | |
2829

2930
# Example:
3031

include/spinner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12
#ifndef __SPINNERCPP__
23
#define __SPINNERCPP__
34

src/main.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@
2020
#include <BlackBone/Misc/Utils.h>
2121
#include <filesystem>
2222
#include <BlackBone/PE/PEImage.h>
23-
#include <spinner.h>
2423
#include <BlackBone/PE/ImageNET.h>
24+
#define NAKED __declspec( naked )
25+
2526

2627
using namespace std::chrono_literals;
2728
namespace po = boost::program_options;
2829

30+
bool nt_error(NTSTATUS status);
31+
32+
// #define WAIT_DEBUG_ATTACH
33+
2934
int main(int argc, char const *argv[])
3035
{
36+
#ifdef WAIT_DEBUG_ATTACH
37+
BOOL isDebuggerPresent;
38+
while (!isDebuggerPresent) { CheckRemoteDebuggerPresent(GetModuleHandle(NULL), &isDebuggerPresent); };
39+
#endif
3140
SetConsoleTitleW(L"Command line dll injector");
3241
blackbone::InitializeOnce();
3342
po::options_description desc("Allowed options:");
@@ -133,12 +142,19 @@ if (vm.count("exe"))
133142
// attach the dll
134143
if (vm.count("unload-dll"))
135144
{
136-
spinnercpp::spinner s(200ms, 63, "Unloaded dll!", "", "", " Unloading " + vm["dll"].as<std::string>() + "...");
137-
s.start();
138-
auto isError = NT_ERROR(process.modules().Unload(process.modules().GetModule(utf8ToUtf16(vm["dll"].as<std::string>()))));
139-
if (isError)
140-
std::cerr << "There was a error unloading the dll on the process. Continuing execution of the program.";
141-
s.stop();
145+
std::cout << "Unloading dll. . ." << std::endl;
146+
auto dll_ = process.modules().GetModule(utf8ToUtf16(vm["dll_"].as<std::string>()));
147+
if (dll_->type != blackbone::eModType::mt_unknown || dll_->size == 0x0)
148+
{
149+
if (nt_error(process.modules().Unload(dll_)))
150+
std::cerr << "There was a error unloading the dll on the process. Continuing execution of the program." << std::endl;
151+
else
152+
{
153+
std::cout << "Unloaded dll!" << std::endl;
154+
}
155+
}
156+
else
157+
std::cerr << "Couldn't unload dll as it's not present in memory." << std::endl;
142158
}
143159

144160
if (dll_peimage.pureIL())
@@ -175,4 +191,9 @@ if (vm.count("exe"))
175191

176192
std::cout << desc << "\n";
177193
return 0;
194+
}
195+
196+
bool nt_error(NTSTATUS status)
197+
{
198+
return ((((ULONG)(status)) >> 30) == 3);
178199
}

0 commit comments

Comments
 (0)