spot-the-bug/stream-ciphers/client.c

39 lines
1.0 KiB
C

#include <stdio.h>
#include <sys/random.h>
#include "epic_drm.h"
#define log(what) printf("[epic_drm] " what "\n")
#define logf(what, ...) printf("[epic_drm] " what "\n", __VA_ARGS__)
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);
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");
log("data");
for (size_t i = 0; i < 64; i++) {
uint8_t b = ((uint8_t*) &chan->data)[i];
printf("%02x ", b);
if (i % 16 == 15) {
printf("\n");
}
}
printf("...\n");
log("sending execute_cmd");
chan->command = EXECUTE_CMD;
sem_post(&chan->sem_c2s);
sem_wait(&chan->sem_s2c);
logf("result: %s", chan->command == SUCCESS ? "success" : "error");
log("done");
}