obfuscate.c 808 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 ?
  18. LOWER_HALFBYTE(dec_val[pos]) :
  19. UPPER_HALFBYTE(dec_val[pos]);
  20. *ch ^= xor;
  21. if (++i == sizeof(uint64_t) * 2)
  22. i = 0;
  23. str++;
  24. }
  25. }
  26. void *get_obfuscated_func(HMODULE module, const char *str, uint64_t val)
  27. {
  28. char new_name[128];
  29. strcpy(new_name, str);
  30. deobfuscate_str(new_name, val);
  31. return GetProcAddress(module, new_name);
  32. }