Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Last active October 23, 2025 00:36
Show Gist options
  • Select an option

  • Save Hashbrown777/5860079e5eb624e25dcfdbe8a7602de6 to your computer and use it in GitHub Desktop.

Select an option

Save Hashbrown777/5860079e5eb624e25dcfdbe8a7602de6 to your computer and use it in GitHub Desktop.
Extract the files from inside Necesse `res.data` file
if (![System.BitConverter]::IsLittleEndian) {
throw [System.BitConverter]::IsLittleEndian
}
$resources = [System.IO.FileStream]::new(
'res.data',
[System.IO.FileMode]::Open,
[System.IO.FileAccess]::Read
)
$number = [byte[]]::new(4)
Function ReadNumber { Param([switch]$safe)
if ($resources.Read($number, 0, $number.Count) -eq $number.Count) {
[System.BitConverter]::ToInt32($number, 0)
}
elseif (!$safe) {
throw 'EOF'
}
}
Function ReadString { Param($length)
$bytes = [byte[]]::new($length)
if ($resources.Read($bytes, 0, $length) -ne $length) {
throw 'EOF'
}
[System.Text.Encoding]::UTF8.GetString($bytes)
}
Function Seek { Param($bytes)
$resources.Seek($bytes, [System.IO.SeekOrigin]::Current) | Out-Null
}
$copied = $True
$copying = [byte[]]::new(4KB),[byte[]]::new(4KB)
Function Read { Param($length)
$resources.ReadAsync($copying[!$copied], 0, [math]::Min($copying[0].Count, $length))
}
Seek 4
try {
for ($length; $length = ReadNumber -safe;) {
$name = ReadString $length
$length = ReadNumber
"$name`t$($length / 1KB)kb" -replace '(?<=\.\d{2})\d+(?=kb)',''
$name = '_extracted/' + $name
$next = Read $length
New-Item -Type Directory -Force ($name -replace '/[^/]+$','') | Out-Null
$file = [System.IO.FileStream]::new(
$name,
[System.IO.FileMode]::CreateNew,
[System.IO.FileAccess]::Write
)
$write = $NULL
try {
for (
$read;
$next;
$write = $file.WriteAsync($copying[$copied], 0, $read)
) {
if (!($read = $next.Result)) {
throw 'EOF'
}
$copied = !$copied
if ($write) {
$write.Wait()
}
if ($length -= $read) {
$next = Read $length
}
else {
$next = $NULL
}
}
}
finally {
if ($write) {
$write.Wait()
}
$file.Close()
}
}
}
finally {
$resources.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment