Skip to content

Instantly share code, notes, and snippets.

@kabbi
Created November 24, 2022 15:44
Show Gist options
  • Save kabbi/1b67784cf123e7781f2b56ac5414757f to your computer and use it in GitHub Desktop.
Save kabbi/1b67784cf123e7781f2b56ac5414757f to your computer and use it in GitHub Desktop.
undefined4 WhatXX(byte *data,int v)
{
uint uVar1;
int iVar2;
uVar1 = 0x80;
for (iVar2 = 0; iVar2 < v % 8; iVar2 = iVar2 + 1) {
uVar1 = uVar1 >> 1;
}
if ((uVar1 & ~(uint)data[(int)(v + ((uint)(v >> 0x1f) >> 0x1d)) >> 3]) != 0) {
return 0;
}
return 1;
}
void WhatYY(byte *data,int v,int param_3)
{
byte bVar1;
uint uVar2;
int iVar3;
uVar2 = 0x80;
for (iVar3 = 0; iVar3 < v % 8; iVar3 = iVar3 + 1) {
uVar2 = uVar2 >> 1;
}
bVar1 = data[(int)(v + ((uint)(v >> 0x1f) >> 0x1d)) >> 3];
if (param_3 == 0) {
bVar1 = bVar1 & ~(byte)uVar2;
}
else {
bVar1 = bVar1 | (byte)uVar2;
}
data[(int)(v + ((uint)(v >> 0x1f) >> 0x1d)) >> 3] = bVar1;
return;
}
int MaybeUnpackSprite(int *src,int *dst)
{
int someCounter2;
undefined4 uVar1;
int iVar2;
int currentByte;
int someCounter1;
int resultLength;
int vvv;
undefined8 uVar3;
uint local_10a0;
byte local_109c [4];
uint local_1098;
byte buf2 [32];
byte buf1 [4096];
undefined4 auStack104 [14];
int *data;
int *piStack44;
*dst = 0;
currentByte = *src;
data = src;
piStack44 = dst;
ClearBuffer(buf1,0x1000);
ClearBuffer(buf2,0x20);
resultLength = 0;
someCounter1 = 0x20;
vvv = 0;
do {
if (currentByte < 1) {
*dst = vvv;
/* success */
return resultLength;
}
someCounter2 = WhatXX((byte *)data,someCounter1);
someCounter1 = someCounter1 + 1;
if (someCounter2 == 1) {
someCounter2 = 0;
local_1098 = 0;
do {
uVar1 = WhatXX((byte *)data,someCounter1);
WhatYY((byte *)&local_1098,someCounter2 + 0x14,uVar1);
someCounter1 = someCounter1 + 1;
someCounter2 = someCounter2 + 1;
} while (someCounter2 < 12);
someCounter2 = 0;
local_10a0 = 0;
do {
uVar1 = WhatXX((byte *)data,someCounter1);
WhatYY((byte *)&local_10a0,someCounter2 + 0x1b,uVar1);
someCounter1 = someCounter1 + 1;
someCounter2 = someCounter2 + 1;
} while (someCounter2 < 5);
local_109c[0] = 0;
someCounter2 = 0;
do {
uVar1 = WhatXX((byte *)data,someCounter1);
WhatYY(local_109c,someCounter2,uVar1);
someCounter1 = someCounter1 + 1;
someCounter2 = someCounter2 + 1;
} while (someCounter2 < 8);
someCounter2 = 0;
/* swap endian */
local_1098 = local_1098 << 24 | (local_1098 >> 8 & 0xff) << 16 |
(local_1098 >> 0x10 & 0xff) << 8 | local_1098 >> 24;
local_10a0 = local_10a0 << 24 | (local_10a0 >> 8 & 0xff) << 16 |
(local_10a0 >> 16 & 0xff) << 8 | local_10a0 >> 24;
if (resultLength < 1) {
iVar2 = malloc(local_10a0 + 1);
if (iVar2 == 0) {
return -1;
}
}
else {
uVar3 = AllocSomething(vvv,resultLength + local_10a0 + 1);
uVar1 = (undefined4)((ulonglong)uVar3 >> 0x20);
iVar2 = (int)uVar3;
if (iVar2 == 0) goto fail;
}
for (; someCounter2 < (int)local_10a0; someCounter2 = someCounter2 + 1) {
if (currentByte < 1) goto LAB_0003ff5c;
currentByte = currentByte + -1;
*(byte *)(iVar2 + resultLength) = buf1[local_1098 + someCounter2];
resultLength = resultLength + 1;
buf2[someCounter2] = buf1[local_1098 + someCounter2];
}
if (0 < currentByte) {
*(byte *)(iVar2 + resultLength) = local_109c[0];
resultLength = resultLength + 1;
buf2[someCounter2] = local_109c[0];
currentByte = currentByte + -1;
}
LAB_0003ff5c:
local_10a0 = local_10a0 + 1;
}
else {
local_109c[0] = 0;
someCounter2 = 0;
do {
uVar1 = WhatXX((byte *)data,someCounter1);
WhatYY(local_109c,someCounter2,uVar1);
someCounter1 = someCounter1 + 1;
someCounter2 = someCounter2 + 1;
} while (someCounter2 < 8);
if (resultLength < 1) {
iVar2 = malloc(1);
if (iVar2 == 0) {
return -1;
}
}
else {
uVar3 = AllocSomething(vvv,resultLength + 1);
uVar1 = (undefined4)((ulonglong)uVar3 >> 0x20);
iVar2 = (int)uVar3;
if (iVar2 == 0) {
fail:
/* fail */
SomeConvolutedCopy(vvv,uVar1);
return -1;
}
}
*(byte *)(iVar2 + resultLength) = local_109c[0];
resultLength = resultLength + 1;
if (0 < currentByte) {
buf2[0] = local_109c[0];
}
currentByte = currentByte + -1;
local_10a0 = 1;
}
memcpy((undefined4 *)buf1,(undefined4 *)((int)buf1 + local_10a0),0x1000 - local_10a0);
memcpy((undefined4 *)((0x1000 - local_10a0) + (int)buf1),(undefined4 *)buf2,local_10a0);
vvv = iVar2;
} while( true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment