Skip to content

Commit

Permalink
Move apps from flipperzero firmware into separate repository
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Jul 19, 2023
0 parents commit 0685939
Show file tree
Hide file tree
Showing 51 changed files with 5,150 additions and 0 deletions.
Binary file added 125_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
App(
appid="picopass",
name="PicoPass",
apptype=FlipperAppType.EXTERNAL,
targets=["f7"],
entry_point="picopass_app",
requires=[
"storage",
"gui",
],
stack_size=4 * 1024,
order=30,
fap_icon="125_10px.png",
fap_category="NFC",
fap_libs=["mbedtls"],
fap_private_libs=[
Lib(
name="loclass",
),
],
fap_icon_assets="icons",
)
164 changes: 164 additions & 0 deletions helpers/iclass_elite_dict.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#include "iclass_elite_dict.h"

#include <lib/toolbox/args.h>
#include <lib/flipper_format/flipper_format.h>

#define ICLASS_ELITE_DICT_FLIPPER_NAME APP_DATA_PATH("assets/iclass_elite_dict.txt")
#define ICLASS_ELITE_DICT_USER_NAME APP_DATA_PATH("assets/iclass_elite_dict_user.txt")
#define ICLASS_STANDARD_DICT_FLIPPER_NAME APP_DATA_PATH("assets/iclass_standard_dict.txt")

#define TAG "IclassEliteDict"

#define ICLASS_ELITE_KEY_LINE_LEN (17)
#define ICLASS_ELITE_KEY_LEN (8)

struct IclassEliteDict {
Stream* stream;
uint32_t total_keys;
};

bool iclass_elite_dict_check_presence(IclassEliteDictType dict_type) {
Storage* storage = furi_record_open(RECORD_STORAGE);

bool dict_present = false;
if(dict_type == IclassEliteDictTypeFlipper) {
dict_present =
(storage_common_stat(storage, ICLASS_ELITE_DICT_FLIPPER_NAME, NULL) == FSE_OK);
} else if(dict_type == IclassEliteDictTypeUser) {
dict_present = (storage_common_stat(storage, ICLASS_ELITE_DICT_USER_NAME, NULL) == FSE_OK);
} else if(dict_type == IclassStandardDictTypeFlipper) {
dict_present =
(storage_common_stat(storage, ICLASS_STANDARD_DICT_FLIPPER_NAME, NULL) == FSE_OK);
}

furi_record_close(RECORD_STORAGE);

return dict_present;
}

IclassEliteDict* iclass_elite_dict_alloc(IclassEliteDictType dict_type) {
IclassEliteDict* dict = malloc(sizeof(IclassEliteDict));
Storage* storage = furi_record_open(RECORD_STORAGE);
dict->stream = buffered_file_stream_alloc(storage);
FuriString* next_line = furi_string_alloc();

bool dict_loaded = false;
do {
if(dict_type == IclassEliteDictTypeFlipper) {
if(!buffered_file_stream_open(
dict->stream, ICLASS_ELITE_DICT_FLIPPER_NAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
buffered_file_stream_close(dict->stream);
break;
}
} else if(dict_type == IclassEliteDictTypeUser) {
if(!buffered_file_stream_open(
dict->stream, ICLASS_ELITE_DICT_USER_NAME, FSAM_READ_WRITE, FSOM_OPEN_ALWAYS)) {
buffered_file_stream_close(dict->stream);
break;
}
} else if(dict_type == IclassStandardDictTypeFlipper) {
if(!buffered_file_stream_open(
dict->stream,
ICLASS_STANDARD_DICT_FLIPPER_NAME,
FSAM_READ,
FSOM_OPEN_EXISTING)) {
buffered_file_stream_close(dict->stream);
break;
}
}

// Read total amount of keys
while(true) { //-V547
if(!stream_read_line(dict->stream, next_line)) break;
if(furi_string_get_char(next_line, 0) == '#') continue;
if(furi_string_size(next_line) != ICLASS_ELITE_KEY_LINE_LEN) continue;
dict->total_keys++;
}
furi_string_reset(next_line);
stream_rewind(dict->stream);

dict_loaded = true;
FURI_LOG_I(TAG, "Loaded dictionary with %lu keys", dict->total_keys);
} while(false);

if(!dict_loaded) { //-V547
buffered_file_stream_close(dict->stream);
free(dict);
dict = NULL;
}

furi_record_close(RECORD_STORAGE);
furi_string_free(next_line);

return dict;
}

void iclass_elite_dict_free(IclassEliteDict* dict) {
furi_assert(dict);
furi_assert(dict->stream);

buffered_file_stream_close(dict->stream);
stream_free(dict->stream);
free(dict);
}

uint32_t iclass_elite_dict_get_total_keys(IclassEliteDict* dict) {
furi_assert(dict);

return dict->total_keys;
}

bool iclass_elite_dict_get_next_key(IclassEliteDict* dict, uint8_t* key) {
furi_assert(dict);
furi_assert(dict->stream);

uint8_t key_byte_tmp = 0;
FuriString* next_line = furi_string_alloc();

bool key_read = false;
*key = 0ULL;
while(!key_read) {
if(!stream_read_line(dict->stream, next_line)) break;
if(furi_string_get_char(next_line, 0) == '#') continue;
if(furi_string_size(next_line) != ICLASS_ELITE_KEY_LINE_LEN) continue;
for(uint8_t i = 0; i < ICLASS_ELITE_KEY_LEN * 2; i += 2) {
args_char_to_hex(
furi_string_get_char(next_line, i),
furi_string_get_char(next_line, i + 1),
&key_byte_tmp);
key[i / 2] = key_byte_tmp;
}
key_read = true;
}

furi_string_free(next_line);
return key_read;
}

bool iclass_elite_dict_rewind(IclassEliteDict* dict) {
furi_assert(dict);
furi_assert(dict->stream);

return stream_rewind(dict->stream);
}

bool iclass_elite_dict_add_key(IclassEliteDict* dict, uint8_t* key) {
furi_assert(dict);
furi_assert(dict->stream);

FuriString* key_str = furi_string_alloc();
for(size_t i = 0; i < 6; i++) {
furi_string_cat_printf(key_str, "%02X", key[i]);
}
furi_string_cat_printf(key_str, "\n");

bool key_added = false;
do {
if(!stream_seek(dict->stream, 0, StreamOffsetFromEnd)) break;
if(!stream_insert_string(dict->stream, key_str)) break;
key_added = true;
} while(false);

furi_string_free(key_str);
return key_added;
}
29 changes: 29 additions & 0 deletions helpers/iclass_elite_dict.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <stdbool.h>
#include <storage/storage.h>
#include <lib/flipper_format/flipper_format.h>
#include <lib/toolbox/stream/file_stream.h>
#include <lib/toolbox/stream/buffered_file_stream.h>

typedef enum {
IclassEliteDictTypeUser,
IclassEliteDictTypeFlipper,
IclassStandardDictTypeFlipper,
} IclassEliteDictType;

typedef struct IclassEliteDict IclassEliteDict;

bool iclass_elite_dict_check_presence(IclassEliteDictType dict_type);

IclassEliteDict* iclass_elite_dict_alloc(IclassEliteDictType dict_type);

void iclass_elite_dict_free(IclassEliteDict* dict);

uint32_t iclass_elite_dict_get_total_keys(IclassEliteDict* dict);

bool iclass_elite_dict_get_next_key(IclassEliteDict* dict, uint8_t* key);

bool iclass_elite_dict_rewind(IclassEliteDict* dict);

bool iclass_elite_dict_add_key(IclassEliteDict* dict, uint8_t* key);
Binary file added icons/DolphinMafia_115x62.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/DolphinNice_96x59.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/Nfc_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/RFIDDolphinReceive_97x61.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/RFIDDolphinSend_97x61.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0685939

Please sign in to comment.