I have made an improved version of this script, called FindIHexStringExtract .ps1
which can also return data from an
offset of the addresses found.
Check it out here: https://gist.github.com/f-steff/cb592cd2d0bdb1d858595118915f3a06
FindIHexString.ps1
is a PowerShell script 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.
This tool is a quick and effective way to locate 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. FindIHexString.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/01ff67a566835a9ca3aba7a0537507c3
.\FindIHexString.ps1 -HexFile <path> -SearchString <string> [-Offset <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.
- -Help: (Optional) Displays usage information and examples.
Search for the string "my_string" in a Intel HEX file:
.\FindIHexString.ps1 -HexFile "C:\path\to\file.hex" -SearchString "my_string"
0xFFF80005
0xFFFF0005
2
Search for "test" in the Intel HEX file, adding an offset of 5 to all found addresses:
.\FindIHexString.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:
.\FindIHexString.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:'
.\FindIHexString.ps1 -HexFile "file.hex" -SearchString '$VER:'
0xFFF70000
0xFFFE0000
2
Display usage information and examples:
.\FindIHexString.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,
FindIHexString
is a valuable resource for developers working with Intel HEX files, providing an easy and reliable way to locate specific data within such files.