I have also made a simpler version of this script, called FindIHexStringExtract .ps1
which can only find the address of substrings in an intel hex file.
Check it out here: https://gist.github.com/f-steff/01ff67a566835a9ca3aba7a0537507c3
FindHexStringExtract.ps1
is an update to FindIHexString.ps1
. It's designed to search for a specific string within an Intel HEX formatted file.
The script outputs the memory addresses where the string is found, followed by a count of occurrences on the final line.
Optionally a 16 bit integer can be extracted from an offset to the found addresses.
This tool is a quick and effective way to locate and extract specific data within a HEX file, particularly useful for embedded
systems developers or anyone working with microcontroller firmware.
When dealing with Intel HEX files, particularly in embedded systems development, it's often necessary to search for
specific strings or patterns. Unfortunately, there aren't many straightforward tools to perform such searches within
Intel HEX files. FindIHexStringExtract.ps1
was created as a quickly hacked together solution to fill this gap, providing an
easy-to-use script for searching and identifying string occurrences within these files.
The latest version of this script can always be found on this Github gist:
https://gist.github.com/f-steff/cb592cd2d0bdb1d858595118915f3a06
.\FindIHexStringExtract.ps1 -HexFile <path> -SearchString <string> [-Offset <integer>] [-ExtractInt <integer>] [-MaxCount <integer>][-Help]
- -HexFile : (Required) The path to the Intel HEX file. Can be an absolute or relative path.
- -SearchString : (Required) The string to search for within the Intel HEX file.
- -Offset : (Optional) An address offset to apply to the found addresses. Can be positive or negative. Default is 0.
- -ExtractInt : (Optional) An address offset to apply from the found addresses offset. Can be positive or negative. A 16 bit integer will be extracted from this address.
- -MaxCount : (Optional) Stop searching after a specified number of SearchString has been found.
- -Help: (Optional) Displays usage information and examples.
Search for the string "my_string" in a Intel HEX file:
.\FindHexStringExtract.ps1 -HexFile "C:\path\to\file.hex" -SearchString "my_string"
0xFFF80005
0xFFFF0005
2
Basic search, extracting 16-bit integer (both Small-Endian and Big-Endian) data 6 bytes after the found address
Search for the string "my_string" in a Intel HEX file:
.\FindHexStringExtract.ps1 -HexFile "C:\path\to\file.hex" -SearchString "my_string" -ExtractInt -6
0xFFF80005 0x1002 0x0201
0xFFFF0005 0x0400 0x0004
2
Basic search, extracting 16-bit integer (both Small-Endian and Big-Endian) data 6 bytes after the found address, stopping after the first found
Search for the string "my_string" in a Intel HEX file:
.\FindHexStringExtract.ps1 -HexFile "C:\path\to\file.hex" -SearchString "my_string" -ExtractInt -6 -MaxCount 1'
0xFFF80005 0x1002 0x0201
1
Search for "test" in the Intel HEX file, adding an offset of 5 to all found addresses:
.\FindHexStringExtract.ps1 -HexFile "file.hex" -SearchString "test" -Offset 5
0xFFF8000A
0xFFFF000A
2
Search for "test" in the Intel HEX file, subtracting 5 from all found addresses:
.\FindHexStringExtract.ps1 -HexFile "file.hex" -SearchString "test" -Offset -5
0xFFF80000
0xFFFF0000
2
Search for "$VER:" in the Intel HEX file, requires a slightly different format, as Powershell will reach to some special characters. To overcome this problem, the search string must be wrapped in single-quotes like this: '$VER:'
.\FindHexStringExtract.ps1 -HexFile "file.hex" -SearchString '$VER:'
0xFFF70000
0xFFFE0000
2
Display usage information and examples:
.\FindHexStringExtract.ps1 -Help
-
Search string cannot be empty.
Occurs when the-SearchString
parameter is provided with an empty string. The script requires a non-empty search string to function. -
Offset must be a numeric value.
Occurs when the-Offset
parameter is provided with a non-numeric value. The offset must be a valid integer. -
File not found: .
Occurs when the file specified by the-HexFile
parameter does not exist. Ensure the path is correct.
- 0: The script executed successfully. All operations were completed without errors.
- 1: The script encountered an error. This could be due to an invalid search string, non-numeric offset, or file not found. Read the exact error description.
- The script was designed as a quick solution to address a specific need. It performs the required operations efficiently but may lack advanced features of more sophisticated tools.
- For lack of a better tool,
FindIHexStringExtract
is a valuable resource for developers working with Intel HEX files, providing an easy and reliable way to locate specific data within such files.