chore: add useful scripts

This commit is contained in:
Timothy Schenk 2023-11-16 17:56:13 +01:00
parent 16673ef3c0
commit 71cf2a8dd3
2 changed files with 50 additions and 0 deletions

View file

@ -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)

View file

@ -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++
}