Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Dec 2, 2023
1 parent 52157fe commit 04c3a60
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 116 deletions.
14 changes: 3 additions & 11 deletions mifare_nested/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@ App(
name="Mifare Nested",
apptype=FlipperAppType.EXTERNAL,
entry_point="mifare_nested_app",
requires=[
"storage",
"gui",
"nfc"
],
requires=["storage", "gui", "nfc"],
stack_size=4 * 1024,
order=30,
fap_icon="assets/icon.png",
fap_category="NFC",
fap_private_libs=[
Lib(name="nested"),
Lib(name="parity"),
Lib(name="crypto1")
],
fap_private_libs=[Lib(name="nested"), Lib(name="parity"), Lib(name="crypto1")],
fap_icon_assets="assets",
fap_author="AloneLiberty",
fap_description="Recover Mifare Classic keys",
fap_weburl="https://github.com/AloneLiberty/FlipperNested",
fap_version="1.5.2"
fap_version="1.5.2",
)
143 changes: 90 additions & 53 deletions nrf24scan/nrf24_packet_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
# NRF24L01+ Enhanced ShockBurst packets decoder
#
payload_len_default = 4
packets = \
(
'10101010 11101110 00000011 00001000 00001011 01000111 000100 10 0 10101010 10101010 10101010 10101010 00011101',
'10101010 11001000 11001000 11000011 110011 10 0 00001011 00000011 00000101 00000000 0010001100100000',
'10101010 11001000 11001000 11000100 000100 11 1 00001011 00000011 00000101 00000000 0010010011100010',
'10101010 11001000 11001000 11000100 00001011 00000011 00000101 00000010 1000010101000010',
'10101010 11001000 11001000 11000000 110011 10 0 11110101 00000010 00000011 00000000 0000111001000000',
'01010101 01000000 01101000 00010101 000000 00 0 0100100000100000',
# '01010101 01000010 11100100 10100110 01010101 01000100 110011 00 0 10010101 10110011 01100100 10101100 10101011 01010010 01111100 01001010 1100110100110001',

packets = (
"10101010 11101110 00000011 00001000 00001011 01000111 000100 10 0 10101010 10101010 10101010 10101010 00011101",
"10101010 11001000 11001000 11000011 110011 10 0 00001011 00000011 00000101 00000000 0010001100100000",
"10101010 11001000 11001000 11000100 000100 11 1 00001011 00000011 00000101 00000000 0010010011100010",
"10101010 11001000 11001000 11000100 00001011 00000011 00000101 00000010 1000010101000010",
"10101010 11001000 11001000 11000000 110011 10 0 11110101 00000010 00000011 00000000 0000111001000000",
"01010101 01000000 01101000 00010101 000000 00 0 0100100000100000",
# '01010101 01000010 11100100 10100110 01010101 01000100 110011 00 0 10010101 10110011 01100100 10101100 10101011 01010010 01111100 01001010 1100110100110001',
)


def bin2hex(x):
def bin2hex_helper(r):
while r:
yield r[0:2].upper()
r = r[2:]
if len(x) == 0: return

if len(x) == 0:
return
fmt = "{0:0" + str(int(len(x) / 8 * 2)) + "X}"
hex_data = fmt.format(int(x, 2))
return list(bin2hex_helper(hex_data))


def bin2hexlong(b):
b = b.replace(" ", "")
out = "";
out = ""
n = 8
for i in range(0, len(b), n):
b2 = b[i:i+n]
out = out + "{0:02X}".format(int(b2.ljust(8, '0'),2))
for i in range(0, len(b), n):
b2 = b[i : i + n]
out = out + "{0:02X}".format(int(b2.ljust(8, "0"), 2))
return out


Expand All @@ -42,7 +44,7 @@ def split_packet(packet, parts):
:return: list of substrings
"""
out = []
packet = packet.replace(' ', '')
packet = packet.replace(" ", "")
for part_length in parts:
out.append(packet[0:part_length])
packet = packet[part_length:]
Expand All @@ -53,15 +55,29 @@ def split_packet(packet, parts):
def parse_packet(packet, address_length, ESB):
"""Split a packet into its fields and return them as tuple."""
if ESB:
preamble, address, payload_length, pid, no_ack, rest = split_packet(packet=packet, parts=(8, 8 * address_length, 6, 2, 1))
payload, crc = split_packet(packet=rest, parts=((payload_len_default if int(payload_length, 2) > 32 else int(payload_length, 2)) * 8,))
preamble, address, payload_length, pid, no_ack, rest = split_packet(
packet=packet, parts=(8, 8 * address_length, 6, 2, 1)
)
payload, crc = split_packet(
packet=rest,
parts=(
(
payload_len_default
if int(payload_length, 2) > 32
else int(payload_length, 2)
)
* 8,
),
)
else:
preamble, address, rest = split_packet(packet=packet, parts=(8, 8 * address_length))
crc = packet.rsplit(' ', 1)[1]
payload = rest[0:len(rest) - len(crc)]
payload_length = pid = no_ack = ''
preamble, address, rest = split_packet(
packet=packet, parts=(8, 8 * address_length)
)
crc = packet.rsplit(" ", 1)[1]
payload = rest[0 : len(rest) - len(crc)]
payload_length = pid = no_ack = ""

assert preamble in ('10101010', '01010101')
assert preamble in ("10101010", "01010101")
assert len(crc) in (8, 16)

return preamble, address, payload_length, pid, no_ack, payload, crc
Expand All @@ -76,56 +92,77 @@ def crc(bits, size=8):
:polynomial: 2 byte CRC - standard is 0x11021 = X^16+X^12+X^5+1, result the same for 0x1021
"""
if size == 8:
polynomial = 0x107
crc = 0xFF
polynomial = 0x107
crc = 0xFF
else:
polynomial = 0x11021
crc = 0xFFFF
polynomial = 0x11021
crc = 0xFFFF
max_crc_value = (1 << size) - 1 # e.g. 0xFF for mode 8bit-crc
for bit in bits:
bit = int(bit, 2)
crc <<= 1
if (crc >> size) ^ bit: # top most lfsr bit xor current data bit
crc ^= polynomial
crc &= max_crc_value # trim the crc to reject carry over bits
# print('{:X}'.format(crc))
# print('{:X}'.format(crc))
return crc


if __name__ == '__main__':
if __name__ == "__main__":
for packet in packets:
fld = packet.split(' ');
fld = packet.split(" ")
address_length = -1
ESB = True
for f in fld:
if len(f) == 6 : break
if len(f) == 0 :
ESB = False
if len(f) == 6:
break
if len(f) == 0:
ESB = False
break
address_length += 1
preamble, address, payload_length, pid, no_ack, payload, crc_received = \
parse_packet(packet=packet, address_length=address_length, ESB=ESB)
(
preamble,
address,
payload_length,
pid,
no_ack,
payload,
crc_received,
) = parse_packet(packet=packet, address_length=address_length, ESB=ESB)
crc_size = len(crc_received)
crc_received = '0x' + '{:X}'.format(int(crc_received, 2))
crc_received = "0x" + "{:X}".format(int(crc_received, 2))
print(f"Packet: {packet}")
print('\n'.join((
f'Hex: {bin2hexlong(packet)}',
'Preamble: 0x%X' % int(preamble,2),
f'Address: {address_length} bytes - {bin2hex(address)}')))
print(
"\n".join(
(
f"Hex: {bin2hexlong(packet)}",
"Preamble: 0x%X" % int(preamble, 2),
f"Address: {address_length} bytes - {bin2hex(address)}",
)
)
)
if ESB:
print('\n'.join((
f'Payload length in packet: {int(payload_length, 2)}, used: {(payload_len_default if int(payload_length, 2) > 32 else int(payload_length, 2))}',
f'Payload: {bin2hex(payload)}',
f'Pid: {int(pid, 2)}',
f'No_ack: {int(no_ack, 2) == 1}')))
print(
"\n".join(
(
f"Payload length in packet: {int(payload_length, 2)}, used: {(payload_len_default if int(payload_length, 2) > 32 else int(payload_length, 2))}",
f"Payload: {bin2hex(payload)}",
f"Pid: {int(pid, 2)}",
f"No_ack: {int(no_ack, 2) == 1}",
)
)
)
else:
print(f'Not Enhanced ShockBurst packet, payload length: {int(len(payload) / 8)}')
print(f'Payload: {bin2hex(payload)}')
print(f'CRC{crc_size}: {crc_received}')
crc_calculated = '0x' + '{:X}'.format(crc(address + payload_length + pid + no_ack + payload, size=crc_size))
print(
f"Not Enhanced ShockBurst packet, payload length: {int(len(payload) / 8)}"
)
print(f"Payload: {bin2hex(payload)}")
print(f"CRC{crc_size}: {crc_received}")
crc_calculated = "0x" + "{:X}".format(
crc(address + payload_length + pid + no_ack + payload, size=crc_size)
)
if crc_received == crc_calculated:
print('CRC is valid!')
print("CRC is valid!")
else:
print(f'CRC mismatch! Calculated CRC is {crc_calculated}.')
print('-------------')

print(f"CRC mismatch! Calculated CRC is {crc_calculated}.")
print("-------------")
1 change: 1 addition & 0 deletions spi_mem_manager/tools/chiplist_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def generateCArr(arr, filename):
else:
print(" " + cur["writeMode"] + "},", file=out)


def main():
filename = "spi_mem_chip_arr.c"
args = getArgs()
Expand Down
35 changes: 20 additions & 15 deletions swd_probe/model/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,42 @@
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')
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
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')
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('};')
f.write(" {%f, %f, %f},\n" % (x, y, z))
f.write("};")

# Extract the faces
faces = plydata['face'].data
faces = plydata["face"].data
num_faces = len(faces)
f.write('int edgeIndices[][3] = {\n')
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]))
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])]
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')
f.write(" {%d, %d},\n" % (edge[0], edge[1]))
f.write("};\n")
30 changes: 15 additions & 15 deletions uart_terminal/scenes/uart_terminal_scene_console_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
FuriString* new_str = furi_string_alloc();

if(app->hex_mode) {
while (len--) {
while(len--) {
uint8_t byte = *(buf++);
if(byte == '\0') break;
furi_string_cat_printf(new_str, "%02X ", byte);
}
}
else {
} else {
buf[len] = '\0';
furi_string_cat_printf(new_str, "%s", buf);
}

// If text box store gets too big, then truncate it
app->text_box_store_strlen += furi_string_size(new_str);;
app->text_box_store_strlen += furi_string_size(new_str);
;
while(app->text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
Expand All @@ -33,13 +33,13 @@ void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo

static uint8_t hex_char_to_byte(const char c) {
if(c >= '0' && c <= '9') {
return c-'0';
return c - '0';
}
if(c >= 'A' && c <= 'F') {
return c-'A'+10;
return c - 'A' + 10;
}
if (c >= 'a' && c <= 'f') {
return c-'a'+10;
if(c >= 'a' && c <= 'f') {
return c - 'a' + 10;
}
return 0;
}
Expand Down Expand Up @@ -91,10 +91,10 @@ void uart_terminal_scene_console_output_on_enter(void* context) {
if(app->hex_mode) {
// Send binary packet
if(app->selected_tx_string) {
const char *str = app->selected_tx_string;
const char* str = app->selected_tx_string;
uint8_t digit_num = 0;
uint8_t byte = 0;
while (*str) {
while(*str) {
byte |= (hex_char_to_byte(*str) << ((1 - digit_num) * 4));

if(++digit_num == 2) {
Expand All @@ -112,13 +112,13 @@ void uart_terminal_scene_console_output_on_enter(void* context) {
} else {
// Send command with CR+LF or newline '\n'
if(app->is_command && app->selected_tx_string) {
if(app->TERMINAL_MODE == 1){
uart_terminal_uart_tx(uart_ch,
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
if(app->TERMINAL_MODE == 1) {
uart_terminal_uart_tx(
uart_ch, (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
uart_terminal_uart_tx(uart_ch, (uint8_t*)("\r\n"), 2);
} else {
uart_terminal_uart_tx(uart_ch,
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
uart_terminal_uart_tx(
uart_ch, (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
uart_terminal_uart_tx(uart_ch, (uint8_t*)("\n"), 1);
}
}
Expand Down
6 changes: 4 additions & 2 deletions uart_terminal/scenes/uart_terminal_scene_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ void uart_terminal_scene_help_on_enter(void* context) {

FuriString* temp_str;
temp_str = furi_string_alloc();
furi_string_printf(temp_str, "\nUART terminal for Flipper\n\nI'm in github: cool4uma\n\nThis app is a modified\nWiFi Marauder companion,\nThanks 0xchocolate(github)\nfor great code and app.\n\n");
furi_string_cat_printf( temp_str, "Press BACK to return\n");
furi_string_printf(
temp_str,
"\nUART terminal for Flipper\n\nI'm in github: cool4uma\n\nThis app is a modified\nWiFi Marauder companion,\nThanks 0xchocolate(github)\nfor great code and app.\n\n");
furi_string_cat_printf(temp_str, "Press BACK to return\n");

widget_add_text_box_element(
app->widget,
Expand Down
Loading

0 comments on commit 04c3a60

Please sign in to comment.