-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
130 lines (106 loc) · 3.65 KB
/
cli.py
File metadata and controls
130 lines (106 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""Command-line interface for iOS Forensics Toolkit."""
import argparse
import sys
from pathlib import Path
from src.parsers import (
SMSParser,
WhatsAppParser,
SafariParser,
CallHistoryParser,
KnowledgeCParser,
ContactsParser,
PlistParser
)
PARSERS = {
'sms': SMSParser,
'whatsapp': WhatsAppParser,
'safari': SafariParser,
'calls': CallHistoryParser,
'knowledgec': KnowledgeCParser,
'contacts': ContactsParser,
'plist': PlistParser
}
def detect_type(path: str) -> str:
"""Auto-detect database type from filename."""
name = Path(path).name.lower()
if name.endswith('.plist'):
return 'plist'
if 'sms' in name:
return 'sms'
if 'chatstorage' in name:
return 'whatsapp'
if 'history' in name:
return 'safari'
if 'callhistory' in name:
return 'calls'
if 'knowledgec' in name:
return 'knowledgec'
if 'addressbook' in name:
return 'contacts'
return None
def main():
parser = argparse.ArgumentParser(
description='iOS Forensics Toolkit',
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument('file', help='Input file path')
parser.add_argument('-t', '--type', choices=list(PARSERS.keys()),
help='Parser type (auto-detected if not set)')
parser.add_argument('-o', '--output', help='Output file path')
parser.add_argument('-f', '--format', choices=['json', 'csv', 'html'],
default='json', help='Output format')
parser.add_argument('-l', '--limit', type=int, help='Limit records')
parser.add_argument('--tables', action='store_true', help='List tables only')
parser.add_argument('--schema', help='Show schema for table')
parser.add_argument('--stats', action='store_true', help='Show statistics')
args = parser.parse_args()
# Detect or use provided type
parser_type = args.type or detect_type(args.file)
if not parser_type:
print(f"Error: Cannot detect file type. Use -t option.")
sys.exit(1)
parser_cls = PARSERS[parser_type]
try:
# Handle plist separately
if parser_type == 'plist':
p = PlistParser(args.file)
data = p.parse()
if args.output:
p.export_json(args.output)
print(f"Exported to {args.output}")
else:
p.print_structure()
return
# Handle database parsers
with parser_cls(args.file) as p:
if args.tables:
for t in p.tables():
print(t)
return
if args.schema:
for col in p.schema(args.schema):
print(f"{col['name']}: {col['type']}")
return
if args.stats and hasattr(p, 'stats'):
import json
print(json.dumps(p.stats(), indent=2))
return
# Parse data
data = p.parse(limit=args.limit)
print(f"Parsed {len(data)} records")
# Export if output specified
if args.output:
if args.format == 'json':
p.export_json(args.output)
elif args.format == 'csv':
p.export_csv(args.output)
print(f"Exported to {args.output}")
except FileNotFoundError as e:
print(f"Error: {e}")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == '__main__':
main()