1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-13 13:09:49 +04:00

Compare commits

..

1 Commits

Author SHA1 Message Date
MX
fc6adcbeb1 WIP - Implement header(preambula) lookup
Bits = unknown
0 = unknown
1 = unknown
2023-02-15 00:42:28 +03:00
1642 changed files with 10136 additions and 23759 deletions

View File

@@ -36,6 +36,13 @@ Min level: 1
Max level: 1
Weight: 3
Name: L1_Happy_holidays_128x64
Min butthurt: 0
Max butthurt: 14
Min level: 1
Max level: 3
Weight: 4
Name: L1_Read_books_128x64
Min butthurt: 0
Max butthurt: 8
@@ -134,9 +141,9 @@ Min level: 3
Max level: 3
Weight: 3
Name: L1_Senpai_128x64
Name: L1_Sleigh_ride_128x64
Min butthurt: 0
Max butthurt: 5
Max butthurt: 14
Min level: 1
Max level: 3
Weight: 4

View File

@@ -192,16 +192,13 @@ steps:
Version: {{build.tag}}
[-> Sponsor our project](https://boosty.to/mmxdev)
[-Github - Changelog-](https://github.com/DarkFlippers/unleashed-firmware/releases/tag/${DRONE_TAG})
[-How to install firmware-](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/HowToInstall.md)
[-Download latest extra apps pack-](https://github.com/xMasterX/unleashed-extra-pack/archive/refs/heads/main.zip)
[-Download latest extra apps pack-](https://download-directory.github.io/?url=https://github.com/xMasterX/unleashed-extra-pack/tree/main/apps)
[-Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw/${DRONE_TAG}/flipper-z-f7-update-${DRONE_TAG}.tgz&channel=release-cfw&version=${DRONE_TAG})
@@ -223,7 +220,7 @@ steps:
commands:
- wget "https://raw.githubusercontent.com/fieu/discord.sh/e1dc1a7595efad2cad8f072f0b3531c470f5b7c8/discord.sh"
- chmod +x ./discord.sh
- ./discord.sh --text 'New Unleashed firmware released!\n\nVersion - '${DRONE_TAG}'\n\n[-> Sponsor our project](https://boosty.to/mmxdev)\n\n[[Github - Changelog]](https://github.com/DarkFlippers/unleashed-firmware/releases/tag/'${DRONE_TAG}')\n\n[-How to install firmware-](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/HowToInstall.md)\n\n[-Download latest extra apps pack-](https://github.com/xMasterX/unleashed-extra-pack/archive/refs/heads/main.zip)\n\n[-Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw/'${DRONE_TAG}'/flipper-z-f7-update-'${DRONE_TAG}'.tgz&channel=release-cfw&version='${DRONE_TAG}')\n\n[-Version without custom animations - Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_no_anim/flipper-z-f7-update-'${DRONE_TAG}'n.tgz&channel=release-cfw&version='${DRONE_TAG}'n)\n\n[-Version with extra apps - Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_extra_apps/flipper-z-f7-update-'${DRONE_TAG}'e.tgz&channel=release-cfw&version='${DRONE_TAG}'e)'
- ./discord.sh --text 'New Unleashed firmware released!\n\nVersion - '${DRONE_TAG}'\n\n[[Github - Changelog]](https://github.com/DarkFlippers/unleashed-firmware/releases/tag/'${DRONE_TAG}')\n\n[-How to install firmware-](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/HowToInstall.md)\n\n[-Download latest extra apps pack-](https://download-directory.github.io/?url=https://github.com/xMasterX/unleashed-extra-pack/tree/main/apps)\n\n[-Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw/'${DRONE_TAG}'/flipper-z-f7-update-'${DRONE_TAG}'.tgz&channel=release-cfw&version='${DRONE_TAG}')\n\n[-Version without custom animations - Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_no_anim/flipper-z-f7-update-'${DRONE_TAG}'n.tgz&channel=release-cfw&version='${DRONE_TAG}'n)\n\n[-Version with extra apps - Install FW via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_extra_apps/flipper-z-f7-update-'${DRONE_TAG}'e.tgz&channel=release-cfw&version='${DRONE_TAG}'e)'
- name: "Send extra pack build to telegram"
image: appleboy/drone-telegram
@@ -388,9 +385,6 @@ steps:
Commit: {{commit.message}}
[-> Sponsor our project](https://boosty.to/mmxdev)
[-Version with extra apps - Install via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_extra_apps/flipper-z-f7-update-${DRONE_BUILD_NUMBER}e.tgz&channel=dev-cfw&version=${DRONE_BUILD_NUMBER}e)
@@ -419,7 +413,7 @@ steps:
commands:
- wget "https://raw.githubusercontent.com/fieu/discord.sh/e1dc1a7595efad2cad8f072f0b3531c470f5b7c8/discord.sh"
- chmod +x ./discord.sh
- ./discord.sh --text 'Unleashed firmware dev build successful!\n\nBuild - '${DRONE_BUILD_NUMBER}'\n\nSHA - '${DRONE_COMMIT_SHA}'\n\n[-> Sponsor our project](https://boosty.to/mmxdev)\n\n[-Version with extra apps - Install via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_extra_apps/flipper-z-f7-update-'${DRONE_BUILD_NUMBER}'e.tgz&channel=dev-cfw&version='${DRONE_BUILD_NUMBER}'e)\n\n[-Install via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw/dev/flipper-z-f7-update-'${DRONE_BUILD_NUMBER}'.tgz&channel=dev-cfw&version='${DRONE_BUILD_NUMBER}')'
- ./discord.sh --text 'Unleashed firmware dev build successful!\n\nBuild - '${DRONE_BUILD_NUMBER}'\n\nSHA - '${DRONE_COMMIT_SHA}'\n\n[-Version with extra apps - Install via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw_extra_apps/flipper-z-f7-update-'${DRONE_BUILD_NUMBER}'e.tgz&channel=dev-cfw&version='${DRONE_BUILD_NUMBER}'e)\n\n[-Install via Web Updater-](https://lab.flipper.net/?url=https://unleashedflip.com/fw/dev/flipper-z-f7-update-'${DRONE_BUILD_NUMBER}'.tgz&channel=dev-cfw&version='${DRONE_BUILD_NUMBER}')'
trigger:
branch:

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
*~
*.swp
*.swo
*.gdb_history

10
.gitmodules vendored
View File

@@ -28,9 +28,9 @@
[submodule "lib/cxxheaderparser"]
path = lib/cxxheaderparser
url = https://github.com/robotpy/cxxheaderparser.git
[submodule "applications/external/dap_link/lib/free-dap"]
path = applications/external/dap_link/lib/free-dap
[submodule "applications/plugins/subbrute"]
path = applications/plugins/subbrute
url = https://github.com/derskythe/flipperzero-subbrute.git
[submodule "applications/plugins/dap_link/lib/free-dap"]
path = applications/plugins/dap_link/lib/free-dap
url = https://github.com/ataradov/free-dap.git
[submodule "applications/external/subbrute"]
path = applications/external/subbrute
url = https://github.com/derskythe/flipperzero-subbrute.git

View File

@@ -44,6 +44,3 @@
# Functions that always return the same error code
//-V:picopass_device_decrypt:1048
# Examples
//V_EXCLUDE_PATH applications/examples/

View File

@@ -1 +1 @@
--ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/micro-ecc -e lib/microtar -e lib/mlib -e lib/qrcode -e lib/ST25RFAL002 -e lib/STM32CubeWB -e lib/u8g2 -e lib/nanopb -e */arm-none-eabi/* -e applications/external/dap_link/lib/free-dap
--ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/micro-ecc -e lib/microtar -e lib/mlib -e lib/qrcode -e lib/ST25RFAL002 -e lib/STM32CubeWB -e lib/u8g2 -e lib/nanopb -e */arm-none-eabi/* -e applications/plugins/dap_link/lib/free-dap

View File

@@ -11,10 +11,9 @@
"args": {
"useSingleResult": true,
"env": {
"PATH": "${workspaceFolder};${env:PATH}",
"FBT_QUIET": 1
"PATH": "${workspaceFolder};${env:PATH}"
},
"command": "fbt get_blackmagic",
"command": "./fbt get_blackmagic",
"description": "Get Blackmagic device",
}
}

View File

@@ -1,20 +1,21 @@
### New changes
* iButton: Add support for DS1420 (not fully tested)
* Desktop: Option to set Tertiary favourite app (Hold right arrow on desktop) - **Desktop settings (pin code, favourite app, autolock time) will be resetted!!! Only one time after installing - due to changes in settings structure, after installing of this release desktop settings will not be reset with next release**
* Desktop: Ability to disable favourite app (use last element in a main list `None (disable)`)
* Desktop: Fix issue #387 (Ok button was showing invalid file error in dummy mode)
* OFW PR: SD Driver: reinit sd card on error (by DrZlo13 | OFW PR 2493)
* OFW PR: iButton -> Fix a typo: use right shift instead of greater than (by gsurkov | OFW PR 2506)
* OFW: Optimize trailing slash check
* SubGHz: **Nice ON2E (Nice One)** support (by @assasinfil | PR #335)
* SubGHz: Remove 467.75 From freq analyzer since it has too much noise (Frequency is still can be used, just excluded from FA to avoid false detections)
* Archive and FileBrowser: **Fixed more navigation issues** (by @Willy-JL | PR #334)
* Plugins -> SubGHz Bruteforcer: Fix Linear Delta 3 repeats (now its more stable and we will be sure signal is received correctly)
* Plugins: Updated TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator)
* OFW: **Fix Cyfral & Metakom emulation (My temp fix removed and proper fix from OFW applied)**
* OFW: BadUSB: disable CDC mode, USB mode switch fix
* OFW: Updater visual fixes
#### [🎲 Download latest extra apps pack](https://github.com/xMasterX/unleashed-extra-pack/archive/refs/heads/main.zip)
#### [🎲 Download latest extra apps pack](https://download-directory.github.io/?url=https://github.com/xMasterX/unleashed-extra-pack/tree/main/apps)
[-> How to install firmware](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/HowToInstall.md)
[-> Download qFlipper (official link)](https://flipperzero.one/update)
## Please support development of the project
* **Boosty** (patreon alternative): https://boosty.to/mmxdev
* Boosty: https://boosty.to/mmxdev
* Ko-Fi: https://ko-fi.com/masterx
* cloudtips (only RU payments accepted): https://pay.cloudtips.ru/p/7b3e9d65
* YooMoney (only RU payments accepted): https://yoomoney.ru/fundraise/XA49mgQLPA0.221209

View File

@@ -12,6 +12,8 @@
Our goal is to make all features possible on this device without any limitations!
Please help us implement emulation for all Sub-GHz dynamic (rolling code) protocols!
<br>
### This software is for experimental purposes only and is not meant for any illegal activity/purposes. <br> We do not condone illegal activity and strongly encourage keeping transmissions to legal/valid uses allowed by law. <br> Also, this software is made without any support from Flipper Devices and is in no way related to the official devs.
@@ -25,7 +27,7 @@ Our Discord Community:
<br>
<br>
## Dev builds (unstable)
## Dev builds
- https://dev.unleashedflip.com/
- https://t.me/kotnehleb
## Releases in Telegram
@@ -35,7 +37,7 @@ Our Discord Community:
* Sub-GHz regional TX restrictions removed
* Sub-GHz frequency range can be extended in settings file (Warning: It can damage Flipper's hardware)
* Many rolling code protocols now have the ability to save & send captured signals
* FAAC SLH (Spa) & BFT Mitto (keeloq secure with seed) manual creation
* FAAC SLH (Spa) & BFT Mitto (secure with seed) manual creation
* Sub-GHz static code brute-force plugin
* LFRFID Fuzzer plugin
* Custom community plugins and games added + all known working apps can be downloaded in extra pack in every release
@@ -43,31 +45,18 @@ Our Discord Community:
* Picopass/iClass plugin included in releases
* Recompiled IR TV Universal Remote for ALL buttons
* Universal remote for Projectors, Fans, A/Cs and Audio(soundbars, etc.)
* BadUSB keyboard layouts
* Customizable Flipper name
- BadUSB -> Keyboard layouts [(by rien > dummy-decoy)](https://github.com/dummy-decoy/flipperzero-firmware/tree/dummy_decoy/bad_usb_keyboard_layout)
- Sub-GHz -> External CC1101 module support - [(by quen0n)](https://github.com/DarkFlippers/unleashed-firmware/pull/307)
- Sub-GHz -> `Add manually` menu extended with new protocols
- Sub-GHz -> New frequency analyzer - [(by ClusterM)](https://github.com/DarkFlippers/unleashed-firmware/pull/43)
- Sub-GHz -> Save last used frequency [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/77)
- Sub-GHz -> Press OK in frequency analyzer to use detected frequency in Read modes [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/77)
- Sub-GHz -> Long press OK button in Sub-GHz Frequency analyzer to switch to Read menu [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/79)
- Lock device with pin(or regular lock if pin not set) by holding UP button on main screen [(by an4tur0r)](https://github.com/DarkFlippers/unleashed-firmware/pull/107)
* Sub-GHz -> Press OK in frequency analyzer to use detected frequency in Read modes
* Sub-GHz -> Long press OK button in Sub-GHz Frequency analyzer to switch to Read menu
* Sub-GHz -> External CC1101 module support
* SubGHz -> **Hold right in received signal list to delete selected signal**
* SubGHz -> **Custom buttons for Keeloq / Alutech AT4N / Nice Flor S / Somfy Telis / Security+ 2.0** - now you can use arrow buttons to send signal with different button code
* SubGHz -> BFT Mitto / Somfy Telis / Nice Flor S manual creation with programming new remote into receiver (use button 0xF for BFT Mitto, 0x8 (Prog) on Somfy Telis)
* SubGHz -> Debug mode counter increase settings (+1 -> +5, +10, default: +1)
* SubGHz -> Debug PIN output settings for protocol development
* Infrared -> Debug TX PIN output settings
* Other small fixes and changes throughout
* See other changes in readme below
* See other changes in changelog and in readme below
Also check the changelog in releases for latest updates!
### Current modified and new Sub-GHz protocols list:
Thanks to Official team (to their SubGHz Developer, Skorp) for implementing decoders for these protocols.
Thanks to Official team (to thier SubGHz Developer, Skorp) for implementing decoders for these protocols.
Encoders/sending made by Eng1n33r & @xMasterX:
@@ -81,13 +70,10 @@ Encoders/sending made by Eng1n33r & @xMasterX:
- Keeloq: FAAC RC,XT
- Keeloq: Mutancode
- Keeloq: Normstahl
- Keeloq: Beninca
- Keeloq: Stilmatic / Schellenberg
- Keeloq: CAME Space
- CAME Atomo
- Nice Flor S
- FAAC SLH (Spa) [External seed calculation required (For info contact me in Discord: Nano#8998)]
- Keeloq: BFT Mitto [External seed calculation required (For info contact me in Discord: Nano#8998)]
- BFT Mitto [External seed calculation required (For info contact me in Discord: Nano#8998)]
- Security+ v1 & v2
- Star Line
@@ -111,7 +97,7 @@ Our team is small and the guys are working on this project as much as they can s
The amount of work done on this project is huge and we need your support, no matter how large or small. Even if you just say, "Thank you Unleashed firmware developers!" somewhere. Doing so will help us continue our work and will help drive us to make the firmware better every time.
Also, regarding our releases, every build has and always will be free and open-source. There will be no paywall releases or closed-source apps within the firmware. As long as I am working on this project it will never happen.
You can support us by using links or addresses below:
* **Boosty** (patreon alternative): https://boosty.to/mmxdev
* Boosty: https://boosty.to/mmxdev
* Ko-Fi: https://ko-fi.com/masterx
* cloudtips (only RU payments accepted): https://pay.cloudtips.ru/p/7b3e9d65
* YooMoney (only RU payments accepted): https://yoomoney.ru/fundraise/XA49mgQLPA0.221209
@@ -132,10 +118,11 @@ You can support us by using links or addresses below:
- ESP8266 Deauther plugin [(by SequoiaSan)](https://github.com/SequoiaSan/FlipperZero-Wifi-ESP8266-Deauther-Module)
- WiFi Scanner plugin [(by SequoiaSan)](https://github.com/SequoiaSan/FlipperZero-WiFi-Scanner_Module)
- MultiConverter plugin [(by theisolinearchip)](https://github.com/theisolinearchip/flipperzero_stuff)
- USB Keyboard plugin [(by huuck)](https://github.com/huuck/FlipperZeroUSBKeyboard)
- WAV Player [(OFW: DrZlo13)](https://github.com/flipperdevices/flipperzero-firmware/tree/zlo/wav-player) - Fixed and improved by [LTVA1](https://github.com/LTVA1/wav_player)
- Barcode generator plugin [(original by McAzzaMan)](https://github.com/McAzzaMan/flipperzero-firmware/tree/UPC-A_Barcode_Generator/applications/barcode_generator) - [EAN-8 and refactoring](https://github.com/DarkFlippers/unleashed-firmware/pull/154) by @msvsergey
- GPIO: Sentry Safe plugin [(by H4ckd4ddy)](https://github.com/H4ckd4ddy/flipperzero-sentry-safe-plugin)
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) - Saving .pcap on flipper microSD [by tcpassos](https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion) -> Only with custom marauder build (It is necessary to uncomment "#define WRITE_PACKETS_SERIAL" in configs.h (in marauder fw) and compile the firmware for the wifi board.) Or download precompiled build -> [Download esp32_marauder_ver_flipper_sd_serial.bin](https://github.com/justcallmekoko/ESP32Marauder/releases/latest)
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion)
- NRF24: Sniffer & MouseJacker (with changes) [(by mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
- Simple Clock (timer by GMMan) [(original by CompaqDisc)](https://gist.github.com/CompaqDisc/4e329c501bd03c1e801849b81f48ea61)
- **Sub-GHz Remote** (UniversalRF Remix) [(by @darmiel & @xMasterX)](https://github.com/darmiel/flipper-playlist/tree/feat/unirf-protocols) (original by @ESurge)
@@ -155,7 +142,6 @@ You can support us by using links or addresses below:
- Text Viewer [(by kowalski7cc & kyhwana)](https://github.com/kowalski7cc/flipper-zero-text-viewer/tree/refactor-text-app)
- **UART Terminal** [(by cool4uma)](https://github.com/cool4uma/UART_Terminal/tree/main)
- **ProtoView** [(by antirez)](https://github.com/antirez/protoview)
- **SWD Probe** [(by g3gg0)](https://github.com/g3gg0/flipper-swd_probe)
Games:
- DOOM (fixed) [(by p4nic4ttack)](https://github.com/p4nic4ttack/doom-flipper-zero/)
@@ -171,6 +157,15 @@ Games:
- BlackJack [(by teeebor)](https://github.com/teeebor/flipper_games)
- 2048 game [(by eugene-kirzhanov)](https://github.com/eugene-kirzhanov/flipper-zero-2048-game)
### Other changes
- BadUSB -> Keyboard layouts [(by rien > dummy-decoy)](https://github.com/dummy-decoy/flipperzero-firmware/tree/dummy_decoy/bad_usb_keyboard_layout)
- Sub-GHz -> External CC1101 module support - [(by quen0n)](https://github.com/DarkFlippers/unleashed-firmware/pull/307)
- Sub-GHz -> New frequency analyzer - [(by ClusterM)](https://github.com/DarkFlippers/unleashed-firmware/pull/43)
- Sub-GHz -> Save last used frequency [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/77)
- Sub-GHz -> Press OK in frequency analyzer to use detected frequency in Read modes [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/77)
- Sub-GHz -> Long press OK button in Sub-GHz Frequency analyzer to switch to Read menu [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/79)
- Lock device with pin(or regular lock if pin not set) by holding UP button on main screen [(by an4tur0r)](https://github.com/DarkFlippers/unleashed-firmware/pull/107)
# Instructions
## [- How to install firmware](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/HowToInstall.md)
@@ -183,20 +178,12 @@ Games:
## [- How to change Flipper name](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/CustomFlipperName.md)
### **Sub-GHz**
## [- Transmission is blocked? - How to extend Sub-GHz frequency range](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/DangerousSettings.md)
## [- How to add extra Sub-GHz frequencies](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzSettings.md)
## [- How to use Flipper as new remote (Nice FlorS, BFT Mitto, Somfy Telis)](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md)
## [- Configure Sub-GHz Remote App](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemotePlugin.md)
### **Plugins**
## [- 🎲 Download Extra plugins for Unleashed](https://github.com/xMasterX/unleashed-extra-pack)
## [- Configure Sub-GHz Remote App](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemotePlugin.md)
## [- TOTP (Authenticator) config description](https://github.com/akopachov/flipper-zero_authenticator/blob/master/docs/conf-file_description.md)
## [- Barcode Generator](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/BarcodeGenerator.md)
@@ -211,9 +198,9 @@ Games:
## [- How to use: Unitemp - Temperature sensors reader](https://github.com/quen0n/unitemp-flipperzero#readme)
## [- How to use: [NMEA] GPS](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/applications/external/gps_nmea_uart/README.md)
## [- How to use: [NMEA] GPS](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/applications/plugins/gps_nmea_uart/README.md)
## [- How to use: i2c Tools](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/applications/external/flipper_i2ctools/README.md)
## [- How to use: i2c Tools](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/applications/plugins/flipper_i2ctools/README.md)
## [- How to use: [NRF24] plugins](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/NRF24.md)
@@ -231,12 +218,20 @@ Games:
## [- How to use: [GPIO] SentrySafe plugin](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SentrySafe.md)
### **Sub-GHz**
## [- Transmission is blocked? - How to extend Sub-GHz frequency range](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/DangerousSettings.md)
## [- How to add extra Sub-GHz frequencies](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzSettings.md)
<br>
<br>
# Where I can find IR, Sub-GHz, ... files, DBs, and other stuff?
## [UberGuidoZ Playground - Large collection of files - Github](https://github.com/UberGuidoZ/Flipper)
## [Awesome Flipper Zero - Github](https://github.com/djsime1/awesome-flipperzero)
## [CAME-12bit, NICE-12bit, Linear-10bit, PT-2240 - Sub-GHz fixed code bruteforce](https://github.com/tobiabocchi/flipperzero-bruteforce)
## [SMC5326, UNILARM - Sub-GHz fixed code bruteforce](https://github.com/Hong5489/flipperzero-gate-bruteforce)
<br>
<br>
@@ -244,9 +239,6 @@ Games:
# Links
* Unofficial Discord: [discord.unleashedflip.com](https://discord.unleashedflip.com)
* Hello world - plugin tutorial (English): [https://github.com/DroomOne/Flipper-Plugin-Tutorial](https://github.com/DroomOne/Flipper-Plugin-Tutorial)
* Hello world - plugin tutorial (in Russian): [https://yakovlev.me/hello-flipper-zero/](https://yakovlev.me/hello-flipper-zero/)
* CLion IDE - How to setup workspace for flipper firmware development: [https://krasovs.ky/2022/11/01/flipper-zero-clion.html](https://krasovs.ky/2022/11/01/flipper-zero-clion.html)
* Docs by atmanos / How to write your own app (outdated API): [https://flipper.atmanos.com/docs/overview/intro](https://flipper.atmanos.com/docs/overview/intro)
* Official Docs: [http://docs.flipperzero.one](http://docs.flipperzero.one)

View File

@@ -139,33 +139,34 @@ if GetOption("fullenv") or any(
basic_dist = distenv.DistCommand("fw_dist", distenv["DIST_DEPENDS"])
distenv.Default(basic_dist)
dist_dir_name = distenv.GetProjectDirName()
dist_dir = distenv.Dir(f"#/dist/{dist_dir_name}")
external_apps_artifacts = firmware_env["FW_EXTAPPS"]
external_app_list = external_apps_artifacts.application_map.values()
dist_dir = distenv.GetProjetDirName()
fap_dist = [
distenv.Install(
dist_dir.Dir("debug_elf"),
list(app_artifact.debug for app_artifact in external_app_list),
distenv.Dir(f"#/dist/{dist_dir}/apps/debug_elf"),
list(
app_artifact.debug
for app_artifact in firmware_env["FW_EXTAPPS"].applications.values()
),
),
*(
distenv.Install(
dist_dir.File(dist_entry[1]).dir,
app_artifact.compact,
f"#/dist/{dist_dir}/apps/{app_artifact.app.fap_category}",
app_artifact.compact[0],
)
for app_artifact in external_app_list
for dist_entry in app_artifact.dist_entries
for app_artifact in firmware_env["FW_EXTAPPS"].applications.values()
),
]
Depends(
fap_dist,
list(app_artifact.validator for app_artifact in external_app_list),
list(
app_artifact.validator
for app_artifact in firmware_env["FW_EXTAPPS"].applications.values()
),
)
Alias("fap_dist", fap_dist)
# distenv.Default(fap_dist)
distenv.Depends(firmware_env["FW_RESOURCES"], external_apps_artifacts.resources_dist)
distenv.Depends(firmware_env["FW_RESOURCES"], firmware_env["FW_EXTAPPS"].resources_dist)
# Copy all faps to device

View File

@@ -36,20 +36,15 @@ Applications for main Flipper menu.
- `u2f` - U2F Application
## External
## plugins
External applications deployed to SD Card
Extra apps for Plugins & App Loader menus.
- `clock` - Clock application
- `dap_link` - DAP Link OnChip debugger
- `hid_app` - USB/BT Remote controller
- `bt_hid_app` - BT Remote controller
- `music_player` - Music player app (demo)
- `nfc_magic` - NFC MFC Magic card application
- `picopass` - Picopass reader / writer
- `signal_generator` - Signal generator app: PWM and clock generator
- `picopass` - Picopass tool
- `snake_game` - Snake game application
- `spi_mem_manager` - SPI Memory reader / flasher
- `weather_station` - SubGHz weather station
## services

View File

@@ -11,7 +11,6 @@ typedef struct {
uint16_t left;
uint16_t right;
uint16_t ok;
FuriMutex* mutex;
} KeypadTestState;
static void keypad_test_reset_state(KeypadTestState* state) {
@@ -23,8 +22,7 @@ static void keypad_test_reset_state(KeypadTestState* state) {
}
static void keypad_test_render_callback(Canvas* canvas, void* ctx) {
KeypadTestState* state = ctx;
furi_mutex_acquire(state->mutex, FuriWaitForever);
KeypadTestState* state = (KeypadTestState*)acquire_mutex((ValueMutex*)ctx, 25);
canvas_clear(canvas);
char strings[5][20];
@@ -53,7 +51,7 @@ static void keypad_test_render_callback(Canvas* canvas, void* ctx) {
canvas_draw_str(canvas, 10, 63, "[back] - reset, hold to exit");
furi_mutex_release(state->mutex);
release_mutex((ValueMutex*)ctx, state);
}
static void keypad_test_input_callback(InputEvent* input_event, void* ctx) {
@@ -66,17 +64,17 @@ int32_t keypad_test_app(void* p) {
FuriMessageQueue* event_queue = furi_message_queue_alloc(32, sizeof(InputEvent));
furi_check(event_queue);
KeypadTestState state = {{false, false, false, false, false}, 0, 0, 0, 0, 0, NULL};
state.mutex = furi_mutex_alloc(FuriMutexTypeNormal);
KeypadTestState _state = {{false, false, false, false, false}, 0, 0, 0, 0, 0};
if(!state.mutex) {
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, &_state, sizeof(KeypadTestState))) {
FURI_LOG_E(TAG, "cannot create mutex");
return 0;
}
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, keypad_test_render_callback, &state);
view_port_draw_callback_set(view_port, keypad_test_render_callback, &state_mutex);
view_port_input_callback_set(view_port, keypad_test_input_callback, event_queue);
// Open GUI and register view_port
@@ -85,7 +83,7 @@ int32_t keypad_test_app(void* p) {
InputEvent event;
while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
furi_mutex_acquire(state.mutex, FuriWaitForever);
KeypadTestState* state = (KeypadTestState*)acquire_mutex_block(&state_mutex);
FURI_LOG_I(
TAG,
"key: %s type: %s",
@@ -94,54 +92,54 @@ int32_t keypad_test_app(void* p) {
if(event.key == InputKeyRight) {
if(event.type == InputTypePress) {
state.press[0] = true;
state->press[0] = true;
} else if(event.type == InputTypeRelease) {
state.press[0] = false;
state->press[0] = false;
} else if(event.type == InputTypeShort) {
++state.right;
++state->right;
}
} else if(event.key == InputKeyLeft) {
if(event.type == InputTypePress) {
state.press[1] = true;
state->press[1] = true;
} else if(event.type == InputTypeRelease) {
state.press[1] = false;
state->press[1] = false;
} else if(event.type == InputTypeShort) {
++state.left;
++state->left;
}
} else if(event.key == InputKeyUp) {
if(event.type == InputTypePress) {
state.press[2] = true;
state->press[2] = true;
} else if(event.type == InputTypeRelease) {
state.press[2] = false;
state->press[2] = false;
} else if(event.type == InputTypeShort) {
++state.up;
++state->up;
}
} else if(event.key == InputKeyDown) {
if(event.type == InputTypePress) {
state.press[3] = true;
state->press[3] = true;
} else if(event.type == InputTypeRelease) {
state.press[3] = false;
state->press[3] = false;
} else if(event.type == InputTypeShort) {
++state.down;
++state->down;
}
} else if(event.key == InputKeyOk) {
if(event.type == InputTypePress) {
state.press[4] = true;
state->press[4] = true;
} else if(event.type == InputTypeRelease) {
state.press[4] = false;
state->press[4] = false;
} else if(event.type == InputTypeShort) {
++state.ok;
++state->ok;
}
} else if(event.key == InputKeyBack) {
if(event.type == InputTypeLong) {
furi_mutex_release(state.mutex);
release_mutex(&state_mutex, state);
break;
} else if(event.type == InputTypeShort) {
keypad_test_reset_state(&state);
keypad_test_reset_state(state);
}
}
furi_mutex_release(state.mutex);
release_mutex(&state_mutex, state);
view_port_update(view_port);
}
@@ -149,7 +147,7 @@ int32_t keypad_test_app(void* p) {
gui_remove_view_port(gui, view_port);
view_port_free(view_port);
furi_message_queue_free(event_queue);
furi_mutex_free(state.mutex);
delete_mutex(&state_mutex);
furi_record_close(RECORD_GUI);

View File

@@ -53,17 +53,15 @@ static void (*text_box_test_render[])(Canvas* canvas) = {
typedef struct {
uint32_t idx;
FuriMutex* mutex;
} TextBoxTestState;
static void text_box_test_render_callback(Canvas* canvas, void* ctx) {
TextBoxTestState* state = ctx;
furi_mutex_acquire(state->mutex, FuriWaitForever);
TextBoxTestState* state = acquire_mutex((ValueMutex*)ctx, 25);
canvas_clear(canvas);
text_box_test_render[state->idx](canvas);
furi_mutex_release(state->mutex);
release_mutex((ValueMutex*)ctx, state);
}
static void text_box_test_input_callback(InputEvent* input_event, void* ctx) {
@@ -76,17 +74,17 @@ int32_t text_box_test_app(void* p) {
FuriMessageQueue* event_queue = furi_message_queue_alloc(32, sizeof(InputEvent));
furi_check(event_queue);
TextBoxTestState state = {.idx = 0, .mutex = NULL};
state.mutex = furi_mutex_alloc(FuriMutexTypeNormal);
TextBoxTestState _state = {.idx = 0};
if(!state.mutex) {
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, &_state, sizeof(TextBoxTestState))) {
FURI_LOG_E(TAG, "Cannot create mutex");
return 0;
}
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, text_box_test_render_callback, &state);
view_port_draw_callback_set(view_port, text_box_test_render_callback, &state_mutex);
view_port_input_callback_set(view_port, text_box_test_input_callback, event_queue);
// Open GUI and register view_port
@@ -96,24 +94,24 @@ int32_t text_box_test_app(void* p) {
uint32_t test_renders_num = COUNT_OF(text_box_test_render);
InputEvent event;
while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
furi_mutex_acquire(state.mutex, FuriWaitForever);
TextBoxTestState* state = acquire_mutex_block(&state_mutex);
if(event.type == InputTypeShort) {
if(event.key == InputKeyRight) {
if(state.idx < test_renders_num - 1) {
state.idx++;
if(state->idx < test_renders_num - 1) {
state->idx++;
}
} else if(event.key == InputKeyLeft) {
if(state.idx > 0) {
state.idx--;
if(state->idx > 0) {
state->idx--;
}
} else if(event.key == InputKeyBack) {
furi_mutex_release(state.mutex);
release_mutex(&state_mutex, state);
break;
}
}
furi_mutex_release(state.mutex);
release_mutex(&state_mutex, state);
view_port_update(view_port);
}
@@ -121,7 +119,7 @@ int32_t text_box_test_app(void* p) {
gui_remove_view_port(gui, view_port);
view_port_free(view_port);
furi_message_queue_free(event_queue);
furi_mutex_free(state.mutex);
delete_mutex(&state_mutex);
furi_record_close(RECORD_GUI);

View File

@@ -1,7 +1,7 @@
App(
appid="UART_Echo",
name="UART Echo",
apptype=FlipperAppType.EXTERNAL,
apptype=FlipperAppType.PLUGIN,
entry_point="uart_echo_app",
cdefines=["APP_UART_ECHO"],
requires=["gui"],

View File

@@ -5,6 +5,7 @@
// v2 tests
void test_furi_create_open();
void test_furi_valuemutex();
void test_furi_concurrent_access();
void test_furi_pubsub();
@@ -29,6 +30,10 @@ MU_TEST(mu_test_furi_create_open) {
test_furi_create_open();
}
MU_TEST(mu_test_furi_valuemutex) {
test_furi_valuemutex();
}
MU_TEST(mu_test_furi_pubsub) {
test_furi_pubsub();
}
@@ -46,6 +51,7 @@ MU_TEST_SUITE(test_suite) {
// v2 tests
MU_RUN_TEST(mu_test_furi_create_open);
MU_RUN_TEST(mu_test_furi_valuemutex);
MU_RUN_TEST(mu_test_furi_pubsub);
MU_RUN_TEST(mu_test_furi_memmgr);
}

View File

@@ -0,0 +1,41 @@
#include <stdio.h>
#include <string.h>
#include <furi.h>
#include "../minunit.h"
void test_furi_valuemutex() {
const int init_value = 0xdeadbeef;
const int changed_value = 0x12345678;
int value = init_value;
bool result;
ValueMutex valuemutex;
// init mutex case
result = init_mutex(&valuemutex, &value, sizeof(value));
mu_assert(result, "init mutex failed");
// acquire mutex case
int* value_pointer = acquire_mutex(&valuemutex, 100);
mu_assert_pointers_eq(value_pointer, &value);
// second acquire mutex case
int* value_pointer_second = acquire_mutex(&valuemutex, 100);
mu_assert_pointers_eq(value_pointer_second, NULL);
// change value case
*value_pointer = changed_value;
mu_assert_int_eq(value, changed_value);
// release mutex case
result = release_mutex(&valuemutex, &value);
mu_assert(result, "release mutex failed");
// TODO
//acquire mutex blocking case
//write mutex blocking case
//read mutex blocking case
mu_check(delete_mutex(&valuemutex));
}

View File

@@ -3,63 +3,56 @@
#include "../minunit.h"
static void power_test_deinit(void) {
// Try to reset to default charge voltage limit
furi_hal_power_set_battery_charge_voltage_limit(4.208f);
// Try to reset to default charging voltage
furi_hal_power_set_battery_charging_voltage(4.208f);
}
MU_TEST(test_power_charge_voltage_limit_exact) {
// Power of 16mV charge voltage limits get applied exactly
MU_TEST(test_power_charge_voltage_exact) {
// Power of 16mV charge voltages get applied exactly
// (bq25896 charge controller works in 16mV increments)
//
// This test may need adapted if other charge controllers are used in the future.
for(uint16_t charge_mv = 3840; charge_mv <= 4208; charge_mv += 16) {
float charge_volt = (float)charge_mv / 1000.0f;
furi_hal_power_set_battery_charge_voltage_limit(charge_volt);
mu_assert_double_eq(charge_volt, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charging_voltage(charge_volt);
mu_assert_double_eq(charge_volt, furi_hal_power_get_battery_charging_voltage());
}
}
MU_TEST(test_power_charge_voltage_limit_floating_imprecision) {
MU_TEST(test_power_charge_voltage_floating_imprecision) {
// 4.016f should act as 4.016 V, even with floating point imprecision
furi_hal_power_set_battery_charge_voltage_limit(4.016f);
mu_assert_double_eq(4.016f, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charging_voltage(4.016f);
mu_assert_double_eq(4.016f, furi_hal_power_get_battery_charging_voltage());
}
MU_TEST(test_power_charge_voltage_limit_inexact) {
// Charge voltage limits that are not power of 16mV get truncated down
furi_hal_power_set_battery_charge_voltage_limit(3.841f);
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
MU_TEST(test_power_charge_voltage_inexact) {
// Charge voltages that are not power of 16mV get truncated down
furi_hal_power_set_battery_charging_voltage(3.841f);
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charging_voltage());
furi_hal_power_set_battery_charge_voltage_limit(3.900f);
mu_assert_double_eq(3.888, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charging_voltage(3.900f);
mu_assert_double_eq(3.888, furi_hal_power_get_battery_charging_voltage());
furi_hal_power_set_battery_charge_voltage_limit(4.200f);
mu_assert_double_eq(4.192, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charging_voltage(4.200f);
mu_assert_double_eq(4.192, furi_hal_power_get_battery_charging_voltage());
}
MU_TEST(test_power_charge_voltage_limit_invalid_clamped) {
// Out-of-range charge voltage limits get clamped to 3.840 V and 4.208 V
furi_hal_power_set_battery_charge_voltage_limit(3.808f);
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charge_voltage_limit(1.0f);
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
MU_TEST(test_power_charge_voltage_invalid_clamped) {
// Out-of-range charge voltages get clamped to 3.840 V and 4.208 V
furi_hal_power_set_battery_charging_voltage(3.808f);
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charging_voltage());
// NOTE: Intentionally picking a small increment above 4.208 V to reduce the risk of an
// unhappy battery if this fails.
furi_hal_power_set_battery_charge_voltage_limit(4.240f);
mu_assert_double_eq(4.208, furi_hal_power_get_battery_charge_voltage_limit());
// Likewise, picking a number that the uint8_t wraparound in the driver would result in a
// VREG value under 23 if this test fails.
// E.g. (uint8_t)((8105-3840)/16) -> 10
furi_hal_power_set_battery_charge_voltage_limit(8.105f);
mu_assert_double_eq(4.208, furi_hal_power_get_battery_charge_voltage_limit());
furi_hal_power_set_battery_charging_voltage(4.240f);
mu_assert_double_eq(4.208, furi_hal_power_get_battery_charging_voltage());
}
MU_TEST_SUITE(test_power_suite) {
MU_RUN_TEST(test_power_charge_voltage_limit_exact);
MU_RUN_TEST(test_power_charge_voltage_limit_floating_imprecision);
MU_RUN_TEST(test_power_charge_voltage_limit_inexact);
MU_RUN_TEST(test_power_charge_voltage_limit_invalid_clamped);
MU_RUN_TEST(test_power_charge_voltage_exact);
MU_RUN_TEST(test_power_charge_voltage_floating_imprecision);
MU_RUN_TEST(test_power_charge_voltage_inexact);
MU_RUN_TEST(test_power_charge_voltage_invalid_clamped);
power_test_deinit();
}

View File

@@ -191,7 +191,7 @@ static void clean_directory(Storage* fs_api, const char* clean_dir) {
size_t size = strlen(clean_dir) + strlen(name) + 1 + 1;
char* fullname = malloc(size);
snprintf(fullname, size, "%s/%s", clean_dir, name);
if(file_info_is_dir(&fileinfo)) {
if(fileinfo.flags & FSF_DIRECTORY) {
clean_directory(fs_api, fullname);
}
FS_Error error = storage_common_remove(fs_api, fullname);
@@ -608,8 +608,9 @@ static void test_rpc_storage_list_create_expected_list(
}
if(path_contains_only_ascii(name)) {
list->file[i].type = file_info_is_dir(&fileinfo) ? PB_Storage_File_FileType_DIR :
PB_Storage_File_FileType_FILE;
list->file[i].type = (fileinfo.flags & FSF_DIRECTORY) ?
PB_Storage_File_FileType_DIR :
PB_Storage_File_FileType_FILE;
list->file[i].size = fileinfo.size;
list->file[i].data = NULL;
/* memory free inside rpc_encode_and_send() -> pb_release() */
@@ -872,7 +873,7 @@ static void test_rpc_storage_stat_run(const char* path, uint32_t command_id) {
if(error == FSE_OK) {
response->which_content = PB_Main_storage_stat_response_tag;
response->content.storage_stat_response.has_file = true;
response->content.storage_stat_response.file.type = file_info_is_dir(&fileinfo) ?
response->content.storage_stat_response.file.type = (fileinfo.flags & FSF_DIRECTORY) ?
PB_Storage_File_FileType_DIR :
PB_Storage_File_FileType_FILE;
response->content.storage_stat_response.file.size = fileinfo.size;

View File

@@ -179,7 +179,7 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
@@ -204,7 +204,7 @@ MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
@@ -219,7 +219,7 @@ static bool test_dirwalk_filter_no_folder_ext(const char* name, FileInfo* filein
UNUSED(ctx);
// only files
if(!file_info_is_dir(fileinfo)) {
if(!(fileinfo->flags & FSF_DIRECTORY)) {
// with ".test" in name
if(strstr(name, ".test") != NULL) {
return true;
@@ -243,7 +243,7 @@ MU_TEST_1(test_dirwalk_filter, Storage* storage) {
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, file_info_is_dir(&fileinfo)));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);

View File

@@ -2,40 +2,9 @@
#include <furi.h>
#include <storage/storage.h>
// DO NOT USE THIS IN PRODUCTION CODE
// This is a hack to access internal storage functions and definitions
#include <storage/storage_i.h>
#define UNIT_TESTS_PATH(path) EXT_PATH("unit_tests/" path)
#define STORAGE_LOCKED_FILE EXT_PATH("locked_file.test")
#define STORAGE_LOCKED_DIR STORAGE_INT_PATH_PREFIX
#define STORAGE_TEST_DIR UNIT_TESTS_PATH("test_dir")
static bool storage_file_create(Storage* storage, const char* path, const char* data) {
File* file = storage_file_alloc(storage);
bool result = false;
do {
if(!storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_NEW)) {
break;
}
if(storage_file_write(file, data, strlen(data)) != strlen(data)) {
break;
}
if(!storage_file_close(file)) {
break;
}
result = true;
} while(0);
storage_file_free(file);
return result;
}
static void storage_file_open_lock_setup() {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
@@ -146,7 +115,7 @@ static int32_t storage_dir_locker(void* ctx) {
File* file = storage_file_alloc(storage);
furi_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
furi_semaphore_release(semaphore);
furi_delay_ms(100);
furi_delay_ms(1000);
furi_check(storage_dir_close(file));
furi_record_close(RECORD_STORAGE);
@@ -183,21 +152,9 @@ MU_TEST(storage_dir_open_lock) {
mu_assert(result, "cannot open locked dir");
}
MU_TEST(storage_dir_exists_test) {
Storage* storage = furi_record_open(RECORD_STORAGE);
mu_check(!storage_dir_exists(storage, STORAGE_TEST_DIR));
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, STORAGE_TEST_DIR));
mu_check(storage_dir_exists(storage, STORAGE_TEST_DIR));
mu_assert_int_eq(FSE_OK, storage_common_remove(storage, STORAGE_TEST_DIR));
furi_record_close(RECORD_STORAGE);
}
MU_TEST_SUITE(storage_dir) {
MU_RUN_TEST(storage_dir_open_close);
MU_RUN_TEST(storage_dir_open_lock);
MU_RUN_TEST(storage_dir_exists_test);
}
static const char* const storage_copy_test_paths[] = {
@@ -346,256 +303,9 @@ MU_TEST_SUITE(storage_rename) {
furi_record_close(RECORD_STORAGE);
}
#define APPSDATA_APP_PATH(path) APPS_DATA_PATH "/" path
static const char* storage_test_apps[] = {
"-_twilight_-",
"-_rainbow_-",
"-_pinkie_-",
"-_apple_-",
"-_flutter_-",
"-_rare_-",
};
static size_t storage_test_apps_count = COUNT_OF(storage_test_apps);
static int32_t storage_test_app(void* arg) {
UNUSED(arg);
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_common_remove(storage, "/data/test");
int32_t ret = storage_file_create(storage, "/data/test", "test");
furi_record_close(RECORD_STORAGE);
return ret;
}
MU_TEST(test_storage_data_path_apps) {
for(size_t i = 0; i < storage_test_apps_count; i++) {
FuriThread* thread =
furi_thread_alloc_ex(storage_test_apps[i], 1024, storage_test_app, NULL);
furi_thread_set_appid(thread, storage_test_apps[i]);
furi_thread_start(thread);
furi_thread_join(thread);
mu_assert_int_eq(true, furi_thread_get_return_code(thread));
// Check if app data dir and file exists
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriString* expected = furi_string_alloc();
furi_string_printf(expected, APPSDATA_APP_PATH("%s"), storage_test_apps[i]);
mu_check(storage_dir_exists(storage, furi_string_get_cstr(expected)));
furi_string_cat(expected, "/test");
mu_check(storage_file_exists(storage, furi_string_get_cstr(expected)));
furi_string_printf(expected, APPSDATA_APP_PATH("%s"), storage_test_apps[i]);
storage_simply_remove_recursive(storage, furi_string_get_cstr(expected));
furi_record_close(RECORD_STORAGE);
furi_string_free(expected);
furi_thread_free(thread);
}
}
MU_TEST(test_storage_data_path) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
mu_check(storage_dir_open(file, "/data"));
mu_check(storage_dir_close(file));
storage_file_free(file);
// check that appsdata folder exists
mu_check(storage_dir_exists(storage, APPS_DATA_PATH));
// check that cli folder exists
mu_check(storage_dir_exists(storage, APPSDATA_APP_PATH("cli")));
storage_simply_remove(storage, APPSDATA_APP_PATH("cli"));
furi_record_close(RECORD_STORAGE);
}
MU_TEST(test_storage_common_migrate) {
Storage* storage = furi_record_open(RECORD_STORAGE);
// Setup test folders
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
// Test migration from non existing
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
// Test migration from existing folder to non existing
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file1"), "test1"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file2.ext"), "test2"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file3.ext.ext"), "test3"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file1")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file2.ext")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext.ext")));
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
// Test migration from existing folder to existing folder
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file1"), "test1"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file2.ext"), "test2"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old/file3.ext.ext"), "test3"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file1")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file2.ext")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext.ext")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file11")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file21.ext")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new/file3.ext1.ext")));
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
// Test migration from empty folder to existing file
// Expected result: FSE_OK, folder removed, file untouched
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new"), "test1"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
// Test migration from empty folder to existing folder
// Expected result: FSE_OK, old folder removed, new folder untouched
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_old")));
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_new")));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_old")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
// Test migration from existing file to non existing, no extension
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
// Test migration from existing file to non existing, with extension
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old.file"), "test1"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old.file"), UNIT_TESTS_PATH("migrate_new.file")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new.file")));
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old.file")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old.file"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new.file"));
// Test migration from existing file to existing file, no extension
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new"), "test2"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1"));
// Test migration from existing file to existing file, with extension
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old.file"), "test1"));
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_new.file"), "test2"));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old.file"), UNIT_TESTS_PATH("migrate_new.file")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new.file")));
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old.file")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1.file")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old.file"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new.file"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1.file"));
// Test migration from existing file to existing folder
mu_check(storage_file_create(storage, UNIT_TESTS_PATH("migrate_old"), "test1"));
mu_assert_int_eq(FSE_OK, storage_common_mkdir(storage, UNIT_TESTS_PATH("migrate_new")));
mu_assert_int_eq(
FSE_OK,
storage_common_migrate(
storage, UNIT_TESTS_PATH("migrate_old"), UNIT_TESTS_PATH("migrate_new")));
mu_check(storage_dir_exists(storage, UNIT_TESTS_PATH("migrate_new")));
mu_check(!storage_file_exists(storage, UNIT_TESTS_PATH("migrate_old")));
mu_check(storage_file_exists(storage, UNIT_TESTS_PATH("migrate_new1")));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_old"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new"));
storage_simply_remove_recursive(storage, UNIT_TESTS_PATH("migrate_new1"));
furi_record_close(RECORD_STORAGE);
}
MU_TEST_SUITE(test_data_path) {
MU_RUN_TEST(test_storage_data_path);
MU_RUN_TEST(test_storage_data_path_apps);
}
MU_TEST_SUITE(test_storage_common) {
MU_RUN_TEST(test_storage_common_migrate);
}
int run_minunit_test_storage() {
MU_RUN_SUITE(storage_file);
MU_RUN_SUITE(storage_dir);
MU_RUN_SUITE(storage_rename);
MU_RUN_SUITE(test_data_path);
MU_RUN_SUITE(test_storage_common);
return MU_EXIT_CODE;
}

View File

@@ -7,6 +7,6 @@ App(
requires=["gui"],
stack_size=1 * 1024,
order=60,
fap_icon="../../external/mousejacker/mouse_10px.png",
fap_icon="../../plugins/mousejacker/mouse_10px.png",
fap_category="Debug",
)

View File

@@ -1,4 +1,3 @@
# Placeholder
App(
appid="example_apps",
name="Example apps bundle",

View File

@@ -1,58 +0,0 @@
# Apps Assets folder Example
This example shows how to use the Apps Assets folder to store data that is not part of the application itself, but is required for its operation, and that data is provided with the application.
## What is the Apps Assets Folder?
The **Apps Assets** folder is a folder where external applications unpack their assets.
The path to the current application folder is related to the `appid` of the app. The `appid` is used to identify the app in the app store and is stored in the `application.fam` file.
The Apps Assets folder is located only on the external storage, the SD card.
For example, if the `appid` of the app is `snake_game`, the path to the Apps Assets folder will be `/ext/apps_assets/snake_game`. But using raw paths is not recommended, because the path to the Apps Assets folder can change in the future. Use the `/assets` alias instead.
## How to get the path to the Apps Assets folder?
You can use `/assets` alias to get the path to the current application data folder. For example, if you want to open a file `database.txt` in the Apps Assets folder, you can use the next path: `/data/database.txt`. But this way is not recommended, because even the `/assets` alias can change in the future.
We recommend to use the `APP_ASSETS_PATH` macro to get the path to the Apps Assets folder. For example, if you want to open a file `database.txt` in the Apps Assets folder, you can use the next path: `APP_ASSETS_PATH("database.txt")`.
## What is the difference between the Apps Assets folder and the Apps Data folder?
The Apps Assets folder is used to store the data <u>provided</u> with the application. For example, if you want to create a game, you can store game levels (contant data) in the Apps Assets folder.
The Apps Data folder is used to store data <u>generated</u> by the application. For example, if you want to create a game, you can save the progress of the game (user-generated data) in the Apps Data folder.
## How to provide the data with the app?
To provide data with an application, you need to create a folder inside your application folder (eg "files") and place the data in it. After that, you need to add `fap_file_assets="files"` to your application.fam file.
For example, if you want to provide game levels with the application, you need to create a "levels" folder inside the "files" folder and put the game levels in it. After that, you need to add `fap_file_assets="files"` to your application.fam file. The final application folder structure will look like this:
```
snake_game
├── application.fam
├── snake_game.c
└── files
└── levels
├── level1.txt
├── level2.txt
└── level3.txt
```
When app is launched, the `files` folder will be unpacked to the Apps Assets folder. The final structure of the Apps Assets folder will look like this:
```
/assets
├── .assets.signature
└── levels
├── level1.txt
├── level2.txt
└── level3.txt
```
## When will the data be unpacked?
The data is unpacked when the application starts, if the application is launched for the first time, or if the data within the application is updated.
When an application is compiled, the contents of the "files" folder are hashed and stored within the application itself. When the application starts, this hash is compared to the hash stored in the `.assets.signature` file. If the hashes differ or the `.assets.signature` file does not exist, the application folder is deleted and the new data is unpacked.

View File

@@ -1,10 +0,0 @@
App(
appid="example_apps_assets",
name="Example: Apps Assets",
apptype=FlipperAppType.EXTERNAL,
entry_point="example_apps_assets_main",
requires=["gui"],
stack_size=4 * 1024,
fap_category="Examples",
fap_file_assets="files",
)

View File

@@ -1,48 +0,0 @@
#include <furi.h>
#include <storage/storage.h>
#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>
// Define log tag
#define TAG "example_apps_assets"
static void example_apps_data_print_file_content(Storage* storage, const char* path) {
Stream* stream = file_stream_alloc(storage);
FuriString* line = furi_string_alloc();
FURI_LOG_I(TAG, "----------------------------------------");
FURI_LOG_I(TAG, "File \"%s\" content:", path);
if(file_stream_open(stream, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
while(stream_read_line(stream, line)) {
furi_string_replace_all(line, "\r", "");
furi_string_replace_all(line, "\n", "");
FURI_LOG_I(TAG, "%s", furi_string_get_cstr(line));
}
} else {
FURI_LOG_E(TAG, "Failed to open file");
}
FURI_LOG_I(TAG, "----------------------------------------");
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
}
// Application entry point
int32_t example_apps_assets_main(void* p) {
// Mark argument as unused
UNUSED(p);
// Open storage
Storage* storage = furi_record_open(RECORD_STORAGE);
example_apps_data_print_file_content(storage, APP_ASSETS_PATH("test_asset.txt"));
example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/a jelly-fish.txt"));
example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/theme in yellow.txt"));
example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/my shadow.txt"));
// Close storage
furi_record_close(RECORD_STORAGE);
return 0;
}

View File

@@ -1,24 +0,0 @@
A Jelly-Fish by Marianne Moore
Visible, invisible,
A fluctuating charm,
An amber-colored amethyst
Inhabits it; your arm
Approaches, and
It opens and
It closes;
You have meant
To catch it,
And it shrivels;
You abandon
Your intent—
It opens, and it
Closes and you
Reach for it—
The blue
Surrounding it
Grows cloudy, and
It floats away
From you.
source: "https://poets.org/anthology/poems-your-poetry-project-public-domain"

View File

@@ -1,23 +0,0 @@
My Shadow by Robert Louis Stevenson
I have a little shadow that goes in and out with me,
And what can be the use of him is more than I can see.
He is very, very like me from the heels up to the head;
And I see him jump before me, when I jump into my bed.
The funniest thing about him is the way he likes to grow—
Not at all like proper children, which is always very slow;
For he sometimes shoots up taller like an India-rubber ball,
And he sometimes gets so little that theres none of him at all.
He hasnt got a notion of how children ought to play,
And can only make a fool of me in every sort of way.
He stays so close beside me, hes a coward you can see;
Id think shame to stick to nursie as that shadow sticks to me!
One morning, very early, before the sun was up,
I rose and found the shining dew on every buttercup;
But my lazy little shadow, like an arrant sleepy-head,
Had stayed at home behind me and was fast asleep in bed.
source: "https://poets.org/anthology/poems-your-poetry-project-public-domain"

View File

@@ -1,19 +0,0 @@
Theme in Yellow by Carl Sandburg
I spot the hills
With yellow balls in autumn.
I light the prairie cornfields
Orange and tawny gold clusters
And I am called pumpkins.
On the last of October
When dusk is fallen
Children join hands
And circle round me
Singing ghost songs
And love to the harvest moon;
I am a jack-o'-lantern
With terrible teeth
And the children know
I am fooling.
source: "https://poets.org/anthology/poems-your-poetry-project-public-domain"

View File

@@ -1 +0,0 @@
## This is test file content

View File

@@ -1,24 +0,0 @@
# Apps Data folder Example
This example demonstrates how to utilize the Apps Data folder to store data that is not part of the app itself, such as user data, configuration files, and so forth.
## What is the Apps Data Folder?
The **Apps Data** folder is a folder used to store data for external apps that are not part of the main firmware.
The path to the current application folder is related to the `appid` of the app. The `appid` is used to identify the app in the app store and is stored in the `application.fam` file.
The Apps Data folder is located only on the external storage, the SD card.
For example, if the `appid` of the app is `snake_game`, the path to the Apps Data folder will be `/ext/apps_data/snake_game`. But using raw paths is not recommended, because the path to the Apps Data folder can change in the future. Use the `/data` alias instead.
## How to get the path to the Apps Data folder?
You can use `/data` alias to get the path to the current application data folder. For example, if you want to open a file `config.txt` in the Apps Data folder, you can use the next path: `/data/config.txt`. But this way is not recommended, because even the `/data` alias can change in the future.
We recommend to use the `APP_DATA_PATH` macro to get the path to the Apps Data folder. For example, if you want to open a file `config.txt` in the Apps Data folder, you can use the next path: `APP_DATA_PATH("config.txt")`.
## What is the difference between the Apps Assets folder and the Apps Data folder?
The Apps Assets folder is used to store the data <u>provided</u> with the application. For example, if you want to create a game, you can store game levels (contant data) in the Apps Assets folder.
The Apps Data folder is used to store data <u>generated</u> by the application. For example, if you want to create a game, you can save the progress of the game (user-generated data) in the Apps Data folder.

View File

@@ -1,9 +0,0 @@
App(
appid="example_apps_data",
name="Example: Apps Data",
apptype=FlipperAppType.EXTERNAL,
entry_point="example_apps_data_main",
requires=["gui"],
stack_size=1 * 1024,
fap_category="Examples",
)

View File

@@ -1,40 +0,0 @@
#include <furi.h>
#include <storage/storage.h>
// Define log tag
#define TAG "example_apps_data"
// Application entry point
int32_t example_apps_data_main(void* p) {
// Mark argument as unused
UNUSED(p);
// Open storage
Storage* storage = furi_record_open(RECORD_STORAGE);
// Allocate file
File* file = storage_file_alloc(storage);
// Get the path to the current application data folder
// That is: /ext/apps_data/<app_name>
// And it will create folders in the path if they don't exist
// In this example it will create /ext/apps_data/example_apps_data
// And file will be /ext/apps_data/example_apps_data/test.txt
// Open file, write data and close it
if(!storage_file_open(file, APP_DATA_PATH("test.txt"), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
FURI_LOG_E(TAG, "Failed to open file");
}
if(!storage_file_write(file, "Hello World!", strlen("Hello World!"))) {
FURI_LOG_E(TAG, "Failed to write to file");
}
storage_file_close(file);
// Deallocate file
storage_file_free(file);
// Close storage
furi_record_close(RECORD_STORAGE);
return 0;
}

View File

@@ -1,31 +0,0 @@
App(
appid="example_plugins",
name="Example: App w/plugin",
apptype=FlipperAppType.EXTERNAL,
entry_point="example_plugins_app",
stack_size=2 * 1024,
fap_category="Examples",
)
App(
appid="example_plugins_multi",
name="Example: App w/plugins",
apptype=FlipperAppType.EXTERNAL,
entry_point="example_plugins_multi_app",
stack_size=2 * 1024,
fap_category="Examples",
)
App(
appid="example_plugin1",
apptype=FlipperAppType.PLUGIN,
entry_point="example_plugin1_ep",
requires=["example_plugins", "example_plugins_multi"],
)
App(
appid="example_plugin2",
apptype=FlipperAppType.PLUGIN,
entry_point="example_plugin2_ep",
requires=["example_plugins_multi"],
)

View File

@@ -1,70 +0,0 @@
/*
* An example of a plugin host application.
* Loads a single plugin and calls its methods.
*/
#include "plugin_interface.h"
#include <furi.h>
#include <flipper_application/flipper_application.h>
#include <loader/firmware_api/firmware_api.h>
#include <storage/storage.h>
#define TAG "example_plugins"
int32_t example_plugins_app(void* p) {
UNUSED(p);
FURI_LOG_I(TAG, "Starting");
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperApplication* app = flipper_application_alloc(storage, firmware_api_interface);
do {
FlipperApplicationPreloadStatus preload_res =
flipper_application_preload(app, APP_DATA_PATH("plugins/example_plugin1.fal"));
if(preload_res != FlipperApplicationPreloadStatusSuccess) {
FURI_LOG_E(TAG, "Failed to preload plugin");
break;
}
if(!flipper_application_is_plugin(app)) {
FURI_LOG_E(TAG, "Plugin file is not a library");
break;
}
FlipperApplicationLoadStatus load_status = flipper_application_map_to_memory(app);
if(load_status != FlipperApplicationLoadStatusSuccess) {
FURI_LOG_E(TAG, "Failed to load plugin file");
break;
}
const FlipperAppPluginDescriptor* app_descriptor =
flipper_application_plugin_get_descriptor(app);
FURI_LOG_I(
TAG,
"Loaded plugin for appid '%s', API %lu",
app_descriptor->appid,
app_descriptor->ep_api_version);
furi_check(app_descriptor->ep_api_version == PLUGIN_API_VERSION);
furi_check(strcmp(app_descriptor->appid, PLUGIN_APP_ID) == 0);
const ExamplePlugin* plugin = app_descriptor->entry_point;
FURI_LOG_I(TAG, "Plugin name: %s", plugin->name);
FURI_LOG_I(TAG, "Plugin method1: %d", plugin->method1());
FURI_LOG_I(TAG, "Plugin method2(7,8): %d", plugin->method2(7, 8));
FURI_LOG_I(TAG, "Plugin method2(1337,228): %d", plugin->method2(1337, 228));
} while(false);
flipper_application_free(app);
furi_record_close(RECORD_STORAGE);
FURI_LOG_I(TAG, "Goodbye!");
return 0;
}

View File

@@ -1,43 +0,0 @@
/*
* An example of an advanced plugin host application.
* It uses PluginManager to load all plugins from a directory
*/
#include "plugin_interface.h"
#include <flipper_application/flipper_application.h>
#include <flipper_application/plugins/plugin_manager.h>
#include <loader/firmware_api/firmware_api.h>
#include <furi.h>
#define TAG "example_plugins"
int32_t example_plugins_multi_app(void* p) {
UNUSED(p);
FURI_LOG_I(TAG, "Starting");
PluginManager* manager =
plugin_manager_alloc(PLUGIN_APP_ID, PLUGIN_API_VERSION, firmware_api_interface);
if(plugin_manager_load_all(manager, APP_DATA_PATH("plugins")) != PluginManagerErrorNone) {
FURI_LOG_E(TAG, "Failed to load all libs");
return 0;
}
uint32_t plugin_count = plugin_manager_get_count(manager);
FURI_LOG_I(TAG, "Loaded %lu plugin(s)", plugin_count);
for(uint32_t i = 0; i < plugin_count; i++) {
const ExamplePlugin* plugin = plugin_manager_get_ep(manager, i);
FURI_LOG_I(TAG, "plugin name: %s", plugin->name);
FURI_LOG_I(TAG, "plugin method1: %d", plugin->method1());
FURI_LOG_I(TAG, "plugin method2(7,8): %d", plugin->method2(7, 8));
}
plugin_manager_free(manager);
FURI_LOG_I(TAG, "Goodbye!");
return 0;
}

View File

@@ -1,32 +0,0 @@
/* A simple plugin implementing example_plugins application's plugin interface */
#include "plugin_interface.h"
#include <flipper_application/flipper_application.h>
static int example_plugin1_method1() {
return 42;
}
static int example_plugin1_method2(int arg1, int arg2) {
return arg1 + arg2;
}
/* Actual implementation of app<>plugin interface */
static const ExamplePlugin example_plugin1 = {
.name = "Demo App Plugin 1",
.method1 = &example_plugin1_method1,
.method2 = &example_plugin1_method2,
};
/* Plugin descriptor to comply with basic plugin specification */
static const FlipperAppPluginDescriptor example_plugin1_descriptor = {
.appid = PLUGIN_APP_ID,
.ep_api_version = PLUGIN_API_VERSION,
.entry_point = &example_plugin1,
};
/* Plugin entry point - must return a pointer to const descriptor */
const FlipperAppPluginDescriptor* example_plugin1_ep() {
return &example_plugin1_descriptor;
}

View File

@@ -1,32 +0,0 @@
/* Second plugin implementing example_plugins application's plugin interface */
#include "plugin_interface.h"
#include <flipper_application/flipper_application.h>
static int example_plugin2_method1() {
return 1337;
}
static int example_plugin2_method2(int arg1, int arg2) {
return arg1 - arg2;
}
/* Actual implementation of app<>plugin interface */
static const ExamplePlugin example_plugin2 = {
.name = "Demo App Plugin 2",
.method1 = &example_plugin2_method1,
.method2 = &example_plugin2_method2,
};
/* Plugin descriptor to comply with basic plugin specification */
static const FlipperAppPluginDescriptor example_plugin2_descriptor = {
.appid = PLUGIN_APP_ID,
.ep_api_version = PLUGIN_API_VERSION,
.entry_point = &example_plugin2,
};
/* Plugin entry point - must return a pointer to const descriptor */
const FlipperAppPluginDescriptor* example_plugin2_ep() {
return &example_plugin2_descriptor;
}

View File

@@ -1,12 +0,0 @@
#pragma once
/* Common interface between a plugin and host applicaion */
#define PLUGIN_APP_ID "example_plugins"
#define PLUGIN_API_VERSION 1
typedef struct {
const char* name;
int (*method1)();
int (*method2)(int, int);
} ExamplePlugin;

View File

@@ -1,25 +0,0 @@
#include "app_api.h"
/* Actual implementation of app's API and its private state */
static uint32_t accumulator = 0;
void app_api_accumulator_set(uint32_t value) {
accumulator = value;
}
uint32_t app_api_accumulator_get() {
return accumulator;
}
void app_api_accumulator_add(uint32_t value) {
accumulator += value;
}
void app_api_accumulator_sub(uint32_t value) {
accumulator -= value;
}
void app_api_accumulator_mul(uint32_t value) {
accumulator *= value;
}

View File

@@ -1,25 +0,0 @@
#pragma once
/*
* This file contains an API that is internally implemented by the application
* It is also exposed to plugins to allow them to use the application's API.
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void app_api_accumulator_set(uint32_t value);
uint32_t app_api_accumulator_get();
void app_api_accumulator_add(uint32_t value);
void app_api_accumulator_sub(uint32_t value);
void app_api_accumulator_mul(uint32_t value);
#ifdef __cplusplus
}
#endif

View File

@@ -1,9 +0,0 @@
#pragma once
#include <flipper_application/api_hashtable/api_hashtable.h>
/*
* Resolver interface with private application's symbols.
* Implementation is contained in app_api_table.c
*/
extern const ElfApiInterface* const application_api_interface;

View File

@@ -1,27 +0,0 @@
#include <flipper_application/api_hashtable/api_hashtable.h>
#include <flipper_application/api_hashtable/compilesort.hpp>
/*
* This file contains an implementation of a symbol table
* with private app's symbols. It is used by composite API resolver
* to load plugins that use internal application's APIs.
*/
#include "app_api_table_i.h"
static_assert(!has_hash_collisions(app_api_table), "Detected API method hash collision!");
constexpr HashtableApiInterface applicaton_hashtable_api_interface{
{
.api_version_major = 0,
.api_version_minor = 0,
/* generic resolver using pre-sorted array */
.resolver_callback = &elf_resolve_from_hashtable,
},
/* pointers to application's API table boundaries */
.table_cbegin = app_api_table.cbegin(),
.table_cend = app_api_table.cend(),
};
/* Casting to generic resolver to use in Composite API resolver */
extern "C" const ElfApiInterface* const application_api_interface =
&applicaton_hashtable_api_interface;

View File

@@ -1,13 +0,0 @@
#include "app_api.h"
/*
* A list of app's private functions and objects to expose for plugins.
* It is used to generate a table of symbols for import resolver to use.
* TBD: automatically generate this table from app's header files
*/
static constexpr auto app_api_table = sort(create_array_t<sym_entry>(
API_METHOD(app_api_accumulator_set, void, (uint32_t)),
API_METHOD(app_api_accumulator_get, uint32_t, ()),
API_METHOD(app_api_accumulator_add, void, (uint32_t)),
API_METHOD(app_api_accumulator_sub, void, (uint32_t)),
API_METHOD(app_api_accumulator_mul, void, (uint32_t))));

View File

@@ -1,24 +0,0 @@
App(
appid="example_advanced_plugins",
name="Example: advanced plugins",
apptype=FlipperAppType.EXTERNAL,
entry_point="example_advanced_plugins_app",
stack_size=2 * 1024,
fap_category="Examples",
)
App(
appid="advanced_plugin1",
apptype=FlipperAppType.PLUGIN,
entry_point="advanced_plugin1_ep",
requires=["example_advanced_plugins"],
sources=["plugin1.c"],
)
App(
appid="advanced_plugin2",
apptype=FlipperAppType.PLUGIN,
entry_point="advanced_plugin2_ep",
requires=["example_advanced_plugins"],
sources=["plugin2.c"],
)

View File

@@ -1,48 +0,0 @@
#include "app_api.h"
#include "plugin_interface.h"
#include "app_api_interface.h"
#include <flipper_application/flipper_application.h>
#include <flipper_application/plugins/plugin_manager.h>
#include <flipper_application/plugins/composite_resolver.h>
#include <loader/firmware_api/firmware_api.h>
#define TAG "example_advanced_plugins"
int32_t example_advanced_plugins_app(void* p) {
UNUSED(p);
FURI_LOG_I(TAG, "Starting");
CompositeApiResolver* resolver = composite_api_resolver_alloc();
composite_api_resolver_add(resolver, firmware_api_interface);
composite_api_resolver_add(resolver, application_api_interface);
PluginManager* manager = plugin_manager_alloc(
PLUGIN_APP_ID, PLUGIN_API_VERSION, composite_api_resolver_get(resolver));
do {
if(plugin_manager_load_all(manager, APP_DATA_PATH("plugins")) != PluginManagerErrorNone) {
FURI_LOG_E(TAG, "Failed to load all libs");
break;
}
uint32_t plugin_count = plugin_manager_get_count(manager);
FURI_LOG_I(TAG, "Loaded libs: %lu", plugin_count);
for(uint32_t i = 0; i < plugin_count; i++) {
const AdvancedPlugin* plugin = plugin_manager_get_ep(manager, i);
FURI_LOG_I(TAG, "plugin name: %s. Calling methods", plugin->name);
plugin->method1(228);
plugin->method2();
FURI_LOG_I(TAG, "Accumulator: %lu", app_api_accumulator_get());
}
} while(0);
plugin_manager_free(manager);
composite_api_resolver_free(resolver);
FURI_LOG_I(TAG, "Goodbye!");
return 0;
}

View File

@@ -1,40 +0,0 @@
/*
* This plugin uses both firmware's API interface and private application headers.
* It can be loaded by a plugin manager that uses CompoundApiInterface,
* which combines both interfaces.
*/
#include "app_api.h"
#include "plugin_interface.h"
#include <flipper_application/flipper_application.h>
#include <furi.h>
static void advanced_plugin1_method1(int arg1) {
/* This function is implemented inside host application */
app_api_accumulator_add(arg1);
}
static void advanced_plugin1_method2() {
/* Accumulator value is stored inside host application */
FURI_LOG_I("TEST", "Plugin 1, accumulator: %lu", app_api_accumulator_get());
}
/* Actual implementation of app<>plugin interface */
static const AdvancedPlugin advanced_plugin1 = {
.name = "Advanced Plugin 1",
.method1 = &advanced_plugin1_method1,
.method2 = &advanced_plugin1_method2,
};
/* Plugin descriptor to comply with basic plugin specification */
static const FlipperAppPluginDescriptor advanced_plugin1_descriptor = {
.appid = PLUGIN_APP_ID,
.ep_api_version = PLUGIN_API_VERSION,
.entry_point = &advanced_plugin1,
};
/* Plugin entry point - must return a pointer to const descriptor */
const FlipperAppPluginDescriptor* advanced_plugin1_ep() {
return &advanced_plugin1_descriptor;
}

View File

@@ -1,40 +0,0 @@
/*
* This plugin uses both firmware's API interface and private application headers.
* It can be loaded by a plugin manager that uses CompoundApiInterface,
* which combines both interfaces.
*/
#include "app_api.h"
#include "plugin_interface.h"
#include <flipper_application/flipper_application.h>
#include <furi.h>
static void advanced_plugin2_method1(int arg1) {
/* This function is implemented inside host application */
app_api_accumulator_mul(arg1);
}
static void advanced_plugin2_method2() {
/* Accumulator value is stored inside host application */
FURI_LOG_I("TEST", "Plugin 2, accumulator: %lu", app_api_accumulator_get());
}
/* Actual implementation of app<>plugin interface */
static const AdvancedPlugin advanced_plugin2 = {
.name = "Advanced Plugin 2",
.method1 = &advanced_plugin2_method1,
.method2 = &advanced_plugin2_method2,
};
/* Plugin descriptor to comply with basic plugin specification */
static const FlipperAppPluginDescriptor advanced_plugin2_descriptor = {
.appid = PLUGIN_APP_ID,
.ep_api_version = PLUGIN_API_VERSION,
.entry_point = &advanced_plugin2,
};
/* Plugin entry point - must return a pointer to const descriptor */
const FlipperAppPluginDescriptor* advanced_plugin2_ep() {
return &advanced_plugin2_descriptor;
}

View File

@@ -1,12 +0,0 @@
#pragma once
/* Common interface between a plugin and host applicaion */
#define PLUGIN_APP_ID "example_plugins_advanced"
#define PLUGIN_API_VERSION 1
typedef struct {
const char* name;
void (*method1)(int);
void (*method2)();
} AdvancedPlugin;

View File

@@ -1,6 +0,0 @@
# Placeholder
App(
appid="external_apps",
name="External apps bundle",
apptype=FlipperAppType.METAPACKAGE,
)

View File

@@ -1,24 +0,0 @@
App(
appid="hid_usb",
name="USB Keyboard & Mouse",
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_usb_app",
stack_size=1 * 1024,
fap_category="Misc",
fap_icon="hid_usb_10px.png",
fap_icon_assets="assets",
fap_icon_assets_symbol="hid",
)
App(
appid="hid_ble",
name="Bluetooth Remote",
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_ble_app",
stack_size=1 * 1024,
fap_category="Misc",
fap_icon="hid_ble_10px.png",
fap_icon_assets="assets",
fap_icon_assets_symbol="hid",
)

View File

@@ -1,43 +0,0 @@
#include "lightmeter_helper.h"
#include "lightmeter_config.h"
extern const float aperture_numbers[];
extern const float speed_numbers[];
float lux2ev(float lux) {
return log2(lux / 2.5);
}
float getMinDistance(float x, float v1, float v2) {
if(x - v1 > v2 - x) {
return v2;
}
return v1;
}
float normalizeAperture(float a) {
for(int i = 0; i < AP_NUM; i++) {
float a1 = aperture_numbers[i];
float a2 = aperture_numbers[i + 1];
if(a1 < a && a2 >= a) {
return getMinDistance(a, a1, a2);
}
}
return 0;
}
float normalizeTime(float a) {
for(int i = 0; i < SPEED_NUM; i++) {
float a1 = speed_numbers[i];
float a2 = speed_numbers[i + 1];
if(a1 < a && a2 >= a) {
return getMinDistance(a, a1, a2);
}
}
return 0;
}

View File

@@ -1,8 +0,0 @@
#include "picopass_keys.h"
const uint8_t picopass_iclass_key[] = {0xaf, 0xa7, 0x85, 0xa7, 0xda, 0xb3, 0x33, 0x78};
const uint8_t picopass_factory_credit_key[] = {0x76, 0x65, 0x54, 0x43, 0x32, 0x21, 0x10, 0x00};
const uint8_t picopass_factory_debit_key[] = {0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87};
const uint8_t picopass_xice_key[] = {0x20, 0x20, 0x66, 0x66, 0x66, 0x66, 0x88, 0x88};
const uint8_t picopass_xicl_key[] = {0x20, 0x20, 0x66, 0x66, 0x66, 0x66, 0x88, 0x88};
const uint8_t picopass_xics_key[] = {0x66, 0x66, 0x20, 0x20, 0x66, 0x66, 0x88, 0x88};

View File

@@ -1,10 +0,0 @@
#pragma once
#include "picopass_device.h"
extern const uint8_t picopass_iclass_key[PICOPASS_BLOCK_LEN];
extern const uint8_t picopass_factory_credit_key[PICOPASS_BLOCK_LEN];
extern const uint8_t picopass_factory_debit_key[PICOPASS_BLOCK_LEN];
extern const uint8_t picopass_xice_key[PICOPASS_BLOCK_LEN];
extern const uint8_t picopass_xicl_key[PICOPASS_BLOCK_LEN];
extern const uint8_t picopass_xics_key[PICOPASS_BLOCK_LEN];

View File

@@ -1,96 +0,0 @@
#include "../picopass_i.h"
#include "../picopass_keys.h"
enum SubmenuIndex {
SubmenuIndexWriteStandard,
SubmenuIndexWriteiCE,
SubmenuIndexWriteiCL,
SubmenuIndexWriteiCS,
SubmenuIndexWriteCustom, //TODO: user input of key
};
void picopass_scene_key_menu_submenu_callback(void* context, uint32_t index) {
Picopass* picopass = context;
view_dispatcher_send_custom_event(picopass->view_dispatcher, index);
}
void picopass_scene_key_menu_on_enter(void* context) {
Picopass* picopass = context;
Submenu* submenu = picopass->submenu;
submenu_add_item(
submenu,
"Write Standard",
SubmenuIndexWriteStandard,
picopass_scene_key_menu_submenu_callback,
picopass);
submenu_add_item(
submenu,
"Write iCE",
SubmenuIndexWriteiCE,
picopass_scene_key_menu_submenu_callback,
picopass);
submenu_add_item(
submenu,
"Write iCL",
SubmenuIndexWriteiCL,
picopass_scene_key_menu_submenu_callback,
picopass);
submenu_add_item(
submenu,
"Write iCS",
SubmenuIndexWriteiCS,
picopass_scene_key_menu_submenu_callback,
picopass);
submenu_set_selected_item(
picopass->submenu,
scene_manager_get_scene_state(picopass->scene_manager, PicopassSceneKeyMenu));
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewMenu);
}
bool picopass_scene_key_menu_on_event(void* context, SceneManagerEvent event) {
Picopass* picopass = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexWriteStandard) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteStandard);
memcpy(picopass->dev->dev_data.pacs.key, picopass_iclass_key, PICOPASS_BLOCK_LEN);
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCE) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xice_key, PICOPASS_BLOCK_LEN);
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCL) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xicl_key, PICOPASS_BLOCK_LEN);
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCS) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xics_key, PICOPASS_BLOCK_LEN);
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = scene_manager_search_and_switch_to_previous_scene(
picopass->scene_manager, PicopassSceneStart);
}
return consumed;
}
void picopass_scene_key_menu_on_exit(void* context) {
Picopass* picopass = context;
submenu_reset(picopass->submenu);
}

View File

@@ -1,80 +0,0 @@
#include "../picopass_i.h"
#include <dolphin/dolphin.h>
#include "../picopass_keys.h"
void picopass_scene_read_factory_success_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
furi_assert(context);
Picopass* picopass = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
}
}
void picopass_scene_read_factory_success_on_enter(void* context) {
Picopass* picopass = context;
FuriString* title = furi_string_alloc_set("Factory Default");
FuriString* subtitle = furi_string_alloc_set("");
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
// Send notification
notification_message(picopass->notifications, &sequence_success);
// Setup view
Widget* widget = picopass->widget;
//PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
PicopassBlock* AA1 = picopass->dev->dev_data.AA1;
uint8_t* configBlock = AA1[PICOPASS_CONFIG_BLOCK_INDEX].data;
uint8_t fuses = configBlock[7];
if((fuses & 0x80) == 0x80) {
furi_string_cat_printf(subtitle, "Personalization mode");
} else {
furi_string_cat_printf(subtitle, "Application mode");
}
widget_add_button_element(
widget,
GuiButtonTypeCenter,
"Write Standard iClass Key",
picopass_scene_read_factory_success_widget_callback,
picopass);
widget_add_string_element(
widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(title));
widget_add_string_element(
widget, 64, 20, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(subtitle));
furi_string_free(title);
furi_string_free(subtitle);
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
}
bool picopass_scene_read_factory_success_on_event(void* context, SceneManagerEvent event) {
Picopass* picopass = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
consumed = scene_manager_previous_scene(picopass->scene_manager);
} else if(event.event == GuiButtonTypeCenter) {
memcpy(picopass->dev->dev_data.pacs.key, picopass_iclass_key, PICOPASS_BLOCK_LEN);
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
}
}
return consumed;
}
void picopass_scene_read_factory_success_on_exit(void* context) {
Picopass* picopass = context;
// Clear view
widget_reset(picopass->widget);
}

View File

@@ -1,53 +0,0 @@
#include "../picopass_i.h"
#include <dolphin/dolphin.h>
void picopass_write_key_worker_callback(PicopassWorkerEvent event, void* context) {
UNUSED(event);
Picopass* picopass = context;
view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventWorkerExit);
}
void picopass_scene_write_key_on_enter(void* context) {
Picopass* picopass = context;
DOLPHIN_DEED(DolphinDeedNfcSave);
// Setup view
Popup* popup = picopass->popup;
popup_set_header(popup, "Writing\niClass\nkey", 68, 30, AlignLeft, AlignTop);
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
// Start worker
view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewPopup);
picopass_worker_start(
picopass->worker,
PicopassWorkerStateWriteKey,
&picopass->dev->dev_data,
picopass_write_key_worker_callback,
picopass);
picopass_blink_start(picopass);
}
bool picopass_scene_write_key_on_event(void* context, SceneManagerEvent event) {
Picopass* picopass = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == PicopassCustomEventWorkerExit) {
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteCardSuccess);
consumed = true;
}
}
return consumed;
}
void picopass_scene_write_key_on_exit(void* context) {
Picopass* picopass = context;
// Stop worker
picopass_worker_stop(picopass->worker);
// Clear view
popup_reset(picopass->popup);
picopass_blink_stop(picopass);
}

View File

@@ -1,52 +0,0 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

View File

@@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -1,17 +0,0 @@
# ARM SWD (Single Wire Debug) Probe
Modern microcontrollers have support for the two wire debug interface SWD, which makes wiring a lot simpler.
When reverse engineering, finding these two pins is a los easier than with JTAG, where you had to wire up twice or more pins. However, finding the two pins is still a bit of work, which gets simplified even more with this application.
This application tries to detect a valid SWD response on the wires you have picked and beeps when you have found the correct pins, showing the detected ID register and, more important, the SWD pinout. It doesn't matter which two pins you choose, just pick any two from the GPIOs on the breakout header.
To achieve this, the application sends packets and scans the response on all pins and elaborates the pins within a few retries. Using some kind of bisect pattern reduces this number to a hand full of tries, yielding in a seemingly instant detection.
For the user it is as simple as a continuity tester - wire up your two test needles (or accupuncture needles), connect the obvious GND pin and probe all test pads.
Now it depends on your bisect capabilities finding all pad combinations, how long it will take this time.
https://cdn.discordapp.com/attachments/954430078882816021/1071603366741938176/20230205_022641.mp4
https://cdn.discordapp.com/attachments/1071712925171056690/1072306469057347594/qFlipper_2023-02-07_01-01-24.mp4
Discussion thread: https://discord.com/channels/740930220399525928/1071712925171056690

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +0,0 @@
#ifndef __ADI_H__
#define __ADI_H__
#include "swd_probe_app.h"
#define ARM_ID 0x23B
#define ARCH_ID(architect, archid) ((architect) << 21) | (archid)
#define BIT(nr) (1UL << (nr))
#define ARM_CS_C9_DEVARCH_PRESENT BIT(20)
#define ARM_CS_C9_DEVARCH_ARCHITECT_MASK (0xFFE00000)
#define ARM_CS_C9_DEVARCH_ARCHID_MASK (0x0000FFFF)
#define DEVARCH_ID_MASK (ARM_CS_C9_DEVARCH_ARCHITECT_MASK | ARM_CS_C9_DEVARCH_ARCHID_MASK)
typedef struct {
uint16_t designer;
uint16_t part;
uint8_t revision;
uint8_t cmod;
uint8_t revand;
uint8_t size;
} pidr_data_t;
typedef enum { CIDR_CLASS_ROMTABLE = 0x01, CIDR_CLASS_CORESIGHT = 0x09 } cidr_classes_t;
uint32_t adi_romtable_entry_count(AppFSM* const ctx, uint32_t base);
uint32_t adi_romtable_get(AppFSM* const ctx, uint32_t base, uint32_t pos);
bool adi_is_romtable(AppFSM* const ctx, uint32_t base);
const char* adi_romtable_type(AppFSM* const ctx, uint32_t base);
const char* adi_romtable_full(AppFSM* const ctx, uint32_t base);
#endif

View File

@@ -1,12 +0,0 @@
App(
appid="swd_probe",
name="SWD Probe",
apptype=FlipperAppType.EXTERNAL,
entry_point="swd_probe_app_main",
requires=["notification", "gui", "storage", "dialogs", "cli"],
stack_size=2 * 1024,
order=10,
fap_icon="icons/app.png",
fap_category="GPIO",
fap_icon_assets="icons"
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 B

View File

@@ -1,26 +0,0 @@
/* https://github.com/openocd-org/openocd/blob/master/src/helper/ */
// SPDX-License-Identifier: GPL-2.0-or-later
/***************************************************************************
* Copyright (C) 2015 Andreas Fritiofson *
* andreas.fritiofson@gmail.com *
***************************************************************************/
#include "jep106.h"
static const char* const jep106[][126] = {
#include "jep106.inc"
};
const char* jep106_table_manufacturer(unsigned int bank, unsigned int id) {
if(id < 1 || id > 126) {
return "<invalid>";
}
/* index is zero based */
id--;
if(bank >= 14 || jep106[bank][id] == 0) return "<unknown>";
return jep106[bank][id];
}

View File

@@ -1,26 +0,0 @@
/* https://github.com/openocd-org/openocd/blob/master/src/helper/ */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/***************************************************************************
* Copyright (C) 2015 Andreas Fritiofson *
* andreas.fritiofson@gmail.com *
***************************************************************************/
#ifndef OPENOCD_HELPER_JEP106_H
#define OPENOCD_HELPER_JEP106_H
/**
* Get the manufacturer name associated with a JEP106 ID.
* @param bank The bank (number of continuation codes) of the manufacturer ID.
* @param id The 7-bit manufacturer ID (i.e. with parity stripped).
* @return A pointer to static const storage containing the name of the
* manufacturer associated with bank and id, or one of the strings
* "<invalid>" and "<unknown>".
*/
const char* jep106_table_manufacturer(unsigned int bank, unsigned int id);
static inline const char* jep106_manufacturer(unsigned int manufacturer) {
return jep106_table_manufacturer(manufacturer >> 7, manufacturer & 0x7f);
}
#endif /* OPENOCD_HELPER_JEP106_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,216 +0,0 @@
ply
format ascii 1.0
comment Created by Blender 3.3.1 - www.blender.org
element vertex 136
property float x
property float y
property float z
element face 70
property list uchar uint vertex_indices
end_header
1.000000 1.000000 0.152153
-1.000000 1.000000 0.152153
-1.000000 -1.000000 0.152153
1.000000 -1.000000 0.152153
1.000000 -1.000000 -0.185787
-1.000000 -1.000000 -0.185787
-1.000000 1.000000 -0.185787
1.000000 1.000000 -0.185787
-1.000043 -0.785071 -0.015780
-1.155724 -0.785071 -0.015780
-1.155724 -0.918718 -0.015780
-1.000043 -0.918718 -0.015780
-1.155724 -0.785071 0.127052
-1.000043 -0.785071 0.127052
-1.000043 -0.918718 0.127052
-1.155724 -0.918718 0.127052
-1.234192 -0.918846 -0.087021
-1.234397 -0.785201 -0.086336
-1.235319 -0.784943 -0.229143
-1.235114 -0.918588 -0.229828
-1.388133 -0.919573 -0.078673
-1.389056 -0.919314 -0.221479
-1.389261 -0.785669 -0.220795
-1.388338 -0.785927 -0.077988
-1.000043 -0.219627 -0.015780
-1.155724 -0.219627 -0.015780
-1.155724 -0.353273 -0.015780
-1.000043 -0.353273 -0.015780
-1.155724 -0.219627 0.127052
-1.000043 -0.219627 0.127052
-1.000043 -0.353273 0.127052
-1.155724 -0.353273 0.127052
-1.234192 -0.353402 -0.087021
-1.234397 -0.219756 -0.086336
-1.235319 -0.219498 -0.229143
-1.235114 -0.353143 -0.229828
-1.388133 -0.354128 -0.078673
-1.389056 -0.353870 -0.221479
-1.389261 -0.220224 -0.220795
-1.388338 -0.220482 -0.077988
-1.000043 0.345818 -0.015780
-1.155724 0.345818 -0.015780
-1.155724 0.212172 -0.015780
-1.000043 0.212172 -0.015780
-1.155724 0.345818 0.127052
-1.000043 0.345818 0.127052
-1.000043 0.212172 0.127052
-1.155724 0.212172 0.127052
-1.234192 0.212043 -0.087021
-1.234397 0.345689 -0.086336
-1.235319 0.345947 -0.229143
-1.235114 0.212301 -0.229828
-1.388133 0.211317 -0.078673
-1.389056 0.211575 -0.221479
-1.389261 0.345221 -0.220795
-1.388338 0.344962 -0.077988
-1.000043 0.911263 -0.015780
-1.155724 0.911263 -0.015780
-1.155724 0.777617 -0.015780
-1.000043 0.777617 -0.015780
-1.155724 0.911263 0.127052
-1.000043 0.911263 0.127052
-1.000043 0.777617 0.127052
-1.155724 0.777617 0.127052
-1.234192 0.777488 -0.087021
-1.234397 0.911133 -0.086336
-1.235319 0.911392 -0.229143
-1.235114 0.777746 -0.229828
-1.388133 0.776762 -0.078673
-1.389056 0.777020 -0.221479
-1.389261 0.910665 -0.220795
-1.388338 0.910407 -0.077988
1.000043 -0.785071 -0.015780
1.000043 -0.918718 -0.015780
1.155723 -0.918718 -0.015780
1.155723 -0.785071 -0.015780
1.155723 -0.785071 0.127052
1.155723 -0.918718 0.127052
1.000043 -0.918718 0.127052
1.000043 -0.785071 0.127052
1.234397 -0.785201 -0.086336
1.234192 -0.918846 -0.087021
1.235114 -0.918588 -0.229828
1.235319 -0.784943 -0.229143
1.388133 -0.919573 -0.078673
1.388338 -0.785927 -0.077988
1.389260 -0.785669 -0.220795
1.389056 -0.919314 -0.221479
1.000043 -0.219627 -0.015780
1.000043 -0.353273 -0.015780
1.155723 -0.353273 -0.015780
1.155723 -0.219627 -0.015780
1.155723 -0.219627 0.127052
1.155723 -0.353273 0.127052
1.000043 -0.353273 0.127052
1.000043 -0.219627 0.127052
1.234397 -0.219756 -0.086336
1.234192 -0.353402 -0.087021
1.235114 -0.353143 -0.229828
1.235319 -0.219498 -0.229143
1.388133 -0.354128 -0.078673
1.388338 -0.220482 -0.077988
1.389260 -0.220224 -0.220795
1.389056 -0.353870 -0.221479
1.000043 0.345818 -0.015780
1.000043 0.212172 -0.015780
1.155723 0.212172 -0.015780
1.155723 0.345818 -0.015780
1.155723 0.345818 0.127052
1.155723 0.212172 0.127052
1.000043 0.212172 0.127052
1.000043 0.345818 0.127052
1.234397 0.345689 -0.086336
1.234192 0.212043 -0.087021
1.235114 0.212301 -0.229828
1.235319 0.345947 -0.229143
1.388133 0.211317 -0.078673
1.388338 0.344962 -0.077988
1.389260 0.345221 -0.220795
1.389056 0.211575 -0.221479
1.000043 0.911263 -0.015780
1.000043 0.777616 -0.015780
1.155723 0.777616 -0.015780
1.155723 0.911263 -0.015780
1.155723 0.911263 0.127052
1.155723 0.777616 0.127052
1.000043 0.777616 0.127052
1.000043 0.911263 0.127052
1.234397 0.911133 -0.086336
1.234192 0.777488 -0.087021
1.235114 0.777746 -0.229828
1.235319 0.911392 -0.229143
1.388133 0.776762 -0.078673
1.388338 0.910407 -0.077988
1.389260 0.910665 -0.220795
1.389056 0.777020 -0.221479
4 0 1 2 3
4 4 3 2 5
4 5 2 1 6
4 6 7 4 5
4 7 0 3 4
4 6 1 0 7
4 8 9 10 11
4 12 13 14 15
4 13 8 11 14
4 12 15 16 17
4 10 9 18 19
4 20 21 22 23
4 17 16 20 23
4 19 18 22 21
4 24 25 26 27
4 28 29 30 31
4 29 24 27 30
4 28 31 32 33
4 26 25 34 35
4 36 37 38 39
4 33 32 36 39
4 35 34 38 37
4 40 41 42 43
4 44 45 46 47
4 45 40 43 46
4 44 47 48 49
4 42 41 50 51
4 52 53 54 55
4 49 48 52 55
4 51 50 54 53
4 56 57 58 59
4 60 61 62 63
4 61 56 59 62
4 60 63 64 65
4 58 57 66 67
4 68 69 70 71
4 65 64 68 71
4 67 66 70 69
4 72 73 74 75
4 76 77 78 79
4 79 78 73 72
4 76 80 81 77
4 74 82 83 75
4 84 85 86 87
4 80 85 84 81
4 82 87 86 83
4 88 89 90 91
4 92 93 94 95
4 95 94 89 88
4 92 96 97 93
4 90 98 99 91
4 100 101 102 103
4 96 101 100 97
4 98 103 102 99
4 104 105 106 107
4 108 109 110 111
4 111 110 105 104
4 108 112 113 109
4 106 114 115 107
4 116 117 118 119
4 112 117 116 113
4 114 119 118 115
4 120 121 122 123
4 124 125 126 127
4 127 126 121 120
4 124 128 129 125
4 122 130 131 123
4 132 133 134 135
4 128 133 132 129
4 130 135 134 131

View File

@@ -1,39 +0,0 @@
#!/usr/bin/python
import plyfile
import argparse
parser = argparse.ArgumentParser(description='Convert a PLY file to C arrays.')
parser.add_argument('input_file', help='the input PLY file')
parser.add_argument('output_file', help='the output C file')
args = parser.parse_args()
# Open the PLY file
plydata = plyfile.PlyData.read(args.input_file)
# Extract the vertices
vertices = plydata['vertex'].data
num_vertices = len(vertices)
with open(args.output_file, 'w') as f:
f.write('#define NUM_VERTICES %d\n' % num_vertices)
f.write('float vertexCoords[NUM_VERTICES][3] = {\n')
for i in range(num_vertices):
x, y, z = vertices[i][0], vertices[i][1], vertices[i][2]
f.write(' {%f, %f, %f},\n' % (x, y, z))
f.write('};')
# Extract the faces
faces = plydata['face'].data
num_faces = len(faces)
f.write('int edgeIndices[][3] = {\n')
for i in range(num_faces):
face = faces[i][0]
if len(face) == 3:
f.write(' {%d, %d, %d},\n' % (face[0], face[1], face[2]))
elif len(face) == 4:
# Convert 4-index face to 2-index edges
edges = [(face[0], face[1]), (face[1], face[2]), (face[2], face[3]), (face[3], face[0])]
for edge in edges:
f.write(' {%d, %d},\n' % (edge[0], edge[1]))
f.write('};\n')

View File

@@ -1,108 +0,0 @@
#define NUM_VERTICES 136
float vertexCoords[NUM_VERTICES][3] = {
{1.000000, 1.000000, 0.152153}, {-1.000000, 1.000000, 0.152153},
{-1.000000, -1.000000, 0.152153}, {1.000000, -1.000000, 0.152153},
{1.000000, -1.000000, -0.185787}, {-1.000000, -1.000000, -0.185787},
{-1.000000, 1.000000, -0.185787}, {1.000000, 1.000000, -0.185787},
{-1.000043, -0.785071, -0.015780}, {-1.155724, -0.785071, -0.015780},
{-1.155724, -0.918718, -0.015780}, {-1.000043, -0.918718, -0.015780},
{-1.155724, -0.785071, 0.127052}, {-1.000043, -0.785071, 0.127052},
{-1.000043, -0.918718, 0.127052}, {-1.155724, -0.918718, 0.127052},
{-1.234192, -0.918846, -0.087021}, {-1.234397, -0.785201, -0.086336},
{-1.235319, -0.784943, -0.229143}, {-1.235114, -0.918588, -0.229828},
{-1.388133, -0.919573, -0.078673}, {-1.389056, -0.919314, -0.221479},
{-1.389261, -0.785669, -0.220795}, {-1.388338, -0.785927, -0.077988},
{-1.000043, -0.219627, -0.015780}, {-1.155724, -0.219627, -0.015780},
{-1.155724, -0.353273, -0.015780}, {-1.000043, -0.353273, -0.015780},
{-1.155724, -0.219627, 0.127052}, {-1.000043, -0.219627, 0.127052},
{-1.000043, -0.353273, 0.127052}, {-1.155724, -0.353273, 0.127052},
{-1.234192, -0.353402, -0.087021}, {-1.234397, -0.219756, -0.086336},
{-1.235319, -0.219498, -0.229143}, {-1.235114, -0.353143, -0.229828},
{-1.388133, -0.354128, -0.078673}, {-1.389056, -0.353870, -0.221479},
{-1.389261, -0.220224, -0.220795}, {-1.388338, -0.220482, -0.077988},
{-1.000043, 0.345818, -0.015780}, {-1.155724, 0.345818, -0.015780},
{-1.155724, 0.212172, -0.015780}, {-1.000043, 0.212172, -0.015780},
{-1.155724, 0.345818, 0.127052}, {-1.000043, 0.345818, 0.127052},
{-1.000043, 0.212172, 0.127052}, {-1.155724, 0.212172, 0.127052},
{-1.234192, 0.212043, -0.087021}, {-1.234397, 0.345689, -0.086336},
{-1.235319, 0.345947, -0.229143}, {-1.235114, 0.212301, -0.229828},
{-1.388133, 0.211317, -0.078673}, {-1.389056, 0.211575, -0.221479},
{-1.389261, 0.345221, -0.220795}, {-1.388338, 0.344962, -0.077988},
{-1.000043, 0.911263, -0.015780}, {-1.155724, 0.911263, -0.015780},
{-1.155724, 0.777617, -0.015780}, {-1.000043, 0.777617, -0.015780},
{-1.155724, 0.911263, 0.127052}, {-1.000043, 0.911263, 0.127052},
{-1.000043, 0.777617, 0.127052}, {-1.155724, 0.777617, 0.127052},
{-1.234192, 0.777488, -0.087021}, {-1.234397, 0.911133, -0.086336},
{-1.235319, 0.911392, -0.229143}, {-1.235114, 0.777746, -0.229828},
{-1.388133, 0.776762, -0.078673}, {-1.389056, 0.777020, -0.221479},
{-1.389261, 0.910665, -0.220795}, {-1.388338, 0.910407, -0.077988},
{1.000043, -0.785071, -0.015780}, {1.000043, -0.918718, -0.015780},
{1.155723, -0.918718, -0.015780}, {1.155723, -0.785071, -0.015780},
{1.155723, -0.785071, 0.127052}, {1.155723, -0.918718, 0.127052},
{1.000043, -0.918718, 0.127052}, {1.000043, -0.785071, 0.127052},
{1.234397, -0.785201, -0.086336}, {1.234192, -0.918846, -0.087021},
{1.235114, -0.918588, -0.229828}, {1.235319, -0.784943, -0.229143},
{1.388133, -0.919573, -0.078673}, {1.388338, -0.785927, -0.077988},
{1.389260, -0.785669, -0.220795}, {1.389056, -0.919314, -0.221479},
{1.000043, -0.219627, -0.015780}, {1.000043, -0.353273, -0.015780},
{1.155723, -0.353273, -0.015780}, {1.155723, -0.219627, -0.015780},
{1.155723, -0.219627, 0.127052}, {1.155723, -0.353273, 0.127052},
{1.000043, -0.353273, 0.127052}, {1.000043, -0.219627, 0.127052},
{1.234397, -0.219756, -0.086336}, {1.234192, -0.353402, -0.087021},
{1.235114, -0.353143, -0.229828}, {1.235319, -0.219498, -0.229143},
{1.388133, -0.354128, -0.078673}, {1.388338, -0.220482, -0.077988},
{1.389260, -0.220224, -0.220795}, {1.389056, -0.353870, -0.221479},
{1.000043, 0.345818, -0.015780}, {1.000043, 0.212172, -0.015780},
{1.155723, 0.212172, -0.015780}, {1.155723, 0.345818, -0.015780},
{1.155723, 0.345818, 0.127052}, {1.155723, 0.212172, 0.127052},
{1.000043, 0.212172, 0.127052}, {1.000043, 0.345818, 0.127052},
{1.234397, 0.345689, -0.086336}, {1.234192, 0.212043, -0.087021},
{1.235114, 0.212301, -0.229828}, {1.235319, 0.345947, -0.229143},
{1.388133, 0.211317, -0.078673}, {1.388338, 0.344962, -0.077988},
{1.389260, 0.345221, -0.220795}, {1.389056, 0.211575, -0.221479},
{1.000043, 0.911263, -0.015780}, {1.000043, 0.777616, -0.015780},
{1.155723, 0.777616, -0.015780}, {1.155723, 0.911263, -0.015780},
{1.155723, 0.911263, 0.127052}, {1.155723, 0.777616, 0.127052},
{1.000043, 0.777616, 0.127052}, {1.000043, 0.911263, 0.127052},
{1.234397, 0.911133, -0.086336}, {1.234192, 0.777488, -0.087021},
{1.235114, 0.777746, -0.229828}, {1.235319, 0.911392, -0.229143},
{1.388133, 0.776762, -0.078673}, {1.388338, 0.910407, -0.077988},
{1.389260, 0.910665, -0.220795}, {1.389056, 0.777020, -0.221479},
};
int edgeIndices[][3] = {
{0, 1}, {1, 2}, {2, 3}, {3, 0}, {4, 3}, {3, 2}, {2, 5}, {5, 4},
{5, 2}, {2, 1}, {1, 6}, {6, 5}, {6, 7}, {7, 4}, {4, 5}, {5, 6},
{7, 0}, {0, 3}, {3, 4}, {4, 7}, {6, 1}, {1, 0}, {0, 7}, {7, 6},
{8, 9}, {9, 10}, {10, 11}, {11, 8}, {12, 13}, {13, 14}, {14, 15}, {15, 12},
{13, 8}, {8, 11}, {11, 14}, {14, 13}, {12, 15}, {15, 16}, {16, 17}, {17, 12},
{10, 9}, {9, 18}, {18, 19}, {19, 10}, {20, 21}, {21, 22}, {22, 23}, {23, 20},
{17, 16}, {16, 20}, {20, 23}, {23, 17}, {19, 18}, {18, 22}, {22, 21}, {21, 19},
{24, 25}, {25, 26}, {26, 27}, {27, 24}, {28, 29}, {29, 30}, {30, 31}, {31, 28},
{29, 24}, {24, 27}, {27, 30}, {30, 29}, {28, 31}, {31, 32}, {32, 33}, {33, 28},
{26, 25}, {25, 34}, {34, 35}, {35, 26}, {36, 37}, {37, 38}, {38, 39}, {39, 36},
{33, 32}, {32, 36}, {36, 39}, {39, 33}, {35, 34}, {34, 38}, {38, 37}, {37, 35},
{40, 41}, {41, 42}, {42, 43}, {43, 40}, {44, 45}, {45, 46}, {46, 47}, {47, 44},
{45, 40}, {40, 43}, {43, 46}, {46, 45}, {44, 47}, {47, 48}, {48, 49}, {49, 44},
{42, 41}, {41, 50}, {50, 51}, {51, 42}, {52, 53}, {53, 54}, {54, 55}, {55, 52},
{49, 48}, {48, 52}, {52, 55}, {55, 49}, {51, 50}, {50, 54}, {54, 53}, {53, 51},
{56, 57}, {57, 58}, {58, 59}, {59, 56}, {60, 61}, {61, 62}, {62, 63}, {63, 60},
{61, 56}, {56, 59}, {59, 62}, {62, 61}, {60, 63}, {63, 64}, {64, 65}, {65, 60},
{58, 57}, {57, 66}, {66, 67}, {67, 58}, {68, 69}, {69, 70}, {70, 71}, {71, 68},
{65, 64}, {64, 68}, {68, 71}, {71, 65}, {67, 66}, {66, 70}, {70, 69}, {69, 67},
{72, 73}, {73, 74}, {74, 75}, {75, 72}, {76, 77}, {77, 78}, {78, 79}, {79, 76},
{79, 78}, {78, 73}, {73, 72}, {72, 79}, {76, 80}, {80, 81}, {81, 77}, {77, 76},
{74, 82}, {82, 83}, {83, 75}, {75, 74}, {84, 85}, {85, 86}, {86, 87}, {87, 84},
{80, 85}, {85, 84}, {84, 81}, {81, 80}, {82, 87}, {87, 86}, {86, 83}, {83, 82},
{88, 89}, {89, 90}, {90, 91}, {91, 88}, {92, 93}, {93, 94}, {94, 95}, {95, 92},
{95, 94}, {94, 89}, {89, 88}, {88, 95}, {92, 96}, {96, 97}, {97, 93}, {93, 92},
{90, 98}, {98, 99}, {99, 91}, {91, 90}, {100, 101}, {101, 102}, {102, 103}, {103, 100},
{96, 101}, {101, 100}, {100, 97}, {97, 96}, {98, 103}, {103, 102}, {102, 99}, {99, 98},
{104, 105}, {105, 106}, {106, 107}, {107, 104}, {108, 109}, {109, 110}, {110, 111}, {111, 108},
{111, 110}, {110, 105}, {105, 104}, {104, 111}, {108, 112}, {112, 113}, {113, 109}, {109, 108},
{106, 114}, {114, 115}, {115, 107}, {107, 106}, {116, 117}, {117, 118}, {118, 119}, {119, 116},
{112, 117}, {117, 116}, {116, 113}, {113, 112}, {114, 119}, {119, 118}, {118, 115}, {115, 114},
{120, 121}, {121, 122}, {122, 123}, {123, 120}, {124, 125}, {125, 126}, {126, 127}, {127, 124},
{127, 126}, {126, 121}, {121, 120}, {120, 127}, {124, 128}, {128, 129}, {129, 125}, {125, 124},
{122, 130}, {130, 131}, {131, 123}, {123, 122}, {132, 133}, {133, 134}, {134, 135}, {135, 132},
{128, 133}, {133, 132}, {132, 129}, {129, 128}, {130, 135}, {135, 134}, {134, 131}, {131, 130},
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,248 +0,0 @@
#ifndef __ARHA_FLIPPERAPP_DEMO
#define __ARHA_FLIPPERAPP_DEMO
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_speaker.h>
#include <gui/gui.h>
#include <gui/elements.h>
#include <dialogs/dialogs.h>
#include <input/input.h>
#include <storage/storage.h>
#include <dolphin/dolphin.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/transmitter.h>
#include <lib/subghz/subghz_file_encoder_worker.h>
#include <notification/notification.h>
#include "usb_uart.h"
#define TAG "SWD"
/* short debug message */
#define DBGS(format) furi_log_print_format(FuriLogLevelDebug, TAG, "%s: " format, __FUNCTION__)
/* formatted debug message */
#define DBG(format, ...) \
furi_log_print_format(FuriLogLevelDebug, TAG, "%s: " format, __FUNCTION__, __VA_ARGS__)
/* log message*/
#define LOG(...) furi_log_print_format(FuriLogLevelDefault, TAG, __VA_ARGS__)
#define COUNT(x) ((size_t)(sizeof(x) / sizeof((x)[0])))
#define ARRAY_SIZE(x) COUNT(x)
#define SWD_DELAY_US 0
#define TIMER_HZ 25
#define TIMEOUT 3
#define QUEUE_SIZE 8
#define IDLE_BITS 8
#define CLOCK_DELAY 0
#define MAX_FILE_LENGTH 128
#define SCRIPT_MAX_LINES 1000
typedef enum {
ModePageScan = 0,
ModePageFound = 1,
ModePageDPRegs = 2,
ModePageDPID = 3,
ModePageAPID = 4,
ModePageCount = 5,
ModePageHexDump = 0x100,
ModePageScript = 0x101,
ModePageCoresight = 0x102,
} ModePages;
#define CDBGPWRUPREQ (1 << 28)
#define CDBGPWRUPACK (1 << 29)
#define CSYSPWRUPREQ (1 << 30)
#define CSYSPWRUPACK (1 << 31)
#define WDATAERR (1 << 7)
#define STICKYERR (1 << 5)
#define STAT_ERROR_FLAGS (WDATAERR | STICKYERR)
#define REG_IDCODE 0x00
#define REG_CTRLSTAT 0x01
#define REG_CTRLSTAT_BANK 0x00
#define REG_DLCR 0x01
#define REG_DLCR_BANK 0x01
#define REG_TARGETID 0x01
#define REG_TARGETID_BANK 0x02
#define REG_DLPIDR 0x01
#define REG_DLPIDR_BANK 0x03
#define REG_EVENTSTAT 0x01
#define REG_EVENTSTAT_BANK 0x04
#define REG_SELECT 0x02
#define MEMAP_CSW 0x00
#define MEMAP_TAR 0x04
#define MEMAP_DRW 0x0C
#define AP_IDR 0xFC
#define AP_BASE 0xF8
#define SCS_CPUID 0xE000ED00u
#define SCS_CPACR 0xE000ED88u
#define SCS_DHCSR 0xE000EDF0u
#define SCS_DHCSR_S_HALT (1u << 17)
#define SCS_DHCSR_C_MASKINTS (1u << 3)
#define SCS_DHCSR_C_STEP (1u << 2)
#define SCS_DHCSR_C_HALT (1u << 1)
#define SCS_DHCSR_C_DEBUGEN (1u << 0)
#define SCS_DHCSR_KEY 0xA05F0000u
#define SCS_DCRSR 0xE000EDF4u
#define SCS_DCRSR_RD 0x00000000u
#define SCS_DCRSR_WR 0x00010000u
#define SCS_DCRDR 0xE000EDF8u
#define SCS_DEMCR 0xE000EDFCu
typedef enum { KeyNone, KeyUp, KeyRight, KeyDown, KeyLeft, KeyOK } KeyCode;
typedef enum {
EventTimerTick,
EventKeyPress,
} EventType;
typedef struct {
EventType type;
InputEvent input;
} AppEvent;
typedef struct {
uint32_t ctrlstat;
bool ctrlstat_ok;
uint32_t dlcr;
bool dlcr_ok;
uint32_t dlpidr;
bool dlpidr_ok;
uint32_t dpidr;
bool dpidr_ok;
uint32_t eventstat;
bool eventstat_ok;
uint32_t select;
bool select_ok;
uint32_t targetid;
bool targetid_ok;
} swd_dpreg_t;
typedef struct {
bool ok;
bool tested;
uint8_t revision;
uint16_t designer;
uint8_t class;
uint8_t variant;
uint8_t type;
uint32_t base;
} swd_apidr_info_t;
typedef struct {
uint8_t revision;
uint8_t partno;
uint8_t version;
uint16_t designer;
} swd_dpidr_info_t;
typedef struct {
uint8_t revision;
uint16_t partno;
uint16_t designer;
} swd_targetid_info_t;
typedef struct sScriptContext ScriptContext;
typedef struct {
Storage* storage;
Gui* gui;
DialogsApp* dialogs;
NotificationApp* notification;
FuriTimer* timer;
UsbUart* uart;
ViewPort* view_port;
FuriMessageQueue* event_queue;
FuriMutex* swd_mutex;
FuriMutex* gui_mutex;
swd_targetid_info_t targetid_info;
swd_dpidr_info_t dpidr_info;
swd_dpreg_t dp_regs;
swd_apidr_info_t apidr_info[256];
ScriptContext* script;
ScriptContext* commandline;
uint8_t timeout_overdue;
uint32_t loop_count;
uint8_t current_mask_id;
uint32_t current_mask;
uint8_t io_swc;
uint8_t io_swd;
uint8_t io_num_swc;
uint8_t io_num_swd;
int32_t detected_timeout;
uint32_t swd_clock_delay;
uint32_t swd_idle_bits;
bool detected;
bool detected_device;
bool detected_notified;
uint32_t mode_page;
uint8_t ap_pos;
uint8_t ap_scanned;
uint32_t coresight_pos[16];
uint32_t coresight_count[16];
uint8_t coresight_level;
uint32_t coresight_bases[16];
uint32_t hex_addr;
uint8_t hex_select;
uint8_t hex_buffer[32];
uint8_t hex_buffer_valid[8];
char state_string[64];
char script_detected[MAX_FILE_LENGTH];
bool script_detected_executed;
} AppFSM;
struct sScriptContext {
AppFSM* app;
ScriptContext* parent;
char filename[MAX_FILE_LENGTH];
/* when used with string input */
char line_data[128];
uint64_t line_pos;
/* when used with file input */
File* script_file;
uint64_t position;
uint32_t selected_ap;
uint32_t max_tries;
uint32_t block_size;
bool abort;
bool restart;
bool errors_ignore;
bool status_ignore;
bool goto_active;
char goto_label[64];
};
typedef struct {
const char* prefix;
bool (*func)(ScriptContext* ctx);
} ScriptFunctionInfo;
uint8_t swd_read_memory(AppFSM* const ctx, uint8_t ap, uint32_t address, uint32_t* data);
#endif

View File

@@ -1,229 +0,0 @@
#include <stdlib.h>
#include "usb_uart.h"
#include "furi_hal.h"
#include <furi_hal_usb_cdc.h>
#include "usb_cdc.h"
#include "cli/cli_vcp.h"
#include <toolbox/api_lock.h>
#include "cli/cli.h"
#define USB_CDC_PKT_LEN CDC_DATA_SZ
#define USB_UART_RX_BUF_SIZE (USB_CDC_PKT_LEN * 5)
#define USB_CDC_BIT_DTR (1 << 0)
#define USB_CDC_BIT_RTS (1 << 1)
typedef enum {
WorkerEvtStop = (1 << 0),
WorkerEvtCdcRx = (1 << 1),
WorkerEvtCfgChange = (1 << 2)
} WorkerEvtFlags;
#define WORKER_ALL_EVENTS (WorkerEvtStop | WorkerEvtCfgChange | WorkerEvtCdcRx)
struct UsbUart {
UsbUartConfig cfg;
UsbUartConfig cfg_new;
FuriThread* thread;
FuriMutex* usb_mutex;
FuriSemaphore* tx_sem;
UsbUartState st;
FuriApiLock cfg_lock;
uint8_t rx_buf[USB_CDC_PKT_LEN];
};
static void vcp_on_cdc_tx_complete(void* context);
static void vcp_on_cdc_rx(void* context);
static void vcp_state_callback(void* context, uint8_t state);
static void vcp_on_cdc_control_line(void* context, uint8_t state);
static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config);
static const CdcCallbacks cdc_cb = {
.tx_ep_callback = &vcp_on_cdc_tx_complete,
.rx_ep_callback = &vcp_on_cdc_rx,
.state_callback = &vcp_state_callback,
.ctrl_line_callback = &vcp_on_cdc_control_line,
.config_callback = &vcp_on_line_config};
static void usb_uart_vcp_init(UsbUart* usb_uart, uint8_t vcp_ch) {
furi_hal_usb_unlock();
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
if(vcp_ch == 0) {
furi_check(furi_hal_usb_set_config(&usb_cdc_single, NULL) == true);
} else {
furi_check(furi_hal_usb_set_config(&usb_cdc_dual, NULL) == true);
cli_session_open(cli, &cli_vcp);
}
furi_record_close(RECORD_CLI);
furi_hal_cdc_set_callbacks(vcp_ch, (CdcCallbacks*)&cdc_cb, usb_uart);
}
static void usb_uart_vcp_deinit(UsbUart* usb_uart, uint8_t vcp_ch) {
UNUSED(usb_uart);
furi_hal_cdc_set_callbacks(vcp_ch, NULL, NULL);
if(vcp_ch != 0) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
furi_record_close(RECORD_CLI);
}
}
bool usb_uart_tx_data(UsbUart* usb_uart, uint8_t* data, size_t length) {
uint32_t pos = 0;
while(pos < length) {
size_t pkt_size = length - pos;
if(pkt_size > USB_CDC_PKT_LEN) {
pkt_size = USB_CDC_PKT_LEN;
}
if(furi_semaphore_acquire(usb_uart->tx_sem, 100) != FuriStatusOk) {
return false;
}
if(furi_mutex_acquire(usb_uart->usb_mutex, 100) != FuriStatusOk) {
furi_semaphore_release(usb_uart->tx_sem);
return false;
}
furi_hal_cdc_send(usb_uart->cfg.vcp_ch, &data[pos], pkt_size);
furi_mutex_release(usb_uart->usb_mutex);
usb_uart->st.tx_cnt += pkt_size;
pos += pkt_size;
}
return true;
}
static int32_t usb_uart_worker(void* context) {
UsbUart* usb_uart = (UsbUart*)context;
memcpy(&usb_uart->cfg, &usb_uart->cfg_new, sizeof(UsbUartConfig));
usb_uart->tx_sem = furi_semaphore_alloc(1, 1);
usb_uart->usb_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
usb_uart_vcp_init(usb_uart, usb_uart->cfg.vcp_ch);
uint8_t data[2 * USB_CDC_PKT_LEN];
size_t remain = 0;
while(1) {
uint32_t events =
furi_thread_flags_wait(WORKER_ALL_EVENTS, FuriFlagWaitAny, FuriWaitForever);
furi_check(!(events & FuriFlagError));
if(events & WorkerEvtStop) {
break;
}
if(events & WorkerEvtCdcRx) {
size_t len = 0;
if(furi_mutex_acquire(usb_uart->usb_mutex, 100) == FuriStatusOk) {
len = furi_hal_cdc_receive(usb_uart->cfg.vcp_ch, &data[remain], USB_CDC_PKT_LEN);
furi_mutex_release(usb_uart->usb_mutex);
}
if(len > 0) {
usb_uart->st.rx_cnt += len;
remain += len;
size_t handled = usb_uart->cfg.rx_data(usb_uart->cfg.rx_data_ctx, data, remain);
memcpy(data, &data[handled], remain - handled);
remain -= handled;
}
}
if(events & WorkerEvtCfgChange) {
if(usb_uart->cfg.vcp_ch != usb_uart->cfg_new.vcp_ch) {
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
usb_uart_vcp_init(usb_uart, usb_uart->cfg_new.vcp_ch);
usb_uart->cfg.vcp_ch = usb_uart->cfg_new.vcp_ch;
}
api_lock_unlock(usb_uart->cfg_lock);
}
}
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
furi_mutex_free(usb_uart->usb_mutex);
furi_semaphore_free(usb_uart->tx_sem);
furi_hal_usb_unlock();
furi_check(furi_hal_usb_set_config(&usb_cdc_single, NULL) == true);
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_open(cli, &cli_vcp);
furi_record_close(RECORD_CLI);
return 0;
}
/* VCP callbacks */
static void vcp_on_cdc_tx_complete(void* context) {
UsbUart* usb_uart = (UsbUart*)context;
furi_semaphore_release(usb_uart->tx_sem);
}
static void vcp_on_cdc_rx(void* context) {
UsbUart* usb_uart = (UsbUart*)context;
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCdcRx);
}
static void vcp_state_callback(void* context, uint8_t state) {
UNUSED(context);
UNUSED(state);
}
static void vcp_on_cdc_control_line(void* context, uint8_t state) {
UNUSED(context);
UNUSED(state);
}
static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config) {
UNUSED(context);
UNUSED(config);
}
UsbUart* usb_uart_enable(UsbUartConfig* cfg) {
UsbUart* usb_uart = malloc(sizeof(UsbUart));
memcpy(&(usb_uart->cfg_new), cfg, sizeof(UsbUartConfig));
usb_uart->thread = furi_thread_alloc_ex("UsbUartWorker", 1024, usb_uart_worker, usb_uart);
furi_thread_start(usb_uart->thread);
return usb_uart;
}
void usb_uart_disable(UsbUart* usb_uart) {
furi_assert(usb_uart);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtStop);
furi_thread_join(usb_uart->thread);
furi_thread_free(usb_uart->thread);
free(usb_uart);
}
void usb_uart_set_config(UsbUart* usb_uart, UsbUartConfig* cfg) {
furi_assert(usb_uart);
furi_assert(cfg);
usb_uart->cfg_lock = api_lock_alloc_locked();
memcpy(&(usb_uart->cfg_new), cfg, sizeof(UsbUartConfig));
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCfgChange);
api_lock_wait_unlock_and_free(usb_uart->cfg_lock);
}
void usb_uart_get_config(UsbUart* usb_uart, UsbUartConfig* cfg) {
furi_assert(usb_uart);
furi_assert(cfg);
memcpy(cfg, &(usb_uart->cfg_new), sizeof(UsbUartConfig));
}
void usb_uart_get_state(UsbUart* usb_uart, UsbUartState* st) {
furi_assert(usb_uart);
furi_assert(st);
memcpy(st, &(usb_uart->st), sizeof(UsbUartState));
}

View File

@@ -1,29 +0,0 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
typedef struct UsbUart UsbUart;
typedef struct {
uint8_t vcp_ch;
size_t (*rx_data)(void* ctx, uint8_t* data, size_t length);
void* rx_data_ctx;
} UsbUartConfig;
typedef struct {
uint32_t rx_cnt;
uint32_t tx_cnt;
} UsbUartState;
UsbUart* usb_uart_enable(UsbUartConfig* cfg);
void usb_uart_disable(UsbUart* usb_uart);
void usb_uart_set_config(UsbUart* usb_uart, UsbUartConfig* cfg);
void usb_uart_get_config(UsbUart* usb_uart, UsbUartConfig* cfg);
void usb_uart_get_state(UsbUart* usb_uart, UsbUartState* st);
bool usb_uart_tx_data(UsbUart* usb_uart, uint8_t* data, size_t length);

View File

@@ -1,33 +0,0 @@
#include "wifi_marauder_app_i.h"
#include "wifi_marauder_pcap.h"
void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) {
int start, end, delta;
start = strlen("sniff");
end = strcspn(command, " ");
delta = end - start;
strncpy(dest, command + start, end - start);
dest[delta] = '\0';
}
void wifi_marauder_create_pcap_file(WifiMarauderApp* app) {
char prefix[10];
char capture_file_path[100];
wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string);
int i = 0;
do {
snprintf(
capture_file_path,
sizeof(capture_file_path),
"%s/%s_%d.pcap",
MARAUDER_APP_FOLDER,
prefix,
i);
i++;
} while(storage_file_exists(app->storage, capture_file_path));
if(!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
}
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include "furi_hal.h"
/**
* Creates a PCAP file to store incoming packets.
* The file name will have a prefix according to the type of scan being performed by the application (Eg: raw_0.pcap)
*
* @param app Application context
*/
void wifi_marauder_create_pcap_file(WifiMarauderApp* app);

View File

@@ -14,7 +14,7 @@ App(
"fap_loader",
"archive",
"clock",
"subghz_remote",
"unirfremix",
],
)

View File

@@ -451,7 +451,7 @@ static bool archive_is_dir_exists(FuriString* path) {
FileInfo file_info;
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
if(file_info_is_dir(&file_info)) {
if(file_info.flags & FSF_DIRECTORY) {
state = true;
}
}
@@ -532,16 +532,12 @@ void archive_enter_dir(ArchiveBrowserView* browser, FuriString* path) {
browser->view, ArchiveBrowserViewModel * model, { idx_temp = model->item_idx; }, false);
furi_string_set(browser->path, path);
file_browser_worker_folder_enter(browser->worker, path, idx_temp);
}
void archive_leave_dir(ArchiveBrowserView* browser) {
furi_assert(browser);
size_t dirname_start = furi_string_search_rchar(browser->path, '/');
furi_string_left(browser->path, dirname_start);
file_browser_worker_folder_exit(browser->worker);
}

View File

@@ -160,7 +160,7 @@ bool archive_favorites_read(void* context) {
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
storage_common_stat(storage, furi_string_get_cstr(buffer), &file_info);
archive_add_file_item(
browser, file_info_is_dir(&file_info), furi_string_get_cstr(buffer));
browser, (file_info.flags & FSF_DIRECTORY), furi_string_get_cstr(buffer));
file_count++;
} else {
need_refresh = true;

View File

@@ -96,7 +96,7 @@ void archive_delete_file(void* context, const char* format, ...) {
bool res = false;
if(file_info_is_dir(&fileinfo)) {
if(fileinfo.flags & FSF_DIRECTORY) {
res = storage_simply_remove_recursive(fs_api, furi_string_get_cstr(filename));
} else {
res = (storage_common_remove(fs_api, furi_string_get_cstr(filename)) == FSE_OK);

View File

@@ -142,6 +142,10 @@ void bad_usb_app_free(BadUsbApp* app) {
app->bad_usb_script = NULL;
}
if(app->usb_if_prev) {
furi_check(furi_hal_usb_set_config(app->usb_if_prev, NULL));
}
// Views
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork);
bad_usb_free(app->bad_usb_view);
@@ -168,10 +172,6 @@ void bad_usb_app_free(BadUsbApp* app) {
furi_string_free(app->file_path);
furi_string_free(app->keyboard_layout);
if(app->usb_if_prev) {
furi_check(furi_hal_usb_set_config(app->usb_if_prev, NULL));
}
free(app);
}

View File

@@ -6,11 +6,11 @@
#include <furi_hal_usb_hid.h>
#include <storage/storage.h>
#include "bad_usb_script.h"
#include "mnemonic.h"
#include <dolphin/dolphin.h>
#define TAG "BadUSB"
#define WORKER_TAG TAG "Worker"
#define FILE_BUFFER_LEN 16
#define SCRIPT_STATE_ERROR (-1)
#define SCRIPT_STATE_END (-2)
@@ -26,6 +26,23 @@ typedef enum {
WorkerEvtDisconnect = (1 << 3),
} WorkerEvtFlags;
struct BadUsbScript {
FuriHalUsbHidConfig hid_cfg;
BadUsbState st;
FuriString* file_path;
uint32_t defdelay;
uint16_t layout[128];
FuriThread* thread;
uint8_t file_buf[FILE_BUFFER_LEN + 1];
uint8_t buf_start;
uint8_t buf_len;
bool file_end;
FuriString* line;
FuriString* line_prev;
uint32_t repeat_cnt;
};
typedef struct {
char* name;
uint16_t keycode;
@@ -94,21 +111,38 @@ static const char ducky_cmd_comment[] = {"REM"};
static const char ducky_cmd_id[] = {"ID"};
static const char ducky_cmd_delay[] = {"DELAY "};
static const char ducky_cmd_string[] = {"STRING "};
static const char ducky_cmd_stringln[] = {"STRINGLN "};
static const char ducky_cmd_defdelay_1[] = {"DEFAULT_DELAY "};
static const char ducky_cmd_defdelay_2[] = {"DEFAULTDELAY "};
static const char ducky_cmd_stringdelay_1[] = {"STRINGDELAY "};
static const char ducky_cmd_stringdelay_2[] = {"STRING_DELAY "};
static const char ducky_cmd_repeat[] = {"REPEAT "};
static const char ducky_cmd_sysrq[] = {"SYSRQ "};
static const char ducky_cmd_hold[] = {"HOLD "};
static const char ducky_cmd_release[] = {"RELEASE "};
static const char ducky_cmd_altchar[] = {"ALTCHAR "};
static const char ducky_cmd_altstr_1[] = {"ALTSTRING "};
static const char ducky_cmd_altstr_2[] = {"ALTCODE "};
uint32_t ducky_get_command_len(const char* line) {
static const uint8_t numpad_keys[10] = {
HID_KEYPAD_0,
HID_KEYPAD_1,
HID_KEYPAD_2,
HID_KEYPAD_3,
HID_KEYPAD_4,
HID_KEYPAD_5,
HID_KEYPAD_6,
HID_KEYPAD_7,
HID_KEYPAD_8,
HID_KEYPAD_9,
};
static bool ducky_get_number(const char* param, uint32_t* val) {
uint32_t value = 0;
if(sscanf(param, "%lu", &value) == 1) {
*val = value;
return true;
}
return false;
}
static uint32_t ducky_get_command_len(const char* line) {
uint32_t len = strlen(line);
for(uint32_t i = 0; i < len; i++) {
if(line[i] == ' ') return i;
@@ -116,11 +150,79 @@ uint32_t ducky_get_command_len(const char* line) {
return 0;
}
bool ducky_is_line_end(const char chr) {
static bool ducky_is_line_end(const char chr) {
return ((chr == ' ') || (chr == '\0') || (chr == '\r') || (chr == '\n'));
}
uint16_t ducky_get_keycode(BadUsbScript* bad_usb, const char* param, bool accept_chars) {
static void ducky_numlock_on() {
if((furi_hal_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
furi_hal_hid_kb_press(HID_KEYBOARD_LOCK_NUM_LOCK);
furi_hal_hid_kb_release(HID_KEYBOARD_LOCK_NUM_LOCK);
}
}
static bool ducky_numpad_press(const char num) {
if((num < '0') || (num > '9')) return false;
uint16_t key = numpad_keys[num - '0'];
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release(key);
return true;
}
static bool ducky_altchar(const char* charcode) {
uint8_t i = 0;
bool state = false;
FURI_LOG_I(WORKER_TAG, "char %s", charcode);
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
while(!ducky_is_line_end(charcode[i])) {
state = ducky_numpad_press(charcode[i]);
if(state == false) break;
i++;
}
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
return state;
}
static bool ducky_altstring(const char* param) {
uint32_t i = 0;
bool state = false;
while(param[i] != '\0') {
if((param[i] < ' ') || (param[i] > '~')) {
i++;
continue; // Skip non-printable chars
}
char temp_str[4];
snprintf(temp_str, 4, "%u", param[i]);
state = ducky_altchar(temp_str);
if(state == false) break;
i++;
}
return state;
}
static bool ducky_string(BadUsbScript* bad_usb, const char* param) {
uint32_t i = 0;
while(param[i] != '\0') {
uint16_t keycode = BADUSB_ASCII_TO_KEY(bad_usb, param[i]);
if(keycode != HID_KEYBOARD_NONE) {
furi_hal_hid_kb_press(keycode);
furi_hal_hid_kb_release(keycode);
}
i++;
}
return true;
}
static uint16_t ducky_get_keycode(BadUsbScript* bad_usb, const char* param, bool accept_chars) {
for(size_t i = 0; i < (sizeof(ducky_keys) / sizeof(ducky_keys[0])); i++) {
size_t key_cmd_len = strlen(ducky_keys[i].name);
if((strncmp(param, ducky_keys[i].name, key_cmd_len) == 0) &&
@@ -138,68 +240,105 @@ static int32_t
ducky_parse_line(BadUsbScript* bad_usb, FuriString* line, char* error, size_t error_len) {
uint32_t line_len = furi_string_size(line);
const char* line_tmp = furi_string_get_cstr(line);
const char* ducky_cmd_table[] = {
ducky_cmd_comment,
ducky_cmd_id,
ducky_cmd_delay,
ducky_cmd_string,
ducky_cmd_defdelay_1,
ducky_cmd_defdelay_2,
ducky_cmd_stringdelay_1,
ducky_cmd_stringdelay_2,
ducky_cmd_repeat,
ducky_cmd_sysrq,
ducky_cmd_altchar,
ducky_cmd_altstr_1,
ducky_cmd_altstr_2,
ducky_cmd_stringln,
ducky_cmd_hold,
ducky_cmd_release,
NULL};
int32_t (*fnc_ptr[])(BadUsbScript*, FuriString*, const char*, char*, size_t) = {
&ducky_fnc_noop,
&ducky_fnc_noop,
&ducky_fnc_delay,
&ducky_fnc_string,
&ducky_fnc_defdelay,
&ducky_fnc_defdelay,
&ducky_fnc_strdelay,
&ducky_fnc_strdelay,
&ducky_fnc_repeat,
&ducky_fnc_sysrq,
&ducky_fnc_altchar,
&ducky_fnc_altstring,
&ducky_fnc_altstring,
&ducky_fnc_stringln,
&ducky_fnc_hold,
&ducky_fnc_release,
NULL};
bool state = false;
if(line_len == 0) {
return SCRIPT_STATE_NEXT_LINE; // Skip empty lines
}
FURI_LOG_D(WORKER_TAG, "line:%s", line_tmp);
// Ducky Lang Functions
for(size_t i = 0; ducky_cmd_table[i]; i++) {
if(strncmp(line_tmp, ducky_cmd_table[i], strlen(ducky_cmd_table[i])) == 0)
return ((fnc_ptr[i])(bad_usb, line, line_tmp, error, error_len));
}
// Special keys + modifiers
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, false);
if(key == HID_KEYBOARD_NONE) {
// General commands
if(strncmp(line_tmp, ducky_cmd_comment, strlen(ducky_cmd_comment)) == 0) {
// REM - comment line
return (0);
} else if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
// ID - executed in ducky_script_preload
return (0);
} else if(strncmp(line_tmp, ducky_cmd_delay, strlen(ducky_cmd_delay)) == 0) {
// DELAY
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint32_t delay_val = 0;
state = ducky_get_number(line_tmp, &delay_val);
if((state) && (delay_val > 0)) {
return (int32_t)delay_val;
}
if(error != NULL) {
snprintf(error, error_len, "No keycode defined for %s", line_tmp);
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
if((key & 0xFF00) != 0) {
// It's a modifier key
} else if(
(strncmp(line_tmp, ducky_cmd_defdelay_1, strlen(ducky_cmd_defdelay_1)) == 0) ||
(strncmp(line_tmp, ducky_cmd_defdelay_2, strlen(ducky_cmd_defdelay_2)) == 0)) {
// DEFAULT_DELAY
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
key |= ducky_get_keycode(bad_usb, line_tmp, true);
state = ducky_get_number(line_tmp, &bad_usb->defdelay);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
} else if(strncmp(line_tmp, ducky_cmd_string, strlen(ducky_cmd_string)) == 0) {
// STRING
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_string(bad_usb, line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid string %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
} else if(strncmp(line_tmp, ducky_cmd_altchar, strlen(ducky_cmd_altchar)) == 0) {
// ALTCHAR
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
ducky_numlock_on();
state = ducky_altchar(line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid altchar %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
} else if(
(strncmp(line_tmp, ducky_cmd_altstr_1, strlen(ducky_cmd_altstr_1)) == 0) ||
(strncmp(line_tmp, ducky_cmd_altstr_2, strlen(ducky_cmd_altstr_2)) == 0)) {
// ALTSTRING
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
ducky_numlock_on();
state = ducky_altstring(line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid altstring %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
} else if(strncmp(line_tmp, ducky_cmd_repeat, strlen(ducky_cmd_repeat)) == 0) {
// REPEAT
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_get_number(line_tmp, &bad_usb->repeat_cnt);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
} else if(strncmp(line_tmp, ducky_cmd_sysrq, strlen(ducky_cmd_sysrq)) == 0) {
// SYSRQ
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, true);
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release_all();
return (0);
} else {
// Special keys + modifiers
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, false);
if(key == HID_KEYBOARD_NONE) {
if(error != NULL) {
snprintf(error, error_len, "No keycode defined for %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
if((key & 0xFF00) != 0) {
// It's a modifier key
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
key |= ducky_get_keycode(bad_usb, line_tmp, true);
}
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release(key);
return (0);
}
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release(key);
return (0);
}
static bool ducky_set_usb_id(BadUsbScript* bad_usb, const char* line) {
@@ -345,19 +484,6 @@ static void bad_usb_hid_state_callback(bool state, void* context) {
furi_thread_flags_set(furi_thread_get_id(bad_usb->thread), WorkerEvtDisconnect);
}
static uint32_t bad_usb_flags_get(uint32_t flags_mask, uint32_t timeout) {
uint32_t flags = furi_thread_flags_get();
furi_check((flags & FuriFlagError) == 0);
if(flags == 0) {
flags = furi_thread_flags_wait(flags_mask, FuriFlagWaitAny, timeout);
furi_check(((flags & FuriFlagError) == 0) || (flags == (unsigned)FuriFlagErrorTimeout));
} else {
uint32_t state = furi_thread_flags_clear(flags);
furi_check((state & FuriFlagError) == 0);
}
return flags;
}
static int32_t bad_usb_worker(void* context) {
BadUsbScript* bad_usb = context;
@@ -394,9 +520,11 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->st.state = worker_state;
} else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected
uint32_t flags = bad_usb_flags_get(
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle, FuriWaitForever);
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
FuriFlagWaitAny,
FuriWaitForever);
furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) {
break;
} else if(flags & WorkerEvtConnect) {
@@ -407,9 +535,11 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->st.state = worker_state;
} else if(worker_state == BadUsbStateIdle) { // State: ready to start
uint32_t flags = bad_usb_flags_get(
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriWaitForever);
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect,
FuriFlagWaitAny,
FuriWaitForever);
furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) {
break;
} else if(flags & WorkerEvtToggle) { // Start executing script
@@ -418,7 +548,6 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->buf_len = 0;
bad_usb->st.line_cur = 0;
bad_usb->defdelay = 0;
bad_usb->stringdelay = 0;
bad_usb->repeat_cnt = 0;
bad_usb->file_end = false;
storage_file_seek(script_file, 0, true);
@@ -429,9 +558,11 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->st.state = worker_state;
} else if(worker_state == BadUsbStateWillRun) { // State: start on connection
uint32_t flags = bad_usb_flags_get(
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle, FuriWaitForever);
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
FuriFlagWaitAny,
FuriWaitForever);
furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) {
break;
} else if(flags & WorkerEvtConnect) { // Start executing script
@@ -440,22 +571,12 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->buf_len = 0;
bad_usb->st.line_cur = 0;
bad_usb->defdelay = 0;
bad_usb->stringdelay = 0;
bad_usb->repeat_cnt = 0;
bad_usb->file_end = false;
storage_file_seek(script_file, 0, true);
// extra time for PC to recognize Flipper as keyboard
flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtDisconnect | WorkerEvtToggle,
FuriFlagWaitAny | FuriFlagNoClear,
1500);
if(flags == (unsigned)FuriFlagErrorTimeout) {
// If nothing happened - start script execution
worker_state = BadUsbStateRunning;
} else if(flags & WorkerEvtToggle) {
worker_state = BadUsbStateIdle;
furi_thread_flags_clear(WorkerEvtToggle);
}
furi_thread_flags_wait(0, FuriFlagWaitAny, 1500);
worker_state = BadUsbStateRunning;
} else if(flags & WorkerEvtToggle) { // Cancel scheduled execution
worker_state = BadUsbStateNotConnected;
}
@@ -465,7 +586,6 @@ static int32_t bad_usb_worker(void* context) {
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriFlagWaitAny, delay_cur);
delay_val -= delay_cur;
if(!(flags & FuriFlagError)) {
if(flags & WorkerEvtEnd) {
@@ -509,9 +629,9 @@ static int32_t bad_usb_worker(void* context) {
} else if(
(worker_state == BadUsbStateFileError) ||
(worker_state == BadUsbStateScriptError)) { // State: error
uint32_t flags =
bad_usb_flags_get(WorkerEvtEnd, FuriWaitForever); // Waiting for exit command
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd, FuriFlagWaitAny, FuriWaitForever); // Waiting for exit command
furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) {
break;
}

View File

@@ -5,9 +5,8 @@ extern "C" {
#endif
#include <furi.h>
#include <furi_hal.h>
#define FILE_BUFFER_LEN 16
typedef struct BadUsbScript BadUsbScript;
typedef enum {
BadUsbStateInit,
@@ -30,24 +29,6 @@ typedef struct {
char error[64];
} BadUsbState;
typedef struct BadUsbScript {
FuriHalUsbHidConfig hid_cfg;
BadUsbState st;
FuriString* file_path;
uint32_t defdelay;
uint16_t layout[128];
uint32_t stringdelay;
FuriThread* thread;
uint8_t file_buf[FILE_BUFFER_LEN + 1];
uint8_t buf_start;
uint8_t buf_len;
bool file_end;
FuriString* line;
FuriString* line_prev;
uint32_t repeat_cnt;
} BadUsbScript;
BadUsbScript* bad_usb_script_open(FuriString* file_path);
void bad_usb_script_close(BadUsbScript* bad_usb);
@@ -62,12 +43,6 @@ void bad_usb_script_toggle(BadUsbScript* bad_usb);
BadUsbState* bad_usb_script_get_state(BadUsbScript* bad_usb);
uint16_t ducky_get_keycode(BadUsbScript* bad_usb, const char* param, bool accept_chars);
uint32_t ducky_get_command_len(const char* line);
bool ducky_is_line_end(const char chr);
#ifdef __cplusplus
}
#endif

View File

@@ -1,327 +0,0 @@
#include <furi_hal.h>
#include <furi_hal_usb_hid.h>
#include "mnemonic.h"
#define TAG "BadUSB"
#define WORKER_TAG TAG "Worker"
#define FILE_BUFFER_LEN 16
#define SCRIPT_STATE_ERROR (-1)
#define SCRIPT_STATE_END (-2)
#define SCRIPT_STATE_NEXT_LINE (-3)
#define BADUSB_ASCII_TO_KEY(script, x) \
(((uint8_t)x < 128) ? (script->layout[(uint8_t)x]) : HID_KEYBOARD_NONE)
static const uint8_t numpad_keys[10] = {
HID_KEYPAD_0,
HID_KEYPAD_1,
HID_KEYPAD_2,
HID_KEYPAD_3,
HID_KEYPAD_4,
HID_KEYPAD_5,
HID_KEYPAD_6,
HID_KEYPAD_7,
HID_KEYPAD_8,
HID_KEYPAD_9,
};
static bool ducky_get_number(const char* param, uint32_t* val) {
uint32_t value = 0;
if(sscanf(param, "%lu", &value) == 1) {
*val = value;
return true;
}
return false;
}
static void ducky_numlock_on() {
if((furi_hal_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
furi_hal_hid_kb_press(HID_KEYBOARD_LOCK_NUM_LOCK);
furi_hal_hid_kb_release(HID_KEYBOARD_LOCK_NUM_LOCK);
}
}
static bool ducky_numpad_press(const char num) {
if((num < '0') || (num > '9')) return false;
uint16_t key = numpad_keys[num - '0'];
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release(key);
return true;
}
static bool ducky_altchar(const char* charcode) {
uint8_t i = 0;
bool state = false;
FURI_LOG_I(WORKER_TAG, "char %s", charcode);
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
while(!ducky_is_line_end(charcode[i])) {
state = ducky_numpad_press(charcode[i]);
if(state == false) break;
i++;
}
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
return state;
}
static bool ducky_altstring(const char* param) {
uint32_t i = 0;
bool state = false;
while(param[i] != '\0') {
if((param[i] < ' ') || (param[i] > '~')) {
i++;
continue; // Skip non-printable chars
}
char temp_str[4];
snprintf(temp_str, 4, "%u", param[i]);
state = ducky_altchar(temp_str);
if(state == false) break;
i++;
}
return state;
}
static bool ducky_string(BadUsbScript* bad_usb, const char* param) {
uint32_t i = 0;
while(param[i] != '\0') {
uint16_t keycode = BADUSB_ASCII_TO_KEY(bad_usb, param[i]);
if(keycode != HID_KEYBOARD_NONE) {
furi_hal_hid_kb_press(keycode);
furi_hal_hid_kb_release(keycode);
if(bad_usb->stringdelay > 0) {
furi_delay_ms(bad_usb->stringdelay);
}
}
i++;
}
bad_usb->stringdelay = 0;
return true;
}
int32_t ducky_fnc_noop(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
(void)bad_usb;
(void)line;
(void)line_tmp;
(void)error;
(void)error_len;
return (0);
}
int32_t ducky_fnc_delay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)bad_usb;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint32_t delay_val = 0;
state = ducky_get_number(line_tmp, &delay_val);
if((state) && (delay_val > 0)) {
return (int32_t)delay_val;
}
if(error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_defdelay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_get_number(line_tmp, &bad_usb->defdelay);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_strdelay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_get_number(line_tmp, &bad_usb->stringdelay);
if((state) && (bad_usb->stringdelay > 0)) {
return state;
}
if(error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_string(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_string(bad_usb, line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid string %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_repeat(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_get_number(line_tmp, &bad_usb->repeat_cnt);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid number %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_sysrq(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
(void)error;
(void)error_len;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, true);
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
furi_hal_hid_kb_press(key);
furi_hal_hid_kb_release_all();
return (0);
}
int32_t ducky_fnc_altchar(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)bad_usb;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
ducky_numlock_on();
state = ducky_altchar(line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid altchar %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_altstring(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)bad_usb;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
ducky_numlock_on();
state = ducky_altstring(line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid altstring %s", line_tmp);
}
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_stringln(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
bool state = false;
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
state = ducky_string(bad_usb, line_tmp);
if(!state && error != NULL) {
snprintf(error, error_len, "Invalid string %s", line_tmp);
}
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
return (state) ? (0) : SCRIPT_STATE_ERROR;
}
int32_t ducky_fnc_hold(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, true);
if(key == HID_KEYBOARD_NONE) {
if(error != NULL) {
snprintf(error, error_len, "No keycode defined for %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
furi_hal_hid_kb_press(key);
return (0);
}
int32_t ducky_fnc_release(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len) {
(void)line;
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, true);
if(key == HID_KEYBOARD_NONE) {
if(error != NULL) {
snprintf(error, error_len, "No keycode defined for %s", line_tmp);
}
return SCRIPT_STATE_ERROR;
}
furi_hal_hid_kb_release(key);
return (0);
}

View File

@@ -1,96 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "bad_usb_script.h"
// A no opperation function
int32_t ducky_fnc_noop(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// DELAY
int32_t ducky_fnc_delay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// DEFAULTDELAY
int32_t ducky_fnc_defdelay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// STRINGDELAY
int32_t ducky_fnc_strdelay(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// STRING
int32_t ducky_fnc_string(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// STRINGLN
int32_t ducky_fnc_stringln(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// REPEAT
int32_t ducky_fnc_repeat(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// SYSRQ
int32_t ducky_fnc_sysrq(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// ALTCHAR
int32_t ducky_fnc_altchar(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// ALTSTRING
int32_t ducky_fnc_altstring(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// HOLD
int32_t ducky_fnc_hold(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
// RELEASE
int32_t ducky_fnc_release(
BadUsbScript* bad_usb,
FuriString* line,
const char* line_tmp,
char* error,
size_t error_len);
#ifdef __cplusplus
}
#endif

View File

@@ -17,7 +17,7 @@ void bad_usb_scene_config_on_enter(void* context) {
submenu_add_item(
submenu,
"Keyboard Layout",
"Keyboard layout",
SubmenuIndexKeyboardLayout,
bad_usb_scene_config_submenu_callback,
bad_usb);

View File

@@ -22,6 +22,7 @@ static bool bad_usb_file_select(BadUsbApp* bad_usb) {
void bad_usb_scene_file_select_on_enter(void* context) {
BadUsbApp* bad_usb = context;
furi_hal_usb_disable();
if(bad_usb->bad_usb_script) {
bad_usb_script_close(bad_usb->bad_usb_script);
bad_usb->bad_usb_script = NULL;
@@ -33,6 +34,7 @@ void bad_usb_scene_file_select_on_enter(void* context) {
scene_manager_next_scene(bad_usb->scene_manager, BadUsbSceneWork);
} else {
furi_hal_usb_enable();
view_dispatcher_stop(bad_usb->view_dispatcher);
}
}

View File

@@ -16,9 +16,7 @@ bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InputKeyLeft) {
if(bad_usb_is_idle_state(app->bad_usb_view)) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneConfig);
}
scene_manager_next_scene(app->scene_manager, BadUsbSceneConfig);
consumed = true;
} else if(event.event == InputKeyOk) {
bad_usb_script_toggle(app->bad_usb_script);

View File

@@ -48,13 +48,17 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone) ||
(model->state.state == BadUsbStateNotConnected)) {
elements_button_center(canvas, "Run");
elements_button_left(canvas, "Config");
} else if((model->state.state == BadUsbStateRunning) || (model->state.state == BadUsbStateDelay)) {
elements_button_center(canvas, "Stop");
} else if(model->state.state == BadUsbStateWillRun) {
elements_button_center(canvas, "Cancel");
}
if((model->state.state == BadUsbStateNotConnected) ||
(model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) {
elements_button_left(canvas, "Config");
}
if(model->state.state == BadUsbStateNotConnected) {
canvas_draw_icon(canvas, 4, 26, &I_Clock_18x18);
canvas_set_font(canvas, FontPrimary);
@@ -199,7 +203,6 @@ void bad_usb_set_layout(BadUsb* bad_usb, const char* layout) {
{ strlcpy(model->layout, layout, MAX_NAME_LEN); },
true);
}
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) {
furi_assert(st);
with_view_model(
@@ -211,19 +214,3 @@ void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) {
},
true);
}
bool bad_usb_is_idle_state(BadUsb* bad_usb) {
bool is_idle = false;
with_view_model(
bad_usb->view,
BadUsbModel * model,
{
if((model->state.state == BadUsbStateIdle) ||
(model->state.state == BadUsbStateDone) ||
(model->state.state == BadUsbStateNotConnected)) {
is_idle = true;
}
},
false);
return is_idle;
}

View File

@@ -19,5 +19,3 @@ void bad_usb_set_file_name(BadUsb* bad_usb, const char* name);
void bad_usb_set_layout(BadUsb* bad_usb, const char* layout);
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st);
bool bad_usb_is_idle_state(BadUsb* bad_usb);

View File

@@ -7,7 +7,6 @@ App(
requires=[
"gui",
"storage",
"loader",
],
stack_size=int(1.5 * 1024),
icon="A_Plugins_14",

View File

@@ -4,8 +4,6 @@
#pragma once
#ifdef __cplusplus
#include <iterator>
#include <array>
@@ -111,5 +109,3 @@ constexpr auto create_array_t(const Ts&&... values) {
static_assert(traits::are_same_type<Ts...>(), "all elements must have same type");
return std::array<array_type, sizeof...(Ts)>{static_cast<T>(values)...};
}
#endif

View File

@@ -0,0 +1,48 @@
#include "compilesort.hpp"
#include "elf_hashtable.h"
#include "elf_hashtable_entry.h"
#include "elf_hashtable_checks.hpp"
#include <array>
#include <algorithm>
/* Generated table */
#include <symbols.h>
#define TAG "elf_hashtable"
static_assert(!has_hash_collisions(elf_api_table), "Detected API method hash collision!");
/**
* Get function address by function name
* @param name function name
* @param address output for function address
* @return true if the table contains a function
*/
bool elf_resolve_from_hashtable(const char* name, Elf32_Addr* address) {
bool result = false;
uint32_t gnu_sym_hash = elf_gnu_hash(name);
sym_entry key = {
.hash = gnu_sym_hash,
.address = 0,
};
auto find_res = std::lower_bound(elf_api_table.cbegin(), elf_api_table.cend(), key);
if((find_res == elf_api_table.cend() || (find_res->hash != gnu_sym_hash))) {
FURI_LOG_W(TAG, "Can't find symbol '%s' (hash %lx)!", name, gnu_sym_hash);
result = false;
} else {
result = true;
*address = find_res->address;
}
return result;
}
const ElfApiInterface hashtable_api_interface = {
.api_version_major = (elf_api_version >> 16),
.api_version_minor = (elf_api_version & 0xFFFF),
.resolver_callback = &elf_resolve_from_hashtable,
};

View File

@@ -0,0 +1,14 @@
#pragma once
#include <stdint.h>
#include <flipper_application/elf/elf_api_interface.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const ElfApiInterface hashtable_api_interface;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,18 @@
/**
* Check for multiple entries with the same hash value at compilation time.
*/
#pragma once
#include <array>
#include "elf_hashtable_entry.h"
template <std::size_t N>
constexpr bool has_hash_collisions(const std::array<sym_entry, N> api_methods) {
for(std::size_t i = 0; i < (N - 1); ++i) {
if(api_methods[i].hash == api_methods[i + 1].hash) {
return true;
}
}
return false;
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct sym_entry {
uint32_t hash;
uint32_t address;
};
#ifdef __cplusplus
}
#include <array>
#include <algorithm>
#define API_METHOD(x, ret_type, args_type) \
sym_entry { \
.hash = elf_gnu_hash(#x), .address = (uint32_t)(static_cast<ret_type(*) args_type>(x)) \
}
#define API_VARIABLE(x, var_type) \
sym_entry { \
.hash = elf_gnu_hash(#x), .address = (uint32_t)(&(x)), \
}
constexpr bool operator<(const sym_entry& k1, const sym_entry& k2) {
return k1.hash < k2.hash;
}
constexpr uint32_t elf_gnu_hash(const char* s) {
uint32_t h = 0x1505;
for(unsigned char c = *s; c != '\0'; c = *++s) {
h = (h << 5) + h + c;
}
return h;
}
#endif

View File

@@ -5,9 +5,8 @@
#include <storage/storage.h>
#include <gui/modules/loading.h>
#include <dialogs/dialogs.h>
#include <toolbox/path.h>
#include <flipper_application/flipper_application.h>
#include <loader/firmware_api/firmware_api.h>
#include "elf_cpp/elf_hashtable.h"
#include "fap_loader_app.h"
#define TAG "fap_loader_app"
@@ -27,7 +26,7 @@ bool fap_loader_load_name_and_icon(
Storage* storage,
uint8_t** icon_ptr,
FuriString* item_name) {
FlipperApplication* app = flipper_application_alloc(storage, firmware_api_interface);
FlipperApplication* app = flipper_application_alloc(storage, &hashtable_api_interface);
FlipperApplicationPreloadStatus preload_res =
flipper_application_preload_manifest(app, furi_string_get_cstr(path));
@@ -71,7 +70,7 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
bool show_error = true;
do {
file_selected = true;
loader->app = flipper_application_alloc(loader->storage, firmware_api_interface);
loader->app = flipper_application_alloc(loader->storage, &hashtable_api_interface);
size_t start = furi_get_tick();
FURI_LOG_I(TAG, "FAP Loader is loading %s", furi_string_get_cstr(loader->fap_path));
@@ -106,12 +105,6 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
FURI_LOG_I(TAG, "FAP Loader is starting app");
FuriThread* thread = flipper_application_spawn(loader->app, NULL);
FuriString* app_name = furi_string_alloc();
path_extract_filename_no_ext(furi_string_get_cstr(loader->fap_path), app_name);
furi_thread_set_appid(thread, furi_string_get_cstr(app_name));
furi_string_free(app_name);
furi_thread_start(thread);
furi_thread_join(thread);

View File

@@ -1,6 +1,10 @@
#include "ibutton.h"
#include "assets_icons.h"
#include "ibutton_i.h"
#include "ibutton/scenes/ibutton_scene.h"
#include <toolbox/path.h>
#include <flipper_format/flipper_format.h>
#include <rpc/rpc_app.h>
#include <dolphin/dolphin.h>
#define TAG "iButtonApp"
@@ -30,13 +34,50 @@ static const NotificationSequence* ibutton_notification_sequences[] = {
};
static void ibutton_make_app_folder(iButton* ibutton) {
Storage* storage = furi_record_open(RECORD_STORAGE);
if(!storage_simply_mkdir(storage, IBUTTON_APP_FOLDER)) {
if(!storage_simply_mkdir(ibutton->storage, IBUTTON_APP_FOLDER)) {
dialog_message_show_storage_error(ibutton->dialogs, "Cannot create\napp folder");
}
}
furi_record_close(RECORD_STORAGE);
bool ibutton_load_key_data(iButton* ibutton, FuriString* key_path, bool show_dialog) {
FlipperFormat* file = flipper_format_file_alloc(ibutton->storage);
bool result = false;
FuriString* data;
data = furi_string_alloc();
do {
if(!flipper_format_file_open_existing(file, furi_string_get_cstr(key_path))) break;
// header
uint32_t version;
if(!flipper_format_read_header(file, data, &version)) break;
if(furi_string_cmp_str(data, IBUTTON_APP_FILE_TYPE) != 0) break;
if(version != 1) break;
// key type
iButtonKeyType type;
if(!flipper_format_read_string(file, "Key type", data)) break;
if(!ibutton_key_get_type_by_string(furi_string_get_cstr(data), &type)) break;
// key data
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
if(!flipper_format_read_hex(file, "Data", key_data, ibutton_key_get_size_by_type(type)))
break;
ibutton_key_set_type(ibutton->key, type);
ibutton_key_set_data(ibutton->key, key_data, IBUTTON_KEY_DATA_SIZE);
result = true;
} while(false);
flipper_format_free(file);
furi_string_free(data);
if((!result) && (show_dialog)) {
dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file");
}
return result;
}
static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context) {
@@ -46,14 +87,14 @@ static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context)
if(event == RpcAppEventSessionClose) {
view_dispatcher_send_custom_event(
ibutton->view_dispatcher, iButtonCustomEventRpcSessionClose);
rpc_system_app_set_callback(ibutton->rpc, NULL, NULL);
ibutton->rpc = NULL;
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
ibutton->rpc_ctx = NULL;
} else if(event == RpcAppEventAppExit) {
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventRpcExit);
} else if(event == RpcAppEventLoadFile) {
view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventRpcLoad);
} else {
rpc_system_app_confirm(ibutton->rpc, event, false);
rpc_system_app_confirm(ibutton->rpc_ctx, event, false);
}
}
@@ -94,13 +135,13 @@ iButton* ibutton_alloc() {
ibutton->gui = furi_record_open(RECORD_GUI);
ibutton->storage = furi_record_open(RECORD_STORAGE);
ibutton->dialogs = furi_record_open(RECORD_DIALOGS);
ibutton->notifications = furi_record_open(RECORD_NOTIFICATION);
ibutton->protocols = ibutton_protocols_alloc();
ibutton->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(ibutton->protocols));
ibutton->worker = ibutton_worker_alloc(ibutton->protocols);
ibutton_worker_start_thread(ibutton->worker);
ibutton->key = ibutton_key_alloc();
ibutton->key_worker = ibutton_worker_alloc();
ibutton_worker_start_thread(ibutton->key_worker);
ibutton->submenu = submenu_alloc();
view_dispatcher_add_view(
@@ -122,9 +163,9 @@ iButton* ibutton_alloc() {
view_dispatcher_add_view(
ibutton->view_dispatcher, iButtonViewWidget, widget_get_view(ibutton->widget));
ibutton->loading = loading_alloc();
ibutton->dialog_ex = dialog_ex_alloc();
view_dispatcher_add_view(
ibutton->view_dispatcher, iButtonViewLoading, loading_get_view(ibutton->loading));
ibutton->view_dispatcher, iButtonViewDialogEx, dialog_ex_get_view(ibutton->dialog_ex));
return ibutton;
}
@@ -132,8 +173,8 @@ iButton* ibutton_alloc() {
void ibutton_free(iButton* ibutton) {
furi_assert(ibutton);
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewLoading);
loading_free(ibutton->loading);
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewDialogEx);
dialog_ex_free(ibutton->dialog_ex);
view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewWidget);
widget_free(ibutton->widget);
@@ -153,6 +194,9 @@ void ibutton_free(iButton* ibutton) {
view_dispatcher_free(ibutton->view_dispatcher);
scene_manager_free(ibutton->scene_manager);
furi_record_close(RECORD_STORAGE);
ibutton->storage = NULL;
furi_record_close(RECORD_NOTIFICATION);
ibutton->notifications = NULL;
@@ -162,83 +206,103 @@ void ibutton_free(iButton* ibutton) {
furi_record_close(RECORD_GUI);
ibutton->gui = NULL;
ibutton_worker_stop_thread(ibutton->worker);
ibutton_worker_free(ibutton->worker);
ibutton_worker_stop_thread(ibutton->key_worker);
ibutton_worker_free(ibutton->key_worker);
ibutton_key_free(ibutton->key);
ibutton_protocols_free(ibutton->protocols);
furi_string_free(ibutton->file_path);
free(ibutton);
}
bool ibutton_load_key(iButton* ibutton) {
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading);
const bool success = ibutton_protocols_load(
ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path));
if(!success) {
dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file");
} else {
FuriString* tmp = furi_string_alloc();
path_extract_filename(ibutton->file_path, tmp, true);
strncpy(ibutton->key_name, furi_string_get_cstr(tmp), IBUTTON_KEY_NAME_SIZE);
furi_string_free(tmp);
}
return success;
}
bool ibutton_select_and_load_key(iButton* ibutton) {
bool ibutton_file_select(iButton* ibutton) {
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, IBUTTON_APP_EXTENSION, &I_ibutt_10px);
browser_options.base_path = IBUTTON_APP_FOLDER;
if(furi_string_empty(ibutton->file_path)) {
furi_string_set(ibutton->file_path, browser_options.base_path);
}
bool success = dialog_file_browser_show(
ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options);
return dialog_file_browser_show(
ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options) &&
ibutton_load_key(ibutton);
}
bool ibutton_save_key(iButton* ibutton) {
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading);
ibutton_make_app_folder(ibutton);
iButtonKey* key = ibutton->key;
const bool success =
ibutton_protocols_save(ibutton->protocols, key, furi_string_get_cstr(ibutton->file_path));
if(!success) {
dialog_message_show_storage_error(ibutton->dialogs, "Cannot save\nkey file");
if(success) {
success = ibutton_load_key_data(ibutton, ibutton->file_path, true);
}
return success;
}
bool ibutton_delete_key(iButton* ibutton) {
bool ibutton_save_key(iButton* ibutton, const char* key_name) {
// Create ibutton directory if necessary
ibutton_make_app_folder(ibutton);
FlipperFormat* file = flipper_format_file_alloc(ibutton->storage);
iButtonKey* key = ibutton->key;
bool result = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
result = storage_simply_remove(storage, furi_string_get_cstr(ibutton->file_path));
furi_record_close(RECORD_STORAGE);
do {
// Check if we has old key
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
// First remove old key
ibutton_delete_key(ibutton);
ibutton_reset_key(ibutton);
// Remove old key name from path
size_t filename_start = furi_string_search_rchar(ibutton->file_path, '/');
furi_string_left(ibutton->file_path, filename_start);
}
furi_string_cat_printf(ibutton->file_path, "/%s%s", key_name, IBUTTON_APP_EXTENSION);
// Open file for write
if(!flipper_format_file_open_always(file, furi_string_get_cstr(ibutton->file_path))) break;
// Write header
if(!flipper_format_write_header_cstr(file, IBUTTON_APP_FILE_TYPE, 1)) break;
// Write key type
if(!flipper_format_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
break;
const char* key_type = ibutton_key_get_string_by_type(ibutton_key_get_type(key));
if(!flipper_format_write_string_cstr(file, "Key type", key_type)) break;
// Write data
if(!flipper_format_write_comment_cstr(
file, "Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8"))
break;
if(!flipper_format_write_hex(
file, "Data", ibutton_key_get_data_p(key), ibutton_key_get_data_size(key)))
break;
result = true;
} while(false);
flipper_format_free(file);
if(!result) { //-V547
dialog_message_show_storage_error(ibutton->dialogs, "Cannot save\nkey file");
}
return result;
}
void ibutton_reset_key(iButton* ibutton) {
memset(ibutton->key_name, 0, IBUTTON_KEY_NAME_SIZE + 1);
furi_string_reset(ibutton->file_path);
ibutton_key_reset(ibutton->key);
bool ibutton_delete_key(iButton* ibutton) {
bool result = false;
result = storage_simply_remove(ibutton->storage, furi_string_get_cstr(ibutton->file_path));
return result;
}
void ibutton_text_store_set(iButton* ibutton, const char* text, ...) {
va_list args;
va_start(args, text);
vsnprintf(ibutton->text_store, IBUTTON_TEXT_STORE_SIZE, text, args);
va_end(args);
}
void ibutton_text_store_clear(iButton* ibutton) {
memset(ibutton->text_store, 0, IBUTTON_TEXT_STORE_SIZE + 1);
}
void ibutton_notification_message(iButton* ibutton, uint32_t message) {
@@ -246,44 +310,36 @@ void ibutton_notification_message(iButton* ibutton, uint32_t message) {
notification_message(ibutton->notifications, ibutton_notification_sequences[message]);
}
void ibutton_submenu_callback(void* context, uint32_t index) {
iButton* ibutton = context;
view_dispatcher_send_custom_event(ibutton->view_dispatcher, index);
}
void ibutton_widget_callback(GuiButtonType result, InputType type, void* context) {
iButton* ibutton = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
}
}
int32_t ibutton_app(void* arg) {
int32_t ibutton_app(void* p) {
iButton* ibutton = ibutton_alloc();
ibutton_make_app_folder(ibutton);
bool key_loaded = false;
bool rpc_mode = false;
if((arg != NULL) && (strlen(arg) != 0)) {
if(sscanf(arg, "RPC %lX", (uint32_t*)&ibutton->rpc) == 1) {
if(p && strlen(p)) {
uint32_t rpc_ctx = 0;
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
FURI_LOG_D(TAG, "Running in RPC mode");
rpc_system_app_set_callback(ibutton->rpc, ibutton_rpc_command_callback, ibutton);
rpc_system_app_send_started(ibutton->rpc);
ibutton->rpc_ctx = (void*)rpc_ctx;
rpc_mode = true;
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
rpc_system_app_send_started(ibutton->rpc_ctx);
} else {
furi_string_set(ibutton->file_path, (const char*)arg);
key_loaded = ibutton_load_key(ibutton);
furi_string_set(ibutton->file_path, (const char*)p);
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
key_loaded = true;
// TODO: Display an error if the key from p could not be loaded
}
}
}
if(ibutton->rpc != NULL) {
if(rpc_mode) {
view_dispatcher_attach_to_gui(
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeDesktop);
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRpc);
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
} else {
view_dispatcher_attach_to_gui(
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);
@@ -297,9 +353,9 @@ int32_t ibutton_app(void* arg) {
view_dispatcher_run(ibutton->view_dispatcher);
if(ibutton->rpc) {
rpc_system_app_set_callback(ibutton->rpc, NULL, NULL);
rpc_system_app_send_exited(ibutton->rpc);
if(ibutton->rpc_ctx) {
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(ibutton->rpc_ctx);
}
ibutton_free(ibutton);
return 0;

View File

@@ -1,14 +1,10 @@
#include <furi.h>
#include <furi_hal.h>
#include <stdarg.h>
#include <cli/cli.h>
#include <toolbox/args.h>
#include <one_wire/one_wire_host.h>
#include <one_wire/ibutton/ibutton_key.h>
#include <lib/toolbox/args.h>
#include <one_wire/ibutton/ibutton_worker.h>
#include <one_wire/ibutton/ibutton_protocols.h>
#include <one_wire/one_wire_host.h>
static void ibutton_cli(Cli* cli, FuriString* args, void* context);
static void onewire_cli(Cli* cli, FuriString* args, void* context);
@@ -26,7 +22,7 @@ void ibutton_on_system_start() {
#endif
}
static void ibutton_cli_print_usage() {
void ibutton_cli_print_usage() {
printf("Usage:\r\n");
printf("ikey read\r\n");
printf("ikey emulate <key_type> <key_data>\r\n");
@@ -38,52 +34,30 @@ static void ibutton_cli_print_usage() {
printf("\t<key_data> are hex-formatted\r\n");
};
static bool ibutton_cli_parse_key(iButtonProtocols* protocols, iButtonKey* key, FuriString* args) {
bool ibutton_cli_get_key_type(FuriString* data, iButtonKeyType* type) {
bool result = false;
FuriString* name = furi_string_alloc();
do {
// Read protocol name
if(!args_read_string_and_trim(args, name)) break;
// Make the protocol name uppercase
const char first = furi_string_get_char(name, 0);
furi_string_set_char(name, 0, toupper((int)first));
const iButtonProtocolId id =
ibutton_protocols_get_id_by_name(protocols, furi_string_get_cstr(name));
if(id == iButtonProtocolIdInvalid) break;
ibutton_key_set_protocol_id(key, id);
// Get the data pointer
iButtonEditableData data;
ibutton_protocols_get_editable_data(protocols, key, &data);
// Read data
if(!args_read_hex_bytes(args, data.ptr, data.size)) break;
if(furi_string_cmp_str(data, "Dallas") == 0 || furi_string_cmp_str(data, "dallas") == 0) {
result = true;
} while(false);
*type = iButtonKeyDS1990;
} else if(furi_string_cmp_str(data, "Cyfral") == 0 || furi_string_cmp_str(data, "cyfral") == 0) {
result = true;
*type = iButtonKeyCyfral;
} else if(furi_string_cmp_str(data, "Metakom") == 0 || furi_string_cmp_str(data, "metakom") == 0) {
result = true;
*type = iButtonKeyMetakom;
}
furi_string_free(name);
return result;
}
static void ibutton_cli_print_key(iButtonProtocols* protocols, iButtonKey* key) {
const char* name = ibutton_protocols_get_name(protocols, ibutton_key_get_protocol_id(key));
void ibutton_cli_print_key_data(iButtonKey* key) {
const uint8_t* key_data = ibutton_key_get_data_p(key);
iButtonKeyType type = ibutton_key_get_type(key);
if(strncmp(name, "DS", 2) == 0) {
name = "Dallas";
}
printf("%s ", name);
iButtonEditableData data;
ibutton_protocols_get_editable_data(protocols, key, &data);
for(size_t i = 0; i < data.size; i++) {
printf("%02X", data.ptr[i]);
printf("%s ", ibutton_key_get_string_by_type(type));
for(size_t i = 0; i < ibutton_key_get_size_by_type(type); i++) {
printf("%02X", key_data[i]);
}
printf("\r\n");
@@ -97,10 +71,9 @@ static void ibutton_cli_worker_read_cb(void* context) {
furi_event_flag_set(event, EVENT_FLAG_IBUTTON_COMPLETE);
}
static void ibutton_cli_read(Cli* cli) {
iButtonProtocols* protocols = ibutton_protocols_alloc();
iButtonWorker* worker = ibutton_worker_alloc(protocols);
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
void ibutton_cli_read(Cli* cli) {
iButtonKey* key = ibutton_key_alloc();
iButtonWorker* worker = ibutton_worker_alloc();
FuriEventFlag* event = furi_event_flag_alloc();
ibutton_worker_start_thread(worker);
@@ -108,25 +81,32 @@ static void ibutton_cli_read(Cli* cli) {
printf("Reading iButton...\r\nPress Ctrl+C to abort\r\n");
ibutton_worker_read_start(worker, key);
while(true) {
uint32_t flags =
furi_event_flag_wait(event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100);
if(flags & EVENT_FLAG_IBUTTON_COMPLETE) {
ibutton_cli_print_key(protocols, key);
ibutton_cli_print_key_data(key);
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
if(!ibutton_key_dallas_crc_is_valid(key)) {
printf("Warning: invalid CRC\r\n");
}
if(!ibutton_key_dallas_is_1990_key(key)) {
printf("Warning: not a key\r\n");
}
}
break;
}
if(cli_cmd_interrupt_received(cli)) break;
}
ibutton_worker_stop(worker);
ibutton_worker_stop_thread(worker);
ibutton_key_free(key);
ibutton_worker_stop_thread(worker);
ibutton_worker_free(worker);
ibutton_protocols_free(protocols);
ibutton_key_free(key);
furi_event_flag_free(event);
};
@@ -144,33 +124,48 @@ static void ibutton_cli_worker_write_cb(void* context, iButtonWorkerWriteResult
}
void ibutton_cli_write(Cli* cli, FuriString* args) {
iButtonProtocols* protocols = ibutton_protocols_alloc();
iButtonWorker* worker = ibutton_worker_alloc(protocols);
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
iButtonKey* key = ibutton_key_alloc();
iButtonWorker* worker = ibutton_worker_alloc();
iButtonKeyType type;
iButtonWriteContext write_context;
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
FuriString* data;
write_context.event = furi_event_flag_alloc();
data = furi_string_alloc();
ibutton_worker_start_thread(worker);
ibutton_worker_write_set_callback(worker, ibutton_cli_worker_write_cb, &write_context);
do {
if(!ibutton_cli_parse_key(protocols, key, args)) {
if(!args_read_string_and_trim(args, data)) {
ibutton_cli_print_usage();
break;
}
if(!(ibutton_protocols_get_features(protocols, ibutton_key_get_protocol_id(key)) &
iButtonProtocolFeatureWriteBlank)) {
if(!ibutton_cli_get_key_type(data, &type)) {
ibutton_cli_print_usage();
break;
}
if(type != iButtonKeyDS1990) {
ibutton_cli_print_usage();
break;
}
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
ibutton_cli_print_usage();
break;
}
ibutton_key_set_type(key, type);
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
printf("Writing key ");
ibutton_cli_print_key(protocols, key);
ibutton_cli_print_key_data(key);
printf("Press Ctrl+C to abort\r\n");
ibutton_worker_write_blank_start(worker, key);
ibutton_worker_write_start(worker, key);
while(true) {
uint32_t flags = furi_event_flag_wait(
write_context.event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100);
@@ -188,53 +183,64 @@ void ibutton_cli_write(Cli* cli, FuriString* args) {
if(cli_cmd_interrupt_received(cli)) break;
}
ibutton_worker_stop(worker);
} while(false);
ibutton_worker_stop(worker);
furi_string_free(data);
ibutton_worker_stop_thread(worker);
ibutton_key_free(key);
ibutton_worker_free(worker);
ibutton_protocols_free(protocols);
ibutton_key_free(key);
furi_event_flag_free(write_context.event);
}
};
void ibutton_cli_emulate(Cli* cli, FuriString* args) {
iButtonProtocols* protocols = ibutton_protocols_alloc();
iButtonWorker* worker = ibutton_worker_alloc(protocols);
iButtonKey* key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(protocols));
iButtonKey* key = ibutton_key_alloc();
iButtonWorker* worker = ibutton_worker_alloc();
iButtonKeyType type;
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
FuriString* data;
data = furi_string_alloc();
ibutton_worker_start_thread(worker);
do {
if(!ibutton_cli_parse_key(protocols, key, args)) {
if(!args_read_string_and_trim(args, data)) {
ibutton_cli_print_usage();
break;
}
if(!ibutton_cli_get_key_type(data, &type)) {
ibutton_cli_print_usage();
break;
}
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
ibutton_cli_print_usage();
break;
}
ibutton_key_set_type(key, type);
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
printf("Emulating key ");
ibutton_cli_print_key(protocols, key);
ibutton_cli_print_key_data(key);
printf("Press Ctrl+C to abort\r\n");
ibutton_worker_emulate_start(worker, key);
while(!cli_cmd_interrupt_received(cli)) {
furi_delay_ms(100);
};
ibutton_worker_stop(worker);
} while(false);
ibutton_worker_stop(worker);
furi_string_free(data);
ibutton_worker_stop_thread(worker);
ibutton_key_free(key);
ibutton_worker_free(worker);
ibutton_protocols_free(protocols);
ibutton_key_free(key);
};
void ibutton_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
static void ibutton_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
FuriString* cmd;
cmd = furi_string_alloc();
@@ -258,7 +264,7 @@ void ibutton_cli(Cli* cli, FuriString* args, void* context) {
furi_string_free(cmd);
}
static void onewire_cli_print_usage() {
void onewire_cli_print_usage() {
printf("Usage:\r\n");
printf("onewire search\r\n");
};
@@ -275,7 +281,7 @@ static void onewire_cli_search(Cli* cli) {
furi_hal_power_enable_otg();
while(!done) {
if(onewire_host_search(onewire, address, OneWireHostSearchModeNormal) != 1) {
if(onewire_host_search(onewire, address, NORMAL_SEARCH) != 1) {
printf("Search finished\r\n");
onewire_host_reset_search(onewire);
done = true;

Some files were not shown because too many files have changed in this diff Show More