Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/parse_mnesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
parser.add_argument('-file', help='choose file to parse', default='no file')
parser.add_argument('-chunk', help='byte count for each file chunk to read (default=1028)', default=1028)
parser.add_argument('-o', help='filename (no extension) for file; print for print to terminal', default='print')
parser.add_argument('-be', help='byte endianess for lenght, e.g. big, little', default="big")
parser.add_argument("-e", help="encoding, e.g. utf-8, ascii", default="utf-8")
parser.add_argument("-ee", help="encoding errors, e.g. strict, ignore", default="strict")
args = parser.parse_args()

if args.file == 'no file':
Expand All @@ -32,6 +35,10 @@

fileName = args.file

endianness = args.be
encoding = args.e
encoding_errors = args.ee

#fileName='/usr/local/var/lib/rabbitmq/mnesia/rabbit/msg_stores/vhosts/2KVL28AS0JEHD0UYQNDTX3QIO/queues/7NJWTXU5MSR21TJGJEOA2NPC2/0.idx'
print('Reading file: ' + fileName)

Expand All @@ -48,19 +55,18 @@ def convert_hex(string):


def extractString(data, hexString, byteLengthHex):
hexdata=convert_hex(data)
dataPos=hexdata.find(hexString.upper())
dataPos = data.find(bytes.fromhex(hexString))
if dataPos == -1:
found=False
unescapedData=''
endPosition = -1
else:
found=True
startofMatch=round(dataPos/2)
startofMatch=round(dataPos)
recordSize = data[startofMatch+byteLengthHex:startofMatch+byteLengthHex+2]
rdqEntryLength = int(convert_hex(recordSize), 16)
rdqEntryLength = int.from_bytes(recordSize, endianness)
dataMessage = data[startofMatch+byteLengthHex+2: startofMatch+byteLengthHex+2+rdqEntryLength]
unescapedData = dataMessage.decode('ascii', 'ignore')
unescapedData = dataMessage.decode(encoding, encoding_errors)
endPosition = startofMatch+byteLengthHex+2+rdqEntryLength
return {"string": unescapedData, "endpos": endPosition, 'found':found}

Expand Down