#define _GNU_SOURCE
#include <dlfcn.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int execvp(const char *file, char *const argv[]) {
  int (*real_execvp)(const char *, char *const[]) = dlsym(RTLD_NEXT, "execvp");
  if (strstr(file, "codex") && !strstr(file, "/tools/codex/") && argv[1] && !strcmp(argv[1], "--version")) _exit(1);
  if (strstr(file, "/tools/codex/.install-") && strstr(file, "/runtime/bin/codex") && argv[1] && !strcmp(argv[1], "--version")) {
    const char *version = getenv("CODEX_EVIDENCE_STALL_VERSION");
    if (version) {
      char manifest[4096], data[4096] = {0};
      snprintf(manifest, sizeof(manifest), "%.*s/codex-package.json", (int)(strlen(file)-strlen("/bin/codex")), file);
      FILE *input = fopen(manifest, "r");
      if (input) { fread(data, 1, sizeof(data)-1, input); fclose(input); }
      if (!strstr(data, version)) return real_execvp(file, argv);
    }
    fprintf(stderr, "Evidence: holding managed Codex verification exec for 100 seconds\n");
    sleep(100);
  }
  return real_execvp(file, argv);
}
