- 2
- 1
Я тренируюсь взаимойдествовать с памятью,и я полный 0 в этом всем. По этому тренируюсь и учусь вместе с ИИШкой. У меня получился вот такой вот код.
Можете дать какие то советы или еще что то? Буду очень благодарен
C++:
#include <windows.h>
#include <iostream>
#include <fcntl.h>
#include <io.h>
#include <TlHelp32.h>
uintptr_t GetModuleBaseAddress(DWORD procId, const wchar_t* modName) {
uintptr_t modBaseAddr = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procId);
if (hSnap != INVALID_HANDLE_VALUE) {
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry)) {
do {
if (!_wcsicmp(modEntry.szModule, modName)) {
modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
break;
}
} while (Module32Next(hSnap, &modEntry));
}
}
CloseHandle(hSnap);
return modBaseAddr;
}
int main() {
_setmode(_fileno(stdout), _O_U16TEXT);
while (true) {
HWND hNotepad = FindWindow(L"Notepad", NULL);
if (hNotepad) {
DWORD pid; // we creating variable for process id
GetWindowThreadProcessId(hNotepad, &pid); // we getting process id of notepad
//Open the process with all access rights
//PROCESS_ALL_ACCESS is a constant that gives us all possible access rights to the process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProcess) {
system("cls"); // we clear console every time we read memory, you can remove this if you want
//add reading and writing memory here if you want
uintptr_t baseModule = GetModuleBaseAddress(pid, L"textinputframework.dll");
uintptr_t address = baseModule + 0xE8400;
wchar_t buffer[128] = { 0 }; // here we download 16 bytes of memory from notepad, you can change it to whatever you want
ReadProcessMemory(hProcess, (LPCVOID)address, buffer, sizeof(buffer), NULL); // we read memory from notepad and save it in buffer variable
RECT rect;
GetWindowRect(hNotepad, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
std::wcout << L" Текст: " << buffer
<< L" | PID: " << pid
<< L" | Размер: " << width << "x" << height
<< L" | Поз: " << rect.left << L"," << rect.top << std::endl;
if (GetAsyncKeyState(VK_F1) & 0x8000) {
wchar_t changeText[] = L"YamoruHack";
WriteProcessMemory(hProcess, (LPVOID)address, changeText, sizeof(changeText), NULL);
}
}
CloseHandle(hProcess);
}
else {
std::cout << "Потерял блокнот... \r";
}
Sleep(500);
}
}