Skip to content

Instantly share code, notes, and snippets.

@chsbuffer
Last active June 30, 2023 03:14
Show Gist options
  • Save chsbuffer/a5518aae7d4f7d0cd0141361dce07e45 to your computer and use it in GitHub Desktop.
Save chsbuffer/a5518aae7d4f7d0cd0141361dce07e45 to your computer and use it in GitHub Desktop.
修复 手机QQ、PC QQ_NT 提取的原创表情 GIF
#Requires -Version 7
Set-StrictMode -Version 3.0
# /sdcard/Android/data/com.tencent.mobileqq/tencent/MobileQQ/.emotionsm
$folder = Get-Item ".\emotionsm"
$outFolder = mkdir -Force ".\outfolder"
Get-ChildItem $folder | ForEach-Object -ThrottleLimit 8 -Parallel {
$outFolder = $using:outFolder
function AlternateEvenOddAdjustment ($buffer, $odd = 0) {
for ($i = 0; $i -lt $buffer.Count; $i++) {
if ($i % 2 -ne $odd) {
if ($buffer[$i] % 2 -eq 0) {
$buffer[$i] = $buffer[$i] + 1
} else {
$buffer[$i] = $buffer[$i] - 1
}
}
}
}
try {
$file = [System.IO.File]::OpenRead($_.FullName)
$out = [System.IO.File]::Create($(Join-Path -Path $outFolder -ChildPath "$($_.BaseName).gif"))
$br = New-Object System.IO.BinaryReader $file
# Fix Head + Logical Screen Descriptor
$head = $br.ReadBytes(6 + 7)
AlternateEvenOddAdjustment $head
$out.Write($head)
# Fix Global Color Table
$globalColorTableSize = $head[10] -band 7
$globalColorTableLength = [System.Math]::Pow(2, $globalColorTableSize + 1) * 3
$globalColorTable = $br.ReadBytes($globalColorTableLength)
AlternateEvenOddAdjustment $globalColorTable 1
$out.Write($globalColorTable)
# Fix App Extension 0
$ext0 = $br.ReadBytes(92)
if ($ext0[0] -eq 0x20) {
AlternateEvenOddAdjustment $ext0 1
}
$out.Write($ext0)
# rest of the content
$file.CopyTo($out)
} finally {
${br}?.Dispose()
${file}?.Dispose()
${out}?.Dispose()
}
}
#Requires -Version 7
Set-StrictMode -Version 3.0
# Tencent Files\<QQ number>\nt_qq\nt_data\Emoji\marketface
$folder = Get-Item ".\marketface"
$outFolder = mkdir -Force ".\outfolder"
Get-ChildItem $folder | ForEach-Object -ThrottleLimit 8 -Parallel {
$outFolder = $using:outFolder
function Invert ($buffer) {
for ($i = 0; $i -lt $buffer.Count; $i++) {
$buffer[$i] = 0xFF - $buffer[$i]
}
}
try {
$file = [System.IO.File]::OpenRead($_.FullName)
$out = [System.IO.File]::Create($(Join-Path -Path $outFolder -ChildPath "$($_.BaseName).gif"))
$br = New-Object System.IO.BinaryReader $file
for ($i = 0; ; $i++) {
$odd = ($i % 2 -eq 0)
$len = $odd ? 20: 30
$data = $br.ReadBytes($len)
if ($odd) {
Invert $data
}
$out.Write($data)
if ($data.Count -lt $len) {
break
}
}
} finally {
${br}?.Dispose()
${file}?.Dispose()
${out}?.Dispose()
}
}
@chsbuffer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment