Hi everyone!
I'm currently in the process of ripping sprites from Sword Art Online: Alicization Lycoris.
After spending probably way too much time on this game, I finally found a way to get the character sprites out of it.
The problem is, with my current methods, it takes ages.
I managed to automate a lot of the usual file-by-file operations using PowerShell.
However, part of the process is decrypting a file header by using a logical XOR operation on the first 32 bytes of the files.
While I can do that for each file individually, I would have to do so for something around 600 files if I want to rip everything.
So my question is: is there a way to automate this process? Potentially a PowerShell function that can XOR a specified amount of bytes?
I did search the web already, but didn't manage to find anything that was able to help my specific case.
If any of you more experienced people know of a way, that would be massively appreciated!
Thanks in advance!
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.
(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!