30 lines
881 B
Python
30 lines
881 B
Python
|
#!/bin/python
|
||
|
|
||
|
import sys
|
||
|
import base64
|
||
|
import struct
|
||
|
|
||
|
def format_base64_to_u32(base64_string):
|
||
|
# Decode the Base64 string
|
||
|
decoded_bytes = base64.b64decode(base64_string)
|
||
|
|
||
|
# Interpret the bytes as a sequence of u32 values
|
||
|
u32_values = struct.unpack('I' * (len(decoded_bytes) // 4), decoded_bytes)
|
||
|
|
||
|
# Format the u32 values as C-style hex values
|
||
|
formatted_u32_values = ', '.join(f'0x{value:08x}' for value in u32_values)
|
||
|
|
||
|
# Split the formatted string into lines of 8 values each
|
||
|
lines = [', '.join(formatted_u32_values.split(', ')[i:i+8]) for i in range(0, len(u32_values), 8)]
|
||
|
|
||
|
# Print the formatted values
|
||
|
print(',\n'.join(lines))
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
if len(sys.argv) != 2:
|
||
|
print(f"Usage: python {sys.argv[0]} <base64_string>")
|
||
|
sys.exit(1)
|
||
|
|
||
|
base64_string = sys.argv[1]
|
||
|
format_base64_to_u32(base64_string)
|