+ if (strchr(filename, '\\') || strchr(filename, '/')) {
+ PrintAndLogEx(FAILED, "Filename must not contain \\ or /. Firmware file will be found in client/sc_upgrade_firmware directory.");
+ return 1;
+ }
+
+ char sc_upgrade_file_path[strlen(get_my_executable_directory()) + strlen(SC_UPGRADE_FILES_DIRECTORY) + strlen(filename) + 1];
+ strcpy(sc_upgrade_file_path, get_my_executable_directory());
+ strcat(sc_upgrade_file_path, SC_UPGRADE_FILES_DIRECTORY);
+ strcat(sc_upgrade_file_path, filename);
+ if (strlen(sc_upgrade_file_path) >= FILE_PATH_SIZE ) {
+ PrintAndLogEx(FAILED, "Filename too long");
+ return 1;
+ }
+
+ char sha512filename[FILE_PATH_SIZE];
+ char *bin_extension = filename;
+ char *dot_position = NULL;
+ while ((dot_position = strchr(bin_extension, '.')) != NULL) {
+ bin_extension = dot_position + 1;
+ }
+ if (!strcmp(bin_extension, "BIN")
+#ifdef _WIN32
+ || !strcmp(bin_extension, "bin")
+#endif
+ ) {
+ strncpy(sha512filename, filename, strlen(filename) - strlen("bin"));
+ strcat(sha512filename, "sha512.txt");
+ } else {
+ PrintAndLogEx(FAILED, "Filename extension of Firmware Upgrade File must be .BIN");
+ return 1;
+ }
+
+ PrintAndLogEx(INFO, "Checking integrity using SHA512 File %s ...", sha512filename);
+ char sc_upgrade_sha512file_path[strlen(get_my_executable_directory()) + strlen(SC_UPGRADE_FILES_DIRECTORY) + strlen(sha512filename) + 1];
+ strcpy(sc_upgrade_sha512file_path, get_my_executable_directory());
+ strcat(sc_upgrade_sha512file_path, SC_UPGRADE_FILES_DIRECTORY);
+ strcat(sc_upgrade_sha512file_path, sha512filename);
+ if (strlen(sc_upgrade_sha512file_path) >= FILE_PATH_SIZE ) {
+ PrintAndLogEx(FAILED, "Filename too long");
+ return 1;
+ }
+
+ // load firmware file
+ f = fopen(sc_upgrade_file_path, "rb");