0x00 linux shell

参数解释: -N[n] 为要读取字节数;-t x1 为指定输出为 16 进制;head -1 为只读取第一行;sed 块为删除 16 进制前的序号 0000000 以及空格;tr -d '\n' 为删除换行符。

od -N4 -t x1 test.txt|head -1|sed -e 's/0000000//g' -e 's/ //g'|tr -d '\n'

0x01 python

示例:

#!/usr/bin/env python    
#encoding: utf-8  
import binascii   
with open('test.o', 'rb') as f:
    hexstr = binascii.b2a_hex(f.read(32))  # 读取前 32 位,并由 2 进制转为 16 进制
print(hexstr)