Skip to content

Commit 572f52d

Browse files
committed
Expose Shellcode Class w/ LoadLibrary & GetProcAddress Pointers
1 parent 40fdbb7 commit 572f52d

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

Source/Reloaded.Injector/Injector.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ public class Injector : IDisposable
2121
/// </summary>
2222
public bool HasExited => _process.HasExited;
2323

24-
private Shellcode _shellCode; /* Call GetProcAddress and LoadLibraryW in remote process. */
25-
private CircularBuffer _circularBuffer; /* Used for calling foreign functions. */
26-
private Process _process; /* Process to DLL Inject into. */
24+
/// <summary>
25+
/// Provides access to the raw GetProcAddress and LoadLibrary calls.
26+
/// </summary>
27+
public Shellcode ShellCode { get; private set; } /* Call GetProcAddress and LoadLibraryW in remote process. */
28+
29+
private CircularBuffer _circularBuffer; /* Used for calling foreign functions. */
30+
private Process _process; /* Process to DLL Inject into. */
2731

2832
/// <summary>
2933
/// Initializes the DLL Injector.
@@ -36,7 +40,7 @@ public Injector(Process process)
3640
// Initiate target process.
3741
_process = process;
3842
_circularBuffer = new CircularBuffer(4096, new ExternalMemory(process));
39-
_shellCode = new Shellcode(process);
43+
ShellCode = new Shellcode(process);
4044
}
4145

4246
~Injector()
@@ -48,7 +52,7 @@ public Injector(Process process)
4852
public void Dispose()
4953
{
5054
_circularBuffer?.Dispose();
51-
_shellCode?.Dispose();
55+
ShellCode?.Dispose();
5256
GC.SuppressFinalize(this);
5357
}
5458

@@ -68,7 +72,7 @@ public long Inject(string modulePath)
6872
if (moduleHandle != IntPtr.Zero)
6973
return (long)moduleHandle;
7074

71-
long address = _shellCode.LoadLibraryW(modulePath);
75+
long address = ShellCode.LoadLibraryW(modulePath);
7276

7377
return address;
7478
}
@@ -86,7 +90,7 @@ public long GetFunctionAddress(string module, string functionToExecute)
8690
if (moduleHandle == IntPtr.Zero)
8791
throw new DllInjectorException("Module not found in target process.");
8892

89-
return _shellCode.GetProcAddress((long)moduleHandle, functionToExecute);
93+
return ShellCode.GetProcAddress((long)moduleHandle, functionToExecute);
9094
}
9195

9296
/// <summary>
@@ -138,7 +142,7 @@ public bool Eject(string module)
138142
if (moduleHandle == IntPtr.Zero)
139143
return false;
140144

141-
long methodAddress = _shellCode.GetProcAddress(_shellCode.Kernel32Handle, "FreeLibrary");
145+
long methodAddress = ShellCode.GetProcAddress(ShellCode.Kernel32Handle, "FreeLibrary");
142146

143147
int result = CallRemoteFunction(_process.Handle, (IntPtr)methodAddress, moduleHandle);
144148
return Convert.ToBoolean(result);

Source/Reloaded.Injector/Reloaded.Injector.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<RepositoryUrl>https://github.com/Reloaded-Project/Reloaded.Injector</RepositoryUrl>
1414
<RepositoryType>git</RepositoryType>
1515
<GenerateDocumentationFile>true</GenerateDocumentationFile>
16-
<Version>1.1.1</Version>
16+
<Version>1.2.0</Version>
1717
<Copyright>LGPLV3</Copyright>
1818
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1919
</PropertyGroup>

Source/Reloaded.Injector/Shellcode.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ namespace Reloaded.Injector
1818
/// Builds the shellcode inside a target process which can be used to
1919
/// call LoadLibrary and GetProcAddress inside a remote process.
2020
/// </summary>
21-
internal class Shellcode : IDisposable
21+
public class Shellcode : IDisposable
2222
{
2323
/* Setup/Build Shellcode */
24-
public long Kernel32Handle { get; } /* Address of Kernel32 in remote process. */
24+
public long Kernel32Handle { get; } /* Address of Kernel32 in remote process. */
25+
public long LoadLibraryAddress { get; private set; } /* Address of LoadLibrary function. */
26+
public long GetProcAddressAddress { get; private set; } /* Address of GetProcAddress function. */
27+
2528
private uint _loadLibraryWOffset; /* Address of LoadLibraryW in remote process. */
2629
private uint _getProcAddressOffset; /* Address of GetProcAddress in remote process. */
2730
private MachineType _machineType; /* Is remote process 64 or 32bit? */
@@ -145,8 +148,9 @@ private void BuildGetProcAddress86()
145148
// GetProcAddress(long hModule, char* lpProcName)
146149
// lpParameter: Address of first struct member.
147150
// Using stdcall calling convention.
148-
long getProcAddressAddress = Kernel32Handle + _getProcAddressOffset;
149-
IntPtr getProcAddressPtr = _privateBuffer.Add(ref getProcAddressAddress);
151+
long getProcAddressAddress = Kernel32Handle + _getProcAddressOffset;
152+
GetProcAddressAddress = getProcAddressAddress;
153+
IntPtr getProcAddressPtr = _privateBuffer.Add(ref getProcAddressAddress);
150154

151155
long dummy = 0;
152156
_getProcAddressReturnValuePtr = (long)_privateBuffer.Add(ref dummy);
@@ -172,8 +176,9 @@ private void BuildGetProcAddress64()
172176
// GetProcAddress(long hModule, char* lpProcName)
173177
// lpParameter: Address of first struct member.
174178
// Using Microsoft X64 calling convention.
175-
long getProcAddressAddress = Kernel32Handle + _getProcAddressOffset;
176-
IntPtr getProcAddressPtr = _privateBuffer.Add(ref getProcAddressAddress);
179+
long getProcAddressAddress = Kernel32Handle + _getProcAddressOffset;
180+
GetProcAddressAddress = getProcAddressAddress;
181+
IntPtr getProcAddressPtr = _privateBuffer.Add(ref getProcAddressAddress);
177182

178183
long dummy = 0;
179184
_getProcAddressReturnValuePtr = (long)_privateBuffer.Add(ref dummy);
@@ -200,6 +205,7 @@ private void BuildLoadLibraryW86()
200205
{
201206
// Using stdcall calling convention.
202207
long loadLibraryAddress = Kernel32Handle + _loadLibraryWOffset;
208+
LoadLibraryAddress = loadLibraryAddress;
203209
IntPtr loadLibraryPtr = _privateBuffer.Add(ref loadLibraryAddress);
204210

205211
long dummy = 0;
@@ -223,8 +229,9 @@ private void BuildLoadLibraryW86()
223229
private void BuildLoadLibraryW64()
224230
{
225231
// Using Microsoft X64 calling convention.
226-
long loadLibraryAddress = Kernel32Handle + _loadLibraryWOffset;
227-
IntPtr loadLibraryPtr = _privateBuffer.Add(ref loadLibraryAddress);
232+
long loadLibraryAddress = Kernel32Handle + _loadLibraryWOffset;
233+
LoadLibraryAddress = loadLibraryAddress;
234+
IntPtr loadLibraryPtr = _privateBuffer.Add(ref loadLibraryAddress);
228235

229236
long dummy = 0;
230237
_loadLibraryWReturnValuePtr = (long)_privateBuffer.Add(ref dummy);

0 commit comments

Comments
 (0)