aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Fincham <michael@hotplate.co.nz>2018-10-27 18:04:26 +1300
committerMichael Fincham <michael@hotplate.co.nz>2018-10-27 18:04:26 +1300
commit4c66e80c8f5fa96646024c7db4d99f94ef13f0ac (patch)
tree34ea45498519cd21d0c7939eb89626cf1e1ffd62
parent7ec6320994c0d532905e3eb625579bab93c69d52 (diff)
downloadkiwicon2038-4c66e80c8f5fa96646024c7db4d99f94ef13f0ac.tar.gz
kiwicon2038-4c66e80c8f5fa96646024c7db4d99f94ef13f0ac.tar.bz2
kiwicon2038-4c66e80c8f5fa96646024c7db4d99f94ef13f0ac.zip
Adding some weak sauce string obfuscation
-rw-r--r--.gitignore1
-rw-r--r--Makefile12
-rwxr-xr-xobfuscate.py34
-rw-r--r--src/ai.c17
-rw-r--r--src/intel.c17
-rw-r--r--src/terminal.c13
6 files changed, 78 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index a7e7324..bcfb23c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@
# Precompiled Headers
*.gch
*.pch
+*_obfuscated.c
# Libraries
*.lib
diff --git a/Makefile b/Makefile
index c808671..f54712f 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,6 @@
ROM_BLOCKS := 32
ROM_BYTES := 0x4000
-C_SRC_FILES := src/ai.c
-
GCC_OPTIONS := -DVENDOR=\"Toshiba\" -DROM_BYTES=\"$(ROM_BYTES)\" -std=gnu99 -nostdlib -m32 -march=i386 -ffreestanding -fno-pie
COM_LD_OPTIONS := --nmagic,--script=com.ld
ROM_LD_OPTIONS := --nmagic,--script=rom.ld
@@ -14,9 +12,10 @@ all: build/chip.rom build/disk.img
build/chip.rom: romify.py $(shell find -name \*.ld) $(shell find src -not -name \*.S)
mkdir -p build
- gcc $(GCC_OPTIONS) -Wl,$(COM_LD_OPTIONS) $(C_SRC_FILES) -o build/ai.com
- gcc $(GCC_OPTIONS) -DROM -Wl,$(ROM_LD_OPTIONS) $(C_SRC_FILES) -o build/ai.rom
-
+ ./obfuscate.py < src/ai.c > src/ai_obfuscated.c
+ gcc $(GCC_OPTIONS) -Wl,$(COM_LD_OPTIONS) src/ai_obfuscated.c -o build/ai.com
+ gcc $(GCC_OPTIONS) -DROM -Wl,$(ROM_LD_OPTIONS) src/ai_obfuscated.c -o build/ai.rom
+
./romify.py $(ROM_BLOCKS) < build/ai.rom > build/padded.rom
# for the hacked up 128k ROM used for Kiwicon 2038 the 16k binary needs to be pushed up to 32k inside the "chip image"
@@ -33,8 +32,9 @@ build/disk.img: build/chip.rom $(shell find src -name \*.S)
cat build/boot.bin build/ai.rom > build/disk.img
dd if=/dev/null of=build/disk.img bs=1 count=0 seek=1440k
-clean:
+clean:
find build -type f -delete
+ rm -f src/ai_obfuscated.c
emu: build/chip.rom
bochs -q -f test/bochsrc -rc test/bochscommands
diff --git a/obfuscate.py b/obfuscate.py
new file mode 100755
index 0000000..50e8058
--- /dev/null
+++ b/obfuscate.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python3
+
+import re
+import sys
+
+source = sys.stdin.read().strip()
+
+def obfuscate_print(match):
+ string = match.group(1)
+ replacement = ''
+ last_char = ''
+ for c in string:
+ if ord(c) >= 97 and ord(c) <= 122 and last_char != '\\':
+ replacement += chr(ord(c) - 1)
+ else:
+ replacement += c
+ last_char = c
+ return 'print("%s"' % replacement
+
+def obfuscate_strings(match):
+ string = match.group(1)
+ replacement = ''
+ last_char = ''
+ for c in string:
+ if ord(c) >= 97 and ord(c) <= 122 and last_char != '\\':
+ replacement += chr(ord(c) - 1)
+ else:
+ replacement += c
+ last_char = c
+ return ' "%s",' % replacement
+
+source = re.sub(r'print\("([^"]*)"', obfuscate_print, source)
+source = re.sub(r'^ "([^"]*)",$', obfuscate_strings, source, flags=re.M)
+print(source)
diff --git a/src/ai.c b/src/ai.c
index 7bd9ca6..619820a 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -140,7 +140,8 @@ void game(void) {
tty = tty - 48;
if (tty == 0) {
- print_fast("\r\nConnecting to TTY 0");
+ print_fast("\r\nConnecting to TTY ");
+ print_char('0');
break;
} else {
print_fast("\r\nInvalid TTY request.\r\n");
@@ -187,7 +188,7 @@ void game(void) {
} else {
print("Operator> ");
}
- print(key_buffer);
+ print_slow(key_buffer, 1);
while (true) {
if (is_key()) {
@@ -200,8 +201,7 @@ void game(void) {
/* look for commands to respond to */
if (match(key_buffer, "help")) {
print("\r\n");
- print(help[randint(0, sizeof(help) / sizeof(help[0]) - 1)]);
- print("\r\n");
+ print_choice(help);
} else if (match(key_buffer, "win")) {
#ifdef DEBUG
goto win;
@@ -248,7 +248,7 @@ void game(void) {
print("\r\nglitter shell, version 6.6.12(1)-release (smp-nine-clap)\r\n");
} else if (starts(key_buffer, "echo ")) {
print("\r\n");
- print(key_buffer+5);
+ print_slow(key_buffer+5, 1);
print("\r\n");
} else if (match(key_buffer, "pwd")) {
print("\r\n/usr/pak0/technician\r\n");\
@@ -287,7 +287,7 @@ void game(void) {
print("\r\n");
} else {
print("\r\ncat: '");
- print(key_buffer+4);
+ print_slow(key_buffer+4, 1);
print("' doesn't exist.\r\n");
}
} else if (starts(key_buffer, "secaudit") || starts(key_buffer, "./secaudit")) {
@@ -363,7 +363,7 @@ void game(void) {
start_ticks = ticks();
} else if (starts(key_buffer, "cd ")) {
print("\r\nglitsh: cd: ");
- print(key_buffer + 3);
+ print_slow(key_buffer + 3, 1);
print(": No no no no no. No.\r\n");
} else {
print("\r\n");
@@ -454,8 +454,9 @@ void game(void) {
}
if (ascii == 'y') {
print_char('y');
+ print("\r\n");
delay(1);
- print("\r\n\r\nOperator> ");
+ print("\r\nOperator> ");
delay(1);
print_slow("format c:", 8);
delay(2);
diff --git a/src/intel.c b/src/intel.c
index 08f9bcb..55be725 100644
--- a/src/intel.c
+++ b/src/intel.c
@@ -65,6 +65,23 @@ void print_char(uint8_t character) {
);
}
+void print_ob_char(uint8_t character) {
+ #ifdef DEBUG
+ bochs_print_char(character);
+ #endif
+ if (character >= 96 && character <= 121) {
+ character = character + 1;
+ }
+ asm volatile(
+ "mov $0x0e, %%ah\n"
+ "mov $0x00, %%bh\n"
+ "int $0x10\n"
+ :
+ : "a"(character)
+ : "bh"
+ );
+}
+
/* return the ASCII code for a key. if no key is in the buffer, block */
uint8_t wait_key() {
uint8_t ascii = 0;
diff --git a/src/terminal.c b/src/terminal.c
index 784c4d4..8ecd204 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -83,6 +83,15 @@ void tick_delay(uint8_t delay_ticks) {
}
}
+void print_ob_slow(uint8_t *buffer, uint8_t ticks) {
+ for (size_t i = 0; buffer[i] != 0; i++) {
+ if (tick_delay > 0) {
+ tick_delay(ticks);
+ }
+ print_ob_char(buffer[i]);
+ }
+}
+
void print_slow(uint8_t *buffer, uint8_t ticks) {
for (size_t i = 0; buffer[i] != 0; i++) {
if (tick_delay > 0) {
@@ -98,9 +107,9 @@ void print_fast(uint8_t *buffer) {
void print(uint8_t *buffer) {
#ifdef DEBUG
- print_slow(buffer, 0);
+ print_ob_slow(buffer, 0);
#else
- print_slow(buffer, 1);
+ print_ob_slow(buffer, 1);
#endif
}