コード例 #1
0
ファイル: exec.c プロジェクト: shentino/simud
int main(string param) {
   string ret;

   WIZ_CHECK

   msg("~[090The exec command has been renamed to 'lpc'. Please use 'lpc' instead. This is to avoid confusion between the verb and the efun. Thanks.~CDEF");

   if(!param) {
      notify_fail("==> [Format] exec code...\n");
      return 0;
   }

   ret = exec_code( param );
   if( ret != "0" )
      msg("Execution returned:\n"+ret);
   return 1;
}
コード例 #2
0
ファイル: long_command.c プロジェクト: AltSysrq/tgl
/* @builtin-bind { 'Q', builtin_long_command }, */
int builtin_long_command(interpreter* interp) {
  unsigned begin, end;
  string commandName;
  long_command* curr;
  int result;

  /* Extract the long name */
  begin = ++interp->ip;
  while (interp->ip < interp->code->len &&
         !isspace(string_data(interp->code)[interp->ip]))
    ++interp->ip;

  end = interp->ip;
  if (begin == end || begin+1 == end) {
    print_error("Long command name expected");
    return 0;
  }

  commandName = create_string(string_data(interp->code)+begin,
                              string_data(interp->code)+end);

  /* Find the first long command name which matches. */
  curr = interp->long_commands;
  while (curr && !string_equals(curr->name, commandName))
    curr = curr->next;

  /* Don't need the command name anymore. */
  free(commandName);

  if (!curr) {
    print_error("Long command not found");
    return 0;
  }

  /* Execute, clean up, and return */
  if (curr->cmd.is_native)
    result = curr->cmd.cmd.native(interp);
  else
    result = exec_code(interp, curr->cmd.cmd.user);

  return result;
}
コード例 #3
0
ファイル: defcon_catwestern.c プロジェクト: bbriggs/DarkArts
int main(int argc, char *argv[])
{
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;   

  char init_state[4097], code[4096];

  portno = 9999;

  /* Create a socket point */
  sockfd = socket(AF_INET, SOCK_STREAM, 0);

  if (sockfd < 0)
  {
    perror("ERROR opening socket");
    exit(1);
  }
  //server = gethostbyname(argv[1]);
  server = gethostbyname("catwestern_631d7907670909fc4df2defc13f2057c.quals.shallweplayaga.me");

  if (server == NULL)
  {
    fprintf(stderr,"ERROR, no such host\n");
    exit(0);
  }

  bzero((char *) &serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
  serv_addr.sin_port = htons(portno);

  /* Now connect to the server */
  if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
  {
    perror("ERROR connecting");
    exit(1);
  }


  /* Now read server response */
  bzero(init_state, 4096);
  n = read(sockfd, init_state, 4096);     
  if (n < 0)
  {
  perror("ERROR reading from socket");
  exit(1);
  }

  bzero(code, 4096);
  n = read(sockfd, code, 4096);
  if (n < 0)
  {
    perror("ERROR reading from socket");
    exit(1);
  }

  code_start = strchr(code, ':') + 3;
  code_back = (char *)0x400b23;

  parse_init_state(init_state + strlen("****Initial Register State****") + 1);
  memcpy(code_start+n-68+1, "\xFF\x24\x25\x60\x31\x60\x00", 7);
  exec_code();
  write(sockfd, result, strlen(result));

  bzero(result, 4096);
  n = read(sockfd, result, 4096);
  if (n < 0)
  {
    perror("ERROR reading from socket");
    exit(1);
  }
  printf("%s\n", result);



  return 0;
}
コード例 #4
0
ファイル: defun.c プロジェクト: AltSysrq/tgl
/* Common function for v and V.
 *
 * aux: if non-NULL, any code to evaluate before the defun
 * defun: command to run to define the command.
 */
static int builtin_defunlibrary_common(interpreter* interp,
                                       string aux,
                                       byte defun) {
  string name, body, code;
  struct tm* now;
  time_t seconds;
  char header[256], date[64];
  FILE* out;
  unsigned i;

  if (!stack_pop_strings(interp, 2, &body, &name)) UNDERFLOW;

  /* We can't allow the name to have parentheses or the NUL character. */
  for (i = 0; i < name->len; ++i)
    if (string_data(name)[i] == '(' || string_data(name)[i] == ')' ||
        string_data(name)[i] == 0) {
      print_error_s("Invalid command name (for use with v/V)", name);
      stack_push(interp, name);
      stack_push(interp, body);
      return 0;
    }

  /* Build code */
  time(&seconds);
  now = localtime(&seconds);
  strftime(date, sizeof(date)-1, "%A, %Y.%m.%d %H:%M:%S", now);
  snprintf(header, sizeof(header), "\n(Added by %s on %s);\n",
           getenv("USER"), date);
  code = convert_string(header);
  if (aux)
    code = append_string(code, aux);
  code = append_cstr(code, "(");
  code = append_string(code, name);
  code = append_cstr(code, ")(");
  code = append_string(code, body);
  code = append_cstr(code, ")");
  code = append_data(code, &defun, (&defun)+1);
  code = append_cstr(code, "\n");

  /* Evaluate in current */
  if (!exec_code(interp, code)) {
    print_error("not adding function to library due to error(s)");
    stack_push(interp, name);
    stack_push(interp, code);
    return 0;
  }

  /* Don't need name or code anymore. */
  free(name);
  free(body);

  /* OK, write out */
  out = fopen(user_library_file, "a");
  if (!out) {
    fprintf(stderr, "tgl: error: unable to open %s: %s\n",
            user_library_file, strerror(errno));
    free(code);
    return 0;
  }
  if (code->len !=
      fwrite(string_data(code), 1, code->len, out)) {
    fprintf(stderr, "tgl: error writing to %s: %s\n",
            user_library_file, strerror(errno));
    free(code);
    fclose(out);
    return 0;
  }

  /* Success */
  fclose(out);
  free(code);
  return 1;
}