wolf9228 Posted September 26, 2015 Share Posted September 26, 2015 (edited) All Files Compression.zip Compression.au3expandcollapse popup#include <WinAPI.au3> #include <Memory.au3> Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $i = 0 , $NuA = 0 ,$NuB = 0 ,$NuC = 0 ,$PtrB , $ReturnSt Local $ByteE,$ByteB,$ByteC,$ByteD,$PtrA,$ByteA,$NuBPtr,$NuCPtr While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 1 Next if $NuA > 2 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnSt = DllStructCreate("Byte CountB;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnSt,"CountB",$NuB) DllStructSetData($ReturnSt,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnSt,"NuB") $NuCPtr = DllStructGetPtr($ReturnSt,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnSt = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnSt,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Return $ReturnSt EndFunc Func CompressionC($TempDataStructA) Local $TestByte = False , $ByteE = 0 ; (Max $TempDataStructA Size Is 254) // (Max $v is 255 Start From Zero) // One Byte Out For $v = 0 To (255 - 1) $TestByte = True For $q = 1 To DllStructGetSize($TempDataStructA) $ByteE = DllStructGetData($TempDataStructA,1,$q) if $v = $ByteE Then $TestByte = False ExitLoop EndIf Next if $TestByte Then $ByteE = $v ExitLoop EndIf Next Return $ByteE EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes, $FileSize , $hFileA , $hFileB , $FileSt , $FileStPtr , $NuF Local $Remainder , $CountBSt , $CountB , $CountCSt , $CountC , $StructBPtr Local $StructCPtr , $NuG , $TempDataStructB , $TempDataStructC , $NewSize Local $ByteA , $ByteB , $ByteE , $vByteE , $TempDataStructD , $StructDPtr $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) if $CountB = 0 Then $FileStPtr += 1 _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= (254 + 1) Else $NuG = 0 $FileStPtr += 1 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC + 2) For $i = $CountC To 3 Step -3 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 2) $ByteA = DllStructGetData($TempDataStructC,1,$i - 1) $ByteB = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Compression.zip Edited October 1, 2015 by wolf9228 Celtic88 and Danyfirex 2 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted September 28, 2015 Author Share Posted September 28, 2015 (edited) Another experiment Compression.zip Compression.au3expandcollapse popup#include <WinAPI.au3> #include <Memory.au3> Opt("MustDeclareVars", 1) Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $TempDataStructE = DllStructCreate( "Byte[254]" ) Local $i = 0 , $NuA = 0 ,$NuB = 0 ,$NuC = 0 ,$PtrB , $ReturnSt Local $ByteE,$ByteB,$ByteC,$ByteD,$PtrA,$ByteA,$NuBPtr,$NuCPtr Local $ReturnStA , $ReturnStB , $ReturnStC , $PtrE $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrA,$PtrE,254) While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStA = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStA,"Type",1) DllStructSetData($ReturnStA,"CountB",$NuB) DllStructSetData($ReturnStA,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") $NuCPtr = DllStructGetPtr($ReturnStA,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStA = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuA += 1 Next if $NuA > 2 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStB = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStB,"Type",2) DllStructSetData($ReturnStB,"CountB",$NuB) DllStructSetData($ReturnStB,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") $NuCPtr = DllStructGetPtr($ReturnStB,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStB = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStC = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStC,"Type",3) DllStructSetData($ReturnStC,"CountB",$NuB) DllStructSetData($ReturnStC,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") $NuCPtr = DllStructGetPtr($ReturnStC,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStC = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Local $ReturnStASize = DllStructGetSize($ReturnStA) Local $ReturnStBSize = DllStructGetSize($ReturnStB) Local $ReturnStCSize = DllStructGetSize($ReturnStC) Local $ReturnSt , $ReturnStSize Local $ReturnStSize = $ReturnStASize , $ReturnSt = $ReturnStA if $ReturnStBSize < $ReturnStSize Then $ReturnStSize = $ReturnStBSize $ReturnSt = $ReturnStB EndIf if $ReturnStCSize < $ReturnStSize Then $ReturnSt = $ReturnStC Return $ReturnSt EndFunc Func CompressionC($TempDataStructA) Local $TestByte = False , $ByteE = 0 ; (Max $TempDataStructA Size Is 254) // (Max $v is 255 Start From Zero) // One Byte Out For $v = 0 To (255 - 1) $TestByte = True For $q = 1 To DllStructGetSize($TempDataStructA) $ByteE = DllStructGetData($TempDataStructA,1,$q) if $v = $ByteE Then $TestByte = False ExitLoop EndIf Next if $TestByte Then $ByteE = $v ExitLoop EndIf Next Return $ByteE EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes,$FileSize ,$hFileA , $hFileB ,$FileSt,$FileStPtr ,$NuF,$Type Local $Remainder , $CountBSt , $CountB , $CountCSt , $CountC , $StructBPtr Local $StructCPtr , $NuG , $TempDataStructB , $TempDataStructC , $NewSize Local $ByteA,$ByteB,$ByteE,$vByteE, $TempDataStructD , $StructDPtr,$TypeSt $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) $FileStPtr += 1 $NuF -= 1 if $CountB = 0 Then _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= 254 Else $TypeSt = DllStructCreate("Byte",$FileStPtr) $Type = DllStructGetData($TypeSt,1) $FileStPtr += 1 $NuF -= 1 $NuG = 0 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $NuF -= 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC) Switch $Type Case 1,3 For $i = $CountC To 3 Step -3 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 2) $ByteA = DllStructGetData($TempDataStructC,1,$i - 1) $ByteB = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then Switch $Type Case 1 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Case 3 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndSwitch Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next Case Else For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 1) $ByteA = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next EndSwitch $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Compression.zip Edited October 1, 2015 by wolf9228 Danyfirex 1 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Celtic88 Posted September 29, 2015 Share Posted September 29, 2015 Waw Superb,thank you Link to comment Share on other sites More sharing options...
wolf9228 Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) Waw Superb,thank you You are Superb ... Thank you Edited September 29, 2015 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted September 30, 2015 Author Share Posted September 30, 2015 (edited) Another experiment Compression.zip Compression.au3expandcollapse popup#include <WinAPI.au3> #include <Memory.au3> Opt("MustDeclareVars", 1) Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $TempDataStructE = DllStructCreate( "Byte[254]" ) Local $i = 0,$j = 0,$NuA = 0,$NuB = 0,$NuC = 0,$PtrB,$ReturnSt Local $ByteE,$ByteB,$ByteC,$ByteD,$PtrA,$ByteA,$NuBPtr,$NuCPtr Local $ReturnStA , $ReturnStB , $ReturnStC , $PtrE , $NuG = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 1 Then ExitLoop $i += 1 $ByteA = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 $j = 0 While 1 if (DllStructGetSize($TempDataStructA) - $j) < 1 Then ExitLoop $j += 1 $ByteB = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteB Then $NuA += 1 if $NuA = 254 Then $NuC = 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC = 2 $NuG = 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 1 DllStructSetData($TempDataStructB,1,$ByteA,$NuB) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf Else if $NuA > 2 Then $NuG = ($j - $NuA) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 0 For $v = 1 To DllStructGetSize($TempDataStructA) if ($v <= $NuG) Or ($v >= $j) Then $NuB += 1 $ByteB = DllStructGetData($TempDataStructA,1,$v) DllStructSetData($TempDataStructB,1,$ByteB,$NuB) EndIf Next $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf $NuA = 0 EndIf WEnd WEnd if $NuC Then $ReturnStA = DllStructCreate("Byte CountB;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStA,"CountB",$NuB) DllStructSetData($ReturnStA,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") $NuCPtr = DllStructGetPtr($ReturnStA,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStA = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Return $ReturnStA EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes, $FileSize , $hFileA , $hFileB , $FileSt , $FileStPtr , $NuF Local $Remainder , $CountBSt , $CountB , $CountCSt , $CountC , $StructBPtr Local $StructCPtr , $NuG , $TempDataStructB , $TempDataStructC , $NewSize Local $ByteA , $ByteB , $ByteE , $vByteE , $TempDataStructD , $StructDPtr Local $Position , $Count $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) if $CountB = 0 Then $FileStPtr += 1 _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= (254 + 1) Else $NuG = 0 $FileStPtr += 1 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC + 2) For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $Count = DllStructGetData($TempDataStructC,1,$i - 1) $Position = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $ByteA = DllStructGetData($TempDataStructB,1,$j) if $Position = $j Then For $v = 1 To $Count $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) Next Else $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Compression.zip Compression.zip Edited October 1, 2015 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted October 1, 2015 Author Share Posted October 1, 2015 (edited) Last experiment Compression2.zipCompression.au3expandcollapse popup#include <WinAPI.au3> #include <Memory.au3> Opt("MustDeclareVars", 1) Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $TempDataStructE = DllStructCreate( "Byte[254]" ) , $NuG Local $i = 0,$NuA = 0,$NuB = 0,$NuC = 0,$PtrB,$ReturnSt,$ReturnStF Local $ByteE ,$ByteB ,$ByteC ,$ByteD ,$PtrA,$ByteA,$NuBPtr,$NuCPtr Local $ReturnStA,$ReturnStB,$ReturnStC,$PtrE,$ReturnStD,$ReturnStE $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrA,$PtrE,254) While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStA = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStA,"Type",1) DllStructSetData($ReturnStA,"CountB",$NuB) DllStructSetData($ReturnStA,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") $NuCPtr = DllStructGetPtr($ReturnStA,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStA = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuA += 1 Next if $NuA > 2 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStB = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStB,"Type",2) DllStructSetData($ReturnStB,"CountB",$NuB) DllStructSetData($ReturnStB,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") $NuCPtr = DllStructGetPtr($ReturnStB,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStB = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStC = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStC,"Type",3) DllStructSetData($ReturnStC,"CountB",$NuB) DllStructSetData($ReturnStC,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") $NuCPtr = DllStructGetPtr($ReturnStC,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStC = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 1 Then ExitLoop $i += 1 $ByteA = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 $j = 0 While 1 if DllStructGetSize($TempDataStructA) - $j < 1 Then ExitLoop $j += 1 $ByteB = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteB Then $NuA += 1 if $NuA = 254 Then $NuC = 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC = 2 $NuG = 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 1 DllStructSetData($TempDataStructB,1,$ByteA,$NuB) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf Else if $NuA > 2 Then $NuG = ($j - $NuA) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 0 For $v = 1 To DllStructGetSize($TempDataStructA) if ($v <= $NuG) Or ($v >= $j) Then $NuB += 1 $ByteB = DllStructGetData($TempDataStructA,1,$v) DllStructSetData($TempDataStructB,1,$ByteB,$NuB) EndIf Next $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf $NuA = 0 EndIf WEnd WEnd if $NuC Then $ReturnStD = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStD,"Type",4) DllStructSetData($ReturnStD,"CountB",$NuB) DllStructSetData($ReturnStD,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStD,"NuB") $NuCPtr = DllStructGetPtr($ReturnStD,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStD = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStD,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 $NuG = 0 While 1 if DllStructGetSize($TempDataStructA) - $i < 2 Then ExitLoop $i += 2 $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 $j = 0 While 1 if DllStructGetSize($TempDataStructA) - $j < 2 Then ExitLoop $j += 2 $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 2 if $NuA = 254 Then $NuC = 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC = 2 $NuG = 2 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 1 DllStructSetData($TempDataStructB,1,$ByteA,$NuB) $NuB = 2 DllStructSetData($TempDataStructB,1,$ByteB,$NuB) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf Else $NuG = ($j - $NuA) if $NuA > 2 Then $NuC += 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 0 For $v = 1 To DllStructGetSize($TempDataStructA) if ($v <= $NuG) Or ($v >= ($j - 1)) Then $NuB += 1 $ByteB = DllStructGetData($TempDataStructA,1,$v) DllStructSetData($TempDataStructB,1,$ByteB,$NuB) EndIf Next $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf $NuA = 0 EndIf WEnd WEnd if $NuC Then $ReturnStE = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStE,"Type",5) DllStructSetData($ReturnStE,"CountB",$NuB) DllStructSetData($ReturnStE,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStE,"NuB") $NuCPtr = DllStructGetPtr($ReturnStE,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStE = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStE,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 $NuG = 0 While 1 if DllStructGetSize($TempDataStructA) - $i < 2 Then ExitLoop $i += 2 $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 $j = 0 While 1 if DllStructGetSize($TempDataStructA) - $j < 2 Then ExitLoop $j += 2 $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuA += 2 if $NuA = 254 Then $NuC = 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC = 2 $NuG = 2 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 1 DllStructSetData($TempDataStructB,1,$ByteB,$NuB) $NuB = 2 DllStructSetData($TempDataStructB,1,$ByteA,$NuB) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf Else $NuG = ($j - $NuA) if $NuA > 2 Then $NuC += 1 DllStructSetData($TempDataStructC,1,$NuA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$NuG,$NuC) $NuB = 0 For $v = 1 To DllStructGetSize($TempDataStructA) if ($v <= $NuG) Or ($v >= ($j - 1)) Then $NuB += 1 $ByteB = DllStructGetData($TempDataStructA,1,$v) DllStructSetData($TempDataStructB,1,$ByteB,$NuB) EndIf Next $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf $NuA = 0 EndIf WEnd WEnd if $NuC Then $ReturnStF = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStF,"Type",6) DllStructSetData($ReturnStF,"CountB",$NuB) DllStructSetData($ReturnStF,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStF,"NuB") $NuCPtr = DllStructGetPtr($ReturnStF,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStF = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStF,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Local $ReturnStASize = DllStructGetSize($ReturnStA) Local $ReturnStBSize = DllStructGetSize($ReturnStB) Local $ReturnStCSize = DllStructGetSize($ReturnStC) Local $ReturnStDSize = DllStructGetSize($ReturnStD) Local $ReturnStESize = DllStructGetSize($ReturnStE) Local $ReturnStFSize = DllStructGetSize($ReturnStF) Local $ReturnSt , $ReturnStSize Local $ReturnStSize = $ReturnStASize , $ReturnSt = $ReturnStA if $ReturnStBSize < $ReturnStSize Then $ReturnStSize = $ReturnStBSize $ReturnSt = $ReturnStB EndIf if $ReturnStCSize < $ReturnStSize Then $ReturnStSize = $ReturnStCSize $ReturnSt = $ReturnStC EndIf if $ReturnStDSize < $ReturnStSize Then $ReturnStSize = $ReturnStDSize $ReturnSt = $ReturnStD EndIf if $ReturnStESize < $ReturnStSize Then $ReturnStSize = $ReturnStESize $ReturnSt = $ReturnStE EndIf if $ReturnStFSize < $ReturnStSize Then $ReturnSt = $ReturnStFSize Return $ReturnSt EndFunc Func CompressionC($TempDataStructA) Local $TestByte = False , $ByteE = 0 ; (Max $TempDataStructA Size Is 254) // (Max $v is 255 Start From Zero) // One Byte Out For $v = 0 To (255 - 1) $TestByte = True For $q = 1 To DllStructGetSize($TempDataStructA) $ByteE = DllStructGetData($TempDataStructA,1,$q) if $v = $ByteE Then $TestByte = False ExitLoop EndIf Next if $TestByte Then $ByteE = $v ExitLoop EndIf Next Return $ByteE EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes,$FileSize ,$hFileA , $hFileB ,$FileSt,$FileStPtr , $NuF,$Type Local $Remainder,$CountBSt,$CountB,$CountCSt,$CountC, $StructBPtr,$Position Local $StructCPtr,$NuG ,$TempDataStructB ,$TempDataStructC ,$NewSize,$Count Local $ByteA ,$ByteB,$ByteE,$vByteE, $TempDataStructD , $StructDPtr,$TypeSt $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) $FileStPtr += 1 $NuF -= 1 if $CountB = 0 Then _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= 254 Else $TypeSt = DllStructCreate("Byte",$FileStPtr) $Type = DllStructGetData($TypeSt,1) $FileStPtr += 1 $NuF -= 1 $NuG = 0 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $NuF -= 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC) Switch $Type Case 1,3 For $i = $CountC To 3 Step -3 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 2) $ByteA = DllStructGetData($TempDataStructC,1,$i - 1) $ByteB = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then Switch $Type Case 1 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Case 3 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndSwitch Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next Case 2 For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 1) $ByteA = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next Case 4 For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $Count = DllStructGetData($TempDataStructC,1,$i - 1) $Position = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $ByteA = DllStructGetData($TempDataStructB,1,$j) if $Position = $j Then For $v = 1 To $Count $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) Next Else $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next Case 5,6 For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $Count = DllStructGetData($TempDataStructC,1,$i - 1) $Position = DllStructGetData($TempDataStructC,1,$i) For $j = 2 To DllStructGetSize($TempDataStructB) Step 2 if DllStructGetSize($TempDataStructB) - $j = 1 Then $ByteB = DllStructGetData($TempDataStructB,1,$j + 1) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) ExitLoop EndIf $ByteA = DllStructGetData($TempDataStructB,1,$j - 1) $ByteB = DllStructGetData($TempDataStructB,1,$j) if $Position = $j Then For $v = 1 To ($Count / 2) Switch $Type Case 5 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Case 6 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndSwitch Next Else $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next EndSwitch $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Edited October 20, 2015 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted March 5, 2021 Author Share Posted March 5, 2021 up صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Developers Jos Posted March 5, 2021 Developers Share Posted March 5, 2021 2 minutes ago, wolf9228 said: up Because? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wolf9228 Posted March 12, 2021 Author Share Posted March 12, 2021 On 3/6/2021 at 1:22 AM, Jos said: Because? For the sake of interest ... I might go back and offer something new about data compression ... It just requires an idea like byte matching, sequence of mathematical relationships between them, larger with a fixed number, smaller than a fixed number, etc. ... Sorry for bringing the topic up ... Thank you. صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now