Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Misc cleanup and README updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyweiss committed Jan 25, 2023
1 parent 366030e commit 92a601d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 243 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# magspoof_flipper
WIP of MagSpoof for the Flipper Zero. Currently rewriting from the ground up; basic TX of saved files should now work over both RFID (using the Flipper's internal coil) and GPIO (pins A6 and A7: such that one can connect an H-bridge and external coil). A sample file with test data is included in `assets`, for anyone wishing to experiment. Using this README as coarse notes of what remains to be done; anyone is welcome to contribute!

Disclaimer: use responsibly, and at your own risk. While in my testing, I've seen no reason to believe this could damage the RFID hardware, this is inherently driving the coil in ways it was not designed or intended for; I take no responsibility for fried/bricked Flippers. Similarly, please only use this with magstripe cards and mag readers you own — this is solely meant as a proof of concept for educational purposes, and I neither condone nor am sympathetic to malicious uses of my code.
Disclaimer: use responsibly, and at your own risk. While in my testing, I've seen no reason to believe this could damage the RFID hardware, this is inherently driving the coil in ways it was not designed or intended for; I take no responsibility for fried/bricked Flippers. Similarly, please only use this with magstripe cards and mag readers you own — this is solely meant as a proof of concept for educational purposes. I neither condone nor am sympathetic to malicious uses of my code.

## TODO
Emulation:
- Clean up old testing scenes, remove deprecated helpers
- Reverse track precomputation
- Does the main timing-sensitive section need to be branchless? (Remove `if`s from the `FURI_CRITICAL...` section of `mag_spoof()`?)
- Implement/integrate better bitmap than hacky first pass? antirez's better approach (from ProtoView) included at bottom of `helpers/mag_helpers.c`
- General code cleanup
- Reverse track precompute & replay
- Implement/integrate better bitmap than hacky first pass? Boilerplate from [antirez](https://github.com/antirez)'s better approach (from [ProtoView](https://github.com/antirez/protoview)) included at the bottom of `helpers/mag_helpers.c`
- Should the main timing-sensitive section be branchless? (Remove `if` and `switch` statements from the `FURI_CRITICAL...` section of `mag_spoof()`?)
- Pursue skunkworks TX improvement ideas listed below

Scenes:
- Complete emulation config scene (include reverse track functionality; possibly expand settings list to include prefix/between/suffix options)
- Finish emulation config scene (reverse track functionality; possibly expand settings list to include prefix/between/suffix options)
- Improved saved info display (better text wrapping options? remove and just include that info on the emulate scene? decode data to fields?)
- Edit saved card scene
- "About" scene?
- "Edit" scene (generalize "Add manually")

File management:
- Parsing loaded files into relevent fields (would we need to specify card type as well, to decode correctly?)
- Modify manual add scene to allow editing and renaming of existing files
- Validation of card track data?
- Parsing loaded files into human-readable fields (would we need to specify card type to decode correctly?)
- Update Add Manually flow to reflect new file format (currently only sets Track 2, and Info/Emulate scene only displays Track 2)

Known bugs:
- Custom text input scene with expanded characterset (Add Manually) has odd behavior when navigating the keys near the numpad
- Track 1 data typically starts with a `%` sign. Unless escaped, it won't be displayed when printed, as C considers it a special character. To confirm: how does this impact the emulation when iterating through the chars? Does it get played correctly?
- Possible file format issues when Track 2 data exists but Track 1 is left empty; doesn't seem to load happily.
- Attempting to play a track that doesn't have data results in a crash (as one might expect). Need to lock out users from selecting empty tracks in the config menu or do better error handling

## Skunkworks ideas
Internal TX improvements:
- Attempt downstream modulation techniques, in addition to upstream, like the LF RFID worker does when writing, for stronger signal
- Implement using the timer system, rather than direct-writing to pins
- Use the NFC (HF RFID) coil instead of or in addition to the LF coil (likely unfruitful from initial tests; we can enable/disable the oscillating field, but even with transparent mode to the ST25R3916, it seems we don't get low-enough-level control to pull it high/low correctly)

External RX options (What is simplest read module?):
- Some UART mag reader (bulky, but likely easiest to read over GPIO, and means one can read all tracks)
- Square audio jack mag reader (this may be DOA; seems like newer versions of the Square modules have some form of preprocessing, that also modifies the signal, perhaps in an effort to discourage folks using their hardware independent of their software. Thanks @[arha](https://github.com/arha) for your work investigating this)
External RX options:
- UART-connected mag reader (bulky, but likely easiest to read over GPIO, and means one can read all tracks)
- Square audio jack mag reader (this may be DOA; seems like newer versions of the Square modules have some form of preprocessing that also modifies the signal, perhaps in an effort to discourage folks using their hardware independent of their software. Thanks [@arha](https://github.com/arha) for your work investigating this)
- Some read-head directly connected to GPIO, ADC'd, and parsed all on the Flipper. Likely the most compact and cheapest module option, but also would require the most work.
- USB HID input feasible? Flipper seemingly can't act as an HID host, is there any way to circumvent this or is it due to a hardware incompatibility? This would be the easiest / best option all-around if feasible.
- USB HID input likely infeasible; seems the FZ cannot act as an HID host.

----
## Credits
This project interpolates work from [Samy Kamkar's original MagSpoof project](https://github.com/samyk/magspoof), [dunaevai135's Flipper hackathon project](https://github.com/dunaevai135/flipperzero-firmware), and the Flipper team's [LF RFID](https://github.com/flipperdevices/flipperzero-firmware/tree/dev/applications/main/lfrfid) and [SubGhz](https://github.com/flipperdevices/flipperzero-firmware/tree/dev/applications/main/subghz) apps.
This project interpolates work from [Samy Kamkar's original MagSpoof project](https://github.com/samyk/magspoof), [dunaevai135 & AlexYaro's Flipper hackathon project](https://github.com/dunaevai135/flipperzero-firmware), and the Flipper team's [LF RFID](https://github.com/flipperdevices/flipperzero-firmware/tree/dev/applications/main/lfrfid) and [SubGhz](https://github.com/flipperdevices/flipperzero-firmware/tree/dev/applications/main/subghz) apps.

Many thanks to everyone who has helped in addition to those above, most notably:
- [antirez](https://github.com/antirez) for bitmapping suggestions and general C wisdom
Expand Down
7 changes: 5 additions & 2 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ App(
entry_point="mag_app",
cdefines=["APP_MAG"],
requires=[
"gui",
"gui",
"storage",
"notification",
"dialogs",
'toolbox',
],
provides=[],
stack_size=2 * 1024,
order=20,
fap_icon="icons/mag_10px.png",
fap_category="Tools",
fap_icon_assets="icons",
fap_version=(0, 1), # major, minor
fap_description="WIP MagSpoof port using the RFID subsystem",
fap_author="Zachary Weiss",
fap_weburl="https://github.com/zacharyweiss/magspoof_flipper",
)
8 changes: 2 additions & 6 deletions helpers/mag_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ void track_to_bits(uint8_t* bit_array, const char* track_data, uint8_t track_ind
bit_array[i] = 2;
i++;

// Log the output
// Log the output (messy but works)
char output[100] = {0x0};
//FURI_LOG_D(TAG, "%s", bit_array);
FuriString* tmp_str;
tmp_str = furi_string_alloc();
for(uint8_t j = 0; bit_array[j] != 2; j++) {
Expand All @@ -201,16 +200,13 @@ void track_to_bits(uint8_t* bit_array, const char* track_data, uint8_t track_ind
}
FURI_LOG_D(TAG, "Track %d: %s", (track_index + 1), output);
furi_string_free(tmp_str);

//bool is_correct_length = (i == (strlen(track_data) * bitlen[track_index]));
//furi_assert(is_correct_length);
}

void mag_spoof(Mag* mag) {
MagSetting* setting = mag->setting;

// precompute tracks (WIP; ignores reverse and 3rd track)
// likely will be reworked to Samy's bitmap method anyway...
// likely will be reworked to antirez's bitmap method anyway...
const char* data1 = furi_string_get_cstr(mag->mag_dev->dev_data.track[0].str);
const char* data2 = furi_string_get_cstr(mag->mag_dev->dev_data.track[1].str);
uint8_t bit_array1[(strlen(data1) * bitlen[0]) + 1];
Expand Down
1 change: 0 additions & 1 deletion scenes/mag_scene_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ADD_SCENE(mag, start, Start)
ADD_SCENE(mag, emulate_test, EmulateTest)
ADD_SCENE(mag, emulate, Emulate)
ADD_SCENE(mag, emulate_config, EmulateConfig)
ADD_SCENE(mag, file_select, FileSelect)
Expand Down
209 changes: 0 additions & 209 deletions scenes/mag_scene_emulate_test.c

This file was deleted.

12 changes: 1 addition & 11 deletions scenes/mag_scene_start.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "../mag_i.h"

typedef enum {
//SubmenuIndexEmulateTest,
SubmenuIndexSaved,
SubmenuIndexAddManually,
} SubmenuIndex;
Expand All @@ -16,15 +15,10 @@ void mag_scene_start_on_enter(void* context) {
Mag* mag = context;
Submenu* submenu = mag->submenu;

/*submenu_add_item(
submenu,
"Emulate (Hardcoded)",
SubmenuIndexEmulateTest,
mag_scene_start_submenu_callback,
mag);*/
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, mag_scene_start_submenu_callback, mag);
submenu_add_item(
submenu, "Add Manually", SubmenuIndexAddManually, mag_scene_start_submenu_callback, mag);
// TODO: "About" scene?

submenu_set_selected_item(
submenu, scene_manager_get_scene_state(mag->scene_manager, MagSceneStart));
Expand All @@ -40,10 +34,6 @@ bool mag_scene_start_on_event(void* context, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
/*if(event.event == SubmenuIndexEmulateTest) {
scene_manager_next_scene(mag->scene_manager, MagSceneEmulateTest);
consumed = true;
} else */
if(event.event == SubmenuIndexSaved) {
furi_string_set(mag->file_path, MAG_APP_FOLDER);
scene_manager_next_scene(mag->scene_manager, MagSceneFileSelect);
Expand Down

0 comments on commit 92a601d

Please sign in to comment.