### Install Hardsploit API using pip Source: https://github.com/serma-safety-security/hardsploit/blob/main/README.md This command installs the Hardsploit API using pip, the Python package installer. Ensure you have Python v3.9 or later installed. ```bash pip install hardsploit ``` -------------------------------- ### Get Board Version using Hardsploit API (Python) Source: https://github.com/serma-safety-security/hardsploit/wiki/Version This snippet demonstrates how to fetch the hardware and software version of a board. It utilizes the HardsploitAPI class from the hardsploit.core module. The output is the version number printed to the console. No specific inputs are required beyond the initialization of the API. ```python from hardsploit.core import HardsploitAPI print(HardsploitAPI().get_version_number()) ``` -------------------------------- ### Initialize SWD Class Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Initializes the HardsploitSWD class with necessary memory addresses and the Hardsploit API instance. This setup is crucial before performing any SWD operations. ```python swd = HardsploitSWD(memory_start_address, memory_size_address, cpu_id_address, device_id_address, hardsploit_api) ``` -------------------------------- ### Generic I2C Data Import Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Facilitates the import of data into an I2C device. This function requires the I2C base address, start address for import, page size, total memory size, the path to the data file, and a write page latency. The data size parameter is a string representing the file path. ```python i2c.i2c_generic_import(i2c_base_address, start_address, page_size, memory_size, data_file, write_page_latency) ``` -------------------------------- ### Generic I2C Data Dump Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Performs a generic dump of data from an I2C device within a specified address range. It requires the I2C base address, start and stop addresses for the dump, and a maximum size for the data to be retrieved. Data is received via a callback for each packet, suitable for large memory storage. ```python i2c.i2c_generic_dump(i2c_base_address, start_address, stop_address, max_size) ``` -------------------------------- ### Generic SPI Memory Dump Source: https://github.com/serma-safety-security/hardsploit/wiki/SPI-Module Reads data from SPI memory within a specified address range. It requires the SPI mode, speed, read command, start address, stop address, and maximum size to read. This function is useful for extracting memory contents from SPI flash or EEPROM chips. ```python spi.spi_generic_dump(mode, speed, read_spi_command, start_address, stop_address, max_size) ``` -------------------------------- ### Initialize HardsploitAPI and Control LEDs Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Demonstrates initializing the HardsploitAPI, checking for connected boards, retrieving version information, and controlling status LEDs. It also shows how to set custom LED patterns and use visual wiring assistance for specific signals. ```python from hardsploit.core import HardsploitAPI, HardsploitConstant, HardsploitUtils # Define progress callback for firmware uploads def callback_progress(percent, start_time, end_time): print(f"Upload progress: {percent}%") # Set the callback before creating the API instance HardsploitAPI.callbackProgress = callback_progress # Check available boards print(f"Boards detected: {HardsploitUtils.get_number_of_board_available()}") # Initialize connection to Hardsploit board hardsploit = HardsploitAPI() # Display all version information hardsploit.get_all_versions() # Output: # API : 2.0.0 # Board : V1.0.3 # FPGA : V1.2.0 # Microcontroller : V1.0.3 # Get board version number version = hardsploit.get_version_number() print(f"Board version: {version}") # Control status LEDs hardsploit.set_status_led(HardsploitConstant.UsbCommand.GREEN_LED, state=True) hardsploit.set_status_led(HardsploitConstant.UsbCommand.RED_LED, state=False) # Set custom wiring LED display (64-bit value for 8x8 LED matrix) hardsploit.set_wiring_leds(value=0xFF00FF00FF00FF00) # Visual wiring help - lights up LED for specific signal hardsploit.signal_helping_wiring(signal="SPI_CLK") # Lights LED for SPI clock pin hardsploit.signal_helping_wiring(signal="MOSI") # Lights LED for MOSI pin ``` -------------------------------- ### Hardsploit API Initialization and Configuration Source: https://github.com/serma-safety-security/hardsploit/wiki/UART-module This section details the necessary steps to initialize the Hardsploit API and configure the cross-wiring for UART communication. ```APIDOC ## Prerequisites ### Description Initializes the Hardsploit API and sets the cross-wiring configuration, which is required for UART communication. ### Method ```python api = HardsploitAPI() api.load_firmware('UART') crossvalue = [8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] ape.set_cross_wiring(crossvalue) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python api = HardsploitAPI() api.load_firmware('UART') crossvalue = [8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] ape.set_cross_wiring(crossvalue) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### I2C Class Initialization Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Initializes the HardsploitI2c class with a specified speed and an instance of HardsploitAPI. ```APIDOC ## I2C Class Initialization ### Description Initializes the HardsploitI2c class with a specified speed and an instance of HardsploitAPI. ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python speed = HardsploitConstant.I2C.KHZ_100 i2c = HardsploitI2c(speed, hardsploit_api) ``` ### Response #### Success Response (200) N/A #### Response Example N/A ### Parameters Details - **speed** (constant) - Required - Speed of the I2C communication, e.g., HardsploitConstant.I2C.KHZ_100. - **hardsploit_api** (instance of HardsploitAPI()) - Required - An instance of the HardsploitAPI class. ``` -------------------------------- ### UART Communication with Hardsploit Source: https://context7.com/serma-safety-security/hardsploit/llms.txt This snippet demonstrates how to initialize and use the Hardsploit UART module. It covers baud rate auto-detection, data reading and writing, and setting up a continuous reader thread. Ensure the Hardsploit API is loaded with 'UART' firmware. ```python from hardsploit.core import HardsploitAPI from hardsploit.modules.uart import HardsploitUART import time import threading hardsploit = HardsploitAPI() hardsploit.load_firmware("UART") # Initialize UART with full configuration uart = HardsploitUART( baud_rate=115200, # Baud rate (2400 to 1036800) word_width=8, # Data bits (5-8) use_parity_bit=0, # 0=no parity, 1=parity enabled parity_type=0, # 0=even, 1=odd nb_stop_bits=1, # 1 or 2 stop bits idle_line_level=1, # Idle state level hardsploit_api=hardsploit ) # Auto-detect baud rate uart.enable_measure_baud_rate() time.sleep(1) # Wait for activity on RX line detected_baud = uart.measure_baud_rate() print(f"Detected baud rate: {detected_baud}") uart.disable_measure_baud_rate() # Update baud rate and apply settings uart.baud_rate = detected_baud uart.set_settings() # Read data from UART def uart_reader(): while True: try: data = uart.send_and_received() if data: print(bytes(data).decode('utf-8', errors='ignore'), end='') except Exception: pass time.sleep(0.1) # Start reader thread reader_thread = threading.Thread(target=uart_reader, daemon=True) reader_thread.start() # Write data to UART uart.write(bytearray(b"AT\r\n")) # Send AT command response = uart.send_and_received() # Get response # Interactive console example uart.write(bytearray(b"help\r")) # Send help command uart.write(bytearray(b"ls -la\r")) # Send ls command uart.write(bytearray(b"cat /etc/passwd\r")) # Read file ``` -------------------------------- ### I2C Generic Import Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Allows importing data into an I2C device. ```APIDOC ## I2C Generic import ### Description This allows you to import data into an I2C device. ### Method POST ### Endpoint /serma-safety-security/hardsploit/i2c/generic_import ### Parameters #### Path Parameters N/A #### Query Parameters - **i2c_base_address** (byte) - Required - The base address of the I2C device (0 to 255). Write address is equal to the base address. - **start_address** (integer) - Required - The starting address for the import (0 to sizeMax-1). - **page_size** (integer) - Required - The size of each page for import (0 to sizeMax-1). - **memory_size** (integer) - Required - The total size of the memory to import data into (up to 2^32, approximately 4GB). - **data_file** (string) - Required - The path to the file containing the data to import. - **write_page_latency** (integer) - Optional - Latency in seconds for writing each page (e.g., 2ms = 0.002). #### Request Body N/A ### Request Example ```python i2c.i2c_generic_import(i2c_base_address, start_address, page_size, memory_size, data_file, write_page_latency) ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success or failure of the import operation. #### Response Example ```json { "status": "import successful" } ``` ``` -------------------------------- ### HardsploitAPI Initialization and Configuration Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Initializes the Hardsploit API and configures the cross-wiring settings, which are essential for SWD communication. ```APIDOC ## HardsploitAPI Initialization and Configuration ### Description Initializes the Hardsploit API and sets the cross-wiring configuration. This is a prerequisite for establishing SWD communication. ### Method ```python api = HardsploitAPI() crossvalue = [24, 25, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] api.set_cross_wiring(crossvalue) ``` ### Parameters #### Request Body - **crossvalue** (list of int) - Required - A list of integers representing the cross-wiring configuration. ### Endpoint N/A (This is an initialization step, not a specific endpoint) ### Response N/A ``` -------------------------------- ### Signal Helping Wiring API Source: https://github.com/serma-safety-security/hardsploit/wiki/Help-Wiring This API allows you to turn on the LED of a Hardsploit pin by providing the signal number or name. ```APIDOC ## POST /serma-safety-security/hardsploit/signal_helping_wiring ### Description This function allows turning on the LED of the Hardsploit pin corresponding to the interface entered as a parameter. ### Method POST ### Endpoint /serma-safety-security/hardsploit/signal_helping_wiring ### Parameters #### Query Parameters - **signal_number_or_name** (string) - Required - The name or number of the signal to activate the corresponding LED. Examples include "A0"-"A31", "D0"-"D15", "CS", "SPI_CLK", "MOSI", "MISO", "I2C_CLK", "SDA", "TX", "RX", "SWD_CLK", "SWD_IO". ### Request Example ```json { "signal_number_or_name": "RX" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. Example: "success" #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Instantiate HardsploitUART Class (Python) Source: https://github.com/serma-safety-security/hardsploit/wiki/UART-module Creates an instance of the HardsploitUART class, configuring the serial communication parameters. This includes baud rate, word width, parity settings, stop bits, idle line level, and the Hardsploit API instance. ```python uart = HardsploitUART(baud_rate, word_width, use_parity_bit, parity_type, nb_stop_bits, idle_line_level, hardsploit_api) ``` -------------------------------- ### Upload Firmware to FPGA Source: https://github.com/serma-safety-security/hardsploit/wiki/Firmaware This endpoint allows you to upload firmware to an FPGA module. You can optionally choose to verify the firmware after upload. ```APIDOC ## Upload Firmware to FPGA ### Description Uploads firmware to an FPGA module. The `check_firmware` parameter determines if the uploaded firmware should be verified against the original. ### Method POST ### Endpoint /serma-safety-security/hardsploit/upload_firmware ### Parameters #### Query Parameters - **path_to_your_fpga_module** (string) - Required - The file path of the module FPGA (.rpd file). - **check_firmware** (boolean) - Optional - If true, the firmware will be checked after upload. Defaults to false. ### Request Example ```json { "path_to_your_fpga_module": "/path/to/your/module.rpd", "check_firmware": true } ``` ### Response #### Success Response (200) - **success** (boolean) - True if the firmware was uploaded successfully (and optionally verified). #### Response Example ```json { "success": true } ``` ### Notes - If `check_firmware` is false, the function always returns true. - If `check_firmware` is true, the function returns true only if the firmware written matches the firmware read. This process is slower as it involves reading the firmware back for verification. ``` -------------------------------- ### Initialize Hardsploit API and Set Cross-Wiring (Python) Source: https://github.com/serma-safety-security/hardsploit/wiki/UART-module Initializes the Hardsploit API and loads the firmware for UART communication. It then sets the cross-wiring configuration, which is essential for establishing physical and logical connections between Hardsploit components. ```python api = HardsploitAPI() api.load_firmware('UART') crossvalue = [8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] api.set_cross_wiring(crossvalue) ``` -------------------------------- ### SPI Module for Hardsploit Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Initializes the SPI module for the Hardsploit API, enabling communication with SPI devices. This includes functionalities for reading, writing, and custom interactions with SPI peripherals. ```python from hardsploit.core import HardsploitAPI from hardsploit.modules import HardsploitSPI # Pin mapping: # SPI_CLK --> Pin A0 ``` -------------------------------- ### Initialize Hardsploit API and Configure SWD Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Initializes the Hardsploit API and sets the cross-wiring configuration required for SWD communication. The `set_cross_wiring` method configures physical and logical connections between Hardsploit components. ```python api = HardsploitAPI() crossvalue = [24, 25, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] api.set_cross_wiring(crossvalue) ``` -------------------------------- ### SWD Class Initialization Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Initializes the SWD class with necessary memory addresses, CPU/Device IDs, and the Hardsploit API instance. ```APIDOC ## SWD Class Initialization ### Description Initializes the SWD class, which is used for Serial Wire Debug communication. It requires memory addresses, CPU/Device IDs, and an instance of the HardsploitAPI. ### Method ```python swd = HardsploitSWD(memory_start_address, memory_size_address, cpu_id_address, device_id_address, hardsploit_api) ``` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **memory_start_address** (String) - Required - The starting address of the memory to be accessed. - **memory_size_address** (String) - Required - The size of the memory region. - **cpu_id_address** (String) - Required - The address of the CPU ID. - **device_id_address** (String) - Required - The address of the Device ID. - **hardsploit_api** (Instance of HardsploitAPI) - Required - An active instance of the HardsploitAPI. ### Endpoint N/A (This is a class instantiation) ### Response N/A ### Notes - SWD_CLK maps to D0 - SWD_IO maps to D1 ``` -------------------------------- ### SWD Debugging with Hardsploit for ARM Cortex Source: https://context7.com/serma-safety-security/hardsploit/llms.txt This snippet shows how to use the HardsploitSWD module to debug and program ARM Cortex microcontrollers via the Serial Wire Debug (SWD) interface. It includes initialization, obtaining target identification, dumping/writing/erasing flash memory, and direct memory access. Ensure the Hardsploit API is loaded with 'SWD' firmware. ```python from hardsploit.core import HardsploitAPI from hardsploit.modules.swd.swd import HardsploitSWD # Pin mapping: # SWD_CLK --> Pin A0 # SWD_IO --> Pin A1 hardsploit = HardsploitAPI() hardsploit.load_firmware("SWD") # Initialize SWD for STM32 target # Parameters: memory_start, memory_size_addr, cpu_id_addr, device_id_addr swd = HardsploitSWD( memory_start_address="0x8000000", # Flash start address memory_size_address="0x1FFFF7E0", # Flash size register cpu_id_address="0xE000ED00", # CPU ID register device_id_address="0x1FFFF7E8", # Device ID register hardsploit_api=hardsploit ) # Get target identification codes = swd.obtain_codes() print(f"Debug Port ID: {hex(codes['DebugPortId'])}") print(f"Access Port ID: {hex(codes['AccessPortId'])}") print(f"CPU ID: {hex(codes['CpuId'])}") # Example output: # Debug Port ID: 0x2ba01477 # Access Port ID: 0x24770011 # CPU ID: 0x411fc231 (Cortex-M3) # Dump flash memory to file swd.dump_flash("/path/to/firmware_dump.bin") # Write firmware to flash swd.write_flash("/path/to/new_firmware.bin") # Erase flash memory swd.erase_flash() # Read/write memory directly data = swd.read_mem32(address=0x08000000, size=16) # Read 16 words print(f"Memory content: {bytes(data).hex()}") swd.write_mem32(address=0x20000000, data=[0x01, 0x02, 0x03, 0x04]) # Write to SRAM # Read CPU registers (halts processor) swd.read_regs() # Control processor execution swd.stop() # Halt processor swd.start() # Resume execution ``` -------------------------------- ### Set Custom Value Wiring LED API Source: https://github.com/serma-safety-security/hardsploit/wiki/Help-Wiring This API allows you to turn on or off LEDs on the Hardsploit pin by specifying a custom value for each port. ```APIDOC ## POST /serma-safety-security/hardsploit/set_wiring_leds ### Description This function allows turning on/off LEDs on the Hardsploit pin by setting a custom value representing the state of each port's LEDs. ### Method POST ### Endpoint /serma-safety-security/hardsploit/set_wiring_leds ### Parameters #### Query Parameters - **port_values** (hexadecimal string) - Required - A hexadecimal string representing the state of LEDs for ports A through H. Each bit corresponds to a port, where '1' means ON and '0' means OFF. The format is a single hexadecimal value, e.g., "0xFF00FFFFFF00FFFF". ### Request Example ```json { "port_values": "0xFF00FFFFFF00FFFF" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. Example: "success" #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Load Hardsploit Firmware for Communication Modules Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Loads specific firmware onto the Hardsploit board to enable different communication protocols and modes. Supports interactive and sniffer modes for protocols like SPI, UART, I2C, SWD, and CAN. ```python from hardsploit.core import HardsploitAPI def callback_progress(percent, start_time, end_time): print(f"Firmware upload: {percent:.1f}%") HardsploitAPI.callbackProgress = callback_progress hardsploit = HardsploitAPI() # Available firmware types: # 'I2C' - I2C interactive mode # 'I2C_SNIFFER' - I2C passive sniffer # 'SPI' - SPI interactive mode # 'SPI_SNIFFER' - SPI passive sniffer # 'UART' - UART interactive mode # 'SWD' - Serial Wire Debug # 'CAN' - CAN sniffer # 'CAN_INTERACT'- CAN interactive mode # 'PARALLEL' - Parallel memory (no mux) # 'MUX_PARALLEL'- Parallel memory (with mux) # 'uC' - Microcontroller firmware (DFU mode only) # Load SPI firmware hardsploit.load_firmware("SPI") # Load UART firmware hardsploit.load_firmware("UART") # Load I2C firmware hardsploit.load_firmware("I2C") ``` -------------------------------- ### Add user to plugdev group Source: https://github.com/serma-safety-security/hardsploit/blob/main/README.md This command adds the specified user to the 'plugdev' group. This is typically done to grant the user necessary permissions for USB device access. ```bash adduser "user" plugdev ``` -------------------------------- ### Initialize Hardsploit SPI Class Source: https://github.com/serma-safety-security/hardsploit/wiki/SPI-Module Initializes the Hardsploit SPI class with specified speed, mode, and an instance of HardsploitAPI. The speed parameter controls the SPI clock frequency, and the mode parameter defines the SPI communication mode (0, 1, 2, or 3). ```python spi = HardsploitSPI(speed, mode, hardsploit_api) ``` -------------------------------- ### Upload Firmware to FPGA using Hardsploit API (Python) Source: https://github.com/serma-safety-security/hardsploit/wiki/Firmaware Uploads firmware to an FPGA module. The `check_firmware` parameter determines if a post-upload verification is performed. If `check_firmware` is false, the function returns true without verification. If true, it verifies the written firmware against the read firmware, which is slower. ```Python HardsploitAPI().upload_firmware(path_to_your_fpga_module, check_firmware) ``` -------------------------------- ### SWD Obtain Device Information Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Retrieves debug port ID, access port ID, and CPU ID. ```APIDOC ## SWD Obtain Device Information ### Description Retrieves essential information about the debug and access ports, as well as the CPU. ### Method ```python swd.obtain_codes() ``` ### Parameters N/A ### Endpoint N/A (This is a method call on the SWD instance) ### Response #### Success Response (200) - **DebugPortId** (String) - The identifier for the debug port. - **AccessPortId** (String) - The identifier for the access port. - **CpuId** (String) - The identifier for the CPU. #### Response Example ```json { "DebugPortId": "some_debug_port_id", "AccessPortId": "some_access_port_id", "CpuId": "some_cpu_id" } ``` ``` -------------------------------- ### Signal Helping Wiring with Hardsploit API Source: https://github.com/serma-safety-security/hardsploit/wiki/Help-Wiring This function enables the control of Hardsploit pin LEDs by specifying the interface signal name or number. It takes a string argument representing the signal and activates the corresponding LED. Supported signals include SPI, I2C, UART, and SWD interfaces, as well as direct pin assignments like 'A0' through 'A31' and 'D0' through 'D15'. ```python HardsploitAPI().signal_helping_wiring(signal_number_or_name) ``` -------------------------------- ### SPI Communication with Hardsploit Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Initialize and interact with SPI devices using the HardsploitSPI module. Supports configuring speed, mode, sending custom commands, and performing generic read/write operations on SPI flash memory. Requires HardsploitAPI and HardsploitSPI classes. ```python from hardsploit.core import HardsploitAPI from hardsploit.modules import HardsploitSPI # Pin mapping: # CS --> Pin A1 # MOSI --> Pin A2 # MISO --> Pin A3 # PULSE --> Pin A4 hardsploit = HardsploitAPI() hardsploit.load_firmware("SPI") # Initialize SPI with speed divisor and mode # Speed: SPI clock = 150MHz / (2 * speed), range 3-255 # Mode: 0-3 (CPOL/CPHA combinations) spi = HardsploitSPI(speed=60, mode=0, hardsploit_api=hardsploit) # Change SPI settings spi.speed = 100 # Slower clock spi.mode = 1 # Change to mode 1 spi.pulse = 1 # Enable pulse signal # Send custom SPI command and receive response payload = [0x9F] # JEDEC ID command for flash chips response = spi.spi_interact(payload) print(f"JEDEC ID: {bytes(response).hex()}") # Read from SPI flash memory # Parameters: read_command, start_address, stop_address, memory_size_max spi.spi_generic_dump( read_spi_command=0x03, # Standard read command start_address=0x000000, # Start at address 0 stop_address=0x0000FF, # Read 256 bytes size_max=0x1000000 # 16MB flash (determines address byte count) ) # Write to SPI flash memory spi.spi_generic_import( start_address=0x000000, page_size=256, # Flash page size memory_size=0x1000000, # 16MB data_file="/path/to/firmware.bin", write_spi_command=0x02, # Page program command write_page_latency=0.005, # 5ms page write time enable_write_spi_command=0x06, # Write enable command clear_spi_command=0x60, # Bulk erase command clear_chip_time=240, # Erase time in seconds is_flash=True # Enable erase before write ) ``` -------------------------------- ### Set Custom Wiring LED Values with Hardsploit API Source: https://github.com/serma-safety-security/hardsploit/wiki/Help-Wiring This function allows for the precise control of LEDs on Hardsploit pins by setting custom values for each port. It accepts a single hexadecimal integer argument where each bit corresponds to the state of an LED on a specific port (A-H). This enables turning LEDs ON or OFF individually or in groups across different ports. ```python HardsploitAPI().set_wiring_leds(0xFF00FFFFFF00FFFF) ``` -------------------------------- ### Copy Hardsploit udev rules Source: https://github.com/serma-safety-security/hardsploit/blob/main/README.md This command copies the Hardsploit udev rules file to the system's udevadm rules directory. This is necessary for non-root users to access USB devices with Hardsploit. ```bash sudo cp data/50-Hardsploit.rules /lib/udev/rules.d/. ``` -------------------------------- ### Verify user group membership Source: https://github.com/serma-safety-security/hardsploit/blob/main/README.md This command verifies if the specified user is part of the 'plugdev' group. Membership in this group is often required for accessing USB devices on Linux systems. ```bash groups "user" ``` -------------------------------- ### Initialize Hardsploit I2C Class Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Initializes the Hardsploit I2C class with a specified speed and an instance of HardsploitAPI. The speed is defined by constants like HardsploitConstant.I2C.KHZ_100. The hardsploit_api parameter is required for the class to function. ```python speed = HardsploitConstant.I2C.KHZ_100 i2c = HardsploitI2c(speed, hardsploit_api) ``` -------------------------------- ### HardsploitUART Class Source: https://github.com/serma-safety-security/hardsploit/wiki/UART-module Details on the HardsploitUART class, including its constructor parameters and signal mapping. ```APIDOC ## UART Class ### Description Represents the UART communication interface for Hardsploit. ### Method ```python uart = HardsploitUART(baud_rate, word_width, use_parity_bit, parity_type, nb_stop_bits, idle_line_level, hardsploit_api) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python uart = HardsploitUART(baud_rate=9600, word_width=8, use_parity_bit=0, parity_type=0, nb_stop_bits=1, idle_line_level=0, hardsploit_api=api) ``` ### Response #### Success Response (200) None #### Response Example None ### Signal Mapping RX -> A1 TX -> A0 ``` -------------------------------- ### Hardsploit API Error Handling Source: https://context7.com/serma-safety-security/hardsploit/llms.txt This snippet demonstrates how to implement robust error handling for Hardsploit API operations. It covers specific HardsploitError exceptions for various modules like UART, SPI, I2C, and SWD, as well as general API errors. This allows for graceful recovery and informative user feedback. ```python from hardsploit.core import HardsploitAPI, HardsploitError try: hardsploit = HardsploitAPI() except HardsploitError.HardsploitNotFound: print("Error: No Hardsploit board detected. Check USB connection.") exit(1) try: hardsploit.load_firmware("SPI") # Perform SPI operations... except HardsploitError.USBError: print("Error: USB communication failed. Reconnecting...") hardsploit.reconnect() except HardsploitError.SPIWrongSpeed: print("Error: Invalid SPI speed value") except HardsploitError.SPIWrongMode: print("Error: Invalid SPI mode (must be 0-3)") except HardsploitError.SPIWrongPayloadSize: print("Error: SPI payload too large (max 4000 bytes)") except HardsploitError.I2CWrongSpeed: print("Error: Invalid I2C speed") except HardsploitError.UARTWrongSettings: print("Error: Invalid UART configuration") except HardsploitError.SWDError: print("Error: SWD communication failed") except HardsploitError.WrongStartAddress: print("Error: Invalid memory start address") except HardsploitError.ApiInvalidFirmware: print("Error: Unknown firmware type requested") except HardsploitError.ApiCrossWiring: print("Error: Cross wiring array must be exactly 64 values") ``` -------------------------------- ### Generic SPI Memory Import Source: https://github.com/serma-safety-security/hardsploit/wiki/SPI-Module Imports data from a specified file into SPI memory. This function handles writing data to the SPI device, including parameters for write commands, page size, latency, and chip erase commands for flash memory. It also supports specifying whether the target is a flash memory. ```python spi.spi_generic_import(start_address, page_size, memory_size, data_file, write_spi_command, write_page_latency, enable_write_spi_command, clear_spi_command, clear_chip_time, is_flash) ``` -------------------------------- ### I2C Generic Dump Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Performs a generic dump of data from an I2C device within a specified address range. ```APIDOC ## I2C Generic dump ### Description This function performs a dump of data from an I2C device within a specified address range. ### Method GET ### Endpoint /serma-safety-security/hardsploit/i2c/generic_dump ### Parameters #### Path Parameters N/A #### Query Parameters - **i2c_base_address** (byte) - Required - The base address of the I2C device (0 to 255). Write address is equal to the base address. - **start_address** (integer) - Required - The starting address for the dump (0 to sizeMax-1). - **stop_address** (integer) - Required - The ending address for the dump (0 to sizeMax-1). - **max_size** (integer) - Optional - The maximum size of data to dump. Defaults to 2^32 (approximately 4GB). #### Request Body N/A ### Request Example ```python i2c.i2c_generic_dump(i2c_base_address, start_address, stop_address, max_size) ``` ### Response #### Success Response (200) - **data** (callback) - A callback function that receives data in packets. This is useful for handling large amounts of data that can be stored in a database, file, etc. #### Response Example N/A (Data is received via callback) ### Tips - The number of bytes for the address is calculated by `max_size`. - Receive data in a callback `data` for each packet and can be stored in a database, file, etc. for large memory is useful. ``` -------------------------------- ### UART Communication with HardsploitUART Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Establish communication over UART serial interfaces for console access and data transfer. This module requires HardsploitAPI and HardsploitUART classes, enabling serial communication functionalities. ```python from hardsploit.core import HardsploitAPI from hardsploit.modules import HardsploitUART import threading import time # Pin mapping: # TX --> Pin A0 ``` -------------------------------- ### Configure Hardsploit Cross Wiring Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Sets up custom signal routing between physical pins and logical signals on the Hardsploit board. This allows for flexible hardware interfacing by remapping signals like UART pins. ```python from hardsploit.core import HardsploitAPI hardsploit = HardsploitAPI() # Create default wiring (1:1 mapping) crossvalue = list(range(64)) # Swap signals: route physical pins 0,1 to logical signals 8,9 and vice versa crossvalue[0] = 8 # Physical pin 0 -> Logical signal 8 crossvalue[1] = 9 # Physical pin 1 -> Logical signal 9 crossvalue[8] = 0 # Physical pin 8 -> Logical signal 0 crossvalue[9] = 1 # Physical pin 9 -> Logical signal 1 # Apply the cross wiring configuration (must be exactly 64 values) hardsploit.set_cross_wiring(crossvalue) # Example: Custom wiring for UART on pins 8,9 instead of default 0,1 contentInset_crossvalue = [8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] hardsploit.set_cross_wiring(uart_crossvalue) ``` -------------------------------- ### SWD Read Flash Memory Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Dumps the flash memory content to a specified file path. ```APIDOC ## SWD Read Flash Memory ### Description Dumps the content of the flash memory to a specified file. ### Method ```python swd.dump_flash(file_path) ``` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **file_path** (String) - Required - The path to the file where the dumped memory will be written. ### Endpoint N/A (This is a method call on the SWD instance) ### Response #### Success Response (200) N/A (This operation writes to a file) #### Response Example N/A ``` -------------------------------- ### UART Measure Baud Rate Function Source: https://github.com/serma-safety-security/hardsploit/wiki/UART-module Documentation for the `measure_baud_rate` function, used to measure the baud rate of a UART chip. ```APIDOC ## UART Info ### Description Allows you to measure the baud rate of a UART chip. ### Method ```python uart.measure_baud_rate() ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python bauadrate = uart.measure_baud_rate() print(f"Measured Baud Rate: {baudrate}") ``` ### Response #### Success Response (200) - **baud_rate** (integer) - The measured baud rate of the UART chip. #### Response Example ```json { "baud_rate": 9600 } ``` ``` -------------------------------- ### I2C Scan Source: https://github.com/serma-safety-security/hardsploit/wiki/I2C-Module Performs an I2C address scan to detect connected devices. ```APIDOC ## I2C Scan ### Description This function performs an I2C address scan to detect connected devices. ### Method GET ### Endpoint /serma-safety-security/hardsploit/i2c/scan ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python i2c.i2c_scan() ``` ### Response #### Success Response (200) - **devices** (array) - An array containing the addresses of detected I2C devices. The array will have 256 items, with detected addresses typically represented by non-null values. #### Response Example ```json { "devices": [ null, null, 42, null, null, 55, ... // Example response structure ] } ``` ### Signals - **I2C_CLK** -> A0 - **SDA** -> A1 ``` -------------------------------- ### Write to Flash Memory using SWD Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Writes a firmware file to the chip's memory. This function takes the path to the firmware file as input. ```python swd.write_flash(firmware_path) ``` -------------------------------- ### I2C Communication with HardsploitI2c Source: https://context7.com/serma-safety-security/hardsploit/llms.txt Interact with I2C/TWI devices like EEPROMs and sensors using HardsploitI2c. Supports scanning the bus, performing raw I2C interactions, and generic read/write operations. Requires HardsploitAPI, HardsploitConstant, HardsploitUtils, and HardsploitI2c classes. ```python from hardsploit.core import HardsploitAPI, HardsploitConstant, HardsploitUtils from hardsploit.modules import HardsploitI2c # Pin mapping: # I2C_CLK --> Pin A0 # SDA --> Pin A1 hardsploit = HardsploitAPI() hardsploit.load_firmware("I2C") # Initialize I2C with speed # Available speeds: KHZ_40, KHZ_100, KHZ_400, KHZ_1000 i2c = HardsploitI2c(speed=HardsploitConstant.I2C.KHZ_100, hardsploit_api=hardsploit) # Scan I2C bus for devices scan_result = i2c.i2c_scan() print("Found I2C devices at addresses:") for addr in range(len(scan_result)): if scan_result[addr] == 1: print(f" 0x{addr:02X} ({'Write' if addr % 2 == 0 else 'Read'})") # Raw I2C interaction # Format: [count_low, count_high, address, data...] # Even address = Write, Odd address = Read payload = [ HardsploitUtils.low_byte(word=2), # 2 bytes to write HardsploitUtils.high_byte(word=2), 0xA0, # Write address (EEPROM at 0x50) 0x00, 0x00, # Memory address HardsploitUtils.low_byte(word=4), # Read 4 bytes HardsploitUtils.high_byte(word=4), 0xA1 # Read address ] result = i2c.i2c_interact(payload=payload) print(f"Read data: {bytes(result).hex()}") # Dump I2C EEPROM contents i2c.i2c_generic_dump( i2c_base_address=0xA0, # EEPROM write address start_address=0x0000, # Start address stop_address=0x00FF, # End address (256 bytes) size_max=0x10000 # Max memory size (64KB) ) # Write data to I2C EEPROM i2c.i2c_generic_import( i2c_base_address=0xA0, start_address=0x0000, page_size=64, # EEPROM page size memory_size=0x10000, # 64KB EEPROM data_file="/path/to/data.bin", write_page_latency=0.01 # 10ms write cycle time ) ``` -------------------------------- ### SWD Write Flash Memory Source: https://github.com/serma-safety-security/hardsploit/wiki/SWD-module Writes the content of a firmware file into the chip's flash memory. ```APIDOC ## SWD Write Flash Memory ### Description Writes the content of a specified firmware file into the chip's flash memory. ### Method ```python swd.write_flash(firmware_path) ``` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **firmware_path** (String) - Required - The path to the firmware file to be written into the chip's memory. ### Endpoint N/A (This is a method call on the SWD instance) ### Response #### Success Response (200) N/A (This operation writes to the chip's memory) #### Response Example N/A ```