コード例 #1
0
ファイル: vm.cpp プロジェクト: coruws/VM_CrackMe_1
//переход на обработчик команды
bool Vm1::exec_command()
{
	if(!parse_command()) return false;

	switch (cmd.id)
	{
	case halt:
		cmd_halt();
		return false;
	case push_reg:
		cmd_push(cmd.operand);
		break;
	case pop_reg:
		cmd_pop(cmd.operand);
		break;
	case cmp_reg_reg:
		cmd_cmp_reg_reg(cmd.operand,cmd.operand2);
		break;
	case mov_reg_reg:
		cmd_mov_reg_reg(cmd.operand,cmd.operand2);
		break;
	case mov_reg_mem:
		cmd_mov_reg_mem(cmd.operand,cmd.operand2);
		break;

	case jmp:
		cmd_jmp(cmd.operand2,cmd.operand);
		break;

	case add_reg_reg:
		cmd_add_reg_reg(cmd.operand,cmd.operand2);
		break;

	case mod_reg_imm:
		cmd_mod_reg_imm(cmd.operand,cmd.operand2);
		break;

	case shl_reg_reg:
		cmd_shl_reg_reg(cmd.operand,cmd.operand2);
		break;
		
	case mov_reg_byte:
		cmd_mov_reg_byte(cmd.operand,cmd.operand2);
		break;

	case mov_reg_imm:
		cmd_mov_reg_imm(cmd.operand,cmd.operand2);
		break;
		
	case mov_reg_ptr_reg:
		cmd_mov_reg_ptr_reg(cmd.operand,cmd.operand2);
		break;
		
	case add_reg_imm:
		cmd_add_reg_imm(cmd.operand,cmd.operand2);
		break;	

	case xor_byte_ptr_reg:
		cmd_xor_byte_ptr_reg(cmd.operand,cmd.operand2);
		break;	

	case antidebug_1:
		cmd_antidebug_1(cmd.operand,cmd.operand2);
		break;	

	default:
		return false;
	}
	//след команда..
	reg.eip+=cmd.len;
	return true;
}
コード例 #2
0
int main(void) {
	int isRunning = 1;
	char buffer[MAX_LINE_LENGTH];
	char command[MAX_LINE_LENGTH];
	while(isRunning){	
		//int i;
		printf("> ");
		fgets(buffer, MAX_LINE_LENGTH, stdin);
		/*for( i = 0; i < MAX_LINE_LENGTH; i++ ){
		  buffer[i] = tolower(buffer[i]);
		}*/
		sscanf(buffer, " %s ", (char*)&command);
		//Switch for commands
		if(strcmp(command, "BYE") == 0){					/*BYE*/
			deleteAllEntry(entry_head);
			deleteAllSnapshot(snapshot_head);
			printf("bye");
			isRunning = 0;
		}else if(strcmp(command, "HELP") == 0){				/*HELP*/
			cmd_help();
		}else if(strcmp(command, "LIST") == 0){
			sscanf(buffer + strlen(command), "%s", (char*)&command);
			if(strcmp(command, "KEYS") == 0){				/*LIST KEYS*/
				cmd_list_keys();
			}else if(strcmp(command, "ENTRIES") == 0){		/*LIST ENTRIES*/
				cmd_list_entries();
			}else if(strcmp(command, "SNAPSHOTS") == 0){	/*LIST SNAPSHOTS*/
				cmd_list_snapshots();
			}
		}else if(strcmp(command, "GET") == 0){				/*GET*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_get(key);
		}else if(strcmp(command, "DEL") == 0){				/*DEL*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_del(key);
		}else if(strcmp(command, "PURGE") == 0){			/*PURGE*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_purge(key);
		}else if(strcmp(command, "SET") == 0){				/*SET*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_set(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PUSH") == 0){				/*PUSH*/
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_push(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "APPEND") == 0){			/*APPEND*/ 
			int i = 0;
			char key[MAX_KEY_LENGTH];
			char *endptr;
			int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int));
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			endptr = buffer + strlen(command) + strlen(key) + 2;
			while(1){
				values[i] = strtol(endptr, &endptr, 10);
				if(*endptr == '\n'){
					cmd_append(key, values, i+1);
					break;
				}
				i++;
			}
			free(values);
		}else if(strcmp(command, "PICK") == 0){				/*PICK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pick(key, index);
		}else if(strcmp(command, "PLUCK") == 0){			/*PLUCK*/
			char key[MAX_KEY_LENGTH];
			int index;
			sscanf(buffer + strlen(command)+1, "%s", (char*)&key);
			index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0);
			cmd_pluck(key, index);
		}else if(strcmp(command, "POP") == 0){				/*POP*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_pop(key);
		}else if(strcmp(command, "DROP") == 0){				/*DROP*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_drop(id);
		}else if(strcmp(command, "ROLLBACK") == 0){			/*ROLLBACK*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_rollback(id);
		}else if(strcmp(command, "CHECKOUT") == 0){			/*CHECKOUT*/
			int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10);
			cmd_checkout(id);
		}else if(strcmp(command, "SNAPSHOT") == 0){			/*SNAPSHOT*/
			cmd_snapshot();
		}else if(strcmp(command, "MIN") == 0){				/*MIN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_min(key);
		}else if(strcmp(command, "MAX") == 0){				/*MAX*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_max(key);
		}else if(strcmp(command, "SUM") == 0){				/*SUM*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sum(key);
		}else if(strcmp(command, "LEN") == 0){				/*LEN*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_len(key);
		}else if(strcmp(command, "REV") == 0){				/*REV*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_rev(key);
		}else if(strcmp(command, "UNIQ") == 0){				/*UNIQ*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_uniq(key);
		}else if(strcmp(command, "SORT") == 0){				/*SORT*/
			char key[MAX_KEY_LENGTH];
			sscanf(buffer + strlen(command), "%s", (char*)&key);
			cmd_sort(key);
		}else{
			printf("\n");
		}
	}
	return 0;
}
コード例 #3
0
ファイル: Led.cpp プロジェクト: jjstecchino/mavsky
void LedController::process_command() {
  current_instruction_pc = pc;
  uint8_t cmd = program[pc++]; 
  switch(cmd) {

    case CMD_GROUP_SET:
      cmd_group_set();
      break;
      
    case CMD_GROUP_CLEAR:
      cmd_group_clear();
      break;

    case CMD_CLEAR_GROUPS:
      cmd_clear_groups();
      break;

    case CMD_DISABLE_ACTIONS:
      cmd_disable_actions();
      break;
          
    case CMD_LOAD_REG_CONST:
      cmd_load_reg_const();
      break;

    case CMD_LDAA8:
      cmd_load_reg_8(0);
      break;
    
    case CMD_LDAB8:
      cmd_load_reg_8(1);
      break;
    
    case CMD_LDAC8:
      cmd_load_reg_8(2);
      break;
    
    case CMD_LDAD8:
      cmd_load_reg_8(3);
      break;
    
    case CMD_LDAE8:
      cmd_load_reg_8(4);
      break;
    
    case CMD_LDAA16:
      cmd_load_reg_16(0);
      break;
    
    case CMD_LDAB16:
      cmd_load_reg_16(1);
      break;
    
    case CMD_LDAC16:
      cmd_load_reg_16(2);
      break;
    
    case CMD_LDAD16:
      cmd_load_reg_16(3);
      break;
        
    case CMD_LDAE16:
      cmd_load_reg_16(4);
      break;
        
    case CMD_LOAD_REG_MAV:
      cmd_load_reg_mav();
      break;
      
    case CMD_PAUSE:
      cmd_pause();
      break;
          
    case CMD_YIELD:
      cmd_yield();
      break;
      
    case CMD_JUMP_ABS:
      cmd_jump_absolute();
      break;

    case CMD_JUMP_REL:
      cmd_jump_relative();
      break;

    case CMD_BZ_REL:
      cmd_bz_relative();
      break;
      
    case CMD_BNZ_REL:
      cmd_bnz_relative();
      break;
      
    case CMD_MOVE_REG:
      cmd_move_register();
      break;
               
    case CMD_SETCOLOR:
      cmd_set_color();
      break;    
      
    case CMD_SETFLASH:
      cmd_set_flash();
      break;
      
    case CMD_SETWAVE:
      cmd_set_wave();
      break;
      
    case CMD_SETBOUNCE:
      cmd_set_bounce();
      break;
      
    case CMD_SETRANDOM:
      cmd_set_random();
      break;
      
    case CMD_SETBAR:
      cmd_set_bar();
      break;     
       
    case CMD_SETOFF:
      cmd_set_off();
      break;

    case CMD_SETFILL:
      cmd_set_fill();
      break;
    case CMD_0EQ1:
      cmd_0eq1();
      break;

    case CMD_0NE1:
      cmd_0ne1();
      break;

    case CMD_0LT1:
      cmd_0lt1();
      break;
    
    case CMD_0LE1:
      cmd_0le1();
      break;
    
    case CMD_0GT1:
      cmd_0gt1();
      break;
    
    case CMD_0GE1:
      cmd_0ge1();
      break;

    case CMD_PUSH:
      cmd_push();
      break;
      
    case CMD_POP:
      cmd_pop();
      break;
      
    case CMD_AND:
      cmd_and();
      break;

    case CMD_OR:
      cmd_or();
      break;
      
    default:
      if(console != NULL)
      {
        console->console_print("Invalid program instruction %d at pc:%d\r\n", cmd, pc);
      }    
  }
}