Skip to content

Commit

Permalink
Squashed 'applications/external/' changes from 828e2b77d2..5890d08342
Browse files Browse the repository at this point in the history
5890d08342 MFkey: Use union for MfClassicNonce, save some ram
e1fe1e8851 Revert "MFkey: Fix progress bar crash"
dfdd9f487b MFkey: Fix complete progressbar, simplify draw code
3b2ea6e566 MFkey: Fix thread race condition, simplify thread usage
dfb255664e Merge mfkey from https://github.com/noproto/FlipperMfkey
9f07c547f3 Bump version to 2.2
3faa571fdb Fix progress bar bug
29da430571 Format
e06c164aab Merge flizzer_tracker from https://github.com/LTVA1/flizzer_tracker
25f785e Update changelog.md
6fc4f2a bump version again...
4486a44 add detune effect

git-subtree-dir: applications/external
git-subtree-split: 5890d08342cf621f5dba8160b8ee87d53c055988
  • Loading branch information
RogueMaster committed Apr 4, 2024
1 parent ca59a11 commit 621dc18
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 63 deletions.
2 changes: 1 addition & 1 deletion flizzer_tracker/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ App(
cdefines=["APP_FLIZZER_TRACKER"],
stack_size=2 * 1024,
order=90,
fap_version=(0, 7),
fap_version=(0, 8),
fap_description="An advanced Flipper Zero chiptune tracker with 4 channels",
fap_author="LTVA",
fap_weburl="https://github.com/LTVA1/flizzer_tracker",
Expand Down
7 changes: 6 additions & 1 deletion flizzer_tracker/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Flizzer Tracker v0.4 #

## Added ##
- Vxx effect (detune)

# Flizzer Tracker v0.3 #

## Added ##
Expand All @@ -12,4 +17,4 @@

# Flizzer Tracker v0.1 #

- Initial release
- Initial release
5 changes: 5 additions & 0 deletions flizzer_tracker/tracker_engine/do_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ void do_command(
break;
}

case TE_EFFECT_PITCH: {
te_channel->finetune_note = ((int16_t)(opcode & 0xff) - 0x80) * 2;
break;
}

case TE_EFFECT_ARPEGGIO_ABS: {
te_channel->arpeggio_note = 0;
te_channel->fixed_note = ((opcode & 0xff) << 8);
Expand Down
3 changes: 2 additions & 1 deletion flizzer_tracker/tracker_engine/tracker_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ void tracker_engine_advance_channel(TrackerEngine* tracker_engine, uint8_t chan)

int32_t chn_note = (int16_t)(te_channel->fixed_note != 0xffff ? te_channel->fixed_note :
te_channel->note) +
vib + ((int16_t)te_channel->arpeggio_note << 8);
vib + ((int16_t)te_channel->arpeggio_note << 8) +
te_channel->finetune_note;

if(chn_note < 0) {
chn_note = 0;
Expand Down
3 changes: 2 additions & 1 deletion flizzer_tracker/tracker_engine/tracker_engine_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ typedef enum {

TE_EFFECT_PORTA_UP_SEMITONE = 0x1d00, // Txx
TE_EFFECT_PORTA_DOWN_SEMITONE = 0x1e00, // Uxx
TE_EFFECT_PITCH = 0x1f00, //Vxx
/*
TE_EFFECT_ = 0x1f00, //Vxx
TE_EFFECT_ = 0x2000, //Wxx
*/

Expand Down Expand Up @@ -155,6 +155,7 @@ typedef struct {
uint8_t channel_flags;

uint16_t note, target_note, last_note, fixed_note;
int16_t finetune_note;
int16_t arpeggio_note;

uint8_t volume;
Expand Down
1 change: 1 addition & 0 deletions flizzer_tracker/view/opcode_description.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static const OpcodeDescription opcode_desc[] = {
{TE_EFFECT_SET_HARD_SYNC_SRC, 0x7f00, "SET HARD SYNC SOURCE CHANNEL", "S.SRC"},
{TE_EFFECT_PORTA_UP_SEMITONE, 0x7f00, "PORTAMENTO UP (SEMITONES)", "PU.SEM"},
{TE_EFFECT_PORTA_DOWN_SEMITONE, 0x7f00, "PORTAMENTO DOWN (SEMITONES)", "PD.SEM"},
{TE_EFFECT_PITCH, 0x7f00, "DETUNE 80=CENT.,0=-1SEM,FF=+1SEM", "DETUNE"},
{TE_EFFECT_LEGATO, 0x7f00, "LEGATO", "LEGATO"},
{TE_EFFECT_ARPEGGIO_ABS, 0x7f00, "ABSOLUTE ARPEGGIO NOTE", ""},
{TE_EFFECT_TRIGGER_RELEASE, 0x7f00, "TRIGGER RELEASE", "TR.REL"},
Expand Down
2 changes: 1 addition & 1 deletion mfkey/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ App(
fap_icon_assets="images",
fap_weburl="https://github.com/noproto/FlipperMfkey",
fap_description="MIFARE Classic key recovery tool",
fap_version="2.1",
fap_version="2.2",
)

App(
Expand Down
72 changes: 28 additions & 44 deletions mfkey/mfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,17 @@ int old_recover(

static inline int sync_state(ProgramState* program_state) {
int ts = furi_hal_rtc_get_timestamp();
program_state->eta_round = program_state->eta_round - (ts - program_state->eta_timestamp);
program_state->eta_total = program_state->eta_total - (ts - program_state->eta_timestamp);
int elapsed_time = ts - program_state->eta_timestamp;
if(elapsed_time < program_state->eta_round) {
program_state->eta_round -= elapsed_time;
} else {
program_state->eta_round = 0;
}
if(elapsed_time < program_state->eta_total) {
program_state->eta_total -= elapsed_time;
} else {
program_state->eta_total = 0;
}
program_state->eta_timestamp = ts;
if(program_state->close_thread_please) {
return 1;
Expand Down Expand Up @@ -669,27 +678,23 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_clear(canvas);
canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_draw_frame(canvas, 0, 15, 128, 64);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 5, 4, AlignLeft, AlignTop, "MFKey");
snprintf(draw_str, sizeof(draw_str), "RAM: %zub", memmgr_get_free_heap());
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 48, 5, AlignLeft, AlignTop, draw_str);
canvas_draw_icon(canvas, 114, 4, &I_mfkey);
if(program_state->is_thread_running && program_state->mfkey_state == MFKeyAttack) {
if(program_state->mfkey_state == MFKeyAttack) {
float eta_round = (float)1 - ((float)program_state->eta_round / (float)eta_round_time);
float eta_total = (float)1 - ((float)program_state->eta_total / (float)eta_total_time);
float progress = (float)program_state->num_completed / (float)program_state->total;
if(eta_round < 0 || eta_round > 1) {
if(eta_round < 0) {
// Round ETA miscalculated
eta_round = 1;
program_state->eta_round = 0;
}
if(eta_total < 0 || eta_total > 1) {
if(eta_total < 0) {
// Total ETA miscalculated
eta_total = 1;
program_state->eta_total = 0;
}
canvas_set_font(canvas, FontSecondary);
snprintf(
draw_str,
sizeof(draw_str),
Expand All @@ -707,39 +712,33 @@ static void render_callback(Canvas* const canvas, void* ctx) {
elements_progress_bar_with_text(canvas, 5, 31, 118, eta_round, draw_str);
snprintf(draw_str, sizeof(draw_str), "Total ETA %03d Sec", program_state->eta_total);
elements_progress_bar_with_text(canvas, 5, 44, 118, eta_total, draw_str);
} else if(program_state->is_thread_running && program_state->mfkey_state == DictionaryAttack) {
canvas_set_font(canvas, FontSecondary);
} else if(program_state->mfkey_state == DictionaryAttack) {
snprintf(
draw_str, sizeof(draw_str), "Dict solves: %d (in progress)", program_state->cracked);
canvas_draw_str_aligned(canvas, 10, 18, AlignLeft, AlignTop, draw_str);
snprintf(draw_str, sizeof(draw_str), "Keys in dict: %d", program_state->dict_count);
canvas_draw_str_aligned(canvas, 26, 28, AlignLeft, AlignTop, draw_str);
} else if(program_state->mfkey_state == Complete) {
// TODO: Scrollable list view to see cracked keys if user presses down
elements_progress_bar_with_text(canvas, 5, 18, 118, 1, draw_str);
canvas_set_font(canvas, FontSecondary);
snprintf(draw_str, sizeof(draw_str), "Complete");
canvas_draw_str_aligned(canvas, 40, 31, AlignLeft, AlignTop, draw_str);
elements_progress_bar(canvas, 5, 18, 118, 1);
canvas_draw_str_aligned(canvas, 40, 31, AlignLeft, AlignTop, "Complete");
snprintf(
draw_str,
sizeof(draw_str),
"Keys added to user dict: %d",
program_state->unique_cracked);
canvas_draw_str_aligned(canvas, 10, 41, AlignLeft, AlignTop, draw_str);
} else if(program_state->mfkey_state == Ready) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 50, 30, AlignLeft, AlignTop, "Ready");
elements_button_center(canvas, "Start");
elements_button_right(canvas, "Help");
} else if(program_state->mfkey_state == Help) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 7, 20, AlignLeft, AlignTop, "Collect nonces using Detect");
canvas_draw_str_aligned(canvas, 7, 30, AlignLeft, AlignTop, "Reader or FlipperNested.");
canvas_draw_str_aligned(canvas, 7, 40, AlignLeft, AlignTop, "Devs: noproto, AG, ALiberty");
canvas_draw_str_aligned(canvas, 7, 50, AlignLeft, AlignTop, "Thanks: bettse, Foxushka");
} else if(program_state->mfkey_state == Error) {
canvas_draw_str_aligned(canvas, 50, 25, AlignLeft, AlignTop, "Error");
canvas_set_font(canvas, FontSecondary);
if(program_state->err == MissingNonces) {
canvas_draw_str_aligned(canvas, 25, 36, AlignLeft, AlignTop, "No nonces found");
} else if(program_state->err == ZeroNonces) {
Expand All @@ -752,6 +751,8 @@ static void render_callback(Canvas* const canvas, void* ctx) {
} else {
// Unhandled program state
}
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 5, 4, AlignLeft, AlignTop, "MFKey");
furi_mutex_release(program_state->mutex);
}

Expand All @@ -763,7 +764,6 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
}

static void mfkey_state_init(ProgramState* program_state) {
program_state->is_thread_running = false;
program_state->mfkey_state = Ready;
program_state->cracked = 0;
program_state->unique_cracked = 0;
Expand All @@ -775,20 +775,12 @@ static void mfkey_state_init(ProgramState* program_state) {
// Entrypoint for worker thread
static int32_t mfkey_worker_thread(void* ctx) {
ProgramState* program_state = ctx;
program_state->is_thread_running = true;
program_state->mfkey_state = Initializing;
//FURI_LOG_I(TAG, "Hello from the mfkey worker thread"); // DEBUG
mfkey(program_state);
program_state->is_thread_running = false;
return 0;
}

void start_mfkey_thread(ProgramState* program_state) {
if(!program_state->is_thread_running) {
furi_thread_start(program_state->mfkeythread);
}
}

int32_t mfkey_main() {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));

Expand All @@ -812,11 +804,8 @@ int32_t mfkey_main() {
Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen);

program_state->mfkeythread = furi_thread_alloc();
furi_thread_set_name(program_state->mfkeythread, "MFKey Worker");
furi_thread_set_stack_size(program_state->mfkeythread, 2048);
furi_thread_set_context(program_state->mfkeythread, program_state);
furi_thread_set_callback(program_state->mfkeythread, mfkey_worker_thread);
program_state->mfkeythread =
furi_thread_alloc_ex("MFKey Worker", 2048, mfkey_worker_thread, program_state);

PluginEvent event;
for(bool main_loop = true; main_loop;) {
Expand All @@ -834,33 +823,27 @@ int32_t mfkey_main() {
case InputKeyDown:
break;
case InputKeyRight:
if(!program_state->is_thread_running &&
program_state->mfkey_state == Ready) {
if(program_state->mfkey_state == Ready) {
program_state->mfkey_state = Help;
view_port_update(view_port);
}
break;
case InputKeyLeft:
break;
case InputKeyOk:
if(!program_state->is_thread_running &&
program_state->mfkey_state == Ready) {
start_mfkey_thread(program_state);
if(program_state->mfkey_state == Ready) {
furi_thread_start(program_state->mfkeythread);
view_port_update(view_port);
}
break;
case InputKeyBack:
if(!program_state->is_thread_running &&
program_state->mfkey_state == Help) {
if(program_state->mfkey_state == Help) {
program_state->mfkey_state = Ready;
view_port_update(view_port);
} else {
program_state->close_thread_please = true;
if(program_state->is_thread_running && program_state->mfkeythread) {
// Wait until thread is finished
furi_thread_join(program_state->mfkeythread);
}
program_state->close_thread_please = false;
// Wait until thread is finished
furi_thread_join(program_state->mfkeythread);
main_loop = false;
}
break;
Expand All @@ -875,6 +858,7 @@ int32_t mfkey_main() {
furi_mutex_release(program_state->mutex);
}

// Thread joined in back event handler
furi_thread_free(program_state->mfkeythread);
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
Expand Down
34 changes: 20 additions & 14 deletions mfkey/mfkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,26 @@ typedef struct {
uint32_t nt1; // tag challenge second
uint32_t uid_xor_nt0; // uid ^ nt0
uint32_t uid_xor_nt1; // uid ^ nt1
// Mfkey32
uint32_t p64; // 64th successor of nt0
uint32_t p64b; // 64th successor of nt1
uint32_t nr0_enc; // first encrypted reader challenge
uint32_t ar0_enc; // first encrypted reader response
uint32_t nr1_enc; // second encrypted reader challenge
uint32_t ar1_enc; // second encrypted reader response
// Nested
uint32_t ks1_1_enc; // first encrypted keystream
uint32_t ks1_2_enc; // second encrypted keystream
char par_1_str[5]; // first parity bits (string representation)
char par_2_str[5]; // second parity bits (string representation)
uint8_t par_1; // first parity bits
uint8_t par_2; // second parity bits
union {
// Mfkey32
struct {
uint32_t p64; // 64th successor of nt0
uint32_t p64b; // 64th successor of nt1
uint32_t nr0_enc; // first encrypted reader challenge
uint32_t ar0_enc; // first encrypted reader response
uint32_t nr1_enc; // second encrypted reader challenge
uint32_t ar1_enc; // second encrypted reader response
};
// Nested
struct {
uint32_t ks1_1_enc; // first encrypted keystream
uint32_t ks1_2_enc; // second encrypted keystream
char par_1_str[5]; // first parity bits (string representation)
char par_2_str[5]; // second parity bits (string representation)
uint8_t par_1; // first parity bits
uint8_t par_2; // second parity bits
};
};
} MfClassicNonce;

typedef struct {
Expand Down

0 comments on commit 621dc18

Please sign in to comment.