Skip to content

Instantly share code, notes, and snippets.

@ducnh1022
Last active June 28, 2024 10:51
Show Gist options
  • Save ducnh1022/7678d673e6a616e12543007ed79cf82f to your computer and use it in GitHub Desktop.
Save ducnh1022/7678d673e6a616e12543007ed79cf82f to your computer and use it in GitHub Desktop.
shorten
def tail_binary_file(input_file, tag, output_file):
try:
with open(input_file, 'rb') as f:
# Read the entire file into memory
data = f.read()
# Find the position of the tag
tag_position = data.find(tag)
if tag_position == -1:
print(f"Tag '{tag}' not found in the file.")
return
# Extract content from the tag to the end of the file
content_from_tag = data[tag_position:]
# Write the content to the new file
with open(output_file, 'wb') as out_f:
out_f.write(content_from_tag)
print(f"Content from tag '{tag}' to the end of the file has been written to '{output_file}'.")
except Exception as e:
print(f"An error occurred: {e}")
# Example usage:
input_file_path = 'path/to/your/binary/file'
tag_to_search = b'YOUR_TAG'
output_file_path = 'path/to/output/file'
tail_binary_file(input_file_path, tag_to_search, output_file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment