Created
May 28, 2014 08:42
-
-
Save Xiol/ee9d6e9d44494ea8df85 to your computer and use it in GitHub Desktop.
Bacula Base64 decode implementation in Python
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
# This is a Python implementation of the Perl code from the following link | |
# http://bacula.10910.n7.nabble.com/The-File-LStat-field-td3960.html | |
# Bacula uses a custom base64 implementation to encode file stats | |
# This should allow us to decode the values in the lstat field in the Bacula DB | |
B64_VALS = { | |
'+': 62, '/': 63, '1': 53, '0': 52, '3': 55, '2': 54, '5': 57, | |
'4': 56, '7': 59, '6': 58, '9': 61, '8': 60, 'A': 0, 'C': 2, | |
'B': 1, 'E': 4, 'D': 3, 'G': 6, 'F': 5, 'I': 8, 'H': 7, 'K': 10, | |
'J': 9, 'M': 12, 'L': 11, 'O': 14, 'N': 13, 'Q': 16, 'P': 15, | |
'S': 18, 'R': 17, 'U': 20, 'T': 19, 'W': 22, 'V': 21, 'Y': 24, | |
'X': 23, 'Z': 25, 'a': 26, 'c': 28, 'b': 27, 'e': 30, 'd': 29, | |
'g': 32, 'f': 31, 'i': 34, 'h': 33, 'k': 36, 'j': 35, 'm': 38, | |
'l': 37, 'o': 40, 'n': 39, 'q': 42, 'p': 41, 's': 44, 'r': 43, | |
'u': 46, 't': 45, 'w': 48, 'v': 47, 'y': 50, 'x': 49, 'z': 51 | |
} | |
def decode_lstats(stats): | |
fields = "st_dev st_ino st_mode st_nlink st_uid st_gid st_rdev st_size st_blksize st_blocks st_atime st_mtime st_ctime LinkFI st_flags data".split() | |
out = {} | |
for i, element in enumerate(stats.split()): | |
result = 0 | |
for n, letter in enumerate(element): | |
if letter: | |
result = result << 6 | |
result += B64_VALS[letter] | |
out[fields[i]] = result | |
return out | |
if __name__ == '__main__': | |
print decode_lstats('gR DwABPN EHA C Pn Pn A G BAA A BC3sbr BC3moS BC3sbr A A C') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! It worked. 😄