Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lua_gettop = sub_7FFA1751B3A0
- x48x8Bx41x10x48x2Bx41x18x48xC1xF8x04xC3, xxxxxxxxxxxxx
- #include <windows.h>
- #include <stdio.h>
- #include <iostream>
- #include <tlhelp32.h>
- #include <fstream>
- #include "tchar.h"
- #include "psapi.h"
- #include "stdafx.h"
- #include "detours.h"
- #include <string>
- #pragma comment (lib, "detours.lib")
- using namespace std;
- void Log(const char* fmt, ...)
- {
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
- printf("n");
- }
- BOOL GetModInfoByName(HANDLE hProcess, wstring name, MODULEINFO& moduleInformation)
- {
- MODULEENTRY32 moduleEntry;
- HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(hProcess));
- moduleEntry.dwSize = sizeof(MODULEENTRY32);
- if (!Module32First(hSnapshot, &moduleEntry))
- {
- CloseHandle(hSnapshot);
- Log("Failed to load modules! Error: %d; Module: %s", GetLastError(), name.c_str());
- return FALSE;
- }
- do
- {
- wstring modName(moduleEntry.szModule);
- if (!modName.compare(name) == 0)
- continue;
- CloseHandle(hSnapshot);
- if (!GetModuleInformation(hProcess, moduleEntry.hModule, &moduleInformation, sizeof(MODULEINFO)))
- {
- Log("Failed to acquire module information! Error: %d, Module: %ls", GetLastError(), modName.c_str());
- return FALSE;
- }
- return TRUE;
- } while (Module32Next(hSnapshot, &moduleEntry));
- }
- //Credits to DarthTon//
- struct PartData
- {
- int32_t mask = 0;
- __m128i needle; //C2797: list initialization inside member initializer list or non-static data member initializer is not implemented
- PartData()
- {
- memset(&needle, 0, sizeof(needle));
- }
- };
- const void* Search(const uint8_t* data, const uint32_t size, const uint8_t* pattern, const char* mask)
- {
- const uint8_t* result = nullptr;
- auto len = strlen(mask);
- auto first = strchr(mask, '?');
- size_t len2 = (first != nullptr) ? (first - mask) : len;
- auto firstlen = min(len2, 16);
- intptr_t num_parts = (len < 16 || len % 16) ? (len / 16 + 1) : (len / 16);
- PartData parts[4];
- for (intptr_t i = 0; i < num_parts; ++i, len -= 16)
- {
- for (size_t j = 0; j < min(len, 16) - 1; ++j)
- if (mask[16 * i + j] == 'x')
- _bittestandset((LONG*)& parts[i].mask, j);
- parts[i].needle = _mm_loadu_si128((const __m128i*)(pattern + i * 16));
- }
- bool abort = false;
- #pragma omp parallel for
- for (intptr_t i = 0; i < static_cast<intptr_t>(size) / 32 - 1; ++i)
- {
- #pragma omp flush (abort)
- if (!abort)
- {
- auto block = _mm256_loadu_si256((const __m256i*)data + i);
- if (_mm256_testz_si256(block, block))
- continue;
- auto offset = _mm_cmpestri(parts->needle, firstlen, _mm_loadu_si128((const __m128i*)(data + i * 32)), 16, _SIDD_CMP_EQUAL_ORDERED);
- if (offset == 16)
- {
- offset += _mm_cmpestri(parts->needle, firstlen, _mm_loadu_si128((const __m128i*)(data + i * 32 + 16)), 16, _SIDD_CMP_EQUAL_ORDERED);
- if (offset == 32)
- continue;
- }
- for (intptr_t j = 0; j < num_parts; ++j)
- {
- auto hay = _mm_loadu_si128((const __m128i*)(data + (2 * i + j) * 16 + offset));
- auto bitmask = _mm_movemask_epi8(_mm_cmpeq_epi8(hay, parts[j].needle));
- if ((bitmask & parts[j].mask) != parts[j].mask)
- goto next;
- }
- result = data + 32 * i + offset;
- abort = true;
- #pragma omp flush (abort)
- }
- //break; //C3010: 'break' : jump out of OpenMP structured block not allowed
- next:;
- }
- return result;
- }
- int lua_State = 0;
- typedef int(__cdecl* gettop)(int);
- DWORD _gettop(int state)
- {
- if (lua_State == 0) {
- lua_State = state;
- }
- return (*(DWORD*)(state + 16) - *(DWORD*)(state + 28)) >> 4;
- }
- void main()
- {
- AllocConsole();
- freopen("CONIN$", "r", stdin);
- freopen("CONOUT$", "w", stdout);
- freopen("CONOUT$", "w", stderr);
- MODULEINFO modInfo;
- wstring wstrName(L"Disrupt_b64.dll");
- if (!GetModInfoByName(GetCurrentProcess(), wstrName, modInfo))
- {
- cin.get();
- FreeConsole();
- ExitThread(0);
- }
- const char* lua_gettop_sig = "x48x8Bx41x10x48x2Bx41x18x48xC1xF8x04xC3";
- gettop lua_gettop_point = (gettop)const_cast<void*>(Search(reinterpret_cast<uint8_t*>(modInfo.lpBaseOfDll), modInfo.SizeOfImage, reinterpret_cast<const uint8_t*>(lua_gettop_sig), "xxxxxxxxxxxxx"));
- Log("GetTop Pointer > 0x%I64X", lua_gettop_point);
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(LPVOID&)lua_gettop_point, (PBYTE)_gettop);
- DetourTransactionCommit();
- Log("LuaState %s", lua_State);
- string input;
- while (getline(cin, input))
- {
- if (strcmp(input.c_str(), "exit") == 0)
- {
- Log("Exiting...");
- break;
- }
- }
- FreeConsole();
- ExitThread(0);
- }
- BOOL APIENTRY DllMain(HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- {
- DisableThreadLibraryCalls(hModule);
- CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& main, 0, 0, 0);
- }
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement