Skip to content

Instantly share code, notes, and snippets.

@yosignals
Created April 15, 2024 14:09
Show Gist options
  • Save yosignals/1edd935d21d1210596ea5538679e359b to your computer and use it in GitHub Desktop.
Save yosignals/1edd935d21d1210596ea5538679e359b to your computer and use it in GitHub Desktop.
Hiding Files in Folders ... names
import os
import argparse
import hashlib
def file_to_hex(filename):
"""Convert file content to a hex string."""
with open(filename, 'rb') as file:
content = file.read()
return content.hex(), content
def create_folders_for_hex(hex_data, base_path, max_length=254):
"""Create folders with names based on segments of the hexadecimal data, including a sequence number."""
num_folders = (len(hex_data) + max_length - 1) // max_length
for i in range(num_folders):
folder_name = f"{i:04d}_{hex_data[i * max_length:(i + 1) * max_length]}"
os.makedirs(os.path.join(base_path, folder_name), exist_ok=True)
return num_folders
def hex_to_binary(hex_str):
"""Convert hexadecimal string to binary data."""
return bytes.fromhex(hex_str)
def rebuild_file_from_folders(base_path, output_filename):
"""Rebuild a file from folders with hexadecimal names that include a sequence number."""
folders = [name for name in os.listdir(base_path) if os.path.isdir(os.path.join(base_path, name))]
# Extract the sequence number and sort by it
folders.sort(key=lambda x: int(x.split('_')[0]))
hex_data = ''.join(name.split('_')[1] for name in folders)
binary_data = hex_to_binary(hex_data)
with open(output_filename, 'wb') as file:
file.write(binary_data)
def calculate_sha256(file_content):
"""Calculate SHA-256 hash of the given file content."""
sha256 = hashlib.sha256()
sha256.update(file_content)
return sha256.hexdigest()
def main():
parser = argparse.ArgumentParser(description="Create or Rebuild files from hex-named folders.")
parser.add_argument('mode', choices=['create', 'rebuild'], help='Operation mode: "create" or "rebuild"')
parser.add_argument('path', help='Path to the file or directory')
parser.add_argument('--output', help='Output file or directory', required=True)
args = parser.parse_args()
if args.mode == 'create':
hex_data, original_content = file_to_hex(args.path)
total_folders = create_folders_for_hex(hex_data, args.output)
file_size = os.path.getsize(args.path)
file_sha256 = calculate_sha256(original_content)
print(f"Created {total_folders} folders in {args.output} based on the file {args.path}")
print(f"Original file size: {file_size} bytes")
print(f"SHA-256 hash of the original file: {file_sha256}")
elif args.mode == 'rebuild':
rebuild_file_from_folders(args.path, args.output)
print(f"Rebuilt file {args.output} from folders in {args.path}")
if __name__ == "__main__":
main()
@Seceventspen
Copy link

NIIIIIICCCCCCCEEEEEEEEEE!

@ZephrFish
Copy link

saved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment