Users browsing this thread: 7 Guest(s)
XOR First Bytes of Files Automatically
#3
Star 
(11-30-2024, 03:35 PM)scurest Wrote: You can use a Python script. You can ask ChatGPT to help write it if you don't know how. Here's what it gave me (which looks fine to me)

Code:
import sys

# Put what you want to xor with here
magic_string = b'XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-'

# Open the file in read and write mode (binary)
with open(sys.argv[1], 'r+b') as file:
    # Read the first 32 bytes
    header = bytearray(file.read(32))
   
    # XOR the file data with the magic string byte by byte
    for i in range(32):
        header[i] ^= magic_string[i]
   
    # Move the file pointer back to the beginning
    file.seek(0)
   
    # Write the modified data back to the file
    file.write(header)

After installing Python, you can call it from the shell like python path/to/script.py path/to/input/file. You should be able to iterate over your files in powershell and call it for each one. Note that it will modify the input file in place, but you can change that if you want of course.

Hiya!

Thanks a lot for this idea, I looked into it and modified the code a bit.
Your version has one major problem, that being that it relies on the “header” variable to be of the data type string.
The issue with that is the fact that you can only XOR with integer variables. So, in order to do this calculation, it would be required to change the type of the variable multiple times in the process.
But when I was trying to figure that out, I realized something: the file header I am trying to replace is the same for every file (should have noticed that sooner…), so I don't actually need to perform that calculation for each file.
All I needed to do was overwrite the first 32 bytes of the file with the decrypted header.

This opens up the issue that it's really not that easy to write this header data, since it contains non-ASCII characters, which I wasn't able to properly write into the file.
Even trying to overwrite the binary data was not successful. But that should be something I'll be able to figure out eventually.

So yeh, the problem was more that I was thinking way too complicated lol
But thanks a lot for the help anyway, I really appreciate it!
Reply
Thanked by:


Messages In This Thread
RE: XOR First Bytes of Files Automatically - by Lillyth-Sillyth - 12-01-2024, 04:09 AM

Forum Jump: