Skip to content

Commit 090cfc1

Browse files
committed
Track SEGB tooling helpers
1 parent a4ebadd commit 090cfc1

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ __pycache__/
77
.venv/
88
dist/
99
*.egg-info/
10-
*.log
10+
*.log
11+
.DS_Store
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Any
2+
3+
from google.protobuf.message import Message
4+
5+
6+
class AppInFocusEvent(Message):
7+
transition_reason: str
8+
kind: int
9+
in_foreground: int
10+
cf_absolute_time: float
11+
bundle_id: str
12+
app_version: str
13+
app_build: str
14+
platform_flag: int
15+
16+
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
17+
def ParseFromString(self, serialized: bytes) -> int: ...
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import pathlib
2+
import sys
3+
4+
import blackboxprotobuf
5+
import ccl_segb.ccl_segb1 as ccl_segb1
6+
import ccl_segb.ccl_segb2 as ccl_segb2
7+
from rich import inspect, pretty, print_json
8+
from rich.console import Console
9+
from rich.traceback import install
10+
11+
install(show_locals=True)
12+
pretty.install()
13+
14+
console = Console()
15+
16+
17+
def insp(arg):
18+
return inspect(arg, all=True, help=True)
19+
20+
21+
def print_d(input_dict):
22+
return print_json(data=input_dict)
23+
24+
25+
if __name__ == "__main__":
26+
if len(sys.argv) < 2:
27+
print(f"USAGE: {pathlib.Path(sys.argv[0]).name} <SEGB file>")
28+
print()
29+
sys.exit(1)
30+
31+
input_path = sys.argv[1]
32+
result = []
33+
if ccl_segb1.file_matches_segbv1_signature(input_path):
34+
for record in ccl_segb1.read_segb1_file(input_path):
35+
offset = record.data_start_offset
36+
state = record.state
37+
data = record.data
38+
ts1 = record.timestamp1
39+
ts2 = record.timestamp2
40+
41+
if not any(data): # null-padded record
42+
continue
43+
44+
message, typedef = blackboxprotobuf.decode_message(data)
45+
46+
result.append(
47+
{
48+
"offset": offset,
49+
"state": state,
50+
"ts1": ts1.strftime("%Y-%m-%d %H:%M:%S %Z"),
51+
"ts2": ts2.strftime("%Y-%m-%d %H:%M:%S %Z"),
52+
"message": message,
53+
}
54+
)
55+
# print_d(result)
56+
console.print(result)
57+
elif ccl_segb2.file_matches_segbv2_signature(input_path):
58+
for record in ccl_segb2.read_segb2_file(input_path):
59+
offset = record.data_start_offset
60+
metadata_offset = record.metadata.metadata_offset
61+
state = record.metadata.state.name
62+
ts = record.metadata.creation
63+
data = record.data
64+
65+
if not any(data): # null-padded record
66+
continue
67+
message, typedef = blackboxprotobuf.decode_message(data)
68+
result.append(
69+
{
70+
"offset": offset,
71+
"metadata_offset": metadata_offset,
72+
"state": state,
73+
"ts": ts.strftime("%Y-%m-%d %H:%M:%S %Z"),
74+
"message": message,
75+
}
76+
)
77+
# print_d(result)
78+
console.print(result)
79+
80+
else:
81+
print("File is not a SEGB File")
82+
sys.exit(1)
83+
print()

0 commit comments

Comments
 (0)