Bläddra i källkod

UI: Add obfuscation func

You could also say..  obs-fuscation.
jp9000 6 år sedan
förälder
incheckning
ccc64df371
3 ändrade filer med 42 tillägg och 0 borttagningar
  1. 2 0
      UI/CMakeLists.txt
  2. 27 0
      UI/obf.c
  3. 13 0
      UI/obf.h

+ 2 - 0
UI/CMakeLists.txt

@@ -107,9 +107,11 @@ endif()
 
 if(BROWSER_AVAILABLE_INTERNAL)
 	list(APPEND obs_PLATFORM_SOURCES
+		obf.c
 		auth-oauth.cpp
 		)
 	list(APPEND obs_PLATFORM_HEADERS
+		obf.h
 		auth-oauth.hpp
 		)
 endif()

+ 27 - 0
UI/obf.c

@@ -0,0 +1,27 @@
+#include "obf.h"
+#include <stdbool.h>
+
+#define LOWER_HALFBYTE(x) ((x) & 0xF)
+#define UPPER_HALFBYTE(x) (((x) >> 4) & 0xF)
+
+void deobfuscate_str(char *str, uint64_t val)
+{
+	uint8_t *dec_val = (uint8_t*)&val;
+	int i = 0;
+
+	while (*str != 0) {
+		int pos = i / 2;
+		bool bottom = (i % 2) == 0;
+		uint8_t *ch = (uint8_t*)str;
+		uint8_t xor = bottom ?
+			LOWER_HALFBYTE(dec_val[pos]) :
+			UPPER_HALFBYTE(dec_val[pos]);
+
+		*ch ^= xor;
+
+		if (++i == sizeof(uint64_t) * 2)
+			i = 0;
+
+		str++;
+	}
+}

+ 13 - 0
UI/obf.h

@@ -0,0 +1,13 @@
+#pragma once
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void deobfuscate_str(char *str, uint64_t val);
+
+#ifdef __cplusplus
+}
+#endif