Last active
July 5, 2024 13:09
-
-
Save kofemann/277d7c414a9d458960fce5b0899fdf73 to your computer and use it in GitHub Desktop.
decode NFS file handle for nfs4j
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import struct | |
import binascii | |
fh = sys.argv[1].upper() | |
version = struct.unpack('b', bytes.fromhex(fh[0:2]) )[0] | |
magic = fh[2:8] | |
generation = struct.unpack('>i', bytes.fromhex(fh[8:16]))[0] | |
index = struct.unpack('>i', bytes.fromhex(fh[16:24]))[0] | |
t = struct.unpack('b', bytes.fromhex(fh[24:26]))[0] | |
l = struct.unpack('b', bytes.fromhex(fh[26:28]) )[0] | |
handle = bytes.fromhex(fh[28:]) | |
INODE_TYPES = { | |
0: "INODE", | |
1: "TAG", | |
2: "TAGS", | |
3: "ID", | |
4: "PATHOF", | |
5: "PARENT", | |
6: "NAMWOF", | |
7: "PGET", | |
8: "PSET", | |
9: "CONST", | |
15: "LABEL" | |
} | |
print ('version : {}'.format(version)) | |
print ('magic : {}'.format(magic)) | |
print ('generation: {}'.format(generation)) | |
print ('index : {}'.format(index)) | |
print ('type : {}'.format(t)) | |
print ('opaque len: {}'.format(l)) | |
print ('handle : {}'.format(fh[28:])) | |
print ('fsid : {}'.format(struct.unpack('b', bytes.fromhex(fh[28:30]) )[0])) | |
inodeType = struct.unpack('b', bytes.fromhex(fh[30:32]) )[0] | |
print ('inode type: {}'.format(INODE_TYPES[inodeType])) | |
idLen = struct.unpack('b', bytes.fromhex(fh[32:34]) )[0] | |
print ('id len : {}'.format(idLen)) | |
print ('inumber : {}'.format(int(fh[34:34+idLen*2], base=16))) | |
argsLen = struct.unpack('b', bytes.fromhex(fh[34+idLen*2:36+idLen*2]) )[0] | |
print ('args : {}'.format(binascii.a2b_hex(fh[36+idLen*2:]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment