imported winuaesrc2020b11b.zip

This commit is contained in:
Toni Wilen 2010-02-13 14:57:53 +02:00
parent dddda49513
commit dc4fd26a84
17 changed files with 87 additions and 89 deletions

View File

@ -75,6 +75,6 @@
#define DIR_SEPARATORS ":\\/"
extern UCHAR *text;
extern UCHAR *dms_text;
extern USHORT dms_lastlen, dms_np;

View File

@ -14,7 +14,7 @@
USHORT Calc_CheckSum(UCHAR *mem, ULONG size){
USHORT dms_Calc_CheckSum(UCHAR *mem, ULONG size){
USHORT u=0;
while(size--) u += *mem++;
@ -23,7 +23,7 @@ USHORT Calc_CheckSum(UCHAR *mem, ULONG size){
USHORT CreateCRC(UCHAR* mem, ULONG size ){
USHORT dms_CreateCRC(UCHAR* mem, ULONG size ){
static USHORT CRCTab[256]={
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,
0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440,

View File

@ -1,4 +1,4 @@
USHORT Calc_CheckSum(UCHAR *, ULONG);
USHORT CreateCRC(UCHAR *, ULONG);
USHORT dms_Calc_CheckSum(UCHAR *, ULONG);
USHORT dms_CreateCRC(UCHAR *, ULONG);

View File

@ -10,7 +10,7 @@
#include "getbits.h"
ULONG mask_bits[]={
ULONG dms_mask_bits[]={
0x000000L,0x000001L,0x000003L,0x000007L,0x00000fL,0x00001fL,
0x00003fL,0x00007fL,0x0000ffL,0x0001ffL,0x0003ffL,0x0007ffL,
0x000fffL,0x001fffL,0x003fffL,0x007fffL,0x00ffffL,0x01ffffL,
@ -19,15 +19,15 @@ ULONG mask_bits[]={
};
UCHAR *indata, bitcount;
ULONG bitbuf;
UCHAR *dms_indata, dms_bitcount;
ULONG dms_bitbuf;
void initbitbuf(UCHAR *in){
bitbuf = 0;
bitcount = 0;
indata = in;
dms_bitbuf = 0;
dms_bitcount = 0;
dms_indata = in;
DROPBITS(0);
}

View File

@ -1,9 +1,9 @@
extern ULONG mask_bits[], bitbuf;
extern UCHAR *indata, bitcount;
extern ULONG dms_mask_bits[], dms_bitbuf;
extern UCHAR *dms_indata, dms_bitcount;
#define GETBITS(n) ((USHORT)(bitbuf >> (bitcount-(n))))
#define DROPBITS(n) {bitbuf &= mask_bits[bitcount-=(n)]; while (bitcount<16) {bitbuf = (bitbuf << 8) | *indata++; bitcount += 8;}}
#define GETBITS(n) ((USHORT)(dms_bitbuf >> (dms_bitcount-(n))))
#define DROPBITS(n) {dms_bitbuf &= dms_mask_bits[dms_bitcount-=(n)]; while (dms_bitcount<16) {dms_bitbuf = (dms_bitbuf << 8) | *dms_indata++; dms_bitcount += 8;}}
void initbitbuf(UCHAR *);

View File

@ -23,7 +23,7 @@ static USHORT mktbl(void);
USHORT make_table(USHORT nchar, UCHAR bitlen[],USHORT tablebits, USHORT table[]){
USHORT dms_make_table(USHORT nchar, UCHAR bitlen[],USHORT tablebits, USHORT table[]){
n = avail = nchar;
blen = bitlen;
tbl = table;
@ -77,8 +77,8 @@ static USHORT mktbl(void){
TabErr = 3;
return 0;
}
left[i] = mktbl();
right[i] = mktbl();
dms_left[i] = mktbl();
dms_right[i] = mktbl();
if (codeword >= tblsiz) {
TabErr = 4;
return 0;

View File

@ -1,5 +1,5 @@
extern USHORT left[], right[];
extern USHORT dms_left[], dms_right[];
USHORT make_table(USHORT nchar, UCHAR bitlen[], USHORT tablebits, USHORT table[]);
USHORT dms_make_table(USHORT nchar, UCHAR bitlen[], USHORT tablebits, USHORT table[]);

View File

@ -47,7 +47,7 @@ static int passfound, passretries;
static TCHAR modes[7][7]={L"NOCOMP",L"SIMPLE",L"QUICK ",L"MEDIUM",L"DEEP ",L"HEAVY1",L"HEAVY2"};
static USHORT PWDCRC;
static UCHAR *text;
UCHAR *dms_text;
static void log_error(int track)
{
@ -91,8 +91,8 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
free(b1);
return ERR_NOMEMORY;
}
text = xcalloc(UCHAR,TEMP_BUFFER_LEN);
if (!text) {
dms_text = xcalloc(UCHAR,TEMP_BUFFER_LEN);
if (!dms_text) {
free(b1);
free(b2);
return ERR_NOMEMORY;
@ -103,7 +103,7 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
if (zfile_fread(b1,1,HEADLEN,fi) != HEADLEN) {
free(b1);
free(b2);
free(text);
free(dms_text);
return ERR_SREAD;
}
@ -111,17 +111,17 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
/* Check the first 4 bytes of file to see if it is "DMS!" */
free(b1);
free(b2);
free(text);
free(dms_text);
return ERR_NOTDMS;
}
hcrc = (USHORT)((b1[HEADLEN-2]<<8) | b1[HEADLEN-1]);
/* Header CRC */
if (hcrc != CreateCRC(b1+4,(ULONG)(HEADLEN-6))) {
if (hcrc != dms_CreateCRC(b1+4,(ULONG)(HEADLEN-6))) {
free(b1);
free(b2);
free(text);
free(dms_text);
return ERR_HCRC;
}
@ -133,7 +133,7 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
if (part && from < 30) {
free(b1);
free(b2);
free(text);
free(dms_text);
return DMS_FILE_END;
}
@ -221,7 +221,7 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
/* It's not a DMS compressed disk image, but a FMS archive */
free(b1);
free(b2);
free(text);
free(dms_text);
return ERR_FMS;
}
@ -290,7 +290,7 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
free(b1);
free(b2);
free(text);
free(dms_text);
return ret;
}
@ -316,7 +316,7 @@ static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR
/* Track Header CRC */
hcrc = (USHORT)((b1[THLEN-2] << 8) | b1[THLEN-1]);
if (CreateCRC(b1,(ULONG)(THLEN-2)) != hcrc) return ERR_THCRC;
if (dms_CreateCRC(b1,(ULONG)(THLEN-2)) != hcrc) return ERR_THCRC;
number = (USHORT)((b1[2] << 8) | b1[3]); /* Number of track */
pklen1 = (USHORT)((b1[6] << 8) | b1[7]); /* Length of packed track data as in archive */
@ -347,7 +347,7 @@ static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR
if (zfile_fread(b1,1,(size_t)pklen1,fi) != pklen1) return ERR_SREAD;
if (CreateCRC(b1,(ULONG)pklen1) != dcrc) {
if (dms_CreateCRC(b1,(ULONG)pklen1) != dcrc) {
log_error (number);
crcerr = 1;
}
@ -480,7 +480,7 @@ static USHORT Unpack_Track(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen,
dms_decrypt(b1, pklen1, b1);
r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
if (r == NO_PROBLEM) {
if (usum1 == Calc_CheckSum(b2,(ULONG)unpklen))
if (usum1 == dms_Calc_CheckSum(b2,(ULONG)unpklen))
return NO_PROBLEM;
}
log_error(number);
@ -497,7 +497,7 @@ static USHORT Unpack_Track(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen,
for (;;) {
r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
if (r == NO_PROBLEM) {
if (usum1 == Calc_CheckSum(b2,(ULONG)unpklen)) {
if (usum1 == dms_Calc_CheckSum(b2,(ULONG)unpklen)) {
passfound = maybeencrypted;
if (passfound)
write_log (L"DMS: decryption key = 0x%04X\n", prevpass);

View File

@ -23,8 +23,8 @@ INLINE void update(USHORT c);
static void reconst(void);
USHORT deep_text_loc;
int init_deep_tabs=1;
USHORT dms_deep_text_loc;
int dms_init_deep_tabs=1;
@ -66,7 +66,7 @@ void Init_DEEP_Tabs(void){
freq[T] = 0xffff;
prnt[R] = 0;
init_deep_tabs = 0;
dms_init_deep_tabs = 0;
}
@ -77,21 +77,21 @@ USHORT Unpack_DEEP(UCHAR *in, UCHAR *out, USHORT origsize){
initbitbuf(in);
if (init_deep_tabs) Init_DEEP_Tabs();
if (dms_init_deep_tabs) Init_DEEP_Tabs();
outend = out+origsize;
while (out < outend) {
c = DecodeChar();
if (c < 256) {
*out++ = text[deep_text_loc++ & DBITMASK] = (UCHAR)c;
*out++ = dms_text[dms_deep_text_loc++ & DBITMASK] = (UCHAR)c;
} else {
j = (USHORT) (c - 255 + THRESHOLD);
i = (USHORT) (deep_text_loc - DecodePosition() - 1);
while (j--) *out++ = text[deep_text_loc++ & DBITMASK] = text[i++ & DBITMASK];
i = (USHORT) (dms_deep_text_loc - DecodePosition() - 1);
while (j--) *out++ = dms_text[dms_deep_text_loc++ & DBITMASK] = dms_text[i++ & DBITMASK];
}
}
deep_text_loc = (USHORT)((deep_text_loc+60) & DBITMASK);
dms_deep_text_loc = (USHORT)((dms_deep_text_loc+60) & DBITMASK);
return 0;
}

View File

@ -2,6 +2,6 @@
USHORT Unpack_DEEP(UCHAR *, UCHAR *, USHORT);
extern int init_deep_tabs;
extern USHORT deep_text_loc;
extern int dms_init_deep_tabs;
extern USHORT dms_deep_text_loc;

View File

@ -21,11 +21,11 @@
#define N1 510
#define OFFSET 253
static USHORT left[2 * NC - 1], right[2 * NC - 1 + 9];
USHORT dms_left[2 * NC - 1], dms_right[2 * NC - 1 + 9];
static UCHAR c_len[NC], pt_len[NPT];
static USHORT c_table[4096], pt_table[256];
USHORT lastlen, np;
USHORT heavy_text_loc;
USHORT dms_lastlen, dms_np;
USHORT dms_heavy_text_loc;
static USHORT read_tree_c(void);
@ -42,10 +42,10 @@ USHORT Unpack_HEAVY(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){
/* Heavy 1 uses a 4Kb dictionary, Heavy 2 uses 8Kb */
if (flags & 8) {
np = 15;
dms_np = 15;
bitmask = 0x1fff;
} else {
np = 14;
dms_np = 14;
bitmask = 0x0fff;
}
@ -61,11 +61,11 @@ USHORT Unpack_HEAVY(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){
while (out<outend) {
c = decode_c();
if (c < 256) {
*out++ = text[heavy_text_loc++ & bitmask] = (UCHAR)c;
*out++ = dms_text[dms_heavy_text_loc++ & bitmask] = (UCHAR)c;
} else {
j = (USHORT) (c - OFFSET);
i = (USHORT) (heavy_text_loc - decode_p() - 1);
while(j--) *out++ = text[heavy_text_loc++ & bitmask] = text[i++ & bitmask];
i = (USHORT) (dms_heavy_text_loc - decode_p() - 1);
while(j--) *out++ = dms_text[dms_heavy_text_loc++ & bitmask] = dms_text[i++ & bitmask];
}
}
@ -85,8 +85,8 @@ INLINE USHORT decode_c(void){
i = GETBITS(16);
m = 0x8000;
do {
if (i & m) j = right[j];
else j = left [j];
if (i & m) j = dms_right[j];
else j = dms_left [j];
m >>= 1;
} while (j >= N1);
DROPBITS(c_len[j] - 12);
@ -100,29 +100,29 @@ INLINE USHORT decode_p(void){
USHORT i, j, m;
j = pt_table[GETBITS(8)];
if (j < np) {
if (j < dms_np) {
DROPBITS(pt_len[j]);
} else {
DROPBITS(8);
i = GETBITS(16);
m = 0x8000;
do {
if (i & m) j = right[j];
else j = left [j];
if (i & m) j = dms_right[j];
else j = dms_left [j];
m >>= 1;
} while (j >= np);
} while (j >= dms_np);
DROPBITS(pt_len[j] - 8);
}
if (j != np-1) {
if (j != dms_np-1) {
if (j > 0) {
j = (USHORT)(GETBITS(i=(USHORT)(j-1)) | (1U << (j-1)));
DROPBITS(i);
}
lastlen=j;
dms_lastlen=j;
}
return lastlen;
return dms_lastlen;
}
@ -139,7 +139,7 @@ static USHORT read_tree_c(void){
DROPBITS(5);
}
for (i=n; i<510; i++) c_len[i] = 0;
if (make_table(510,c_len,12,c_table)) return 1;
if (dms_make_table(510,c_len,12,c_table)) return 1;
} else {
n = GETBITS(9);
DROPBITS(9);
@ -161,12 +161,12 @@ static USHORT read_tree_p(void){
pt_len[i] = (UCHAR)GETBITS(4);
DROPBITS(4);
}
for (i=n; i<np; i++) pt_len[i] = 0;
if (make_table(np,pt_len,8,pt_table)) return 1;
for (i=n; i<dms_np; i++) pt_len[i] = 0;
if (dms_make_table(dms_np,pt_len,8,pt_table)) return 1;
} else {
n = GETBITS(5);
DROPBITS(5);
for (i=0; i<np; i++) pt_len[i] = 0;
for (i=0; i<dms_np; i++) pt_len[i] = 0;
for (i=0; i<256; i++) pt_table[i] = n;
}
return 0;

View File

@ -2,5 +2,5 @@
USHORT Unpack_HEAVY(UCHAR *, UCHAR *, UCHAR, USHORT);
extern USHORT heavy_text_loc;
extern USHORT dms_heavy_text_loc;

View File

@ -16,16 +16,14 @@
#include "u_deep.h"
#include "u_heavy.h"
extern USHORT lastlen, np;
void Init_Decrunchers(void){
quick_text_loc = 251;
medium_text_loc = 0x3fbe;
heavy_text_loc = 0;
deep_text_loc = 0x3fc4;
init_deep_tabs = 1;
memset(text,0,0x3fc8);
lastlen = 0;
np = 0;
dms_quick_text_loc = 251;
dms_medium_text_loc = 0x3fbe;
dms_heavy_text_loc = 0;
dms_deep_text_loc = 0x3fc4;
dms_init_deep_tabs = 1;
memset(dms_text,0,0x3fc8);
dms_lastlen = 0;
dms_np = 0;
}

View File

@ -19,7 +19,7 @@
#define MBITMASK 0x3fff
USHORT medium_text_loc;
USHORT dms_medium_text_loc;
@ -34,7 +34,7 @@ USHORT Unpack_MEDIUM(UCHAR *in, UCHAR *out, USHORT origsize){
while (out < outend) {
if (GETBITS(1)!=0) {
DROPBITS(1);
*out++ = text[medium_text_loc++ & MBITMASK] = (UCHAR)GETBITS(8);
*out++ = dms_text[dms_medium_text_loc++ & MBITMASK] = (UCHAR)GETBITS(8);
DROPBITS(8);
} else {
DROPBITS(1);
@ -44,13 +44,13 @@ USHORT Unpack_MEDIUM(UCHAR *in, UCHAR *out, USHORT origsize){
c = (USHORT) (((c << u) | GETBITS(u)) & 0xff); DROPBITS(u);
u = d_len[c];
c = (USHORT) ((d_code[c] << 8) | (((c << u) | GETBITS(u)) & 0xff)); DROPBITS(u);
i = (USHORT) (medium_text_loc - c - 1);
i = (USHORT) (dms_medium_text_loc - c - 1);
while(j--) *out++ = text[medium_text_loc++ & MBITMASK] = text[i++ & MBITMASK];
while(j--) *out++ = dms_text[dms_medium_text_loc++ & MBITMASK] = dms_text[i++ & MBITMASK];
}
}
medium_text_loc = (USHORT)((medium_text_loc+66) & MBITMASK);
dms_medium_text_loc = (USHORT)((dms_medium_text_loc+66) & MBITMASK);
return 0;
}

View File

@ -1,5 +1,5 @@
USHORT Unpack_MEDIUM(UCHAR *, UCHAR *, USHORT);
extern USHORT medium_text_loc;
extern USHORT dms_medium_text_loc;

View File

@ -17,7 +17,7 @@
#define QBITMASK 0xff
USHORT quick_text_loc;
USHORT dms_quick_text_loc;
USHORT Unpack_QUICK(UCHAR *in, UCHAR *out, USHORT origsize){
@ -30,17 +30,17 @@ USHORT Unpack_QUICK(UCHAR *in, UCHAR *out, USHORT origsize){
while (out < outend) {
if (GETBITS(1)!=0) {
DROPBITS(1);
*out++ = text[quick_text_loc++ & QBITMASK] = (UCHAR)GETBITS(8); DROPBITS(8);
*out++ = dms_text[dms_quick_text_loc++ & QBITMASK] = (UCHAR)GETBITS(8); DROPBITS(8);
} else {
DROPBITS(1);
j = (USHORT) (GETBITS(2)+2); DROPBITS(2);
i = (USHORT) (quick_text_loc - GETBITS(8) - 1); DROPBITS(8);
i = (USHORT) (dms_quick_text_loc - GETBITS(8) - 1); DROPBITS(8);
while(j--) {
*out++ = text[quick_text_loc++ & QBITMASK] = text[i++ & QBITMASK];
*out++ = dms_text[dms_quick_text_loc++ & QBITMASK] = dms_text[i++ & QBITMASK];
}
}
}
quick_text_loc = (USHORT)((quick_text_loc+5) & QBITMASK);
dms_quick_text_loc = (USHORT)((dms_quick_text_loc+5) & QBITMASK);
return 0;
}

View File

@ -1,5 +1,5 @@
USHORT Unpack_QUICK(UCHAR *, UCHAR *, USHORT);
extern USHORT quick_text_loc;
extern USHORT dms_quick_text_loc;