[C++ Release] NOS Unpacker + Decrypter

09/30/2013 21:06 ernilos#16
Quote:
Originally Posted by Vilius242lt View Post
The program crashes when you open a .nos file with it
Only works for text files
11/27/2013 18:27 malek00810#17
I've a problem.
When I run the extractor I got this error :
The NTVDM CPU has encountered an illegal instruction.
Choose 'Close' to terminate the application
04/12/2014 17:10 gaetano1291#18
I use vs2013 but should not be what the problem is
08/30/2014 04:17 Kingrap#19
Clear code

Code:
unsigned int Decrypt(unsigned char *encBuffer, unsigned int encBufferLen, unsigned char *decBuffer)
{
	unsigned int decBufferLen;

	unsigned char table[] = { NULL, ' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0x0D };

	unsigned int offset = 0, i = 0;
	unsigned char encStrLen = 0, c = 0;

	while (offset < encBufferLen)
	{
		if (encBuffer[offset] == 0xFFU) // if byte is 0xFF then add 0x0D to new buffer and continue
		{
			*(decBuffer + decBufferLen++) = 0x0D;
			offset++;
			continue;
		}

		encStrLen = encBuffer[offset++]; // get string length

		i = 0;
		if ((encStrLen & 0x80U) == 0) // if result is 0 then decrypt the string by Xor 33
		{
			while ((i++ < encStrLen) && (offset < encBufferLen))
			{
				*(decBuffer + decBufferLen++) = (encBuffer[offset++] ^ 0x33U);
			}
		}
		else // otherwise
		{
			encStrLen &= 0x7FU;
			while ((i < encStrLen) && (offset < encBufferLen))
			{
				c = encBuffer[offset++]; // c = current byte, increment the index
				*(decBuffer + decBufferLen++) = (table[(c & 0xF0U) >> 4]);

				if (table[c & 0x0FU] != NULL)
				{
					*(decBuffer + decBufferLen++) = table[c & 0x0FU];
				}

				i += 2;
			}
		}
	}

	return decBufferLen;
}