ソースを参照

Adjusted the script's select stage to allow applying filters

tcpassos 2 年 前
コミット
dcda917277

+ 26 - 1
applications/external/wifi_marauder_companion/script/wifi_marauder_script.c

@@ -89,6 +89,8 @@ WifiMarauderScriptStageSelect* _wifi_marauder_script_get_stage_select(cJSON *sta
 
     cJSON *type_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "type");
     cJSON *filter_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "filter");
+    cJSON *indexes_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "indexes");
+    cJSON *index_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "index");
     cJSON *allow_repeat_json = cJSON_GetObjectItemCaseSensitive(select_stage_json, "allow_repeat");
 
     if (!cJSON_IsString(type_json) || !cJSON_IsString(filter_json)) {
@@ -113,6 +115,24 @@ WifiMarauderScriptStageSelect* _wifi_marauder_script_get_stage_select(cJSON *sta
     stage_select->filter = filter_str;
     stage_select->allow_repeat = cJSON_IsBool(allow_repeat_json) ? allow_repeat_json->valueint : true;
 
+    if (cJSON_IsNumber(index_json)) {
+        int* indexes = (int*) malloc(sizeof(int));
+        indexes[0] = index_json->valueint;
+        stage_select->indexes = indexes;
+    } else if (cJSON_IsArray(indexes_json)) {
+        int indexes_size = cJSON_GetArraySize(indexes_json);
+        int* indexes = (int*) malloc(indexes_size * sizeof(int));
+        for (int i = 0; i < indexes_size; i++) {
+            cJSON *index_item = cJSON_GetArrayItem(indexes_json, i);
+            if (cJSON_IsNumber(index_item)) {
+                indexes[i] = index_item->valueint;
+            }
+        }
+        stage_select->indexes = indexes;
+    } else {
+        stage_select->indexes = NULL;
+    }
+
     return stage_select;
 }
 
@@ -512,7 +532,12 @@ void wifi_marauder_script_free(WifiMarauderScript *script) {
                 free(current_stage->stage);
                 break;
             case WifiMarauderScriptStageTypeSelect:
-                free(((WifiMarauderScriptStageSelect *) current_stage->stage)->filter);
+                if (((WifiMarauderScriptStageSelect *) current_stage->stage)->filter != NULL) {
+                    free(((WifiMarauderScriptStageSelect *) current_stage->stage)->filter);
+                }
+                if (((WifiMarauderScriptStageSelect *) current_stage->stage)->indexes != NULL) {
+                    free(((WifiMarauderScriptStageSelect *) current_stage->stage)->indexes);
+                }
                 free(current_stage->stage);
                 break;
             case WifiMarauderScriptStageTypeDeauth:

+ 4 - 1
applications/external/wifi_marauder_companion/script/wifi_marauder_script.h

@@ -47,7 +47,9 @@
  *         },
  *         "select": {
  *             "type": "ap" | "station" | "ssid",
- *             "filter": "all" | "contains \"{SSID fragment}\" or equals \"{SSID}\" or ..." (Not implemented yet on Marauder firmware)
+ *             "filter": "all" | "contains -f '{SSID fragment}' or equals '{SSID}' or ...",
+ *             "index": index number,
+ *             "indexes": [0, 1, 2, 3...],
  *         },
  *         "deauth": {
  *             "timeout": seconds
@@ -139,6 +141,7 @@ typedef struct WifiMarauderScriptStageScan {
 typedef struct WifiMarauderScriptStageSelect {
     WifiMarauderScriptSelectType type;
     char* filter;
+    int* indexes;
     // TODO: Implement a feature to not select the same items in the next iteration of the script
     bool allow_repeat;
 } WifiMarauderScriptStageSelect;

+ 17 - 4
applications/external/wifi_marauder_companion/script/wifi_marauder_script_executor.c

@@ -56,13 +56,26 @@ void _wifi_marauder_script_execute_select(WifiMarauderScriptStageSelect* stage)
     }
 
     char command[256];
-    if (strcmp(stage->filter, "all") == 0) {
-        snprintf(command, sizeof(command), "select %s all\n", select_type);
+    size_t command_length = 0;
+
+    if (stage->indexes != NULL) {
+        command_length = snprintf(command, sizeof(command), "select %s ", select_type);
+
+        for (int i = 0; stage->indexes[i] != -1; i++) {
+            int index = stage->indexes[i];
+            command_length += snprintf(command + command_length, sizeof(command) - command_length, "%d, ", index);
+        }
+
+        // Remove the trailing comma and space
+        command_length -= 2;
+        command[command_length] = '\n';
+        command_length++;
+    } else if (stage->filter == NULL || strcmp(stage->filter, "all") == 0) {
+        command_length = snprintf(command, sizeof(command), "select %s all\n", select_type);
     } else {
-        snprintf(command, sizeof(command), "select %s {%s}\n", select_type, stage->filter);
+        command_length = snprintf(command, sizeof(command), "select %s -f \"%s\"\n", select_type, stage->filter);
     }
 
-    const size_t command_length = strlen(command);
     wifi_marauder_uart_tx((uint8_t*)command, command_length);
 }