### Full Round-Trip Workflow Example Source: https://context7.com/axcheron/ptexplorer/llms.txt Demonstrates a complete workflow of decoding a Packet Tracer file to XML, inspecting/modifying the XML, and then re-encoding it back to the binary format. ```APIDOC ## Full Round-Trip Workflow Decode a `.pka` file, inspect or modify the XML, then re-encode it for use in Packet Tracer. ```bash # Step 1 — decode binary to XML python3 ptexplorer.py -d lab_assignment.pka lab_assignment.xml # Step 2 — inspect the topology (standard XML tools work) grep -i "Router0 # Switch1 # Step 3 — modify the XML with any editor, then re-encode python3 ptexplorer.py -e lab_assignment.xml lab_assignment_v2.pkt # Step 4 — verify round-trip integrity (file sizes should match original) ls -lh lab_assignment.pka lab_assignment_v2.pkt ``` ``` -------------------------------- ### Full Round-Trip Workflow Example Source: https://context7.com/axcheron/ptexplorer/llms.txt Demonstrates a complete workflow: decoding a .pka file to XML, inspecting the XML, modifying it, and then re-encoding it back to a .pkt file. This process allows for inspection, modification, and version control of Packet Tracer projects. ```bash # Step 1 — decode binary to XML python3 ptexplorer.py -d lab_assignment.pka lab_assignment.xml # Step 2 — inspect the topology (standard XML tools work) grep -i "Router0 # Switch1 # Step 3 — modify the XML with any editor, then re-encode python3 ptexplorer.py -e lab_assignment.xml lab_assignment_v2.pkt # Step 4 — verify round-trip integrity (file sizes should match original) ls -lh lab_assignment.pka lab_assignment_v2.pkt ``` -------------------------------- ### Show ptexplorer CLI Help Source: https://context7.com/axcheron/ptexplorer/llms.txt Run the script with -h to display all available command-line options and argument references. ```bash python3 ptexplorer.py -h # usage: ptexplorer.py [-h] [-d | -e] infile outfile # # Convert Packet Tracer files (.pkt/.pka) to XML and vice versa # # positional arguments: # infile Packet Tracer file (or XML file when encoding) # outfile Output file path # # optional arguments: # -h, --help show this help message and exit # -d, --decode Converts Packet Tracer file to XML # -e, --encode Converts XML to Packet Tracer File ``` -------------------------------- ### CLI Usage - Help and Argument Reference Source: https://context7.com/axcheron/ptexplorer/llms.txt This section details how to access the help message and understand the arguments for the ptexplorer command-line utility. ```APIDOC ## CLI Usage - Help and Argument Reference Run with `-h` to see all available options. ```bash python3 ptexplorer.py -h # usage: ptexplorer.py [-h] [-d | -e] infile outfile # # Convert Packet Tracer files (.pkt/.pka) to XML and vice versa # # positional arguments: # infile Packet Tracer file (or XML file when encoding) # outfile Output file path # # optional arguments: # -h, --help show this help message and exit # -d, --decode Converts Packet Tracer file to XML # -e, --encode Converts XML to Packet Tracer File ``` ``` -------------------------------- ### Show ptexplorer help message Source: https://github.com/axcheron/ptexplorer/blob/master/README.md Use the -h flag to display the usage instructions for the ptexplorer script, including positional and optional arguments for decoding and encoding files. ```bash python3 ptexplorer.py -h ``` -------------------------------- ### Encode XML File to Packet Tracer Format using CLI Source: https://context7.com/axcheron/ptexplorer/llms.txt Employ the ptexplorer command-line tool with the -e flag to convert an XML file back into a .pkt file. This is the command-line equivalent of the ptfile_encode library function. ```bash # --- As a CLI tool --- python3 ptexplorer.py -e campus_network_modified.xml campus_network_modified.pkt # [*] Opening XML file 'campus_network_modified.xml' # [*] File size uncompressed = 3475692 bytes # [*] File size compressed = 164664 bytes # [*] Writing PKT to 'campus_network_modified.pkt' ``` -------------------------------- ### Decode Packet Tracer File to XML using CLI Source: https://context7.com/axcheron/ptexplorer/llms.txt Utilize the ptexplorer command-line tool with the -d flag to convert a .pka file to an XML file. This is the command-line equivalent of the ptfile_decode library function. ```bash # --- As a CLI tool --- python3 ptexplorer.py -d campus_network.pka campus_network.xml # [*] Opening Packet Tracer file 'campus_network.pka' # [*] File size compressed = 164664 bytes # [*] File size uncompressed = 3475692 bytes # [*] Writing XML to 'campus_network.xml' ``` -------------------------------- ### ptfile_encode(infile, outfile) Source: https://context7.com/axcheron/ptexplorer/llms.txt Encodes an XML file back into the binary Packet Tracer format (.pkt or .pka). This function compresses the XML and applies the obfuscation cipher. ```APIDOC ## `ptfile_encode(infile, outfile)` — Encode an XML file back to Packet Tracer format Reads a plain XML file, compresses it with zlib, prepends a 4-byte big-endian header containing the uncompressed size, then applies the rolling XOR cipher (keyed on the compressed+header length) to produce a valid `.pkt` or `.pka` binary file. ### Library Usage Example ```python # --- As a library --- from ptexplorer import ptfile_encode # Re-encode a modified XML file back to .pkt format ptfile_encode("campus_network_modified.xml", "campus_network_modified.pkt") # [*] Opening XML file 'campus_network_modified.xml' # [*] File size uncompressed = 3475692 bytes # [*] File size compressed = 164664 bytes # [*] Writing PKT to 'campus_network_modified.pkt' # The output .pkt file can be opened directly in Cisco Packet Tracer. ``` ### CLI Usage Example ```bash # --- As a CLI tool --- python3 ptexplorer.py -e campus_network_modified.xml campus_network_modified.pkt # [*] Opening XML file 'campus_network_modified.xml' # [*] File size uncompressed = 3475692 bytes # [*] File size compressed = 164664 bytes # [*] Writing PKT to 'campus_network_modified.pkt' ``` ``` -------------------------------- ### Encode XML to Packet Tracer file Source: https://github.com/axcheron/ptexplorer/blob/master/README.md Use the -e flag to convert an XML file back into a Packet Tracer file (.pkt). This process involves compressing the XML data and applying XOR encryption. ```bash python3 ptexplorer.py -e sample.xml sample.pkt [*] Opening XML file 'sample.xml' [*] File size uncompressed = 3475692 bytes [*] File size compressed = 164664 bytes [*] Writing PKT to 'sample.pkt' ``` -------------------------------- ### ptfile_decode(infile, outfile) Source: https://context7.com/axcheron/ptexplorer/llms.txt Decodes a binary Packet Tracer file (.pkt or .pka) into a human-readable XML file. This function reverses the obfuscation and decompression process. ```APIDOC ## `ptfile_decode(infile, outfile)` — Decode a Packet Tracer file to XML Reads a binary `.pkt` or `.pka` file, reverses the rolling XOR cipher using the file's byte length as the initial key, strips the 4-byte big-endian uncompressed-size header, and writes the resulting zlib-decompressed XML to `outfile`. ### Library Usage Example ```python # --- As a library --- from ptexplorer import ptfile_decode # Decode a .pka activity file to XML ptfile_decode("campus_network.pka", "campus_network.xml") # [*] Opening Packet Tracer file 'campus_network.pka' # [*] File size compressed = 164664 bytes # [*] File size uncompressed = 3475692 bytes # [*] Writing XML to 'campus_network.xml' # The resulting XML exposes the full topology: # # 5.2.0.0068 # # # # # Router # Internal # true # # # # # ``` ### CLI Usage Example ```bash # --- As a CLI tool --- python3 ptexplorer.py -d campus_network.pka campus_network.xml # [*] Opening Packet Tracer file 'campus_network.pka' # [*] File size compressed = 164664 bytes # [*] File size uncompressed = 3475692 bytes # [*] Writing XML to 'campus_network.xml' ``` ``` -------------------------------- ### Programmatic Round-trip with Error Handling Source: https://context7.com/axcheron/ptexplorer/llms.txt Use this snippet to decode a Packet Tracer file to XML, modify the XML, and then re-encode it back to a Packet Tracer file. Includes basic error handling for FileNotFoundError and other exceptions. ```python from ptexplorer import ptfile_decode, ptfile_encode import os src_pka = "lab_assignment.pka" xml_path = "lab_assignment.xml" out_pkt = "lab_assignment_v2.pkt" try: ptfile_decode(src_pka, xml_path) # ... inspect / modify xml_path here ... ptfile_encode(xml_path, out_pkt) print(f"Round-trip complete. Output: {out_pkt} ({os.path.getsize(out_pkt)} bytes)") except FileNotFoundError as e: print(f"[!] File not found: {e}") except Exception as e: print(f"[!] Unexpected error: {e}") ``` -------------------------------- ### Decode Packet Tracer file to XML Source: https://github.com/axcheron/ptexplorer/blob/master/README.md Use the -d flag to convert a Packet Tracer file (.pka) into an XML file. This process involves reversing XOR encryption and decompressing the binary data. ```bash python3 ptexplorer.py -d sample.pka sample.xml [*] Opening Packet Tracer file 'sample.pka' [*] File size compressed = 164664 bytes [*] File size uncompressed = 3475692 bytes [*] Writing XML to 'sample.xml' ``` -------------------------------- ### Decode Packet Tracer File to XML using Library Source: https://context7.com/axcheron/ptexplorer/llms.txt Use the ptfile_decode function from the ptexplorer library to convert a .pka activity file to an XML representation. The function handles the XOR cipher reversal and zlib decompression. ```python # --- As a library --- from ptexplorer import ptfile_decode # Decode a .pka activity file to XML ptfile_decode("campus_network.pka", "campus_network.xml") # [*] Opening Packet Tracer file 'campus_network.pka' # [*] File size compressed = 164664 bytes # [*] File size uncompressed = 3475692 bytes # [*] Writing XML to 'campus_network.xml' # The resulting XML exposes the full topology: # # 5.2.0.0068 # # # # # Router # Internal # true # # # # # ``` -------------------------------- ### Encode XML File to Packet Tracer Format using Library Source: https://context7.com/axcheron/ptexplorer/llms.txt Use the ptfile_encode function from the ptexplorer library to convert a modified XML file back into a .pkt format. This function compresses the XML and applies the rolling XOR cipher. ```python # --- As a library --- from ptexplorer import ptfile_encode # Re-encode a modified XML file back to .pkt format ptfile_encode("campus_network_modified.xml", "campus_network_modified.pkt") # [*] Opening XML file 'campus_network_modified.xml' # [*] File size uncompressed = 3475692 bytes # [*] File size compressed = 164664 bytes # [*] Writing PKT to 'campus_network_modified.pkt' # The output .pkt file can be opened directly in Cisco Packet Tracer. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.