Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <iostream>
- #include <format>
- #include <vector>
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h>
- std::vector<char> readMemory(LPVOID location, SIZE_T length) {
- std::vector<char> buffer(length);
- DWORD oldProtection;
- VirtualProtect(location, length, PAGE_EXECUTE_READWRITE, &oldProtection);
- memcpy(buffer.data(), location, length);
- VirtualProtect(location, length, oldProtection, &oldProtection);
- return buffer;
- }
- int main() {
- HMODULE kernel32 = GetModuleHandleA("KERNEL32.DLL");
- if (kernel32 == NULL) {
- std::cout << "Failed to locate kernel32.dll\n";
- return 1;
- }
- LPVOID codeLocation = GetProcAddress(kernel32, "QueryPerformanceCounter");
- if (codeLocation == NULL) {
- std::cout << "Failed to locate QueryPerformanceCounter()\n";
- return 1;
- }
- SIZE_T length = 16;
- std::cout << "QueryPerformanceCounter() ";
- do {
- std::cout << "@ " << std::format("{:016x}", reinterpret_cast<uintptr_t>(codeLocation)) << ":\n";
- std::vector<char> instructionBytes = readMemory(codeLocation, length);
- for (auto ch : instructionBytes)
- std::cout << std::format("{:02x}", static_cast<unsigned>(static_cast<unsigned char>(ch))) << ' ';
- std::cout << '\n';
- std::cout << "Next read (0 to quit): ";
- uintptr_t nextPtr;
- std::cin >> std::hex >> nextPtr;
- codeLocation = reinterpret_cast<LPVOID>(nextPtr);
- if (codeLocation != 0) {
- std::cout << "Next length: ";
- std::cin >> std::hex >> length;
- }
- } while (codeLocation);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement