-static USHORT Unpack_Track_2(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen, UCHAR cmode, UCHAR flags){
+static USHORT Unpack_Track_2(UCHAR *b1, UCHAR *b2, USHORT pklen1, USHORT pklen2, USHORT unpklen, UCHAR cmode, UCHAR flags){
switch (cmode){
case 0:
/* No Compression */
break;
case 1:
/* Simple Compression */
- if (Unpack_RLE(b1,b2,unpklen)) return ERR_BADDECR;
+ if (Unpack_RLE(b1,b2, pklen1,unpklen)) return ERR_BADDECR;
break;
case 2:
/* Quick Compression */
- if (Unpack_QUICK(b1,b2,pklen2)) return ERR_BADDECR;
- if (Unpack_RLE(b2,b1,unpklen)) return ERR_BADDECR;
+ if (Unpack_QUICK(b1,b2,pklen1,pklen2)) return ERR_BADDECR;
+ if (Unpack_RLE(b2,b1,pklen2,unpklen)) return ERR_BADDECR;
memcpy(b2,b1,(size_t)unpklen);
break;
case 3:
/* Medium Compression */
- if (Unpack_MEDIUM(b1,b2,pklen2)) return ERR_BADDECR;
- if (Unpack_RLE(b2,b1,unpklen)) return ERR_BADDECR;
+ if (Unpack_MEDIUM(b1,b2,pklen1,pklen2)) return ERR_BADDECR;
+ if (Unpack_RLE(b2,b1,pklen2,unpklen)) return ERR_BADDECR;
memcpy(b2,b1,(size_t)unpklen);
break;
case 4:
/* Deep Compression */
- if (Unpack_DEEP(b1,b2,pklen2)) return ERR_BADDECR;
- if (Unpack_RLE(b2,b1,unpklen)) return ERR_BADDECR;
+ if (Unpack_DEEP(b1,b2,pklen1,pklen2)) return ERR_BADDECR;
+ if (Unpack_RLE(b2,b1,pklen2,unpklen)) return ERR_BADDECR;
memcpy(b2,b1,(size_t)unpklen);
break;
case 5:
/* Heavy Compression */
if (cmode==5) {
/* Heavy 1 */
- if (Unpack_HEAVY(b1,b2,flags & 7,pklen2)) return ERR_BADDECR;
+ if (Unpack_HEAVY(b1,b2,flags & 7,pklen1,pklen2)) return ERR_BADDECR;
} else {
/* Heavy 2 */
- if (Unpack_HEAVY(b1,b2,flags | 8,pklen2)) return ERR_BADDECR;
+ if (Unpack_HEAVY(b1,b2,flags | 8,pklen1,pklen2)) return ERR_BADDECR;
}
if (flags & 4) {
memset(b1,0,unpklen);
/* Unpack with RLE only if this flag is set */
- if (Unpack_RLE(b2,b1,unpklen)) return ERR_BADDECR;
+ if (Unpack_RLE(b2,b1,pklen2,unpklen)) return ERR_BADDECR;
memcpy(b2,b1,(size_t)unpklen);
}
break;
static USHORT pass;
int maybeencrypted;
int pwrounds;
- UCHAR *tmp;
- USHORT prevpass = 0;
+ int firstpass = -1;
+ UCHAR *tmp, *tmp_dms_text;
+ USHORT prevpass = pass;
if (passfound) {
if (number != 80)
dms_decrypt(b1, pklen1, b1);
- r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
+ r = Unpack_Track_2(b1, b2, pklen1, pklen2, unpklen, cmode, flags);
if (r == NO_PROBLEM) {
if (usum1 == dms_Calc_CheckSum(b2,(ULONG)unpklen))
return NO_PROBLEM;
passretries--;
pwrounds = 0;
maybeencrypted = 0;
- tmp = (unsigned char*)malloc (pklen1);
+ tmp = xmalloc(UCHAR, pklen1);
+ tmp_dms_text = xmalloc(UCHAR, 0x3fc8);
memcpy (tmp, b1, pklen1);
memset(b2, 0, unpklen);
+ memcpy(tmp_dms_text, dms_text, 0x3fc8);
for (;;) {
- r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
+ r = Unpack_Track_2(b1, b2, pklen1, pklen2, unpklen, cmode, flags);
if (r == NO_PROBLEM) {
if (usum1 == dms_Calc_CheckSum(b2,(ULONG)unpklen)) {
passfound = maybeencrypted;
if (passfound)
write_log (_T("DMS: decryption key = 0x%04X\n"), prevpass);
- err = NO_PROBLEM;
- pass = prevpass;
- break;
+ // if bootblock does not have "DOS", check other keys too
+ if (number > 0 || firstpass == pass || (b2[0] == 'D' && b2[1] == 'O' && b2[2] == 'S')) {
+ err = NO_PROBLEM;
+ pass = prevpass;
+ break;
+ }
+ if (firstpass < 0) {
+ firstpass = pass;
+ }
}
}
if (number == 80 || !enc) {
pass++;
dms_decrypt(b1, pklen1, tmp);
pwrounds++;
- if (pwrounds == 65536) {
- err = ERR_CSUM;
- passfound = 0;
- break;
+ if (pwrounds >= 65536) {
+ if (firstpass < 0) {
+ err = ERR_CSUM;
+ passfound = 0;
+ break;
+ }
+ pass = firstpass;
+ PWDCRC = pass;
+ dms_decrypt(b1, pklen1, tmp);
}
+ memcpy(dms_text, tmp_dms_text, 0x3fc8);
}
- free (tmp);
+ xfree(tmp_dms_text);
+ xfree(tmp);
return err;
}
#include "u_deep.h"
#include "getbits.h"
-
-INLINE USHORT DecodeChar(void);
-INLINE USHORT DecodePosition(void);
-INLINE void update(USHORT c);
+static USHORT DecodeChar(void);
+static USHORT DecodePosition(void);
+static void update(USHORT c);
static void reconst(void);
-
USHORT dms_deep_text_loc;
int dms_init_deep_tabs=1;
-
-
#define DBITMASK 0x3fff /* uses 16Kb dictionary */
#define F 60 /* lookahead buffer size */
#define R (T - 1) /* position of root */
#define MAX_FREQ 0x8000 /* updates tree when the */
-
static USHORT freq[T + 1]; /* frequency table */
static USHORT prnt[T + N_CHAR]; /* pointers to parent nodes, except for the */
static USHORT son[T]; /* pointers to child nodes (son[], son[] + 1) */
-
-
static void Init_DEEP_Tabs(void){
USHORT i, j;
dms_init_deep_tabs = 0;
}
-
-
-USHORT Unpack_DEEP(UCHAR *in, UCHAR *out, USHORT origsize){
+USHORT Unpack_DEEP(UCHAR *in, UCHAR *out, USHORT pklen1, USHORT origsize){
USHORT i, j, c;
UCHAR *outend;
dms_deep_text_loc = (USHORT)((dms_deep_text_loc+60) & DBITMASK);
- return 0;
-}
-
+ in += pklen1;
+ if (dms_indata == in + 2 || dms_indata == in + 1 || dms_indata == in + 0) return 0;
+ return 1;
+}
-INLINE USHORT DecodeChar(void){
+static USHORT DecodeChar(void){
USHORT c;
c = son[R];
return c;
}
-
-
-INLINE USHORT DecodePosition(void){
+static USHORT DecodePosition(void){
USHORT i, j, c;
i = GETBITS(8); DROPBITS(8);
return (USHORT) (c | i) ;
}
-
-
/* reconstruction of tree */
static void reconst(void){
}
}
-
-
/* increment frequency of given code by one, and update tree */
-INLINE void update(USHORT c){
+static void update(USHORT c){
USHORT i, j, k, l;
if (freq[R] == MAX_FREQ) {
}
} while ((c = prnt[c]) != 0); /* repeat up to root */
}
-
-
*
*/
-
#include "cdata.h"
#include "u_heavy.h"
#include "getbits.h"
#include "maketbl.h"
-
#define NC 510
#define NPT 20
#define N1 510
USHORT dms_lastlen, dms_np;
USHORT dms_heavy_text_loc;
-
static USHORT read_tree_c(void);
static USHORT read_tree_p(void);
-INLINE USHORT decode_c(void);
-INLINE USHORT decode_p(void);
-
+static USHORT decode_c(void);
+static USHORT decode_p(void);
-
-USHORT Unpack_HEAVY(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){
+USHORT Unpack_HEAVY(UCHAR *in, UCHAR *out, UCHAR flags, USHORT pklen1, USHORT origsize){
USHORT j, i, c, bitmask;
UCHAR *outend;
}
}
- return 0;
-}
-
+ in += pklen1;
+ if (dms_indata == in + 2 || dms_indata == in + 1 || dms_indata == in + 0) return 0;
+ return 1;
+}
-INLINE USHORT decode_c(void){
+static USHORT decode_c(void){
USHORT i, j, m;
j = c_table[GETBITS(12)];
return j;
}
-
-
-INLINE USHORT decode_p(void){
+static USHORT decode_p(void){
USHORT i, j, m;
j = pt_table[GETBITS(8)];
}
-
-
static USHORT read_tree_c(void){
USHORT i,n;
return 0;
}
-
-
static USHORT read_tree_p(void){
USHORT i,n;