forked from phra/PEzor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request phra#89 from phra/feat/dll-sideload
Add DLL Sideloading capability
- Loading branch information
Showing
19 changed files
with
226 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.res | ||
*.o | ||
*.exe | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <windows.h> | ||
#include <stdio.h> | ||
|
||
BOOL WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { | ||
puts("ForwardedDLL DllMain"); | ||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <windows.h> | ||
|
||
#pragma comment(linker, "/EXPORT:DllMain") | ||
|
||
extern "C" { | ||
#pragma comment(linker, "/EXPORT:1=library.dll.DllMain,@1") | ||
#pragma comment(linker, "/EXPORT:2=library.dll.myFunction1,@2") | ||
#pragma comment(linker, "/EXPORT:3=library.dll.myFunction2,@3") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
EXPORTS | ||
myFunction1=library.myFunction1 @2 | ||
myFunction2=library.myFunction2 @3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x86_64-w64-mingw32-gcc -shared -static library.c -o library.dll library.def -Wall -pedantic -Wextra && | ||
x86_64-w64-mingw32-g++ -static main.cpp -o main.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 <OriginalDLL.dll>" | ||
exit 1 | ||
fi | ||
|
||
original_dll="$1" | ||
output_def="ForwardedDLL.def" | ||
output_dll="ForwardedDLL.dll" | ||
|
||
winedump dump -C -j export "$original_dll" | \ | ||
awk ' | ||
BEGIN { | ||
print "EXPORTS" | ||
} | ||
/Entry/,/Done/ { | ||
if ($2 ~ /^[0-9]+/) { | ||
ordinal = $2 | ||
name = $3 | ||
if (name ~ /</) { | ||
# Exported by ordinal (TODO: syntax error in .def file) | ||
# printf " @%s=%s.#%s @%s\n", ordinal, "library", ordinal, ordinal | ||
} else if (name !~ /DllMain/){ | ||
# Exported function with a name | ||
printf " %s=%s.%s @%s\n", name, "library", name, ordinal | ||
} | ||
} | ||
} | ||
' > $output_def | ||
|
||
# Compile the C++ source code into a DLL using clang and mingw | ||
x86_64-w64-mingw32-gcc -shared -o "$output_dll" "$output_def" | ||
|
||
echo "Forwarded DLL created: $output_dll" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <windows.h> | ||
#include <stdio.h> | ||
|
||
__declspec(dllexport) int myFunction1() { | ||
return 1; | ||
} | ||
|
||
__declspec(dllexport) int myFunction2() { | ||
return 2; | ||
} | ||
|
||
int myAnonymousFunction() { | ||
return 3; | ||
} | ||
|
||
__declspec(dllexport) int DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) | ||
{ | ||
puts("libray.dll DLLMain\n"); | ||
return 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
EXPORTS | ||
DllMain @1 | ||
myFunction1 @2 | ||
myFunction2 @3 | ||
myAnonymousFunction @4 NONAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern "C" { | ||
int myExportedVariable1(); // Ordinal 1 | ||
int myExportedVariable2(); // Ordinal 2 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <windows.h> | ||
#include <iostream> | ||
|
||
int main() { | ||
HMODULE hModule = LoadLibraryW(L"library.dll"); // Load the DLL | ||
if (hModule != NULL) { | ||
int (*getVariable1)() = (int(*)())GetProcAddress(hModule, (LPCSTR)2); // Access ordinal 1 | ||
int (*getVariable2)() = (int(*)())GetProcAddress(hModule, (LPCSTR)3); // Access ordinal 2 | ||
|
||
if (getVariable1 != NULL && getVariable2 != NULL) { | ||
int value1 = getVariable1(); | ||
int value2 = getVariable2(); | ||
|
||
// Use 'value1' and 'value2' here | ||
std::cout << "Value 1: " << value1 << std::endl; | ||
std::cout << "Value 2: " << value2 << std::endl; | ||
} | ||
|
||
Sleep(10000); | ||
|
||
FreeLibrary(hModule); // Unload the DLL when done | ||
} else { | ||
std::cout << "DLL NOT FOUND" << std::endl; | ||
} | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.res | ||
*.o | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x86_64-w64-mingw32-windres resource.rc -o resource.o && | ||
x86_64-w64-mingw32-gcc resource.c resource.o -o MessageBoxExample.exe -mwindows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <windows.h> | ||
#include "resource.h" | ||
|
||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { | ||
// Load the message and title from the resource | ||
wchar_t message[256], title[256]; | ||
|
||
LoadStringW(hInstance, IDS_MESSAGE, message, sizeof(message) / sizeof(wchar_t)); | ||
LoadStringW(hInstance, IDS_TITLE, title, sizeof(title) / sizeof(wchar_t)); | ||
|
||
// Display the MessageBox | ||
MessageBoxW(NULL, message, title, MB_OK | MB_ICONINFORMATION); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef RESOURCE_H | ||
#define RESOURCE_H | ||
|
||
#define IDS_MESSAGE 101 | ||
#define IDS_TITLE 102 | ||
|
||
#endif // RESOURCE_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <windows.h> | ||
#include "resource.h" | ||
|
||
STRINGTABLE | ||
BEGIN | ||
IDS_MESSAGE "Hello, World!" | ||
IDS_TITLE "MessageBox Example" | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters