MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / decode_pcapng

Function decode_pcapng

decode_pcapng.py:226–288  ·  view source on GitHub ↗
(path, bus_id, dev, second_first)

Source from the content-addressed store, hash-verified

224
225
226def decode_pcapng(path, bus_id, dev, second_first):
227 img1_binary = [] # [(addr, row)]
228 img2_binary = [] # [(addr, row)]
229 with open(path, "rb") as f:
230 scanner = FileScanner(f)
231 block_no = 1
232 for i, block in enumerate(scanner):
233 if type(block) is blocks.EnhancedPacket or type(block) is blocks.SimplePacket:
234 img1 = False
235 img2 = False
236
237 #print(block_no, block.packet_len, block.packet_data)
238 packet = block.packet_data
239 urb = usb_urb(packet[0:usb_urb_sz])
240
241 # Filter device
242 if urb.bus_id == bus_id and urb.device == dev:
243 img1 = True
244 elif urb.bus_id == bus_id and urb.device == dev+1:
245 img2 = True
246 else:
247 #print(f"Other device bus_id: {urb.bus_id}, dev: {urb.device}")
248 #print(f"bus_id: {bus_id}, dev_id: {dev}")
249 continue
250
251 # Only consider outgoing packets
252 if urb.irp_info != 0:
253 continue
254
255 #print(block_no, urb)
256
257 # Skip small packets
258 if urb.data_length != 140:
259 continue
260
261 if DEBUG:
262 print(block_no, " ", format_hex(packet))
263
264 hid_packet = packet[36:]
265 if DEBUG:
266 print(block_no, " ", format_hex(hid_packet))
267
268 addr = (hid_packet[3] << 8) + hid_packet[2]
269 payload = hid_packet[4:]
270 if VERBOSE:
271 print("{:4d} 0x{:08X} {}".format(block_no, addr, format_hex(payload)))
272
273 if img1:
274 if second_first:
275 img2_binary.append((addr, payload))
276 else:
277 img1_binary.append((addr, payload))
278 elif img2:
279 if second_first:
280 img1_binary.append((addr, payload))
281 else:
282 img2_binary.append((addr, payload))
283

Callers 1

mainFunction · 0.85

Calls 2

usb_urbFunction · 0.85
format_hexFunction · 0.85

Tested by

no test coverage detected