Files
dobin-ShellcodeObfuscationLab/lab_results/random_shellcode/reverse_hex_string_work.c
T
2025-09-02 21:39:37 +02:00

50 lines
1.2 KiB
C

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char reversed_hex_string[] = "0x0,23x0,0x0,23x0,0x0,f6x0,0x0,77x0,0x0,a7x0,0x0,37x0,0x0,e6x0,0x0,96x0,0x0,56x0,0x0,f6x0,0x0,77x0,0x0,a7x0,0x0,37x0,0x0,e6x0,0x0,96x0,0x0,56x0,0x0,47x0,0x0,37x0,0x0,56x0,0x0,47x0,efx0,ffx0";
unsigned int shellcode_len = 42;
// reverse the string
char* hex_string = _strrev(reversed_hex_string);
printf("Reversed hex string: %s\n", hex_string);
// declare a new shellcode byte array
char shellcode[sizeof(reversed_hex_string)] = { 0 };
// define an index to keep track of where we're at
int idx = 0;
int count = 0;
const int MAX_TOKENS = sizeof(reversed_hex_string);
char* next_token = NULL;
char* token = strtok_s(hex_string, ",", &next_token);
while (token != NULL && count < MAX_TOKENS) {
shellcode[count++] = strtol(token, NULL, 16);
token = strtok_s(NULL, ",", &next_token);
}
idx = 0;
while ( idx < shellcode_len)
{
if (idx == (shellcode_len - 1) )
{
printf("0x%02x ", (unsigned char)shellcode[idx]);
}
else
{
printf("0x%02x, ", (unsigned char)shellcode[idx]);
}
idx++;
}
return 0;
}