From 353a90304ee4f71b233fabd021999ffc112aea17 Mon Sep 17 00:00:00 2001 From: AGG2017 Date: Sun, 10 Mar 2024 11:26:38 -0400 Subject: [PATCH] Added 3.1.0 support for modify_mqtt --- RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Max | 4 ++ RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Plus | 4 ++ RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Pro | 4 ++ RESOURCES/OPTIONS/modify_mqtt/modify_mqtt.sh | 46 ++++++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Max create mode 100644 RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Plus create mode 100644 RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Pro diff --git a/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Max b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Max new file mode 100644 index 0000000..afd3af6 --- /dev/null +++ b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Max @@ -0,0 +1,4 @@ +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552876 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552892 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552908 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552924 diff --git a/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Plus b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Plus new file mode 100644 index 0000000..afd3af6 --- /dev/null +++ b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Plus @@ -0,0 +1,4 @@ +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552876 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552892 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552908 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552924 diff --git a/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Pro b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Pro new file mode 100644 index 0000000..54b4799 --- /dev/null +++ b/RESOURCES/OPTIONS/modify_mqtt/3.1.0/K2Pro @@ -0,0 +1,4 @@ +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552804 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552820 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552836 +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@4552852 diff --git a/RESOURCES/OPTIONS/modify_mqtt/modify_mqtt.sh b/RESOURCES/OPTIONS/modify_mqtt/modify_mqtt.sh index 0384a3d..2a3ea66 100755 --- a/RESOURCES/OPTIONS/modify_mqtt/modify_mqtt.sh +++ b/RESOURCES/OPTIONS/modify_mqtt/modify_mqtt.sh @@ -3,6 +3,9 @@ # default urls to be replaced mqtt_urls="mqtt-universe-test.anycubic.com mqtt-universe.anycubic.com mqtt-test.anycubic.com mqtt.anycubic.com" +# server urls to check the message source for app version >= 3.1.0 +mqtt_new_urls="myqcloud.com amazonaws.com anycubic.com anycubicloud.com" + project_root="$1" # check the parameters @@ -16,18 +19,26 @@ def_target="$ROOTFS_DIR/app/app" def_url="$2" # check the required tools -check_tools "printf dd grep awk" +check_tools "printf dd grep awk app_version.sh app_model.sh" # check the project root folder if [ ! -d "$project_root" ]; then echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" - exit 3 + exit 2 fi # check the input file if [ ! -f "$def_target" ]; then echo -e "${RED}ERROR: Cannot find the app file ${NC}" - exit 2 + exit 3 +fi + +# try to find out the app version (like app_ver="309") +def_target="$ROOTFS_DIR/app/app" +app_ver=$("$app_version_tool" "$def_target") +if [ $? != 0 ]; then + echo -e "${RED}ERROR: Cannot find the app version ${NC}" + exit 4 fi # check if the target is original or already patched @@ -47,11 +58,38 @@ for url in $mqtt_urls; do offset=$(grep --binary-files=text -m1 -b -o "$mqtt_url" "$def_target" | awk -F: '{print $1}') if [ -z "$offset" ]; then echo -e "${RED}ERROR: The 'app' might be already patched. Cannot find the expected URL '$mqtt_url' ${NC}" - exit 4 + exit 5 fi printf "mqtts://%s:8883\x00" "$def_url" | dd of="$def_target" bs=1 seek="$offset" conv=notrunc &>>/dev/null done +ver_int=${app_ver//./} +if [ "$ver_int" -ge 310 ]; then + # for version >= 3.1.0 patch the server url check, replace all 4 oem mqtt server urls with + # empty string to trick the check condition + + # try to find out the model + app_model=$("$app_model_tool" "$def_target") + if [ $? != 0 ]; then + echo -e "${RED}ERROR: Cannot find the app model ${NC}" + exit 6 + fi + + # find if the selected setting file exists + settings_file="$OPTIONS_DIR/modify_mqtt/${app_ver}/${app_model}" + if [ ! -f "$settings_file" ]; then + echo -e "${RED}ERROR: Unsupported model and version! Cannot find the settings file '$settings_file' ${NC}" + exit 7 + fi + + # patch the app based on the model and the version + while read -r line; do + settings_data=$(echo -n "$line" | cut -d "@" -f 1) + settings_addr=$(echo -n "$line" | cut -d "@" -f 2) + printf "$settings_data" | dd of="$def_target" bs=1 seek="$settings_addr" conv=notrunc + done <"$settings_file" +fi + echo -e "${GREEN}INFO: The 'app' file has been successfully patched with the custom MQTT URL ${NC}" exit 0