|
#2
|
|||
|
|||
|
The decompression for the program is as follows:
int srcPos; /* start at the end of the packed exe, because the unpacker works downwards */ int dstPos; int commandByte, lengthWord, fillByte; /* skip all 0xff bytes (they're just padding to make the packed exe's size a multiple of 16 */ while (*srcPos == 0xff) { srcPos--; } /* unpack */ do { commandByte = *(srcPos--); switch (commandByte & 0xFE) { /* (byte)value (word)length (byte)0xb0 */ /* writes a run of <length> bytes with a value of <value> */ case 0xb0: lengthWord = (*(srcPos--))*0x100; lengthWord += *(srcPos--); fillByte = *(srcPos--); for (i = 0; i < lengthWord; i++) { *(dstPos--) = fillByte; } break; /* (word)length (byte)0xb2 */ /* copies the next <length> bytes */ case 0xb2: lengthWord = (*(srcPos--))*0x100; lengthWord += *(srcPos--); for (i = 0; i < lengthWord; i++) { *(dstPos--) = *(srcPos--); } break; /* unknown command */ default: printf("Unknown command %x at position %x\n", commandByte, srcPos); exit(1); break; } } while ((commandByte & 1) != 1); /* lowest bit set => last block */ |
| The Following User Says Thank You to For This Useful Post: | ||
Jiva newstone (22-12-2018) | ||
|
|