obfuscate.c 841 B

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