From bf6ee6d02f13803e8d7f9b0ba2a7f59608e199f1 Mon Sep 17 00:00:00 2001 From: Jan Wiesemann Date: Sat, 3 Aug 2024 14:11:02 +0200 Subject: [PATCH] patterns: Added pattern for Flipper Zero settings (#281) * Added pattern for Flipper Zero settings * Added readme entry --------- Co-authored-by: Nik --- README.md | 1 + patterns/flipper_settings.hexpat | 263 ++++++++++++++++++ .../flipper_settings.hexpat/bt.settings | Bin 0 -> 9 bytes .../flipper_settings.hexpat/desktop.settings | Bin 0 -> 1052 bytes .../flipper_settings.hexpat/dolphin.state | Bin 0 -> 40 bytes .../expansion.settings | Bin 0 -> 9 bytes .../flipper_settings.hexpat/infrared.settings | Bin 0 -> 10 bytes .../notification.settings | Bin 0 -> 24 bytes 8 files changed, 264 insertions(+) create mode 100644 patterns/flipper_settings.hexpat create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/bt.settings create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/desktop.settings create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/dolphin.state create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/expansion.settings create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/infrared.settings create mode 100644 tests/patterns/test_data/flipper_settings.hexpat/notification.settings diff --git a/README.md b/README.md index 7a3a952..4a7ae73 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi | FFX | | [`patterns/ffx/*`](https://gitlab.com/EvelynTSMG/imhex-ffx-pats) | Various Final Fantasy X files | | File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System | | FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format | +| Flipper Zero Settings | | [`patterns/flipper_settings.hexpat`](patterns/flipper_settings.hexpat) | Flipper Zero Settings Files | | GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Gameboy ROM | | GGUF | | [`patterns/gguf.hexpat`](patterns/gguf.hexpat) | GGML Inference Models | | GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files | diff --git a/patterns/flipper_settings.hexpat b/patterns/flipper_settings.hexpat new file mode 100644 index 0000000..e8b633f --- /dev/null +++ b/patterns/flipper_settings.hexpat @@ -0,0 +1,263 @@ +/*! + This pattern can be used to parse Flipper Zero settings. + It supports SavedStructure based settings and Notification settings. +*/ + +#pragma author Jan Wiesemann +#pragma description Flipper Zero Settings + +/** + Infrared + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/main/infrared/infrared_app.c#L17 +*/ +#define MAGIC_IR 0x1F +#pragma magic [ 1F ] @ 0x00 + +/** + Expansion/UART + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/expansion/expansion_settings.c#L10 +*/ +#define MAGIC_UART 0xEA +#pragma magic [ EA ] @ 0x00 + +/** + Bluetooth + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/bt/bt_settings.c#L9 +*/ +#define MAGIC_BT 0x19 +#pragma magic [ 19 ] @ 0x00 + +/** + Dolphin + @source https://github.com/DarkFlippers/unleashed-firmware/blob/b2305ce5c7a6ab36babc30243a589eccfa9edcb6/applications/services/dolphin/helpers/dolphin_state.c#L14 +*/ +#define MAGIC_DOLPHIN 0xD0 +#pragma magic [ 0D ] @ 0x00 + +/** + Desktop + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L14 +*/ +#define MAGIC_DEKTOP 0x17 +#pragma magic [ 1/ ] @ 0x00 + +/* ======= Common structures ======= + + Flipper datatype aliases + They are added for easyer translatiom from the Flipper soruce into ImHex +*/ +using int8_t = u8; +using uint8_t = u8; + +using int16_t = u16; +using uint16_t = u16; + +using int32_t = s32; +using uint32_t = u32; + +using int64_t = s64; +using uint64_t = u64; + +/* ======= Common structures ======= */ + +/** + Header for a saved structure file + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/lib/toolbox/saved_struct.c#L14 +*/ +struct SavedStructHeader { + uint8_t magic; + uint8_t version; + uint8_t checksum; //Sum of data-bytes + uint8_t flags; //Not used always 0 + uint32_t timestamp; //Not used alwas 0 +}; + +/* ======= Infrared settings '.infrared.settings' ======= */ + +/* + Lists all avalible outputs for the Infrared appication + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/targets/furi_hal_include/furi_hal_infrared.h#L23 +*/ +enum FuriHalInfraredTxPin : uint8_t { + FuriHalInfraredTxPinInternal, + FuriHalInfraredTxPinExtPA7, + FuriHalInfraredTxPinMax +}; + +/* + Infrared Settings + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/main/infrared/infrared_app.c#L22 +*/ +struct InfraredSettings { + FuriHalInfraredTxPin tx_pin; + bool otg_enabled; +}; + +/* ======= Expansion settings '.expansion.settings' ======= */ + +/** + ??? + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/expansion/expansion_settings.h#L23 +*/ +struct ExpansionSettings { + uint8_t uart_index; +}; + +/* ======= Bluetooth settings '.bt.settings' ======= */ + +/** + Bluetooth Settings + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/bt/bt_settings.h#L14 +*/ +struct BtSettings { + bool enabled; +}; + +/* ======= Dolphin state '.dolphin.state' ======= */ + +/** + Lists all avalible Apps, that grand you points + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/dolphin/helpers/dolphin_deed.h#L18 +*/ +enum DolphinApp : uint16_t { + DolphinAppSubGhz, + DolphinAppRfid, + DolphinAppNfc, + DolphinAppIr, + DolphinAppIbutton, + DolphinAppBadusb, + DolphinAppPlugin, + DolphinAppMAX +}; + +/** + States for the Dolphin + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/dolphin/helpers/dolphin_state.h#L17 +*/ +struct DolphinStoreData{ + uint8_t icounter_daily_limit[DolphinApp::DolphinAppMAX]; + uint8_t butthurt_daily_limit; + uint32_t flags; // Not used always 0 + uint32_t icounter; + int32_t butthurt; + uint64_t timestamp; + padding[4]; +}; + +/* ======= Desktop settings '.dektop.settings' ======= */ + +#define MAX_PIN_SIZE 10 +#define MIN_PIN_SIZE 4 +#define MAX_APP_LENGTH 128 + +/** + Represents a Input Key + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/targets/f7/furi_hal/furi_hal_resources.h#L22 +*/ +enum InputKey : uint8_t{ + InputKeyUp, + InputKeyDown, + InputKeyRight, + InputKeyLeft, + InputKeyOk, + InputKeyBack, + InputKeyMAX, /**< Special value */ +}; + +/** + Stores the Pin-Code + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L58 +*/ +struct PinCode{ + InputKey data[MAX_PIN_SIZE]; + uint8_t length; +}; + +/** + Possible buttons for the Shortcut menu + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L45 +*/ +enum FavoriteAppShortcut : uint32_t { + FavoriteAppLeftShort, + FavoriteAppLeftLong, + FavoriteAppRightShort, + FavoriteAppRightLong, + FavoriteAppNumber +}; +/** + Possible buttons for the Shortcut menu while using the dummy mode + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L53 +*/ +enum DummyAppShortcut : uint32_t{ + DummyAppLeft = 0, + DummyAppRight, + DummyAppDown, + DummyAppOk, + DummyAppNumber, +}; + +/** + Path or Appname for a Shortcut + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L62 +*/ +struct FavoriteApp { + char name_or_path[MAX_APP_LENGTH]; +}; +/** + Settings for the Desktop + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/desktop/desktop_settings.h#L71 +*/ +struct DesktopSettings { + PinCode pin_code; + padding[1]; + uint32_t auto_lock_delay_ms; + uint8_t dummy_mode; + uint8_t display_clock; + FavoriteApp favorite_apps[FavoriteAppShortcut::FavoriteAppNumber]; + FavoriteApp dummy_apps[DummyAppShortcut::DummyAppNumber]; + padding[2]; +}; + +/* ======= Helper======= */ + +/** + Container for SavedStruct based settings +*/ +struct SavedStructure { + SavedStructHeader header; + + match(header.magic, sizeof($) - sizeof(SavedStructHeader)) { + (MAGIC_IR, sizeof(InfraredSettings)): InfraredSettings infraredSettings; + (MAGIC_UART, sizeof(ExpansionSettings)): ExpansionSettings expansionSettings; + (MAGIC_BT, sizeof(BtSettings)): BtSettings btSettings; + (MAGIC_DOLPHIN, sizeof(DolphinStoreData)): DolphinStoreData dolphinStoreData; + (MAGIC_DEKTOP, sizeof(DesktopSettings)): DesktopSettings desktopSettings; + } +}; + +/** + Settings for the LCD and Notifications + @source https://github.com/flipperdevices/flipperzero-firmware/blob/a403e5f543a5423e39ac1700ae4711e9e489445e/applications/services/notification/notification_app.h#L46 +*/ +struct NotificationSettings { + uint8_t version; + padding[3]; + float display_brightness; + float led_brightness; + float speaker_volume; + uint32_t display_off_delay_ms; + int8_t contrast; + bool vibro_on; + padding[2]; +}; + +/** + Wrapper for SavedStructure or Notificaition settings +*/ +struct FlipperSettings { + if(sizeof($) == sizeof(NotificationSettings)) + NotificationSettings notificationSettings; + else + SavedStructure savedStructure; +}; +FlipperSettings flipperSettings @ 0x00; diff --git a/tests/patterns/test_data/flipper_settings.hexpat/bt.settings b/tests/patterns/test_data/flipper_settings.hexpat/bt.settings new file mode 100644 index 0000000000000000000000000000000000000000..6a8f316c9fcdc96fb85921ed060b31c659199017 GIT binary patch literal 9 Ncmb1SU}OLRMgRcv02}}S literal 0 HcmV?d00001 diff --git a/tests/patterns/test_data/flipper_settings.hexpat/desktop.settings b/tests/patterns/test_data/flipper_settings.hexpat/desktop.settings new file mode 100644 index 0000000000000000000000000000000000000000..d60ae2f7a6f01c8f527b9bf6a2ab36f06f0f406e GIT binary patch literal 1052 zcmWgVn$3U?4qRbmU;v_l1)h0nMTteJDFf?@fwNsdwW35nv7n$>-#sxmwOBtLNX8o( Tm{{ngB^C^vvqo(mF(Ci|u8a>@ literal 0 HcmV?d00001 diff --git a/tests/patterns/test_data/flipper_settings.hexpat/dolphin.state b/tests/patterns/test_data/flipper_settings.hexpat/dolphin.state new file mode 100644 index 0000000000000000000000000000000000000000..51ea3f443e20f70080f183811015ec5dc246b178 GIT binary patch literal 40 Wcmcb>$jyKb{vZi>?Oc`y;sO9eVgu*^ literal 0 HcmV?d00001 diff --git a/tests/patterns/test_data/flipper_settings.hexpat/expansion.settings b/tests/patterns/test_data/flipper_settings.hexpat/expansion.settings new file mode 100644 index 0000000000000000000000000000000000000000..a64a0d225500aad51d9c8771ce881a0d8c08aa0f GIT binary patch literal 9 KcmaFG00jUDLjdal literal 0 HcmV?d00001 diff --git a/tests/patterns/test_data/flipper_settings.hexpat/infrared.settings b/tests/patterns/test_data/flipper_settings.hexpat/infrared.settings new file mode 100644 index 0000000000000000000000000000000000000000..00b3d42f7ed2950095090c07f285134384277208 GIT binary patch literal 10 Lcmb1VWPkzy0Z9NM literal 0 HcmV?d00001 diff --git a/tests/patterns/test_data/flipper_settings.hexpat/notification.settings b/tests/patterns/test_data/flipper_settings.hexpat/notification.settings new file mode 100644 index 0000000000000000000000000000000000000000..4fa4d2048b0882d817b2d3119243c059c1d7b1f5 GIT binary patch literal 24 XcmZQ#00Vmlh6XTBcm?D$GB5xDA4&rY literal 0 HcmV?d00001