void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { char* cmd = strdup(command); char* action = strtok(cmd, " "); debug("Executing %s\n", action); if (!strcmp(cmd, "/exit")) { quit = 1; } else if (!strcmp(cmd, "/help")) { shell_usage(); } else if (!strcmp(cmd, "/upload")) { char* filename = strtok(NULL, " "); debug("Uploading files %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } } else if (!strcmp(cmd, "/deviceinfo")) { int ret; unsigned int cpid, bdid; unsigned long long ecid; unsigned char srnm[12], imei[15], bt[15]; ret = irecv_get_cpid(client, &cpid); if(ret == IRECV_E_SUCCESS) { printf("CPID: %d\n", cpid); } ret = irecv_get_bdid(client, &bdid); if(ret == IRECV_E_SUCCESS) { printf("BDID: %d\n", bdid); } ret = irecv_get_ecid(client, &ecid); if(ret == IRECV_E_SUCCESS) { printf("ECID: %lld\n", ecid); } ret = irecv_get_srnm(client, srnm); if(ret == IRECV_E_SUCCESS) { printf("SRNM: %s\n", srnm); } ret = irecv_get_imei(client, imei); if(ret == IRECV_E_SUCCESS) { printf("IMEI: %s\n", imei); } } else if (!strcmp(cmd, "/exploit")) { char* filename = strtok(NULL, " "); debug("Sending exploit %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } irecv_send_exploit(client); } else if (!strcmp(cmd, "/execute")) { char* filename = strtok(NULL, " "); debug("Executing script %s\n", filename); if (filename != NULL) { irecv_execute_script(client, filename); } } free(action); }
static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { char* cmd = strdup((char*)command); char* action = strtok(cmd, " "); if (!strcmp(cmd, "/exit")) { quit = 1; } else if (!strcmp(cmd, "/help")) { shell_usage(); } else if (!strcmp(cmd, "/upload")) { char* filename = strtok(NULL, " "); debug("Uploading files %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } } else if (!strcmp(cmd, "/deviceinfo")) { int ret, mode; unsigned int cpid, bdid; unsigned long long ecid; char srnm[12], imei[15]; ret = irecv_get_cpid(client, &cpid); if(ret == IRECV_E_SUCCESS) { printf("CPID: %d\n", cpid); } ret = irecv_get_bdid(client, &bdid); if(ret == IRECV_E_SUCCESS) { printf("BDID: %d\n", bdid); } ret = irecv_get_ecid(client, &ecid); if(ret == IRECV_E_SUCCESS) { printf("ECID: " _FMT_lld "\n", ecid); } ret = irecv_get_srnm(client, srnm); if(ret == IRECV_E_SUCCESS) { printf("SRNM: %s\n", srnm); } ret = irecv_get_imei(client, imei); if(ret == IRECV_E_SUCCESS) { printf("IMEI: %s\n", imei); } ret = irecv_get_mode(client, &mode); if (ret == IRECV_E_SUCCESS) { printf("MODE: %s\n", mode_to_str(mode)); } } else if (!strcmp(cmd, "/limera1n")) { char* filename = strtok(NULL, " "); debug("Sending limera1n payload %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } irecv_trigger_limera1n_exploit(client); } else if (!strcmp(cmd, "/execute")) { char* filename = strtok(NULL, " "); debug("Executing script %s\n", filename); if (filename != NULL) { char* buffer = NULL; uint64_t buffer_length = 0; buffer_read_from_filename(filename, &buffer, &buffer_length); if (buffer) { buffer[buffer_length] = '\0'; irecv_execute_script(client, buffer); free(buffer); } else { printf("Could not read file '%s'\n", filename); } } } free(action); }
static int shell_get_command(player_cmd_t *playercmd) { int ret; fd_set rfds; struct timeval tv; int fd=fileno(stdin); #define is_CMD(str,cmd,s_cmd1,s_cmd2) (strcmp(str,cmd)==0 || strcmp(str,s_cmd1)==0 || strcmp(str,s_cmd2)==0) FD_ZERO(&rfds); FD_SET(fd, &rfds); tv.tv_sec = 0; tv.tv_usec = 3 * 1000 * 1000; ret = select(fd+1, &rfds, NULL, NULL, &tv); if(ret > 0 && FD_ISSET(fd, &rfds)) { char str[100]={0}; scanf("%s",str); //gets(str); if(is_CMD(str,"quit","x","X")) { playercmd->ctrl_cmd = CMD_EXIT; } else if(is_CMD(str,"stop","s","s")) { playercmd->ctrl_cmd = CMD_STOP; } else if(is_CMD(str,"pause","p","P")) { playercmd->ctrl_cmd = CMD_PAUSE; } else if(is_CMD(str,"resume","r","R")) { playercmd->ctrl_cmd = CMD_RESUME; } else if(is_CMD(str,"mute","m","m")) { playercmd->set_mode = CMD_MUTE ; } else if(is_CMD(str,"unmute","M","M")) { playercmd->set_mode = CMD_UNMUTE; } else if(is_CMD(str,"volget","v","v")) { playercmd->info_cmd = CMD_GET_VOLUME; } else if(memcmp(str,"volset:",strlen("volset:"))==0 || (str[0]=='V' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->set_mode = CMD_SET_VOLUME; playercmd->param = r; } else { log_print("error command for set vol(fmt:\"V:value\")\n"); } } else if(memcmp(str,"search:",strlen("search:"))==0 || (str[0]=='t' && str[1]==':')|| (str[0]=='T' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->ctrl_cmd = CMD_SEARCH; playercmd->param = r; } else { log_print("error command for search(fmt:\"T:value\")\n"); } } else if(memcmp(str,"forward:",strlen("forward:"))==0 || (str[0]=='f' && str[1]==':')|| (str[0]=='F' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->ctrl_cmd = CMD_FF; playercmd->param= r; } else { log_print("error command for forward(fmt:\"F:value\")\n"); } } else if(memcmp(str,"backward:",strlen("backward:"))==0 || (str[0]=='b' && str[1]==':')|| (str[0]=='B' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->ctrl_cmd = CMD_FB; playercmd->param= r; log_print("[%s:%d]fb---step=%d\n",__FUNCTION__, __LINE__, r); } else { log_print("error command for backward(fmt:\"B:value\")\n"); } } else if(memcmp(str,"aid:",strlen("aid:"))==0 || (str[0]=='a' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->ctrl_cmd = CMD_SWITCH_AID; playercmd->param= r; } else { log_print("error command for audio id(fmt:\"a:value\")\n"); } } else if(memcmp(str,"sid:",strlen("sid:"))==0 || (str[0]=='y' && str[1]==':')) { int r=-1; char *p; p=strstr(str,":"); if(p!=NULL) { p++; sscanf(p,"%d",&r); playercmd->ctrl_cmd = CMD_SWITCH_SID; playercmd->param= r; } else { log_print("error command for subtitle id(fmt:\"y:value\")\n"); } } else if(is_CMD(str, "volrange", "g", "G")) { playercmd->info_cmd = CMD_GET_VOL_RANGE; } else if(is_CMD(str, "spectrum", "u", "U")) { playercmd->set_mode = CMD_SPECTRUM_SWITCH; } else if(is_CMD(str, "balance", "e", "E")) { playercmd->set_mode = CMD_SET_BALANCE; } else if(is_CMD(str, "swap", "w", "W")) { playercmd->set_mode = CMD_SWAP_LR; } else if(is_CMD(str, "lmono", "l", "l")) { playercmd->set_mode = CMD_LEFT_MONO; } else if(is_CMD(str, "rmono", "L", "L")) { playercmd->set_mode = CMD_RIGHT_MONO; } else if(is_CMD(str, "setreo", "o", "O")) { playercmd->set_mode = CMD_SET_STEREO; } else if(is_CMD(str, "curtime", "c", "C")) { playercmd->info_cmd = CMD_GET_CURTIME; } else if(is_CMD(str, "duration", "d", "D")) { playercmd->info_cmd = CMD_GET_DURATION; } else if(is_CMD(str, "status", "S", "S")) { playercmd->info_cmd = CMD_GET_PLAY_STA; } else if(is_CMD(str, "media", "i", "I")) { playercmd->info_cmd = CMD_GET_MEDIA_INFO; } else if(is_CMD(str, "pid", "k", "K")) { playercmd->info_cmd = CMD_LIST_PID; } else if(is_CMD(str, "mutesta", "z", "z")) { ret = codec_get_mutesta(NULL); log_print("======[shell_get_command]mute status=%d\n",ret); } else if(is_CMD(str,"help","h","H")) { shell_usage(); } else { if(strlen(str) > 1) // not only enter shell_usage(); } } else if(ret < 0) log_print("[shell_get_command] select error!\n"); //else //ret = 0 //log_print("[shell_get_command] select time out!\n"); //log_print("[shell_get_command:%d]ccmd=%x param=%d\n",__LINE__,playercmd->ctrl_cmd,playercmd->param); if((playercmd->ctrl_cmd!=0) || (playercmd->info_cmd!=0)|| (playercmd->set_mode != 0)) { char pid[MAX_PLAYER_THREADS]; int num = 0; num = player_list_pid(pid, MAX_PLAYER_THREADS); if(num == 1) playercmd->pid = pid[0]; //log_print("[shell_get_command:%d]num=%d pid=%d param=%d\n",__LINE__,num,playercmd->pid, playercmd->param); return 0; } else return -1; }
static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { char* cmd = strdup((char*)command); char* action = strtok(cmd, " "); if (!strcmp(cmd, "/exit")) { quit = 1; } else if (!strcmp(cmd, "/help")) { shell_usage(); } else if (!strcmp(cmd, "/upload")) { char* filename = strtok(NULL, " "); debug("Uploading file %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } } else if (!strcmp(cmd, "/deviceinfo")) { int ret, mode; const struct irecv_device_info *devinfo = irecv_get_device_info(client); if (devinfo) { printf("CPID: %04x\n", devinfo->cpid); printf("CPRV: %02x\n", devinfo->cprv); printf("BDID: %02x\n", devinfo->bdid); printf("ECID: " _FMT_lld "\n", devinfo->ecid); printf("CPFM: %02x\n", devinfo->cpfm); printf("SCEP: %02x\n", devinfo->scep); printf("IBFL: %02x\n", devinfo->ibfl); printf("SRNM: %s\n", (devinfo->srnm) ? devinfo->srnm : "N/A"); printf("IMEI: %s\n", (devinfo->imei) ? devinfo->imei : "N/A"); } else { printf("Could not get device info?!\n"); } ret = irecv_get_mode(client, &mode); if (ret == IRECV_E_SUCCESS) { printf("MODE: %s\n", mode_to_str(mode)); } } else if (!strcmp(cmd, "/limera1n")) { char* filename = strtok(NULL, " "); debug("Sending limera1n payload %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename, 0); } irecv_trigger_limera1n_exploit(client); } else if (!strcmp(cmd, "/execute")) { char* filename = strtok(NULL, " "); debug("Executing script %s\n", filename); if (filename != NULL) { char* buffer = NULL; uint64_t buffer_length = 0; buffer_read_from_filename(filename, &buffer, &buffer_length); if (buffer) { buffer[buffer_length] = '\0'; irecv_execute_script(client, buffer); free(buffer); } else { printf("Could not read file '%s'\n", filename); } } } else { printf("Unsupported command %s. Use /help to get a list of available commands.\n", cmd); } free(action); }