|
@@ -91,10 +91,9 @@ WifiMarauderScriptStageSelect* _wifi_marauder_script_get_stage_select(cJSON *sta
|
|
|
cJSON *indexes_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "indexes");
|
|
cJSON *indexes_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "indexes");
|
|
|
cJSON *allow_repeat_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "allow_repeat");
|
|
cJSON *allow_repeat_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "allow_repeat");
|
|
|
|
|
|
|
|
- if (!cJSON_IsString(type_json) || !cJSON_IsString(filter_json)) {
|
|
|
|
|
|
|
+ if (!cJSON_IsString(type_json)) {
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
WifiMarauderScriptSelectType select_type;
|
|
WifiMarauderScriptSelectType select_type;
|
|
|
if (strcmp(type_json->valuestring, "ap") == 0) {
|
|
if (strcmp(type_json->valuestring, "ap") == 0) {
|
|
|
select_type = WifiMarauderScriptSelectTypeAp;
|
|
select_type = WifiMarauderScriptSelectTypeAp;
|
|
@@ -105,13 +104,12 @@ WifiMarauderScriptStageSelect* _wifi_marauder_script_get_stage_select(cJSON *sta
|
|
|
} else {
|
|
} else {
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- char *filter_str = strdup(filter_json->valuestring);
|
|
|
|
|
|
|
+ char *filter_str = cJSON_IsString(filter_json) ? strdup(filter_json->valuestring) : NULL;
|
|
|
|
|
|
|
|
WifiMarauderScriptStageSelect *stage_select = (WifiMarauderScriptStageSelect*) malloc(sizeof(WifiMarauderScriptStageSelect));
|
|
WifiMarauderScriptStageSelect *stage_select = (WifiMarauderScriptStageSelect*) malloc(sizeof(WifiMarauderScriptStageSelect));
|
|
|
stage_select->type = select_type;
|
|
stage_select->type = select_type;
|
|
|
- stage_select->filter = filter_str;
|
|
|
|
|
stage_select->allow_repeat = cJSON_IsBool(allow_repeat_json) ? allow_repeat_json->valueint : true;
|
|
stage_select->allow_repeat = cJSON_IsBool(allow_repeat_json) ? allow_repeat_json->valueint : true;
|
|
|
|
|
+ stage_select->filter = filter_str;
|
|
|
|
|
|
|
|
if (cJSON_IsArray(indexes_json)) {
|
|
if (cJSON_IsArray(indexes_json)) {
|
|
|
int indexes_size = cJSON_GetArraySize(indexes_json);
|
|
int indexes_size = cJSON_GetArraySize(indexes_json);
|
|
@@ -319,6 +317,36 @@ WifiMarauderScriptStageBeaconAp* _wifi_marauder_script_get_stage_beacon_ap(cJSON
|
|
|
return beacon_ap_stage;
|
|
return beacon_ap_stage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+WifiMarauderScriptStageExec* _wifi_marauder_script_get_stage_exec(cJSON *stages) {
|
|
|
|
|
+ cJSON* exec_stage_json = cJSON_GetObjectItem(stages, "exec");
|
|
|
|
|
+ if (exec_stage_json == NULL) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cJSON *command_json = cJSON_GetObjectItemCaseSensitive(exec_stage_json, "command");
|
|
|
|
|
+ char *command_str = cJSON_IsString(command_json) ? strdup(command_json->valuestring) : NULL;
|
|
|
|
|
+
|
|
|
|
|
+ WifiMarauderScriptStageExec *exec_stage = (WifiMarauderScriptStageExec*) malloc(sizeof(WifiMarauderScriptStageExec));
|
|
|
|
|
+ exec_stage->command = command_str;
|
|
|
|
|
+
|
|
|
|
|
+ return exec_stage;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+WifiMarauderScriptStageDelay* _wifi_marauder_script_get_stage_delay(cJSON *stages) {
|
|
|
|
|
+ cJSON* delay_stage_json = cJSON_GetObjectItem(stages, "delay");
|
|
|
|
|
+ if (delay_stage_json == NULL) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cJSON* timeout_json = cJSON_GetObjectItem(delay_stage_json, "timeout");
|
|
|
|
|
+ int timeout = timeout_json != NULL ? (int)cJSON_GetNumberValue(timeout_json) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ WifiMarauderScriptStageDelay *delay_stage = (WifiMarauderScriptStageDelay*) malloc(sizeof(WifiMarauderScriptStageDelay));
|
|
|
|
|
+ delay_stage->timeout = timeout;
|
|
|
|
|
+
|
|
|
|
|
+ return delay_stage;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
WifiMarauderScriptStage* _wifi_marauder_script_create_stage(WifiMarauderScriptStageType type, void* stage_data) {
|
|
WifiMarauderScriptStage* _wifi_marauder_script_create_stage(WifiMarauderScriptStageType type, void* stage_data) {
|
|
|
WifiMarauderScriptStage* stage = (WifiMarauderScriptStage*) malloc(sizeof(WifiMarauderScriptStage));
|
|
WifiMarauderScriptStage* stage = (WifiMarauderScriptStage*) malloc(sizeof(WifiMarauderScriptStage));
|
|
|
stage->type = type;
|
|
stage->type = type;
|
|
@@ -365,6 +393,10 @@ void _wifi_marauder_script_load_stages(WifiMarauderScript *script, cJSON *stages
|
|
|
wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconList, _wifi_marauder_script_get_stage_beacon_list(stages));
|
|
wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconList, _wifi_marauder_script_get_stage_beacon_list(stages));
|
|
|
// Beacon Ap stage
|
|
// Beacon Ap stage
|
|
|
wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconAp, _wifi_marauder_script_get_stage_beacon_ap(stages));
|
|
wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconAp, _wifi_marauder_script_get_stage_beacon_ap(stages));
|
|
|
|
|
+ // Exec stage
|
|
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeExec, _wifi_marauder_script_get_stage_exec(stages));
|
|
|
|
|
+ // Delay stage
|
|
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeDelay, _wifi_marauder_script_get_stage_delay(stages));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
WifiMarauderScript *wifi_marauder_script_parse_raw(const char* json_raw) {
|
|
WifiMarauderScript *wifi_marauder_script_parse_raw(const char* json_raw) {
|
|
@@ -596,6 +628,26 @@ cJSON* _wifi_marauder_script_create_json_beaconap(WifiMarauderScriptStageBeaconA
|
|
|
return stage_json;
|
|
return stage_json;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+cJSON* _wifi_marauder_script_create_json_exec(WifiMarauderScriptStageExec* exec_stage) {
|
|
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
|
|
+ cJSON_AddItemToObject(stage_json, "exec", cJSON_CreateObject());
|
|
|
|
|
+ cJSON* exec_json = cJSON_GetObjectItem(stage_json, "exec");
|
|
|
|
|
+ // Command
|
|
|
|
|
+ cJSON_AddStringToObject(exec_json, "command", exec_stage->command != NULL ? exec_stage->command : "");
|
|
|
|
|
+ return stage_json;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+cJSON* _wifi_marauder_script_create_json_delay(WifiMarauderScriptStageDelay* delay_stage) {
|
|
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
|
|
+ cJSON_AddItemToObject(stage_json, "delay", cJSON_CreateObject());
|
|
|
|
|
+ cJSON* delay_json = cJSON_GetObjectItem(stage_json, "delay");
|
|
|
|
|
+ // Timeout
|
|
|
|
|
+ if (delay_stage->timeout > 0) {
|
|
|
|
|
+ cJSON_AddNumberToObject(delay_json, "timeout", delay_stage->timeout);
|
|
|
|
|
+ }
|
|
|
|
|
+ return stage_json;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void wifi_marauder_script_save_json(Storage* storage, const char* file_path, WifiMarauderScript* script) {
|
|
void wifi_marauder_script_save_json(Storage* storage, const char* file_path, WifiMarauderScript* script) {
|
|
|
File* script_file = storage_file_alloc(storage);
|
|
File* script_file = storage_file_alloc(storage);
|
|
|
|
|
|
|
@@ -676,6 +728,16 @@ void wifi_marauder_script_save_json(Storage* storage, const char* file_path, Wif
|
|
|
stage_json = _wifi_marauder_script_create_json_beaconap(beaconap_stage);
|
|
stage_json = _wifi_marauder_script_create_json_beaconap(beaconap_stage);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ case WifiMarauderScriptStageTypeExec: {
|
|
|
|
|
+ WifiMarauderScriptStageExec* exec_stage = (WifiMarauderScriptStageExec*) stage->stage;
|
|
|
|
|
+ stage_json = _wifi_marauder_script_create_json_exec(exec_stage);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case WifiMarauderScriptStageTypeDelay: {
|
|
|
|
|
+ WifiMarauderScriptStageDelay* delay_stage = (WifiMarauderScriptStageDelay*) stage->stage;
|
|
|
|
|
+ stage_json = _wifi_marauder_script_create_json_delay(delay_stage);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Add the stage JSON object to the "stages" array
|
|
// Add the stage JSON object to the "stages" array
|
|
@@ -764,6 +826,15 @@ void wifi_marauder_script_free(WifiMarauderScript *script) {
|
|
|
case WifiMarauderScriptStageTypeBeaconAp:
|
|
case WifiMarauderScriptStageTypeBeaconAp:
|
|
|
free(current_stage->stage);
|
|
free(current_stage->stage);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case WifiMarauderScriptStageTypeExec:
|
|
|
|
|
+ if (((WifiMarauderScriptStageExec *) current_stage->stage)->command != NULL) {
|
|
|
|
|
+ free(((WifiMarauderScriptStageExec *) current_stage->stage)->command);
|
|
|
|
|
+ }
|
|
|
|
|
+ free(current_stage->stage);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case WifiMarauderScriptStageTypeDelay:
|
|
|
|
|
+ free(current_stage->stage);
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
free(current_stage);
|
|
free(current_stage);
|
|
|
current_stage = next_stage;
|
|
current_stage = next_stage;
|