Skip to content

Commit

Permalink
uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyesh committed Jun 4, 2023
1 parent 28b6a34 commit 042008b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions write_process_dll.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Importing required modules
#include <Windows.h>
#include <iostream>
#include "pch.h"
Expand All @@ -8,9 +9,11 @@
using std::ostringstream;
using std::ends;

// Define TrueWriteProcessMemory
typedef BOOL(WINAPI* TrueWriteProcessMemory)(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten);
TrueWriteProcessMemory originalWriteProcessMemory = WriteProcessMemory;

// Initializing lists
unsigned char originalBytes[5];
unsigned char trampoline[5];

Expand All @@ -19,6 +22,14 @@ HANDLE hFile;
template<typename T>
void LOG(const char* message, T parameter) {

/**
* Logs a message to a file.
*
* @tparam T The type of the parameter to be logged.
* @param message The message to be logged.
* @param parameter The parameter to be logged.
*/

WriteFile(hFile, message, strlen(message), NULL, nullptr);
//WriteFile(hFile, "\n", strlen("\n"), NULL, nullptr);
ostringstream oss;
Expand All @@ -31,6 +42,17 @@ void LOG(const char* message, T parameter) {

BOOL WINAPI MyWriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten)
{
/**
* Custom implementation of the WriteProcessMemory function.
*
* @param hProcess A handle to the process whose memory is to be modified.
* @param lpBaseAddress A pointer to the base address in the specified process to which data is written.
* @param lpBuffer A pointer to the buffer that contains data to be written in the address space of the specified process.
* @param nSize The number of bytes to be written to the specified process.
* @param lpNumberOfBytesWritten A pointer to the number of bytes transferred.
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
*/

// Perform any desired actions here (e.g. logging)
LOG("\n----------intercepted call to WriteProcessMemory----------\n\n", "");
LOG("A pointer to the base address in the specified process to which data is written is ", lpBaseAddress);
Expand All @@ -54,6 +76,14 @@ BOOL WINAPI MyWriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
/**
* The entry point for the DLL.
*
* @param hModule A handle to the DLL module.
* @param ul_reason_for_call The reason code that indicates why the DLL entry point function is being called.
* @param lpReserved Reserved for future use.
* @return The function returns `TRUE` if successful or `FALSE` otherwise.
*/
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Expand All @@ -77,6 +107,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
break;
}
case DLL_PROCESS_DETACH:

// Cleanup any allocated resources
DWORD oldProtection;
VirtualProtect(WriteProcessMemory, 5, PAGE_EXECUTE_READWRITE, &oldProtection);
Expand Down

0 comments on commit 042008b

Please sign in to comment.