obfuscate.c 811 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifdef _MSC_VER
  2. #pragma warning(disable : 4152) /* casting func ptr to void */
  3. #endif
  4. #include <stdbool.h>
  5. #include <windows.h>
  6. #include "obfuscate.h"
  7. #define LOWER_HALFBYTE(x) ((x)&0xF)
  8. #define UPPER_HALFBYTE(x) (((x) >> 4) & 0xF)
  9. static void deobfuscate_str(char *str, uint64_t val)
  10. {
  11. uint8_t *dec_val = (uint8_t *)&val;
  12. int i = 0;
  13. while (*str != 0) {
  14. int pos = i / 2;
  15. bool bottom = (i % 2) == 0;
  16. uint8_t *ch = (uint8_t *)str;
  17. uint8_t xor = bottom ? LOWER_HALFBYTE(dec_val[pos])
  18. : UPPER_HALFBYTE(dec_val[pos]);
  19. *ch ^= xor;
  20. if (++i == sizeof(uint64_t) * 2)
  21. i = 0;
  22. str++;
  23. }
  24. }
  25. void *get_obfuscated_func(HMODULE module, const char *str, uint64_t val)
  26. {
  27. char new_name[128];
  28. strcpy(new_name, str);
  29. deobfuscate_str(new_name, val);
  30. return GetProcAddress(module, new_name);
  31. }