Skip to content

Instantly share code, notes, and snippets.

@timb-machine
Created June 7, 2022 16:33
Show Gist options
  • Save timb-machine/0729f1a17a716690230c895b8dcf46a6 to your computer and use it in GitHub Desktop.
Save timb-machine/0729f1a17a716690230c895b8dcf46a6 to your computer and use it in GitHub Desktop.
pacmanTTY.c
#include <sys/types.h>
#include <sys/ptrace.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <openssl/aes.h>
#define MAXIMUMWIDTH 80
#define MAXIMUMHEIGHT 20
int map[MAXIMUMWIDTH][MAXIMUMHEIGHT];
const unsigned char *key = ".:|:. Cisco .:|:.";
//const unsigned char *ciphertext = "flag{@....}";
const unsigned char ciphertext[] = {0x67, 0xba, 0x97, 0x2d, 0x44, 0xfa, 0xdd, 0x45, 0xa1, 0xba, 0x4b, 0x4f, 0x48, 0x60, 0xe2, 0x0e, 0x00};
void handlesegv(int signalid, siginfo_t *signalinfo, void *unused) {
if (signalid == SIGINT) {
return;
} else {
printf("E: b00p. overflow detected.\n");
exit(EXIT_FAILURE);
}
}
void draw(int x, int y) {
int rowcounter;
int columncounter;
for (rowcounter = 0; rowcounter < MAXIMUMHEIGHT; rowcounter ++) {
for (columncounter = 0; columncounter < MAXIMUMWIDTH; columncounter ++) {
if ((columncounter == x) && (rowcounter == y)) {
printf("@");
} else {
if (map[columncounter][rowcounter] == 0) {
printf(" ");
} else {
printf(".");
}
}
}
printf("\n");
}
}
int main (int argc, char **argv) {
struct sigaction signalaction;
int rowcounter;
int columncounter;
int gametimer;
int x;
int y;
char inputbuffer[2];
int inputcounter;
int dotcounter;
unsigned char outputbuffer[1024];
int outputcounter;
AES_KEY aeskey;
unsigned char outputbuffer2[1024];
// handle attempts to ptrace()
//ptrace(PT_TRACE_ME, 0, NULL, NULL);
// eat all the harmful signals
//signalaction.sa_flags = SA_SIGINFO;
//sigemptyset(&signalaction.sa_mask);
//signalaction.sa_sigaction = handlesegv;
//sigaction(SIGSEGV, &signalaction, NULL);
//sigaction(SIGBUS, &signalaction, NULL);
//sigaction(SIGINT, &signalaction, NULL);
for (rowcounter = 0; rowcounter < MAXIMUMHEIGHT; rowcounter ++) {
for (columncounter = 0; columncounter < MAXIMUMWIDTH; columncounter ++) {
map[columncounter][rowcounter] = 1;
}
}
dotcounter = (MAXIMUMWIDTH * MAXIMUMHEIGHT);
gametimer = (rand() % (MAXIMUMHEIGHT * MAXIMUMWIDTH)) + 500;
x = rand() % MAXIMUMWIDTH;
y = rand() % MAXIMUMHEIGHT;
x = 0;
y = 0;
while ((gametimer > 0) && (dotcounter != 0)) {
if (map[x][y] == 1) {
map[x][y] = 0;
dotcounter --;
}
system("clear");
draw(x, y);
inputcounter = read(0, inputbuffer, 1);
switch(inputbuffer[0]) {
case 'h':
x --;
break;
case 'j':
y ++;
break;
case 'k':
y --;
break;
case 'l':
x ++;
break;
// vi style quit
//case ':':
// inputcounter = read(0, inputbuffer, 1);
// switch(inputbuffer[0]) {
// case 'q':
// exit(EXIT_SUCCESS);
// break;
// }
// break;
}
gametimer --;
sleep(1);
}
if (dotcounter == 0) {
printf("complete!\n");
if (gametimer > 450) {
//AES_set_encrypt_key(key, 128, &aeskey);
//AES_encrypt(ciphertext, outputbuffer, &aeskey);
//for (outputcounter = 0; *(outputbuffer + outputcounter) != 0x00; outputcounter ++) {
// printf("%X ", *(outputbuffer + outputcounter));
//}
AES_set_decrypt_key(key, 128, &aeskey);
//AES_decrypt(outputbuffer, outputbuffer2, &aeskey);
AES_decrypt(ciphertext, outputbuffer2, &aeskey);
printf("%s\n", outputbuffer2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment