Exemple #1
0
/**
 * @brief         shell_func
 * @param[in]     void
 * @param[in,out] void
 * @return        void
 */
void shell_func (void)
{
    cursor_blink();

    while(1)
    {
        PRINT("\r\nBOS# ");
        
        UART0_AsyncReceive(64, g_rx_buffer, &rx_complete);
        BOS_WaitEvent(EVT_UART_RECEIVE);
        BOS_ClearEvent(EVT_UART_RECEIVE);

        if(check_cmd((char *)g_rx_buffer, "help"))
        {
            cmd_help();
        }
        else if(check_cmd((char *)g_rx_buffer, "info"))
        {
            cmd_info();
        }
        else if(check_cmd((char *)g_rx_buffer, "ps"))
        {
            cmd_ps();
        }
        else if(check_cmd((char *)g_rx_buffer, "mbx"))
        {
            cmd_mbx();
        }
        else
        {
            PRINT("\r\nCommand not found, type help for more details\r\n");
        }
    }
}
Exemple #2
0
/* main
 *
 *	do some main stuff.
 */
int main( int argc, char ** argv )
{
	basic_program * bp;
	basic_line * bl;


	printf( "0\n" );
	/* set up our program space */
	bp = newProgram();
	if( !bp ) {
		errorReport( kErrorMalloc, 1 );
		return 0;
	}

	/* display version info */
	cmd_info( bp, NULL );

	bl = consumeString( bp, program[0] );
	bl = consumeString( bp, program[1] );
	bl = consumeString( bp, program[2] );
	bl = consumeString( bp, program[3] );
	bl = consumeString( bp, program[4] );

	/* and run the program, if we should... */
	printf( "Running program\n" );
	runProgram( bp, 0 );
	while( run_poll( bp ) );

	/* just show access of variables */
	printf( "Variable 'a' is %ld\n", getVariableNumber( bp->variables, "a" ));

	deleteProgram( bp );

	return 0;
}
Exemple #3
0
/*
 * Console Initialization Routine
 */
void console_init() {
    memset(cmdEntries,0, sizeof(struct COMMAND_ENTRY) * CONSOLE_MAX_COMMAND);
    cmdCount = 0;

    // Initialize the commands
#if CONSOLE_SETTINGS_COMMANDS_ENABLED
    // settings
    console_add_command(PSTR("CALL"),cmd_settings_mycall);		// setup my callsign-ssid
    console_add_command(PSTR("DEST"),cmd_settings_destcall);	// setup destination call-ssid
    console_add_command(PSTR("PATH"),cmd_settings_path);		// setup path like WIDEn-N for beaco
    console_add_command(PSTR("RESET"),cmd_settings_reset);				// reset the tnc
    console_add_command(PSTR("SYMBOL"),cmd_settings_symbol);	// setup the beacon symbol

    console_add_command(PSTR("BEACON"), cmd_settings_beacon_interval); // setup beacon interval

#if SETTINGS_SUPPORT_BEACON_TEXT
    console_add_command(PSTR("TEXT"),cmd_settings_beacon_text);
#endif
#endif

#if CONSOLE_SEND_COMMAND_ENABLED
    console_add_command(PSTR("SEND"),cmd_send);
#endif

    // Initialization done, display the welcome banner and settings info
    cmd_info(&g_serial,0,0);
}
Exemple #4
0
int main(int argc, char** argv)
{
	if(argc < 2) {
		print_help();
		return 1;
	}

	const char*  const command = argv[1];
	const char** const cargv   = const_quirk(argv);
	if(IS_CMD("decode-all", 1)) {
		return cmd_get_all_and_decode(argv + 2, argc - 2);
	}
	else if(IS_CMD("decode", 2)) {
		return cmd_decode(argv[2], cargv + 3, argc - 3);
	}
	else if(IS_CMD("append-all", 2)) {
		return cmd_append_all(argv[2], argv[3]);
	}
	else if(IS_CMD("recode", 3)) {
		return cmd_recode(argv[2], argv[3], cargv + 4, argc - 4);
	}
	else if(IS_CMD("info", 1)) {
		return cmd_info(argv[2]);
	}
	else if(IS_CMD("dump", 1)) {
		return cmd_dump(argv[2]);
	}
	else {
		print_help();
		return 1;
	}

	return 0;
}
Exemple #5
0
int main(void)
{
    puts("ROM flash read write test\n");
    puts("Please refer to the README.md for further information\n");

    cmd_info(0, NULL);

    /* run the shell */
    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}
Exemple #6
0
static int cmd_info(void *data, const char *input) {
	RCore *core = (RCore *)data;
	ut64 offset = r_bin_get_offset (core->bin);
	int va = core->io->va || core->io->debug;
	int mode = 0;
	if (input[0]) {
		switch (input[1]) {
		case '*': mode = R_CORE_BIN_RADARE; break;
		case 'j': mode = R_CORE_BIN_JSON; break;
		case 'q': mode = R_CORE_BIN_SIMPLE; break;
		}
	}

	switch (*input) {
	case 'o': r_core_bin_load (core, input[1]==' '?
			input+1: core->file->filename); break;
#define RBININFO(x) r_core_bin_info(core,x,mode,va,NULL,offset)
	case 'S': RBININFO (R_CORE_BIN_ACC_SECTIONS); break;
	case 'h': RBININFO (R_CORE_BIN_ACC_FIELDS); break;
	case 'l': RBININFO (R_CORE_BIN_ACC_LIBS); break;
	case 's': RBININFO (R_CORE_BIN_ACC_SYMBOLS); break;
	case 'd': RBININFO (R_CORE_BIN_ACC_DWARF); break;
	case 'i': RBININFO (R_CORE_BIN_ACC_IMPORTS); break;
	case 'I': RBININFO (R_CORE_BIN_ACC_INFO); break;
	case 'e': RBININFO (R_CORE_BIN_ACC_ENTRIES); break;
	case 'z': RBININFO (R_CORE_BIN_ACC_STRINGS); break;
	case 'c':
	case 'C': RBININFO (R_CORE_BIN_ACC_CLASSES); break;
	case 'a':
		if (input[1]=='*') {
			cmd_info (core, "I*");
			cmd_info (core, "e*");
			cmd_info (core, "i*");
			cmd_info (core, "s*");
			cmd_info (core, "S*");
			cmd_info (core, "z*");
		} else {
			cmd_info (core, "I");
			cmd_info (core, "e");
			cmd_info (core, "i");
			cmd_info (core, "s");
			cmd_info (core, "S");
			cmd_info (core, "z");
		}
		break;
	case '?':
		r_cons_printf (
		"Usage: i[aeciIsosSz][jq*]      ; get info from opened file\n"
		"Output mode:\n"
		" '*'   output in radare commands\n"
		" 'j'   output in json\n"
		" 'q'   simple quiet output\n"
		"Actions:\n"
		" io [file] ; load info from given file (or last opened)\n"
		" ia        ; show all info (imports, exports, sections..)\n"
		" ic        ; list classes\n"
		" id        ; debug information (source lines)\n"
		" ie        ; entrypoint\n"
		" ih        ; headers\n"
		" ii        ; imports\n"
		" iI        ; binary info\n"
		" is        ; symbols\n"
		" iS        ; sections\n"
		" iz        ; strings\n");
		break;
	case '*': mode = R_CORE_BIN_RADARE;
	case 'j': if (*input=='j') mode = R_CORE_BIN_JSON;
	default:
		if (core->file) {
			if (mode == R_CORE_BIN_JSON)
				r_cons_printf ("{\"bin\":");
			r_core_bin_info (core, R_CORE_BIN_ACC_INFO,
				mode, va, NULL, offset);
			if (mode == R_CORE_BIN_JSON)
				r_cons_printf (",\"core\":");
			r_core_file_info (core, mode);
			if (mode == R_CORE_BIN_JSON)
				r_cons_printf ("}\n");
		} else eprintf ("No selected file\n");
	}
	return 0;
}
Exemple #7
0
/* command line arguments */
int main (int argc, char * argv[]) {
	int ask_help = 0;
	int ask_version = 0;
	struct option long_options[] = {
		{ "help", no_argument, &ask_help, 1},
		{ "version", no_argument, &ask_version, 1},
		{ "max_mem", required_argument, NULL, 'm' },
		{ "colors", required_argument, NULL, 'c' },
		{ 0, 0 , 0, 0},
	};
	const char * short_opts ="hVm:c:";
	int c;
	int option_index = 0;

	// parse options
	while (1) {
		c = getopt_long (argc, argv, short_opts, long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case 0:
				break;
			case 'c':
				{
					char * opt = optarg;
					if (opt[0] == 'L') {
						arg_is_color_cache_level = 1;
						opt++;
					}
					arg_colors = atoi (opt);
					if (arg_colors < 0)
						error (EXIT_FAILURE, 0, "invalid --colors value \"%s\"", optarg);
				}
				break;
			case 'm':
				arg_max_mem = optarg;
				break;
			case 'h':
				ask_help = 1;
				break;
			case 'V':
				ask_version = 1;
				break;
			default:
				error (EXIT_FAILURE, 0, "getopt: unknown option code '%c' (%d)", c, c);
				break;
		}
	}
	// forget the parsed part of argv
	argc -= optind;
	argv = &argv[optind];

	if (ask_version) {
		printf ("ccontrol: version %s\n", PACKAGE_STRING);
		return EXIT_SUCCESS;
	}

	if (ask_help || argc == 0) {
		print_help ();
		return EXIT_SUCCESS;
	}

	if (strcmp (argv[0], "info") == 0) {
		return cmd_info ();
	} else if (strcmp (argv[0], "load") == 0) {
		return load_module ();
	} else if (strcmp (argv[0], "unload") == 0) {
		return unload_module();
	} else {
		fprintf (stderr, "unknown command \"%s\"\n", argv[0]);
		print_help ();
		return EXIT_FAILURE;
	}
}
Exemple #8
0
int main (int argc, char * argv[])
{
  fillheader();
  getentirecommandline(argc, argv);

  args_init(argc, argv);
  
  srand((unsigned int)opt_seed);

  if (!opt_quiet)
    show_header();

  if (opt_help)
  {
    cmd_help();
  }
  else if (opt_lca_left)
  {
    cmd_lca_left();
  }
  else if (opt_identical)
  {
    cmd_identical();
  }
  else if (opt_root)
  {
    cmd_root();
  }
  else if (opt_extract_ltips)
  {
    cmd_extract_ltips();
  }
  else if (opt_extract_rtips)
  {
    cmd_extract_rtips();
  }
  else if (opt_extract_tips)
  {
    cmd_extract_tips();
  }
  else if (opt_prune_tips || opt_prune_random)
  {
    cmd_prune_tips();
  }
  else if (opt_svg)
  {
    cmd_svg();
  }
  else if (opt_extract_lsubtree)
  {
    cmd_extract_subtree(0);
  }
  else if (opt_extract_rsubtree)
  {
    cmd_extract_subtree(1);
  }
  else if (opt_treeshow)
  {
    cmd_tree_show();
  }
  else if (opt_induce_subtree)
  {
    cmd_induce_tree();
  }
  else if (opt_subtree_short >= 0)
  {
    cmd_subtree_short();
  }
  else if (opt_info)
  {
    cmd_info();
  }
  else if (opt_make_binary)
  {
    cmd_make_binary();
  }
  else if (opt_alltree_filename)
  {
    cmd_utree_bf();
  }
  else if (opt_randomtree_binary)
  {
    cmd_randomtree_binary();
  }
  else if (opt_simulate_bd)
  {
    cmd_simulate_bd();
  }
  else if (opt_attach_filename)
  {
    cmd_attach_tree();
  }
  else if (opt_scalebranch)
  {
    cmd_scalebranch();
  }

  free(cmdline);
  return (0);
}
static int cmd_info(void *data, const char *input) {
	RCore *core = (RCore *)data;
	int newline = r_config_get_i (core->config, "scr.interactive");
	ut64 offset = r_bin_get_offset (core->bin);
	RBinObject *o = r_bin_cur_object (core->bin);
	RCoreFile *cf = core->file;

	int va = core->io->va || core->io->debug;
	int mode = 0; //R_CORE_BIN_SIMPLE;
	int is_array = 0;
	Sdb *db;

	if (strchr (input, '*'))
		mode = R_CORE_BIN_RADARE;
	if (strchr (input, 'j'))
		mode = R_CORE_BIN_JSON;

	if (mode == R_CORE_BIN_JSON) {
		if (strlen (input+1)>1)
			is_array = 1;
	}
	if (is_array)
		r_cons_printf ("{");
	if (!*input)
		cmd_info_bin (core, offset, va, mode);
	while (*input) {
		switch (*input) {
		case 'b':
			{
			ut64 baddr = r_config_get_i (core->config, "bin.baddr");
			if (input[1]==' ')
				baddr = r_num_math (core->num, input+1);
			// XXX: this will reload the bin using the buffer.
			// An assumption is made that assumes there is an underlying
			// plugin that will be used to load the bin (e.g. malloc://)
			// TODO: Might be nice to reload a bin at a specified offset?
			r_core_bin_reload (core, NULL, baddr);
			r_core_block_read (core, 0);
			}
			break;
		case 'k':
			db = o ? o->kv : NULL;
			//:eprintf ("db = %p\n", db);
			switch (input[1]) {
			case 'v':
				if (db) sdb_query (db, input+3);
				break;
			case '.':
			case ' ':
				if (db) sdb_query (db, input+2);
				break;
			case '\0':
				if (db) sdb_list (db);
				break;
			case '?':
			default:
				eprintf ("Usage: ik [sdb-query]\n");
			}
			break;
		case 'o': 
			 {
				const char *fn = input[1]==' '? input+2: cf->desc->name;
				ut64 laddr = UT64_MAX;
				laddr = r_config_get_i (core->config, "bin.baddr");
				r_core_bin_load (core, fn, laddr);
			 }
			break;
	#define RBININFO(n,x) \
	if (is_array) { \
		if (is_array==1) is_array++; else r_cons_printf (","); \
		r_cons_printf ("\"%s\":",n); \
	}\
	r_core_bin_info (core,x,mode,va,NULL,offset,NULL);
		case 'A': newline=0; r_bin_list_archs (core->bin, 1); break;
		case 'Z': RBININFO ("size",R_CORE_BIN_ACC_SIZE); break;
		case 'S': RBININFO ("sections",R_CORE_BIN_ACC_SECTIONS); break;
		case 'h': RBININFO ("fields", R_CORE_BIN_ACC_FIELDS); break;
		case 'l': RBININFO ("libs", R_CORE_BIN_ACC_LIBS); break;
		case 's': RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS); break;
		case 'R':
		case 'r': RBININFO ("relocs", R_CORE_BIN_ACC_RELOCS); break;
		case 'd': RBININFO ("dwarf", R_CORE_BIN_ACC_DWARF); break;
		case 'i': RBININFO ("imports",R_CORE_BIN_ACC_IMPORTS); break;
		case 'I': RBININFO ("info", R_CORE_BIN_ACC_INFO); break;
		case 'e': RBININFO ("entries",R_CORE_BIN_ACC_ENTRIES); break;
		case 'z': RBININFO ("strings",R_CORE_BIN_ACC_STRINGS); break;
		case 'c':
		case 'C': RBININFO ("classes",R_CORE_BIN_ACC_CLASSES); break;
		case 'a':
			{
				switch (mode) {
				case R_CORE_BIN_RADARE: cmd_info (core, "i*IiesSz"); break;
				case R_CORE_BIN_JSON: cmd_info (core, "iIiesSzj"); break;
				default:
				case R_CORE_BIN_SIMPLE: cmd_info (core, "iIiesSz"); break;
				}
			}
			break;
		case '?': {
				const char * help_message[] = {
				"Usage: i", "", "Get info from opened file",
				"Output mode:", "", "",
				"'*'", "", "Output in radare commands",
				"'j'", "", "Output in json",
				"'q'", "", "Simple quiet output",
				"Actions:", "", "",
				"i|ij", "", "Show info of current file (in JSON)",
				"iA", "", "List archs",
				"ia", "", "Show all info (imports, exports, sections..)",
				"ib", "", "Reload the current buffer for setting of the bin (use once only)",
				"ic", "", "List classes",
				"id", "", "Debug information (source lines)",
				"ie", "", "Entrypoint",
				"ih", "", "Headers",
				"ii", "", "Imports",
				"iI", "", "Binary info",
				"ik", " [query]", "Key-value database from RBinObject",
				"il", "", "Libraries",
				"io", " [file]", "Load info from file (or last opened) use bin.baddr",
				"ir|iR", "", "Relocs",
				"is", "", "Symbols",
				"iS", "", "Sections",
				"iz", "", "Strings",
				NULL
				};
				r_core_cmd_help(core, help_message);

				}
			goto done;
		case '*':
			mode = R_CORE_BIN_RADARE;
			goto done;
		case 'j':
			mode = R_CORE_BIN_JSON;
			cmd_info_bin (core, offset, va, mode);
			goto done;
		default:
			cmd_info_bin (core, offset, va, mode);
			break;
		}
		input++;
		if (!strcmp (input, "j"))
			break;
	}
done:
	if (is_array)
		r_cons_printf ("}\n");
	if (newline) r_cons_newline();
	return 0;
}
Exemple #10
0
cmd_table init_cmd_table() {
    cmd_table r;
    add_cmd(r, cmd_info("using",        "create aliases for declarations, and use objects defined in other namespaces", using_cmd));
    add_cmd(r, cmd_info("set_option",   "set configuration option", set_option_cmd));
    add_cmd(r, cmd_info("exit",         "exit", exit_cmd));
    add_cmd(r, cmd_info("print",        "print a string", print_cmd));
    add_cmd(r, cmd_info("section",      "open a new section", section_cmd));
    add_cmd(r, cmd_info("namespace",    "open a new namespace", namespace_cmd));
    add_cmd(r, cmd_info("end",          "close the current namespace/section", end_scoped_cmd));
    add_cmd(r, cmd_info("check",        "type check given expression, and display its type", check_cmd));
    add_cmd(r, cmd_info("coercion",     "add a new coercion", coercion_cmd));
    add_cmd(r, cmd_info("opaque_hint",  "add hints for the elaborator/unifier", opaque_hint_cmd));
    add_cmd(r, cmd_info("#setline",     "modify the current line number, it only affects error/report messages", set_line_cmd));
    register_decl_cmds(r);
    register_inductive_cmd(r);
    register_notation_cmds(r);
    register_calc_cmds(r);
    register_proof_qed_cmds(r);
    register_class_cmds(r);
    register_tactic_hint_cmd(r);
    return r;
}
void doCommand( void )
{
  int rv = 0;

  switch( ( *gbuffer & ~0x20 ) ) {
    
    // AT<CR>
  case 0x00:
    // OK
    break;

    // Autobaud detection
  case 'A': 
    rv = cmd_autobaud();
    break;
    
    // Set Baudrate
  case 'B': 
    rv = cmd_baudrate();
    break;
    
  case 'C': //
    {
      char buf[20];
      int rr;

      *buf = 0;
      rr = getNumericValue( ( gbuffer + 1 ) );
      itoa( rr, buf, 10 );
      uart0BlockingPutch( ' ' );
      uart0BlockingPuts( buf );
    }
    break;
    
  case 'D': // Dial - Go online
    rv = cmd_online();
    break;

  case 'E': // Turn on/off echo
    rv = cmd_echo();
    break;
    
  case 'F': // Set Filter/Mask
    rv = cmd_filter();
    break;
    
  case 'G': // Send Burst n - number of messages. sz - delay between frames
    rv = cmd_sendBurst();
    break;
    
  case 'H': // Hook - Go online
    rv = cmd_online();
    break;
    
  case 'I': // Information
    rv = cmd_info();
    break;
    
  case 'J':
    rv = -1; // Not implemented
    break;
    
  case 'K': 
    {
      canmsg_t msg;
      msg.id = 0x334;
      msg.length = 2;
      msg.data[ 0 ] = 1;
      msg.data[ 1 ] = 2;
      msg.flags |=  MSG_EXT;

      //if ( !sja1000_sendMsg( &msg ) ) {
      //doResponse( FALSE, 0  );
      //}
      if ( !sja1000_writeMsgToBuf( &msg ) ) {
	rv = -1; // Not implemented;
      }

      rv = 0;
    }
    break;
    
  case 'L':  // Go online in Listen only mode
    rv = cmd_listen();
    break;
    
  case 'M':
    rv = -1; // Not implemented
    break;
    
  case 'N':
    rv = -1; // Not implemented
    break;
    
  case 'O':
    rv = -1; // Not implemented
    break;
    
  case 'P':
    rv = -1; // Not implemented
    break;
    
  case 'Q': // Quite 
    rv = cmd_quite();
    break;
    
  case 'R': // Read message
    rv = cmd_readmsg();
    break;
    
  case 'S': // Set/read registers
    rv = cmd_register();
    break;
    
  case 'T':
    rv = -1; // Not implemented
    break;
    
  case 'U':
    rv = -1; // Not implemented
    break;
    
  case 'V': // Verbal
    rv = cmd_verbal();
    break;
    
  case 'W': // Write message
    rv = cmd_writemsg();
    break;
    
  case 'X':
    rv = -1; // Not implemented
    break;
    
  case 'Y':
    rv = -1; // Not implemented
    break;
    
  case 'Z': // Reset device
    rv = cmd_reset();
    break;
    
  case '?': // Get statistics
    rv = -1; // Not implemented
    break;

  default:  // Uknown command
    rv = -1; // Not implemented
    break;
  }

  // Print out response
  if ( 0 == rv ) {
    doResponse( TRUE, rv  );
  }
  else {
    doResponse( FALSE, rv  );
  }
}
Exemple #12
0
int
main (int argc, char *argv[])
{
    int result;

    char *config = NULL;

    int ch;
    progname = argv[0];

    while ((ch = getopt(argc, argv, "c:vVh")) != -1) {
        switch (ch) {
        case 'c':
            config = strdup(optarg);
            break;
        case 'v':
            verbose++;
            break;
        case 'V':
            version();
            exit(0);
            break;
        case 'h':
            usage();
            exit(0);
            break;
        default:
            usage();
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (!argc) {
        usage();
        exit(1);
    }


    if (!strcasecmp(argv[0], "logout")) {
        if (config) free(config);
        exit(cmd_logout());
    }

    result = hsm_open(config, hsm_prompt_pin);
    if (result) {
        hsm_print_error(NULL);
        exit(-1);
    }

    openlog("hsmutil", LOG_PID, LOG_USER);

    if (!strcasecmp(argv[0], "login")) {
        argc --;
        argv ++;
        result = cmd_login();
    } else if (!strcasecmp(argv[0], "list")) {
        argc --;
        argv ++;
        result = cmd_list(argc, argv);
    } else if (!strcasecmp(argv[0], "generate")) {
        argc --;
        argv ++;
        result = cmd_generate(argc, argv);
    } else if (!strcasecmp(argv[0], "remove")) {
        argc --;
        argv ++;
        result = cmd_remove(argc, argv);
    } else if (!strcasecmp(argv[0], "purge")) {
        argc --;
        argv ++;
        result = cmd_purge(argc, argv);
    } else if (!strcasecmp(argv[0], "dnskey")) {
        argc --;
        argv ++;
        result = cmd_dnskey(argc, argv);
    } else if (!strcasecmp(argv[0], "test")) {
        argc --;
        argv ++;
        result = cmd_test(argc, argv);
    } else if (!strcasecmp(argv[0], "info")) {
        argc --;
        argv ++;
        result = cmd_info();
    } else if (!strcasecmp(argv[0], "debug")) {
        argc --;
        argv ++;
        result = cmd_debug();
    } else {
        usage();
        result = -1;
    }

    (void) hsm_close();
    if (config) free(config);

    closelog();

    exit(result);
}
Exemple #13
0
void console_parse_command(char* command, size_t commandLen) {
    char *key = NULL, *value = NULL;
    uint8_t valueLen = 0;
    Serial *pSer = &g_serial;

    // A simple hack to command "!5"
#if CFG_BEACON_TEST
    if(commandLen > 0 && command[0] == '!') {
        cmd_test_send(pSer, command+1,commandLen - 1);
        return;
    }
#endif

    if(commandLen >0 && command[0] == '?') {
        cmd_info(pSer,0,0);
#if CONSOLE_HELP_COMMAND_ENABLED
        cmd_help(pSer,0,0);
#endif
        return;
    }

    //TinyAPRS AT Command Handler
    if(commandLen >=6 && (command[0] == 'A' || command[0] == 'a') && (command[1] == 'T' || command[1] == 't') && (command[2] == '+') ) {
        // looking for the '='
        char* t = NULL;
        uint8_t i = 3;
        for(; i < commandLen; i++) {
            if(command[i] == '=') {
                t = command + i;
                break;
            }
        }
        if(t != NULL) {
            *t = 0; // split the key=value string into 2 strings.
            key = command + 3;
            value = t + 1;
            valueLen = strlen(value);
        }
    }

    // Compatible with OT2/Other TNCs KISS init command
    else if( (commandLen >=10) && (strcasecmp_P(command,PSTR("AMODE KISS")) == 0)) {
        // enter the kiss mode
        // reuse the existing command buffer
        key = command + 6;
        key[4] = 0;
        value = command;
        value[0] = '1';
        value[1] = 0;
        valueLen = 1;
    }
    else if( (commandLen >=7) && (strcasecmp_P(command,PSTR("KISS ON")) == 0)) {
        key = command;
        key[4] = 0;
        value = command + 5;
        value[0] = '1';
        value[1] = 0;
        valueLen = 1;
    }

    if(key == NULL && value == NULL) {
        // bail out
        SERIAL_PRINTF_P(pSer,PSTR("INVALID CMD: %.*s\r\n"),commandLen,command);
        return;
    }

    // look the command registry
    // convert to upper case
    strupr(key);
    PFUN_CMD_HANDLER fun = console_lookup_command(key);
    if(fun) {
        if(!fun(pSer, value, valueLen)) {
            // handle failure, should be invalid values
            SERIAL_PRINT_P(pSer,PSTR("INVALID CMD VALUE\r\n")); // user input command is parsed but the value is not valid
        }
    } else {
        SERIAL_PRINTF_P(pSer,PSTR("UNKNOWN CMD: %.*s\r\n"),commandLen,command);
    }

    return;
}
Exemple #14
0
static int cmd_info(void *data, const char *input) {
	RCore *core = (RCore *)data;
	int newline = r_config_get_i (core->config, "scr.interactive");
	ut64 offset = r_bin_get_offset (core->bin);
	RBinObject *o = r_bin_cur_object (core->bin);
	RCoreFile *cf = core->file;

	int va = core->io->va || core->io->debug;
	int mode = 0; //R_CORE_BIN_SIMPLE;
	int is_array = 0;
	Sdb *db;

	if (strchr (input, '*'))
		mode = R_CORE_BIN_RADARE;
	if (strchr (input, 'j'))
		mode = R_CORE_BIN_JSON;

	if (mode == R_CORE_BIN_JSON) {
		if (strlen (input+1)>1)
			is_array = 1;
	}
	if (is_array)
		r_cons_printf ("{");
	if (!*input)
		cmd_info_bin (core, offset, va, mode);
	while (*input) {
		switch (*input) {
		case 'b':
			{
			ut64 baddr = r_config_get_i (core->config, "bin.baddr");
			if (input[1]==' ')
				baddr = r_num_math (core->num, input+1);
			// XXX: this will reload the bin using the buffer.
			// An assumption is made that assumes there is an underlying
			// plugin that will be used to load the bin (e.g. malloc://)
			// TODO: Might be nice to reload a bin at a specified offset?
			r_core_bin_reload (core, NULL, baddr);
			r_core_block_read (core, 0);
			}
			break;
		case 'k':
			db = o ? o->kv : NULL;
			//:eprintf ("db = %p\n", db);
			switch (input[1]) {
			case 'v':
				if (db) sdb_query (db, input+3);
				break;
			case '.':
			case ' ':
				if (db) sdb_query (db, input+2);
				break;
			case '\0':
				if (db) sdb_list (db);
				break;
			case '?':
			default:
				eprintf ("Usage: ik [sdb-query]\n");
			}
			break;
		case 'o': r_core_bin_load (core, input[1]==' '?
				input+2: cf->filename,
				r_config_get_i (core->config, "bin.baddr"));
			break;
	#define RBININFO(n,x) \
	if (is_array) { \
		if (is_array==1) is_array++; else r_cons_printf (","); \
		r_cons_printf ("\"%s\":",n); \
	}\
	r_core_bin_info (core,x,mode,va,NULL,offset);
		case 'A': newline=0; r_bin_list_archs (core->bin, 1); break;
		case 'S': RBININFO ("sections",R_CORE_BIN_ACC_SECTIONS); break;
		case 'h': RBININFO ("fields", R_CORE_BIN_ACC_FIELDS); break;
		case 'l': RBININFO ("libs", R_CORE_BIN_ACC_LIBS); break;
		case 's': RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS); break;
		case 'R':
		case 'r': RBININFO ("relocs", R_CORE_BIN_ACC_RELOCS); break;
		case 'd': RBININFO ("dwarf", R_CORE_BIN_ACC_DWARF); break;
		case 'i': RBININFO ("imports",R_CORE_BIN_ACC_IMPORTS); break;
		case 'I': RBININFO ("info", R_CORE_BIN_ACC_INFO); break;
		case 'e': RBININFO ("entries",R_CORE_BIN_ACC_ENTRIES); break;
		case 'z': RBININFO ("strings",R_CORE_BIN_ACC_STRINGS); break;
		case 'c':
		case 'C': RBININFO ("classes",R_CORE_BIN_ACC_CLASSES); break;
		case 'a':
			{
				switch (mode) {
				case R_CORE_BIN_RADARE: cmd_info (core, "i*IiesSz"); break;
				case R_CORE_BIN_JSON: cmd_info (core, "ijIiesSz"); break;
				default:
				case R_CORE_BIN_SIMPLE: cmd_info (core, "iIiesSz"); break;
				}
			}
			break;
		case '?':
			r_cons_printf (
			"|Usage: i[aeciIsosSz][jq*]      ; get info from opened file\n"
			"|Output mode:\n"
			"| '*'   output in radare commands\n"
			"| 'j'   output in json\n"
			"| 'q'   simple quiet output\n"
			"|Actions:\n"
			"| i, ij       show info of current file (in JSON)\n"
			"| iA          list archs\n"
			"| ia          show all info (imports, exports, sections..)\n"
			"| ib          reload the current buffer for setting of the bin (use once only)\n"
			"| ic          list classes\n"
			"| id          debug information (source lines)\n"
			"| ie          entrypoint\n"
			"| ih          headers\n"
			"| ii          imports\n"
			"| iI          binary info\n"
			"| il          libraries\n"
			"| ik [query]  key-value database from RBinObject\n"
			"| io [file]   load info from file (or last opened) use bin.baddr\n"
			"| is          symbols\n"
			"| iS          sections\n"
			"| ir/iR       relocs\n"
			"| iz          strings\n"
			);
			goto done;
		case '*':
			mode = R_CORE_BIN_RADARE;
			goto done;
		case 'j':
			mode = R_CORE_BIN_JSON;
			cmd_info_bin (core, offset, va, mode);
			goto done;
		default:
			cmd_info_bin (core, offset, va, mode);
			break;
		}
		input++;
		if (!strcmp (input, "j"))
			break;
	}
done:
	if (is_array)
		r_cons_printf ("}\n");
	if (newline) r_cons_newline();
	return 0;
}
Exemple #15
0
int
main (int argc, char *argv[])
{
	char *path = 0;
	unsigned int lba = 0x0;
	char **sub_argv = 0;
	int num_sub_args = 0;
	
	enum param {
		PARAM_NONE = 0,
		PARAM_LBA_OFFSET = 1,
		PARAM_IMAGE_PATH = 2,
		PARAM_CMD_ARG = 3
	} next_param;
	
	next_param = PARAM_NONE;
	
	int i;
	for (i=1;i<argc;i++)
	{
		switch (next_param)
		{
			case PARAM_NONE:
				if (strcmp(argv[i], "-o") == 0)
				{
					next_param = PARAM_LBA_OFFSET;
				} else if (strcmp(argv[i], "-f") == 0) {
					next_param = PARAM_IMAGE_PATH;					
				} else {
					next_param = PARAM_CMD_ARG;
					sub_argv = malloc(sizeof(char*)*(argc-i));					
					i--;
				}
				break;
			case PARAM_LBA_OFFSET:
				lba = strtol(argv[i], 0, 0);
				next_param = PARAM_NONE;
				break;
			case PARAM_IMAGE_PATH:
				path = argv[i];
				next_param = PARAM_NONE;
				break;
			case PARAM_CMD_ARG:
				sub_argv[num_sub_args++] = argv[i];
				break;
		}
	}
	
	FILE* f = fopen(path, "r");
	if (!f)
	{
		printf("fopen: failed opening %s\n", path);
		return 1;
	}

	hfsp_info *hfsp;
	hfsp = hfsp_mount(f, lba);

	if (hfsp)
	{
		if (num_sub_args)
		{
			if (strcmp(sub_argv[0], "info") == 0) {
				cmd_info(hfsp, num_sub_args-1, sub_argv+1);
			} else {
				printf("unknown command: %s!\n", sub_argv[0]);
			}				
		} else {
			printf("no command given\n");
		}

		hfsp_umount(hfsp);		
	}
	
	if (sub_argv) free(sub_argv);

	fflush(f);
	fclose(f);
	
	return 0;
}