2020-09-25 05:58:08 +00:00
|
|
|
#include <stdio.h>
|
2020-09-25 06:17:04 +00:00
|
|
|
#include <string.h>
|
2020-09-25 05:58:08 +00:00
|
|
|
#include <sys/random.h>
|
|
|
|
|
|
|
|
#include "epic_drm.h"
|
|
|
|
|
2020-09-25 06:17:04 +00:00
|
|
|
#define log(what) printf("[client] " what "\n")
|
|
|
|
#define logf(what, ...) printf("[client] " what "\n", __VA_ARGS__)
|
2020-09-25 05:58:08 +00:00
|
|
|
|
2020-09-25 06:17:04 +00:00
|
|
|
// this code is untrusted
|
|
|
|
// but don't worry, Epic DRM(tm) protections are unbreakable
|
|
|
|
|
|
|
|
void* get_cmd(struct command_channel* chan) {
|
|
|
|
// get the protected shell command from the DRM server
|
|
|
|
void* dst = malloc(sizeof(chan->data));
|
2020-09-25 05:58:08 +00:00
|
|
|
|
|
|
|
log("sending get_cmd");
|
|
|
|
chan->command = GET_CMD;
|
|
|
|
sem_post(&chan->sem_c2s);
|
|
|
|
sem_wait(&chan->sem_s2c);
|
|
|
|
logf("result: %s", chan->command == SUCCESS ? "success" : "error");
|
2020-09-25 06:17:04 +00:00
|
|
|
if (chan->command == SUCCESS) {
|
|
|
|
memcpy(dst, &chan->data, sizeof(chan->data));
|
|
|
|
return dst;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_cmd(struct command_channel* chan, void* data) {
|
|
|
|
// send a protected shell command back to the server
|
|
|
|
log("sending execute_cmd");
|
|
|
|
memcpy(&chan->data, data, sizeof(chan->data));
|
2020-09-25 05:58:08 +00:00
|
|
|
|
2020-09-25 06:17:04 +00:00
|
|
|
chan->command = EXECUTE_CMD;
|
|
|
|
sem_post(&chan->sem_c2s);
|
|
|
|
sem_wait(&chan->sem_s2c);
|
|
|
|
logf("result: %s", chan->command == SUCCESS ? "success" : "error");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
// perform a basic interaction with epic_drm
|
|
|
|
log("opening drm");
|
|
|
|
int shm = shm_open(SHM_NAME, O_RDWR, 0);
|
|
|
|
struct command_channel* chan = mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm, 0);
|
|
|
|
|
|
|
|
// get protected shell command
|
|
|
|
void* data = get_cmd(chan);
|
2020-09-25 05:58:08 +00:00
|
|
|
log("data");
|
|
|
|
for (size_t i = 0; i < 64; i++) {
|
2020-09-25 06:17:04 +00:00
|
|
|
uint8_t b = ((uint8_t*)data)[i];
|
2020-09-25 05:58:08 +00:00
|
|
|
printf("%02x ", b);
|
|
|
|
if (i % 16 == 15) {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("...\n");
|
|
|
|
|
2020-09-25 06:17:04 +00:00
|
|
|
// send back
|
|
|
|
send_cmd(chan, data);
|
2020-09-25 05:58:08 +00:00
|
|
|
|
|
|
|
log("done");
|
|
|
|
}
|