I learned that in python3 there are 5 diferent protocols for a pickle file (Link). I wonder how to get meta-data-information (especialy the protocol) from a pickle-file.
Asked
Active
Viewed 997 times
1 Answers
2
based on the pickle source in Python 3.8 and a bit of experimentation it's pretty easy to get to version numbers 2 and above by looking at the first 2 bytes. the first is documented as:
PROTO = b'\x80' # identify pickle protocol
in the above file, and can be tested with:
' '.join(f'{c:02x}' for c in pickle.dumps(42, protocol=2))
which gives me:
80 02 4b 2a 2e
i.e. a byte (0x80) which says we're about to get a version number, then the version number 2. if we run it with more recent version numbers it changes appropriately, i.e. version 5 gives:
80 05 4b 2a 2e
which looks easy enough. lower version numbers don't seem to report anything, but maybe somebody else will suggest something!

Sam Mason
- 15,216
- 1
- 41
- 60