mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 17:58:36 -07:00
New namespoof implementation
This commit is contained in:
@@ -42,7 +42,7 @@ void xtreme_app_scene_misc_rename_on_enter(void* context) {
|
|||||||
xtreme_app_scene_misc_rename_text_input_callback,
|
xtreme_app_scene_misc_rename_text_input_callback,
|
||||||
app,
|
app,
|
||||||
app->device_name,
|
app->device_name,
|
||||||
NAMECHANGER_TEXT_STORE_SIZE,
|
FURI_HAL_VERSION_ARRAY_NAME_LENGTH,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewTextInput);
|
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewTextInput);
|
||||||
|
|||||||
@@ -69,28 +69,15 @@ bool xtreme_app_apply(XtremeApp* app) {
|
|||||||
|
|
||||||
if(app->save_name) {
|
if(app->save_name) {
|
||||||
if(strcmp(app->device_name, "") == 0) {
|
if(strcmp(app->device_name, "") == 0) {
|
||||||
storage_simply_remove(storage, NAMECHANGER_PATH);
|
storage_simply_remove(storage, NAMESPOOF_PATH);
|
||||||
} else {
|
} else {
|
||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) break;
|
if(!flipper_format_file_open_always(file, NAMESPOOF_PATH)) break;
|
||||||
|
if(!flipper_format_write_header_cstr(file, NAMESPOOF_HEADER, NAMESPOOF_VERSION))
|
||||||
if(!flipper_format_write_header_cstr(file, NAMECHANGER_HEADER, 1)) break;
|
|
||||||
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file, "Changing the value below will change your FlipperZero device name."))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file,
|
|
||||||
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _"))
|
|
||||||
break;
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file, "It cannot contain any other characters."))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break;
|
if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break;
|
||||||
|
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|
||||||
flipper_format_free(file);
|
flipper_format_free(file);
|
||||||
@@ -262,7 +249,7 @@ XtremeApp* xtreme_app_alloc() {
|
|||||||
|
|
||||||
furi_hal_subghz_get_extend_settings(&app->subghz_extend, &app->subghz_bypass);
|
furi_hal_subghz_get_extend_settings(&app->subghz_extend, &app->subghz_bypass);
|
||||||
|
|
||||||
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), NAMECHANGER_TEXT_STORE_SIZE);
|
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||||
|
|
||||||
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
||||||
DolphinStats stats = dolphin_stats(dolphin);
|
DolphinStats stats = dolphin_stats(dolphin);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <gui/modules/popup.h>
|
#include <gui/modules/popup.h>
|
||||||
#include <lib/toolbox/value_index.h>
|
#include <lib/toolbox/value_index.h>
|
||||||
#include <toolbox/stream/file_stream.h>
|
#include <toolbox/stream/file_stream.h>
|
||||||
#include <namechangersrv/namechangersrv.h>
|
|
||||||
#include "scenes/xtreme_app_scene.h"
|
#include "scenes/xtreme_app_scene.h"
|
||||||
#include "dolphin/helpers/dolphin_state.h"
|
#include "dolphin/helpers/dolphin_state.h"
|
||||||
#include "dolphin/dolphin.h"
|
#include "dolphin/dolphin.h"
|
||||||
@@ -23,6 +22,7 @@
|
|||||||
#include <notification/notification_app.h>
|
#include <notification/notification_app.h>
|
||||||
#include <rgb_backlight/rgb_backlight.h>
|
#include <rgb_backlight/rgb_backlight.h>
|
||||||
#include <m-array.h>
|
#include <m-array.h>
|
||||||
|
#include <namespoof.h>
|
||||||
#include <xtreme.h>
|
#include <xtreme.h>
|
||||||
|
|
||||||
#define XTREME_SUBGHZ_FREQ_BUFFER_SIZE 6
|
#define XTREME_SUBGHZ_FREQ_BUFFER_SIZE 6
|
||||||
@@ -52,7 +52,7 @@ typedef struct {
|
|||||||
char subghz_freq_buffer[XTREME_SUBGHZ_FREQ_BUFFER_SIZE];
|
char subghz_freq_buffer[XTREME_SUBGHZ_FREQ_BUFFER_SIZE];
|
||||||
bool subghz_extend;
|
bool subghz_extend;
|
||||||
bool subghz_bypass;
|
bool subghz_bypass;
|
||||||
char device_name[NAMECHANGER_TEXT_STORE_SIZE];
|
char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
|
||||||
int32_t xp_level;
|
int32_t xp_level;
|
||||||
FuriString* version_tag;
|
FuriString* version_tag;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,5 @@ App(
|
|||||||
"loader",
|
"loader",
|
||||||
"power",
|
"power",
|
||||||
"rgb_backlight",
|
"rgb_backlight",
|
||||||
"namechangersrv",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
App(
|
|
||||||
appid="namechangersrv",
|
|
||||||
apptype=FlipperAppType.STARTUP,
|
|
||||||
entry_point="namechanger_on_system_start",
|
|
||||||
requires=["storage"],
|
|
||||||
order=1000,
|
|
||||||
)
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
#include "namechangersrv.h"
|
|
||||||
#include "m-string.h"
|
|
||||||
#include <toolbox/path.h>
|
|
||||||
#include <flipper_format/flipper_format.h>
|
|
||||||
|
|
||||||
void namechanger_on_system_start() {
|
|
||||||
if(!furi_hal_is_normal_boot()) {
|
|
||||||
FURI_LOG_W(TAG, "NameChangerSRV load skipped. Device is in special startup mode.");
|
|
||||||
} else {
|
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
||||||
|
|
||||||
FuriString* NAMEHEADER;
|
|
||||||
NAMEHEADER = furi_string_alloc_set("Flipper Name File");
|
|
||||||
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
FuriString* data;
|
|
||||||
data = furi_string_alloc();
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(!flipper_format_file_open_existing(file, NAMECHANGER_PATH)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// header
|
|
||||||
uint32_t version;
|
|
||||||
|
|
||||||
if(!flipper_format_read_header(file, data, &version)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(furi_string_cmp_str(data, furi_string_get_cstr(NAMEHEADER)) != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(version != 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get Name
|
|
||||||
if(!flipper_format_read_string(file, "Name", data)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
} while(false);
|
|
||||||
|
|
||||||
flipper_format_free(file);
|
|
||||||
|
|
||||||
if(!result) {
|
|
||||||
//file not good - write new one
|
|
||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
||||||
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
do {
|
|
||||||
// Open file for write
|
|
||||||
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write header
|
|
||||||
if(!flipper_format_write_header_cstr(file, furi_string_get_cstr(NAMEHEADER), 1)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write comments
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file,
|
|
||||||
"Changing the value below will change your FlipperZero device name.")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file,
|
|
||||||
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file, "It can contain other characters but use at your own risk.")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Write name
|
|
||||||
if(!flipper_format_write_string_cstr(
|
|
||||||
file, "Name", furi_hal_version_get_name_ptr())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = true;
|
|
||||||
} while(false);
|
|
||||||
|
|
||||||
flipper_format_free(file);
|
|
||||||
|
|
||||||
if(!res) {
|
|
||||||
FURI_LOG_E(TAG, "Save failed.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(!furi_string_size(data)) {
|
|
||||||
//Empty file - get default name and write to file.
|
|
||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
||||||
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
do {
|
|
||||||
// Open file for write
|
|
||||||
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write header
|
|
||||||
if(!flipper_format_write_header_cstr(
|
|
||||||
file, furi_string_get_cstr(NAMEHEADER), 1)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write comments
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file,
|
|
||||||
"Changing the value below will change your FlipperZero device name.")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file,
|
|
||||||
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!flipper_format_write_comment_cstr(
|
|
||||||
file, "It cannot contain any other characters.")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Write name
|
|
||||||
if(!flipper_format_write_string_cstr(
|
|
||||||
file, "Name", furi_hal_version_get_name_ptr())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = true;
|
|
||||||
} while(false);
|
|
||||||
|
|
||||||
flipper_format_free(file);
|
|
||||||
|
|
||||||
if(!res) {
|
|
||||||
FURI_LOG_E(TAG, "Save failed.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
char newdata[9];
|
|
||||||
snprintf(newdata, 9, "%s", furi_string_get_cstr(data));
|
|
||||||
//set name from file
|
|
||||||
furi_hal_version_set_custom_name(newdata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
furi_string_free(data);
|
|
||||||
|
|
||||||
furi_record_close(RECORD_STORAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <furi_hal.h>
|
|
||||||
#include <storage/storage.h>
|
|
||||||
|
|
||||||
#define NAMECHANGER_TEXT_STORE_SIZE 9
|
|
||||||
#define NAMECHANGER_HEADER "Flipper Name File"
|
|
||||||
#define NAMECHANGER_PATH EXT_PATH("dolphin/name.txt")
|
|
||||||
|
|
||||||
#define TAG "NameChangerSRV"
|
|
||||||
@@ -1535,7 +1535,7 @@ Function,+,furi_hal_version_get_model_name,const char*,
|
|||||||
Function,+,furi_hal_version_get_name_ptr,const char*,
|
Function,+,furi_hal_version_get_name_ptr,const char*,
|
||||||
Function,+,furi_hal_version_get_otp_version,FuriHalVersionOtpVersion,
|
Function,+,furi_hal_version_get_otp_version,FuriHalVersionOtpVersion,
|
||||||
Function,-,furi_hal_version_init,void,
|
Function,-,furi_hal_version_init,void,
|
||||||
Function,+,furi_hal_version_set_custom_name,void,const char*
|
Function,-,furi_hal_version_set_name,void,const char*
|
||||||
Function,+,furi_hal_version_uid,const uint8_t*,
|
Function,+,furi_hal_version_uid,const uint8_t*,
|
||||||
Function,+,furi_hal_version_uid_size,size_t,
|
Function,+,furi_hal_version_uid_size,size_t,
|
||||||
Function,-,furi_hal_vibro_init,void,
|
Function,-,furi_hal_vibro_init,void,
|
||||||
|
|||||||
|
@@ -90,26 +90,13 @@ typedef struct {
|
|||||||
|
|
||||||
static FuriHalVersion furi_hal_version = {0};
|
static FuriHalVersion furi_hal_version = {0};
|
||||||
|
|
||||||
void furi_hal_version_set_custom_name(const char* name) {
|
void furi_hal_version_set_name(const char* name) {
|
||||||
if((name != NULL) && ((strlen(name) >= 1) && (strlen(name) <= 8))) {
|
if(name != NULL && strlen(name)) {
|
||||||
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||||
snprintf(
|
snprintf(
|
||||||
furi_hal_version.device_name,
|
furi_hal_version.device_name,
|
||||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||||
"x%s", // Someone tell me why that X is needed
|
"x%s", // Someone tell me why that X is needed - it's for BLE adv name type (6 lines below)
|
||||||
name);
|
|
||||||
|
|
||||||
furi_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void furi_hal_version_set_name(const char* name) {
|
|
||||||
if(name != NULL) {
|
|
||||||
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
|
||||||
snprintf(
|
|
||||||
furi_hal_version.device_name,
|
|
||||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
|
||||||
"x%s", // Someone tell me why that X is needed
|
|
||||||
furi_hal_version.name);
|
furi_hal_version.name);
|
||||||
} else {
|
} else {
|
||||||
snprintf(furi_hal_version.device_name, FURI_HAL_VERSION_DEVICE_NAME_LENGTH, "xFlipper");
|
snprintf(furi_hal_version.device_name, FURI_HAL_VERSION_DEVICE_NAME_LENGTH, "xFlipper");
|
||||||
@@ -119,8 +106,8 @@ static void furi_hal_version_set_name(const char* name) {
|
|||||||
|
|
||||||
// BLE Mac address
|
// BLE Mac address
|
||||||
uint32_t udn = LL_FLASH_GetUDN();
|
uint32_t udn = LL_FLASH_GetUDN();
|
||||||
if(version_get_custom_name(NULL) != NULL) {
|
if(name != NULL) {
|
||||||
udn = *((uint32_t*)version_get_custom_name(NULL));
|
udn = *((uint32_t*)name);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ FuriHalVersionDisplay furi_hal_version_get_hw_display();
|
|||||||
uint32_t furi_hal_version_get_hw_timestamp();
|
uint32_t furi_hal_version_get_hw_timestamp();
|
||||||
|
|
||||||
// Set custom name
|
// Set custom name
|
||||||
void furi_hal_version_set_custom_name(const char* name);
|
void furi_hal_version_set_name(const char* name);
|
||||||
|
|
||||||
/** Get pointer to target name
|
/** Get pointer to target name
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ void flipper_start_service(const FlipperApplication* service) {
|
|||||||
|
|
||||||
FuriThread* thread =
|
FuriThread* thread =
|
||||||
furi_thread_alloc_ex(service->name, service->stack_size, service->app, NULL);
|
furi_thread_alloc_ex(service->name, service->stack_size, service->app, NULL);
|
||||||
furi_thread_mark_as_service(thread);
|
furi_thread_mark_as_service(thread);
|
||||||
furi_thread_set_appid(thread, service->appid);
|
furi_thread_set_appid(thread, service->appid);
|
||||||
|
|
||||||
furi_thread_start(thread);
|
furi_thread_start(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flipper_init() {
|
void flipper_init() {
|
||||||
flipper_print_version("Firmware", furi_hal_version_get_firmware_version());
|
flipper_print_version("Firmware", furi_hal_version_get_firmware_version());
|
||||||
@@ -47,6 +47,7 @@ void flipper_init() {
|
|||||||
// Start storage service first, thanks OFW :/
|
// Start storage service first, thanks OFW :/
|
||||||
flipper_start_service(&FLIPPER_SERVICES[0]);
|
flipper_start_service(&FLIPPER_SERVICES[0]);
|
||||||
|
|
||||||
|
NAMESPOOF_INIT();
|
||||||
XTREME_SETTINGS_LOAD();
|
XTREME_SETTINGS_LOAD();
|
||||||
XTREME_ASSETS_LOAD();
|
XTREME_ASSETS_LOAD();
|
||||||
|
|
||||||
|
|||||||
26
lib/xtreme/namespoof.c
Normal file
26
lib/xtreme/namespoof.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "namespoof.h"
|
||||||
|
#include <furi_hal.h>
|
||||||
|
#include <flipper_format/flipper_format.h>
|
||||||
|
|
||||||
|
#define TAG "NameSpoof"
|
||||||
|
|
||||||
|
void NAMESPOOF_INIT() {
|
||||||
|
FuriString* str = furi_string_alloc();
|
||||||
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
|
|
||||||
|
do {
|
||||||
|
uint32_t version;
|
||||||
|
if(!flipper_format_file_open_existing(file, NAMESPOOF_PATH)) break;
|
||||||
|
if(!flipper_format_read_header(file, str, &version)) break;
|
||||||
|
if(furi_string_cmp_str(str, NAMESPOOF_HEADER)) break;
|
||||||
|
if(version != NAMESPOOF_VERSION) break;
|
||||||
|
|
||||||
|
if(!flipper_format_read_string(file, "Name", str)) break;
|
||||||
|
furi_hal_version_set_name(furi_string_get_cstr(str));
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
flipper_format_free(file);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
furi_string_free(str);
|
||||||
|
}
|
||||||
5
lib/xtreme/namespoof.h
Normal file
5
lib/xtreme/namespoof.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define NAMESPOOF_HEADER "Flipper Name File"
|
||||||
|
#define NAMESPOOF_VERSION 1
|
||||||
|
#define NAMESPOOF_PATH EXT_PATH("dolphin/name.txt")
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
void NAMESPOOF_INIT();
|
||||||
void XTREME_SETTINGS_LOAD();
|
void XTREME_SETTINGS_LOAD();
|
||||||
void XTREME_ASSETS_LOAD();
|
void XTREME_ASSETS_LOAD();
|
||||||
|
|||||||
Reference in New Issue
Block a user