This is squashed commit from the follwing commits:

* various changes to make it compile with clang

* don't compile recompiler on linux yet but make the CMake build include asmjit already

* add experimental travis bot

* modify yml to match

* try to build and install wxWidgets, since it's not in the travis repo

* use newer cmake version for travis

* add keys with sudo

* use sudo for all apt- commands

* Add additional dependencies

* use version approriate gcc flags for c++11

* try clang, gcc too old

* set c++0x flag for clang

* use gcc 4.8

* use gcc 4.8 and add the repo for it

* use gcc 4.8 even for clang to get newer headers

* fix ambiguous conversions

* add lz from hykem and more explicit conversions from be for x86

* more switch disambiguation

* more switch disambiguation

* add additional unigned int casts to deal with be_t conversion ambiguity

* remove unnecessary clang flag

* add lz.cpp to vcxproj and cast to u32 instead of unsigned int

* correct temporaray #ifdefs
This commit is contained in:
Bigpet 2014-04-25 18:57:00 +02:00 committed by Peter Tissen
parent a2157a5365
commit eea3aa9729
23 changed files with 459 additions and 680 deletions

View file

@ -139,609 +139,9 @@ bool cmac_hash_compare(unsigned char *key, int key_len, unsigned char *in, int i
return true;
}
#include "lz.h"
// Reverse-engineered custom LempelZivMarkov based compression (unknown variant of LZRC).
int lz_decompress(unsigned char *out, unsigned char *in, unsigned int size)
{
char *tmp = new char[3272];
char *p;
char *p2;
char *sub;
char *sub2;
char *sub3;
int offset;
int index;
int index2;
int unk;
int flag;
int flag2;
unsigned int c;
int cc;
int sp;
unsigned int sc;
int scc;
char st;
char t;
unsigned int n_size;
unsigned int r_size;
signed int f_size;
signed int b_size;
signed int diff;
signed int diff_pad;
bool adjust;
int pos;
int end;
int n_end;
signed int end_size;
int chunk_size;
char pad;
unsigned int remainder;
int result;
adjust = true;
offset = 0;
index = 0;
remainder = -1;
end = (int)((char *)out + size);
pos = (int)in;
pad = *in;
chunk_size = (*(in + 1) << 24) | (*(in + 2) << 16) | (*(in + 3) << 8) | *(in + 4);
if (*in >= 0) // Check if we have a valid starting byte.
{
memset(tmp, 128, 0xCA8u);
end_size = 0;
while (1)
{
while (1)
{
p = &tmp[offset];
c = (unsigned char)tmp[offset + 2920];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
cc = c - (c >> 3);
r_size = c * (remainder >> 8);
f_size = (unsigned int)chunk_size < r_size;
if ((unsigned int)chunk_size < r_size)
break;
remainder -= r_size;
chunk_size -= r_size;
p[2920] = cc;
offset = (offset - 1) & ((u64)~(offset - 1) >> 32);
if (out == (void *)end)
return -1;
sub = &tmp[255 * ((((((unsigned char)out & 7) << 8) | index & 0xFFFFF8FFu) >> pad) & 7)];
index = 1;
do
{
sp = (int)&sub[index];
sc = (unsigned char)sub[index - 1];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
index *= 2;
n_size = sc * (remainder >> 8);
scc = sc - (sc >> 3);
st = scc;
if ((unsigned int)chunk_size < n_size)
{
remainder = n_size;
++index;
st = scc + 31;
}
else
{
remainder -= n_size;
chunk_size -= n_size;
}
*(unsigned char *)(sp - 1) = st;
}
while (index <= 255);
out += 1;
++end_size;
*(out - 1) = index;
}
remainder = c * (remainder >> 8);
p[2920] = cc + 31;
index = -1;
while (1)
{
c = (unsigned char)p[2928];
if (!(r_size >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder = r_size << 8;
chunk_size = (chunk_size << 8) + add;
}
p += 8;
r_size = c * (remainder >> 8);
cc = c - (c >> 3);
if ((unsigned int)chunk_size >= r_size)
break;
remainder = r_size;
p[2920] = cc + 31;
++index;
if (index == 6)
{
adjust = false;
break;
}
}
if (adjust)
{
remainder -= r_size;
chunk_size -= r_size;
p[2920] = cc;
}
adjust = true;
p2 = &tmp[index];
if (index >= 0)
{
sub3 = &tmp[offset & 7 | 8 * (((unsigned int)out << index) & 3) | 32 * index];
flag = index - 3;
c = (unsigned char)sub3[2984];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
index2 = 2;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
index2 = 3;
t = cc + 31;
}
if (flag < 0)
{
sub3[2984] = t;
}
else
{
if (flag <= 0)
{
sub3[2984] = t;
}
else
{
c = (unsigned char)t;
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub3[2984] = t;
if (flag != 1)
{
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
do
{
remainder >>= 1;
index2 = ((unsigned int)chunk_size < remainder) + 2 * index2;
if ((unsigned int)chunk_size >= remainder)
chunk_size -= remainder;
--flag;
}
while (flag != 1);
}
}
c = (unsigned char)sub3[3008];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub3[3008] = t;
}
if (index > 0)
{
c = (unsigned char)sub3[2992];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub3[2992] = t;
if (index != 1)
{
c = (unsigned char)sub3[3000];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub3[3000] = t;
}
}
f_size = index2;
if (index2 == 255)
break;
}
index = 8;
b_size = 352;
if (f_size <= 2)
{
p2 += 248;
b_size = 64;
}
do
{
unk = (int)&p2[index];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
c = *(unsigned char *)(unk + 2033);
index *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size < n_size)
{
remainder = n_size;
t = cc + 31;
index += 8;
}
else
{
remainder -= n_size;
chunk_size -= n_size;
}
*(unsigned char *)(unk + 2033) = t;
diff = index - b_size;
}
while ((index - b_size) < 0);
if (index != b_size)
{
diff_pad = diff >> 3;
flag = diff_pad - 1;
flag2 = diff_pad - 4;
sub2 = &tmp[32 * (diff_pad - 1)];
c = (unsigned char)sub2[2344];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
index2 = 2;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
index2 = 3;
t = cc + 31;
}
if (flag2 < 0)
{
sub2[2344] = t;
}
else
{
if (flag2 <= 0)
{
sub2[2344] = t;
}
else
{
c = (unsigned char)t;
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub2[2344] = t;
if (flag2 != 1)
{
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
do
{
remainder >>= 1;
index2 = ((unsigned int)chunk_size < remainder) + 2 * index2;
if ((unsigned int)chunk_size >= remainder)
chunk_size -= remainder;
--flag2;
}
while (flag2 != 1);
}
}
c = (unsigned char)sub2[2368];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub2[2368] = t;
}
if (flag > 0)
{
c = (unsigned char)sub2[2352];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos++ + 5);
remainder <<= 8;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub2[2352] = t;
if (flag != 1)
{
c = (unsigned char)sub2[2360];
if (!(remainder >> 24))
{
int add = *(unsigned char *)(pos + 5);
remainder <<= 8;
++pos;
chunk_size = (chunk_size << 8) + add;
}
index2 *= 2;
n_size = c * (remainder >> 8);
cc = c - (c >> 3);
t = cc;
if ((unsigned int)chunk_size >= n_size)
{
remainder -= n_size;
chunk_size -= n_size;
}
else
{
remainder = n_size;
++index2;
t = cc + 31;
}
sub2[2360] = t;
}
}
diff = index2 - 1;
}
if (end_size <= diff)
return -1;
index = *(out - diff - 1);
n_end = (int)(out + f_size);
offset = (((unsigned char)f_size + (unsigned char)out) & 1) + 6;
if ((unsigned int)(out + f_size) >= (unsigned int)end)
return -1;
do
{
out += 1;
++end_size;
*(out - 1) = index;
index = *(out - diff - 1);
}
while (out != (void *)n_end);
out += 1;
++end_size;
*((unsigned char *)out - 1) = index;
}
result = end_size;
}
else // Starting byte is invalid.
{
result = -1;
if (chunk_size <= (int)size)
{
memcpy(out, (const void *)(in + 5), chunk_size);
result = chunk_size;
}
}
delete[] tmp;
return result;
return decompress(out,in,size);
}