Skip to content
Prev Previous commit
Next Next commit
Add CLI command to parse files as blink
  • Loading branch information
sydp committed Apr 30, 2024
commit a9bbca326dab0839aa10702f7b1d75dc2c6216f9
28 changes: 28 additions & 0 deletions dfindexeddb/indexeddb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from dfindexeddb import errors
from dfindexeddb import version
from dfindexeddb.leveldb import record as leveldb_record
from dfindexeddb.indexeddb.chromium import blink
from dfindexeddb.indexeddb.chromium import record as chromium_record
from dfindexeddb.indexeddb.chromium import v8
from dfindexeddb.indexeddb.safari import record as safari_record
Expand Down Expand Up @@ -74,6 +75,14 @@ def _Output(structure, output):
print(structure)


def BlinkCommand(args):
"""The CLI for processing a file as a blink value."""
with open(args.source, 'rb') as fd:
buffer = fd.read()
blink_value = blink.V8ScriptValueDecoder.FromBytes(buffer)
_Output(blink_value, output=args.output)


def DbCommand(args):
"""The CLI for processing a directory as IndexedDB."""
if args.format in ('chrome', 'chromium'):
Expand Down Expand Up @@ -146,6 +155,25 @@ def App():

subparsers = parser.add_subparsers()

parser_blink = subparsers.add_parser(
'blink', help='Parse a file as a blink value.')
parser_blink.add_argument(
'-s', '--source',
required=True,
type=pathlib.Path,
help=(
'The source file.'))
parser_blink.add_argument(
'-o',
'--output',
choices=[
'json',
'jsonl',
'repr'],
default='json',
help='Output format. Default is json')
parser_blink.set_defaults(func=BlinkCommand)

parser_db = subparsers.add_parser(
'db', help='Parse a directory as IndexedDB.')
parser_db.add_argument(
Expand Down