summaryrefslogtreecommitdiffstats
path: root/tools/ghidra/gsp-tu104-570.144/scripts/extract_gsp_version.py
blob: 8e577f14bae6717d8cd2219ffafdaee35370ac57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Open-IOV contributors
# Ghidra script to extract version from .fwversion section of GSP binary
# Usage: analyzeHeadless ... -postScript extract_gsp_version.py

import sys

# Get the current program
program = getCurrentProgram()

# Get the .fwversion section
fwversion_section = program.getSection(".fwversion")
if fwversion_section:
    # Get the data from the section
    data = getBytes(fwversion_section.getStart(), fwversion_section.getLength())
    version_str = data.decode('ascii').strip('\x00')
    print(f"GSP Firmware Version: {version_str}")
    
    # Also save to a file
    with open("/home/rmcore/Git/integdev_gpu_drv/open-iov/tools/ghidra/gsp-tu104-570.144/gsp_version.txt", "w") as f:
        f.write(version_str)
else:
    print("No .fwversion section found")
    
    # Try to find version in memory
    listing = program.getListing()
    for i in range(listing.getNumAddresses()):
        addr = listing.getAddress(i)
        data = getBytes(addr, 32)
        if data and b"570.144" in data:
            print(f"Found version at {addr}: {data}")
            break