From 71cf2a8dd3c0086d69954e9ed917db95faf7e3d5 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Thu, 16 Nov 2023 17:56:13 +0100 Subject: [PATCH] chore: add useful scripts --- scripts/dexor_binary_file.ps1 | 14 ++++++++++++++ scripts/split_dat_file.ps1 | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 scripts/dexor_binary_file.ps1 create mode 100644 scripts/split_dat_file.ps1 diff --git a/scripts/dexor_binary_file.ps1 b/scripts/dexor_binary_file.ps1 new file mode 100644 index 0000000..5df9244 --- /dev/null +++ b/scripts/dexor_binary_file.ps1 @@ -0,0 +1,14 @@ +$SourceFilePath = $args[0] +$DestinationFilePath = $args[1] +$XorKey = [byte]$args[2] + +# Load the binary data from the file +$data = [System.IO.File]::ReadAllBytes($SourceFilePath) + +# Apply the XOR operation +for ($i = 0; $i -lt $data.Length; $i++) { + $data[$i] = $data[$i] -bxor $XorKey +} + +# Write the output to the destination file +[System.IO.File]::WriteAllBytes($DestinationFilePath, $data) diff --git a/scripts/split_dat_file.ps1 b/scripts/split_dat_file.ps1 new file mode 100644 index 0000000..39be178 --- /dev/null +++ b/scripts/split_dat_file.ps1 @@ -0,0 +1,36 @@ +$SourceFilePath = $args[0] +$ChunkSize = $args[1] +$Offset = $args[2] + +# Function to create chunk file +function Create-ChunkFile { + param ( + [byte[]]$ChunkData, + [int]$ChunkNumber + ) + + $chunkFileName = Join-Path $subDir ("{0}_{1:D5}.bin" -f [System.IO.Path]::GetFileNameWithoutExtension($SourceFilePath), $ChunkNumber) + [System.IO.File]::WriteAllBytes($chunkFileName, $ChunkData) +} + +# Create subdirectory named after the source file (without extension) for chunks +$subDir = Join-Path ([System.IO.Path]::GetDirectoryName($SourceFilePath)) ([System.IO.Path]::GetFileNameWithoutExtension($SourceFilePath)) +if (!(Test-Path -Path $subDir)) { + New-Item -ItemType Directory -Path $subDir +} + +# Read the binary data from the file +$data = [System.IO.File]::ReadAllBytes($SourceFilePath) +$dataLength = $data.Length +$chunkNumber = 0 + +# Adjust the start position based on the offset +$startPosition = [Math]::Min($Offset, $dataLength) + +# Process chunks +for ($i = $startPosition; $i -lt $dataLength; $i += $ChunkSize) { + $chunkEnd = [Math]::Min($i + $ChunkSize, $dataLength) + $chunkData = $data[$i..($chunkEnd - 1)] + Create-ChunkFile -ChunkData $chunkData -ChunkNumber $chunkNumber + $chunkNumber++ +}