Skip to content

Commit

Permalink
pcap: include timestamp info into recorded packets
Browse files Browse the repository at this point in the history
Co-authored-by: djo <[email protected]>
  • Loading branch information
Valkhes and djo authored Nov 13, 2024
1 parent 096dcb0 commit 28098d6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pymobiledevice3/services/pcapd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import enum
import time
from collections.abc import Generator
from typing import Optional

Expand Down Expand Up @@ -391,10 +392,21 @@ def write_to_pcap(self, out, packet_generator) -> None:
writer = FileWriter(out, shb)

for packet in packet_generator:
if hasattr(packet, 'timestamp'):
packet_time = packet.timestamp
else:
packet_time = time.time()

timestamp_microseconds = int(packet_time * 1_000_000)
timestamp_high = (timestamp_microseconds >> 32) & 0xFFFFFFFF
timestamp_low = timestamp_microseconds & 0xFFFFFFFF

enhanced_packet = shb.new_member(blocks.EnhancedPacket, options={
'opt_comment': f'PID: {packet.pid}, ProcName: {packet.comm}, EPID: {packet.epid}, '
f'EProcName: {packet.ecomm}, SVC: {packet.svc}'
})

enhanced_packet.packet_data = packet.data
enhanced_packet.timestamp_high = timestamp_high
enhanced_packet.timestamp_low = timestamp_low
writer.write_block(enhanced_packet)

0 comments on commit 28098d6

Please sign in to comment.