-
-
Save fygonzalo/a4118d35620d48bacea2253d5aa48e6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signed int __cdecl DescomprimirMSG(_BYTE *inputStream, int length, _BYTE *outputStrm, _DWORD *outputStream) | |
{ | |
_BYTE *inputBuffer; // esi@1 | |
_BYTE *lastByte; // ebp@1 | |
_BYTE *outputBuffer; // eax@1 | |
unsigned int bytesDescomprimidos; // ecx@2 | |
unsigned int firstByte; // ecx@5 | |
_BYTE *secondByte; // esi@5 | |
char v10; // dl@8 | |
unsigned int iteraciones; // ecx@10 | |
int v12; // edx@18 | |
int v13; // edx@18 | |
_BYTE *v14; // eax@19 | |
int fpointer; // edi@24 | |
unsigned int cantidadCopiar; // ecx@24 | |
_BYTE *spointer; // eax@25 | |
_BYTE *tpointer; // edi@25 | |
char v19; // dl@31 | |
int v20; // edi@35 | |
char v21; // dl@37 | |
unsigned int v22; // edi@39 | |
_BYTE *pointer; // edi@43 | |
unsigned int contador; // ecx@43 | |
signed int result; // eax@50 | |
inputBuffer = inputStream; | |
*outputStream = 0; | |
lastByte = &inputStream[length]; | |
outputBuffer = outputStrm; | |
if ( *inputStream > 0x11u ) | |
{ | |
bytesDescomprimidos = *inputStream - 17; | |
inputBuffer = inputStream + 1; | |
if ( bytesDescomprimidos < 4 ) | |
goto LABEL_21; | |
do | |
{ | |
*outputBuffer++ = *inputBuffer++; | |
--bytesDescomprimidos; | |
} | |
while ( bytesDescomprimidos ); | |
goto LABEL_17; | |
} | |
LABEL_5: | |
firstByte = *inputBuffer; // Tomo el primer byte del par | |
secondByte = inputBuffer + 1; // Tomo el segundo byte del par | |
if ( firstByte < 0x10 ) // Si es menor que 16 | |
{ | |
if ( !firstByte ) // Si es 0 | |
{ | |
if ( !*secondByte ) | |
{ | |
do | |
{ | |
v10 = secondByte[1]; | |
firstByte += 255; | |
++secondByte; | |
} | |
while ( !v10 ); | |
} | |
firstByte += *secondByte++ + 15; // Sumo 15 al valor del segundo byte del par | |
} | |
*(_DWORD *)outputBuffer = *(_DWORD *)secondByte;// Copio una DWORD (4 bytes) | |
outputBuffer += 4; // Avanzo el buffer de salida 4 bytes | |
inputBuffer = secondByte + 4; // Avanzo el buffer de entrada 4 bytes | |
iteraciones = firstByte - 1; // Disminuyo en 1 la cantidad de bytes a copiar | |
if ( iteraciones ) // Proceso de copia | |
{ | |
if ( iteraciones < 4 ) | |
{ | |
do | |
{ | |
*outputBuffer++ = *inputBuffer++; | |
--iteraciones; | |
} | |
while ( iteraciones ); | |
} | |
else | |
{ | |
do | |
{ | |
*(_DWORD *)outputBuffer = *(_DWORD *)inputBuffer; | |
iteraciones -= 4; | |
outputBuffer += 4; | |
inputBuffer += 4; | |
} | |
while ( iteraciones >= 4 ); | |
for ( ; iteraciones; --iteraciones ) | |
*outputBuffer++ = *inputBuffer++; | |
} | |
} | |
LABEL_17: | |
firstByte = *inputBuffer; // Toma el primer byte del par | |
secondByte = inputBuffer + 1; // Toma el segundo byte del par | |
if ( firstByte < 0x10 ) // Si el primer byte es menor que 16 | |
{ | |
v12 = (int)(&outputBuffer[-(firstByte >> 2)] - 4 * *secondByte); | |
inputBuffer = secondByte + 1; | |
*outputBuffer++ = *(_BYTE *)(v12 - 2049); | |
v13 = v12 - 2049 + 1; | |
LABEL_19: | |
*outputBuffer = *(_BYTE *)v13; | |
v14 = outputBuffer + 1; | |
*v14 = *(_BYTE *)(v13 + 1); | |
outputBuffer = v14 + 1; | |
goto LABEL_20; | |
} | |
} | |
while ( 1 ) | |
{ | |
if ( firstByte >= 0x40 ) | |
{ | |
fpointer = (int)(&outputBuffer[-((firstByte >> 2) & 7) - 1] - 8 * *secondByte); | |
inputBuffer = secondByte + 1; | |
cantidadCopiar = (firstByte >> 5) - 1; | |
LABEL_25: | |
*outputBuffer = *(_BYTE *)fpointer; | |
spointer = outputBuffer + 1; | |
*spointer = *(_BYTE *)(fpointer + 1); | |
outputBuffer = spointer + 1; | |
tpointer = (_BYTE *)(fpointer + 2); | |
do | |
{ | |
*outputBuffer++ = *tpointer++; | |
--cantidadCopiar; | |
} | |
while ( cantidadCopiar ); | |
goto LABEL_20; | |
} | |
if ( firstByte < 0x20 ) // Si el primer byte es menor que 0x20 | |
break; | |
cantidadCopiar = firstByte & 0x1F; // Si el primer byte es menor que 0x40 y mayor o igual que 0x20 | |
if ( !cantidadCopiar ) // Si cantidadCopiar es 0 | |
{ | |
if ( !*secondByte ) // Si el segundo byte es cero | |
{ | |
do | |
{ | |
v19 = secondByte[1]; | |
cantidadCopiar += 255; | |
++secondByte; | |
} | |
while ( !v19 ); | |
} | |
cantidadCopiar += *secondByte++ + 31; // Segundo byte del par + 31 | |
} | |
fpointer = (int)&outputBuffer[-((unsigned int)*(_WORD *)secondByte >> 2) - 1];// Toma el puntero de la posicion a copiar | |
inputBuffer = secondByte + 2; // Avanza el input buffer salteando el par que se esta trabajando y una posicion mas | |
LABEL_41: | |
if ( cantidadCopiar < 6 || (signed int)&outputBuffer[-fpointer] < 4 ) | |
goto LABEL_25; | |
*(_DWORD *)outputBuffer = *(_DWORD *)fpointer;// Copia una DWORD | |
outputBuffer += 4; // Avanza 4 posiciones buffer de salida | |
pointer = (_BYTE *)(fpointer + 4); // Avanza el puntero 4 posiciones | |
contador = cantidadCopiar - 2; // Disminuye la cantidad por copiar en 2 | |
do | |
{ | |
*(_DWORD *)outputBuffer = *(_DWORD *)pointer; | |
contador -= 4; | |
outputBuffer += 4; | |
pointer += 4; | |
} | |
while ( contador >= 4 ); | |
for ( ; contador; --contador ) | |
*outputBuffer++ = *pointer++; | |
LABEL_20: | |
bytesDescomprimidos = *(inputBuffer - 2) & 3;// Verifica si quedan bytes por copiar | |
if ( !(*(inputBuffer - 2) & 3) ) | |
goto LABEL_5; | |
do | |
{ | |
LABEL_21: | |
*outputBuffer++ = *inputBuffer++; | |
--bytesDescomprimidos; | |
} | |
while ( bytesDescomprimidos ); | |
firstByte = *inputBuffer; | |
secondByte = inputBuffer + 1; | |
} | |
if ( firstByte < 0x10 ) | |
{ | |
v13 = (int)(&outputBuffer[-(firstByte >> 2) - 1] - 4 * *secondByte); | |
inputBuffer = secondByte + 1; | |
goto LABEL_19; | |
} | |
v20 = (int)&outputBuffer[-2048 * (firstByte & 8)]; | |
cantidadCopiar = firstByte & 7; | |
if ( !cantidadCopiar ) | |
{ | |
if ( !*secondByte ) | |
{ | |
do | |
{ | |
v21 = secondByte[1]; | |
cantidadCopiar += 255; | |
++secondByte; | |
} | |
while ( !v21 ); | |
} | |
cantidadCopiar += *secondByte++ + 7; | |
} | |
v22 = v20 - ((unsigned int)*(_WORD *)secondByte >> 2); | |
inputBuffer = secondByte + 2; | |
if ( (_BYTE *)v22 != outputBuffer ) | |
{ | |
fpointer = v22 - 0x4000; | |
goto LABEL_41; | |
} | |
*outputStream = outputBuffer - outputStrm; | |
if ( inputBuffer == lastByte ) | |
result = 0; | |
else | |
result = inputBuffer < lastByte ? -8 : -4; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment