-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (103 loc) · 3.97 KB
/
Program.cs
File metadata and controls
105 lines (103 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace dll_injector
{
internal class Program
{
static Version version = new Version(1,0);
static int Main(string[] args)
{
Process process = null;
FileInfo dllFile = null;
for(int x =0;x < args.Length; x++)
{
string arg = args[x];
string value;
switch (arg)
{
case "-pid":
value = args.Length > x + 1 ? args[++x] : null;
int pid = 0;
if (int.TryParse(value, out pid))
{
process = Process.GetProcessById(pid);
}
if(process == null)
{
Console.Error.WriteLine($"Process not found using pid {value}");
return -1;
}
break;
case "-pname":
value = args.Length > x + 1 ? args[++x] : null;
if(value != null)
{
Process[] processScan = Process.GetProcessesByName(value);
if(processScan.Length > 0)
{
process = processScan[0];
}
}
if(process == null)
{
Console.Error.WriteLine($"Process not found using process name {value}");
}
break;
case "-dll":
value = args.Length > x + 1 ? args[++x] : null;
dllFile = new FileInfo(value);
if (!dllFile.Exists)
{
Console.Error.WriteLine($"DLL File {value} does not exist");
return -2;
}
break;
case "/?":
case "-help":
DisplayHelp();
break;
default:
Console.WriteLine($"Unknown command line argument {arg}");
break;
}
}
if(process == null || dllFile == null)
{
DisplayHelp();
return -3;
}
else
{
return (int)DllInjector.InjectDll(process, dllFile);
}
}
static void DisplayHelp()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Simple DLL Injector CLI");
sb.AppendLine($"Author: Wo1fie");
sb.AppendLine($"Version: {version}");
sb.AppendLine();
sb.AppendLine("Usage: dll-injector.exe [-pid <process Id> | -pname <process name>] -dll \"<file path>\"");
sb.AppendLine("Examples:");
sb.AppendLine("dll-injector.exe -pid 9999 -dll \"injectable.dll\"");
sb.AppendLine("dll-injector.exe -pname \"notepad.exe\" -dll \"injectable.dll\"");
sb.AppendLine();
sb.AppendLine("\"-help\" or \"/?\": Displays this help message");
sb.AppendLine();
sb.AppendLine("Return values:");
sb.AppendLine("-1 Process not found");
sb.AppendLine("-2 DLL File not found");
sb.AppendLine("-3 Command line arguments missing");
sb.AppendLine("0 Success");
for(int x = 1;x <= (int)DllInjector.InjectReturnStatus.VirtualFreeEx; x++)
{
DllInjector.InjectReturnStatus status = (DllInjector.InjectReturnStatus)x;
sb.AppendLine($"{x} {status} failed");
}
Console.WriteLine(sb.ToString());
}
}
}