daa2iso-0.1.7e/0000755000175000017500000000000011317173742011314 5ustar jamjamdaa2iso-0.1.7e/src/0000755000175000017500000000000010770013510012067 5ustar jamjamdaa2iso-0.1.7e/src/LzmaDec.c0000644000175000017500000006542111254275040013570 0ustar jamjam/* LzmaDec.c -- LZMA Decoder 2008-11-06 : Igor Pavlov : Public domain */ #include "LzmaDec.h" #include #define kNumTopBits 24 #define kTopValue ((UInt32)1 << kNumTopBits) #define kNumBitModelTotalBits 11 #define kBitModelTotal (1 << kNumBitModelTotalBits) #define kNumMoveBits 5 #define RC_INIT_SIZE 5 #define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } #define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) #define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); #define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); #define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \ { UPDATE_0(p); i = (i + i); A0; } else \ { UPDATE_1(p); i = (i + i) + 1; A1; } #define GET_BIT(p, i) GET_BIT2(p, i, ; , ;) #define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); } #define TREE_DECODE(probs, limit, i) \ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; } /* #define _LZMA_SIZE_OPT */ #ifdef _LZMA_SIZE_OPT #define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i) #else #define TREE_6_DECODE(probs, i) \ { i = 1; \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ TREE_GET_BIT(probs, i); \ i -= 0x40; } #endif #define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); } #define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) #define UPDATE_0_CHECK range = bound; #define UPDATE_1_CHECK range -= bound; code -= bound; #define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ { UPDATE_0_CHECK; i = (i + i); A0; } else \ { UPDATE_1_CHECK; i = (i + i) + 1; A1; } #define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;) #define TREE_DECODE_CHECK(probs, limit, i) \ { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; } #define kNumPosBitsMax 4 #define kNumPosStatesMax (1 << kNumPosBitsMax) #define kLenNumLowBits 3 #define kLenNumLowSymbols (1 << kLenNumLowBits) #define kLenNumMidBits 3 #define kLenNumMidSymbols (1 << kLenNumMidBits) #define kLenNumHighBits 8 #define kLenNumHighSymbols (1 << kLenNumHighBits) #define LenChoice 0 #define LenChoice2 (LenChoice + 1) #define LenLow (LenChoice2 + 1) #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) #define kNumLenProbs (LenHigh + kLenNumHighSymbols) #define kNumStates 12 #define kNumLitStates 7 #define kStartPosModelIndex 4 #define kEndPosModelIndex 14 #define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) #define kNumPosSlotBits 6 #define kNumLenToPosStates 4 #define kNumAlignBits 4 #define kAlignTableSize (1 << kNumAlignBits) #define kMatchMinLen 2 #define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols) #define IsMatch 0 #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) #define IsRepG0 (IsRep + kNumStates) #define IsRepG1 (IsRepG0 + kNumStates) #define IsRepG2 (IsRepG1 + kNumStates) #define IsRep0Long (IsRepG2 + kNumStates) #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) #define LenCoder (Align + kAlignTableSize) #define RepLenCoder (LenCoder + kNumLenProbs) #define Literal (RepLenCoder + kNumLenProbs) #define LZMA_BASE_SIZE 1846 #define LZMA_LIT_SIZE 768 #define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp))) #if Literal != LZMA_BASE_SIZE StopCompilingDueBUG #endif static const Byte kLiteralNextStates[kNumStates * 2] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10 }; #define LZMA_DIC_MIN (1 << 12) /* First LZMA-symbol is always decoded. And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization Out: Result: SZ_OK - OK SZ_ERROR_DATA - Error p->remainLen: < kMatchSpecLenStart : normal remain = kMatchSpecLenStart : finished = kMatchSpecLenStart + 1 : Flush marker = kMatchSpecLenStart + 2 : State Init Marker */ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit) { CLzmaProb *probs = p->probs; unsigned state = p->state; UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1; unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; unsigned lc = p->prop.lc; Byte *dic = p->dic; SizeT dicBufSize = p->dicBufSize; SizeT dicPos = p->dicPos; UInt32 processedPos = p->processedPos; UInt32 checkDicSize = p->checkDicSize; unsigned len = 0; const Byte *buf = p->buf; UInt32 range = p->range; UInt32 code = p->code; do { CLzmaProb *prob; UInt32 bound; unsigned ttt; unsigned posState = processedPos & pbMask; prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; IF_BIT_0(prob) { unsigned symbol; UPDATE_0(prob); prob = probs + Literal; if (checkDicSize != 0 || processedPos != 0) prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc)))); if (state < kNumLitStates) { symbol = 1; do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100); } else { unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; unsigned offs = 0x100; symbol = 1; do { unsigned bit; CLzmaProb *probLit; matchByte <<= 1; bit = (matchByte & offs); probLit = prob + offs + bit + symbol; GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit) } while (symbol < 0x100); } dic[dicPos++] = (Byte)symbol; processedPos++; state = kLiteralNextStates[state]; /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */ continue; } else { UPDATE_1(prob); prob = probs + IsRep + state; IF_BIT_0(prob) { UPDATE_0(prob); state += kNumStates; prob = probs + LenCoder; } else { UPDATE_1(prob); if (checkDicSize == 0 && processedPos == 0) return SZ_ERROR_DATA; prob = probs + IsRepG0 + state; IF_BIT_0(prob) { UPDATE_0(prob); prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; IF_BIT_0(prob) { UPDATE_0(prob); dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; dicPos++; processedPos++; state = state < kNumLitStates ? 9 : 11; continue; } UPDATE_1(prob); } else { UInt32 distance; UPDATE_1(prob); prob = probs + IsRepG1 + state; IF_BIT_0(prob) { UPDATE_0(prob); distance = rep1; } else { UPDATE_1(prob); prob = probs + IsRepG2 + state; IF_BIT_0(prob) { UPDATE_0(prob); distance = rep2; } else { UPDATE_1(prob); distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } state = state < kNumLitStates ? 8 : 11; prob = probs + RepLenCoder; } { unsigned limit, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; limit = (1 << kLenNumLowBits); } else { UPDATE_1(probLen); probLen = prob + LenChoice2; IF_BIT_0(probLen) { UPDATE_0(probLen); probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; limit = (1 << kLenNumMidBits); } else { UPDATE_1(probLen); probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; limit = (1 << kLenNumHighBits); } } TREE_DECODE(probLen, limit, len); len += offset; } if (state >= kNumStates) { UInt32 distance; prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); TREE_6_DECODE(prob, distance); if (distance >= kStartPosModelIndex) { unsigned posSlot = (unsigned)distance; int numDirectBits = (int)(((distance >> 1) - 1)); distance = (2 | (distance & 1)); if (posSlot < kEndPosModelIndex) { distance <<= numDirectBits; prob = probs + SpecPos + distance - posSlot - 1; { UInt32 mask = 1; unsigned i = 1; do { GET_BIT2(prob + i, i, ; , distance |= mask); mask <<= 1; } while (--numDirectBits != 0); } } else { numDirectBits -= kNumAlignBits; do { NORMALIZE range >>= 1; { UInt32 t; code -= range; t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */ distance = (distance << 1) + (t + 1); code += range & t; } /* distance <<= 1; if (code >= range) { code -= range; distance |= 1; } */ } while (--numDirectBits != 0); prob = probs + Align; distance <<= kNumAlignBits; { unsigned i = 1; GET_BIT2(prob + i, i, ; , distance |= 1); GET_BIT2(prob + i, i, ; , distance |= 2); GET_BIT2(prob + i, i, ; , distance |= 4); GET_BIT2(prob + i, i, ; , distance |= 8); } if (distance == (UInt32)0xFFFFFFFF) { len += kMatchSpecLenStart; state -= kNumStates; break; } } } rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance + 1; if (checkDicSize == 0) { if (distance >= processedPos) return SZ_ERROR_DATA; } else if (distance >= checkDicSize) return SZ_ERROR_DATA; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3; /* state = kLiteralNextStates[state]; */ } len += kMatchMinLen; if (limit == dicPos) return SZ_ERROR_DATA; { SizeT rem = limit - dicPos; unsigned curLen = ((rem < len) ? (unsigned)rem : len); SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0); processedPos += curLen; len -= curLen; if (pos + curLen <= dicBufSize) { Byte *dest = dic + dicPos; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; const Byte *lim = dest + curLen; dicPos += curLen; do *(dest) = (Byte)*(dest + src); while (++dest != lim); } else { do { dic[dicPos++] = dic[pos]; if (++pos == dicBufSize) pos = 0; } while (--curLen != 0); } } } } while (dicPos < limit && buf < bufLimit); NORMALIZE; p->buf = buf; p->range = range; p->code = code; p->remainLen = len; p->dicPos = dicPos; p->processedPos = processedPos; p->reps[0] = rep0; p->reps[1] = rep1; p->reps[2] = rep2; p->reps[3] = rep3; p->state = state; return SZ_OK; } static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) { if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) { Byte *dic = p->dic; SizeT dicPos = p->dicPos; SizeT dicBufSize = p->dicBufSize; unsigned len = p->remainLen; UInt32 rep0 = p->reps[0]; if (limit - dicPos < len) len = (unsigned)(limit - dicPos); if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len) p->checkDicSize = p->prop.dicSize; p->processedPos += len; p->remainLen -= len; while (len-- != 0) { dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; dicPos++; } p->dicPos = dicPos; } } static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) { do { SizeT limit2 = limit; if (p->checkDicSize == 0) { UInt32 rem = p->prop.dicSize - p->processedPos; if (limit - p->dicPos > rem) limit2 = p->dicPos + rem; } RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit)); if (p->processedPos >= p->prop.dicSize) p->checkDicSize = p->prop.dicSize; LzmaDec_WriteRem(p, limit); } while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart); if (p->remainLen > kMatchSpecLenStart) { p->remainLen = kMatchSpecLenStart; } return 0; } typedef enum { DUMMY_ERROR, /* unexpected end of input stream */ DUMMY_LIT, DUMMY_MATCH, DUMMY_REP } ELzmaDummy; static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) { UInt32 range = p->range; UInt32 code = p->code; const Byte *bufLimit = buf + inSize; CLzmaProb *probs = p->probs; unsigned state = p->state; ELzmaDummy res; { CLzmaProb *prob; UInt32 bound; unsigned ttt; unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK /* if (bufLimit - buf >= 7) return DUMMY_LIT; */ prob = probs + Literal; if (p->checkDicSize != 0 || p->processedPos != 0) prob += (LZMA_LIT_SIZE * ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) + (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc)))); if (state < kNumLitStates) { unsigned symbol = 1; do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100); } else { unsigned matchByte = p->dic[p->dicPos - p->reps[0] + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)]; unsigned offs = 0x100; unsigned symbol = 1; do { unsigned bit; CLzmaProb *probLit; matchByte <<= 1; bit = (matchByte & offs); probLit = prob + offs + bit + symbol; GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit) } while (symbol < 0x100); } res = DUMMY_LIT; } else { unsigned len; UPDATE_1_CHECK; prob = probs + IsRep + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; state = 0; prob = probs + LenCoder; res = DUMMY_MATCH; } else { UPDATE_1_CHECK; res = DUMMY_REP; prob = probs + IsRepG0 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; NORMALIZE_CHECK; return DUMMY_REP; } else { UPDATE_1_CHECK; } } else { UPDATE_1_CHECK; prob = probs + IsRepG1 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; } else { UPDATE_1_CHECK; prob = probs + IsRepG2 + state; IF_BIT_0_CHECK(prob) { UPDATE_0_CHECK; } else { UPDATE_1_CHECK; } } } state = kNumStates; prob = probs + RepLenCoder; } { unsigned limit, offset; CLzmaProb *probLen = prob + LenChoice; IF_BIT_0_CHECK(probLen) { UPDATE_0_CHECK; probLen = prob + LenLow + (posState << kLenNumLowBits); offset = 0; limit = 1 << kLenNumLowBits; } else { UPDATE_1_CHECK; probLen = prob + LenChoice2; IF_BIT_0_CHECK(probLen) { UPDATE_0_CHECK; probLen = prob + LenMid + (posState << kLenNumMidBits); offset = kLenNumLowSymbols; limit = 1 << kLenNumMidBits; } else { UPDATE_1_CHECK; probLen = prob + LenHigh; offset = kLenNumLowSymbols + kLenNumMidSymbols; limit = 1 << kLenNumHighBits; } } TREE_DECODE_CHECK(probLen, limit, len); len += offset; } if (state < 4) { unsigned posSlot; prob = probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot); if (posSlot >= kStartPosModelIndex) { int numDirectBits = ((posSlot >> 1) - 1); /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */ if (posSlot < kEndPosModelIndex) { prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1; } else { numDirectBits -= kNumAlignBits; do { NORMALIZE_CHECK range >>= 1; code -= range & (((code - range) >> 31) - 1); /* if (code >= range) code -= range; */ } while (--numDirectBits != 0); prob = probs + Align; numDirectBits = kNumAlignBits; } { unsigned i = 1; do { GET_BIT_CHECK(prob + i, i); } while (--numDirectBits != 0); } } } } } NORMALIZE_CHECK; return res; } static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) { p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]); p->range = 0xFFFFFFFF; p->needFlush = 0; } void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) { p->needFlush = 1; p->remainLen = 0; p->tempBufSize = 0; if (initDic) { p->processedPos = 0; p->checkDicSize = 0; p->needInitState = 1; } if (initState) p->needInitState = 1; } void LzmaDec_Init(CLzmaDec *p) { p->dicPos = 0; LzmaDec_InitDicAndState(p, True, True); } static void LzmaDec_InitStateReal(CLzmaDec *p) { UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp)); UInt32 i; CLzmaProb *probs = p->probs; for (i = 0; i < numProbs; i++) probs[i] = kBitModelTotal >> 1; p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1; p->state = 0; p->needInitState = 0; } SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) { SizeT inSize = *srcLen; (*srcLen) = 0; LzmaDec_WriteRem(p, dicLimit); *status = LZMA_STATUS_NOT_SPECIFIED; while (p->remainLen != kMatchSpecLenStart) { int checkEndMarkNow; if (p->needFlush != 0) { for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--) p->tempBuf[p->tempBufSize++] = *src++; if (p->tempBufSize < RC_INIT_SIZE) { *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (p->tempBuf[0] != 0) return SZ_ERROR_DATA; LzmaDec_InitRc(p, p->tempBuf); p->tempBufSize = 0; } checkEndMarkNow = 0; if (p->dicPos >= dicLimit) { if (p->remainLen == 0 && p->code == 0) { *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK; return SZ_OK; } if (finishMode == LZMA_FINISH_ANY) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_OK; } if (p->remainLen != 0) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } checkEndMarkNow = 1; } if (p->needInitState) LzmaDec_InitStateReal(p); if (p->tempBufSize == 0) { SizeT processed; const Byte *bufLimit; if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) { int dummyRes = LzmaDec_TryDummy(p, src, inSize); if (dummyRes == DUMMY_ERROR) { memcpy(p->tempBuf, src, inSize); p->tempBufSize = (unsigned)inSize; (*srcLen) += inSize; *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (checkEndMarkNow && dummyRes != DUMMY_MATCH) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } bufLimit = src; } else bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX; p->buf = src; if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0) return SZ_ERROR_DATA; processed = (SizeT)(p->buf - src); (*srcLen) += processed; src += processed; inSize -= processed; } else { unsigned rem = p->tempBufSize, lookAhead = 0; while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize) p->tempBuf[rem++] = src[lookAhead++]; p->tempBufSize = rem; if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) { int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem); if (dummyRes == DUMMY_ERROR) { (*srcLen) += lookAhead; *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } if (checkEndMarkNow && dummyRes != DUMMY_MATCH) { *status = LZMA_STATUS_NOT_FINISHED; return SZ_ERROR_DATA; } } p->buf = p->tempBuf; if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0) return SZ_ERROR_DATA; lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf)); (*srcLen) += lookAhead; src += lookAhead; inSize -= lookAhead; p->tempBufSize = 0; } } if (p->code == 0) *status = LZMA_STATUS_FINISHED_WITH_MARK; return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; } SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) { SizeT outSize = *destLen; SizeT inSize = *srcLen; *srcLen = *destLen = 0; for (;;) { SizeT inSizeCur = inSize, outSizeCur, dicPos; ELzmaFinishMode curFinishMode; SRes res; if (p->dicPos == p->dicBufSize) p->dicPos = 0; dicPos = p->dicPos; if (outSize > p->dicBufSize - dicPos) { outSizeCur = p->dicBufSize; curFinishMode = LZMA_FINISH_ANY; } else { outSizeCur = dicPos + outSize; curFinishMode = finishMode; } res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status); src += inSizeCur; inSize -= inSizeCur; *srcLen += inSizeCur; outSizeCur = p->dicPos - dicPos; memcpy(dest, p->dic + dicPos, outSizeCur); dest += outSizeCur; outSize -= outSizeCur; *destLen += outSizeCur; if (res != 0) return res; if (outSizeCur == 0 || outSize == 0) return SZ_OK; } } void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) { alloc->Free(alloc, p->probs); p->probs = 0; } static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc) { alloc->Free(alloc, p->dic); p->dic = 0; } void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc) { LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeDict(p, alloc); } SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) { UInt32 dicSize; Byte d; if (size < LZMA_PROPS_SIZE) return SZ_ERROR_UNSUPPORTED; else dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24); if (dicSize < LZMA_DIC_MIN) dicSize = LZMA_DIC_MIN; p->dicSize = dicSize; d = data[0]; if (d >= (9 * 5 * 5)) return SZ_ERROR_UNSUPPORTED; p->lc = d % 9; d /= 9; p->pb = d / 5; p->lp = d % 5; return SZ_OK; } static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) { UInt32 numProbs = LzmaProps_GetNumProbs(propNew); if (p->probs == 0 || numProbs != p->numProbs) { LzmaDec_FreeProbs(p, alloc); p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); p->numProbs = numProbs; if (p->probs == 0) return SZ_ERROR_MEM; } return SZ_OK; } SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) { CLzmaProps propNew; RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); p->prop = propNew; return SZ_OK; } SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) { CLzmaProps propNew; SizeT dicBufSize; RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); dicBufSize = propNew.dicSize; if (p->dic == 0 || dicBufSize != p->dicBufSize) { LzmaDec_FreeDict(p, alloc); p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); if (p->dic == 0) { LzmaDec_FreeProbs(p, alloc); return SZ_ERROR_MEM; } } p->dicBufSize = dicBufSize; p->prop = propNew; return SZ_OK; } SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc) { CLzmaDec p; SRes res; SizeT inSize = *srcLen; SizeT outSize = *destLen; *srcLen = *destLen = 0; if (inSize < RC_INIT_SIZE) return SZ_ERROR_INPUT_EOF; LzmaDec_Construct(&p); res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc); if (res != 0) return res; p.dic = dest; p.dicBufSize = outSize; LzmaDec_Init(&p); *srcLen = inSize; res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status); if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT) res = SZ_ERROR_INPUT_EOF; (*destLen) = p.dicPos; LzmaDec_FreeProbs(&p, alloc); return res; } daa2iso-0.1.7e/src/daa_crypt.h0000644000175000017500000000705511140237614014222 0ustar jamjam/* Copyright 2007,2008,2009 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://www.gnu.org/licenses/gpl-2.0.txt */ static u8 daa_crypt_table[128][256]; void daa_crypt_key(u8 *pass, int num) { // 00453360 int a, b, c, d, s, i, p, passlen; short tmp[256]; u8 *tab; passlen = strlen(pass); tab = daa_crypt_table[num - 1]; d = num << 1; for(i = 0; i < 256; i++) { tmp[i] = i; } memset(tab, 0, 256); if(d <= 64) { a = pass[0] >> 5; if(a >= d) a = d - 1; for(c = 0; c < d; c++) { for(s = 0; s != 11;) { a++; if(a == d) a = 0; if(tmp[a] != -1) s++; } tab[c] = a; tmp[a] = -1; } return; } a = pass[0]; b = d - 32; a >>= 5; tmp[a + 32] = -1; tab[0] = a + 32; p = 1; for(s = 1; s < b; s++) { c = 11; if(p < passlen) { c = pass[p]; p++; if(!c) c = 11; } for(i = 0; i != c;) { a++; if(a == d) a = 32; if(tmp[a] != -1) i++; } tmp[a] = -1; tab[s] = a; } i = pass[0] & 7; if(!i) i = 7; for(; s < d; s++) { for(c = 0; c != i;) { a++; if(a == d) a = 0; if(tmp[a] != -1) c++; } tmp[a] = -1; tab[s] = a; } for(i = 0; i < d; i++) { tmp[i] = tab[i]; } i = pass[0] & 24; if(i) { a = 0; for(s = 0; s < d; s++) { for(c = 0; c != i;) { a++; if(a == d) a = 0; if(tmp[a] != -1) c++; } c = tmp[a]; tmp[a] = -1; tab[s] = c; } } } void daa_crypt_block(u8 *ret, u8 *data, int size) { // 00453540 int i; u8 c, t, *tab; if(!size) return; tab = daa_crypt_table[size - 1]; memset(ret, 0, size); for(i = 0; i < size; i++) { c = data[i] & 15; t = tab[i << 1]; if(t & 1) c <<= 4; ret[t >> 1] |= c; c = data[i] >> 4; t = tab[(i << 1) + 1]; if(t & 1) c <<= 4; ret[t >> 1] |= c; } } void daa_crypt(u8 *data, int size) { int blocks, rem; u8 tmp[128], *p; blocks = size >> 7; for(p = data; blocks--; p += 128) { daa_crypt_block(tmp, p, 128); memcpy(p, tmp, 128); } rem = size & 127; if(rem) { daa_crypt_block(tmp, p, rem); memcpy(p, tmp, rem); } } void daa_crypt_init(u8 *pwdkey, u8 *pass, u8 *daakey) { int i; for(i = 1; i <= 128; i++) { daa_crypt_key(pass, i); } daa_crypt_block(pwdkey, daakey, 128); } daa2iso-0.1.7e/src/daa2iso.c0000644000175000017500000007355111255023104013567 0ustar jamjam/* Copyright 2007,2008,2009 Luigi Auriemma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://www.gnu.org/licenses/gpl-2.0.txt */ #define _LARGE_FILES // if it's not supported the tool will work #define __USE_LARGEFILE64 // without support for large files #define __USE_FILE_OFFSET64 #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include "LzmaDec.h" // http://www.7-zip.org #include "tinf.h" // http://www.ibsensoftware.com #ifdef __DJGPP__ // thanx to Robert Riebisch http://www.bttr-software.de #define NOLFS char **__crt0_glob_function (char *arg) { return 0; } void __crt0_load_environment_file (char *progname) { } #endif #ifdef WIN32 #include HWND mywnd; char *get_file(void); char *put_file(char *suggested); #else #define stricmp strcasecmp #endif typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; #include "daa_crypt.h" #define VER "0.1.7e" #define PRINTF64(x) (u32)(((x) >> 32) & 0xffffffff), (u32)((x) & 0xffffffff) // I64x, llx? blah #if defined(_LARGE_FILES) #if defined(__APPLE__) #define fseek fseeko #define ftell ftello #elif defined(__FreeBSD__) #elif !defined(NOLFS) // use -DNOLFS if this tool can't be compiled on your OS! #define off_t off64_t #define fopen fopen64 #define fseek fseeko64 #define ftell ftello64 #endif #endif #pragma pack(4) typedef struct { u8 sign[16]; // DAA u32 size_offset; // where starts the list of sizes of the zipped chunks u32 version; // version u32 data_offset; // where the zipped chunks start u32 b1; // must be 1 u32 b0; // ever 0 u32 chunksize; // size of each output chunk u64 isosize; // total size of the output ISO u64 daasize; // total size of the DAA file u8 hdata[16]; // it's ever zero u32 crc; // checksum calculated on the first 0x48 bytes } daa_t; #pragma pack(1) typedef struct { u8 n1; // strange way to store numbers... u8 n2; u8 n3; } daa_data_t; #pragma pack() enum { TYPE_DAA, TYPE_GBI, TYPE_NONE }; unsigned int daa2iso_read_bits(unsigned int bits, unsigned char *in, unsigned int in_bits, unsigned int lame, int lame_increase); void gburner_lame(u8 *data, int size, u8 crc8); void poweriso_lame(u8 *data, int size, u64 isosize); void poweriso_is_shit(u8 *chunk, int chunksize); u8 *find_ext(u8 *fname, u8 *ext); FILE *daa_next(void); void myalloc(u8 **data, unsigned wantsize, unsigned *currsize); void myfr(FILE *fd, void *data, unsigned size); void myfw(FILE *fd, void *data, unsigned size); int unlzma(CLzmaDec *lzma, u8 *in, u32 insz, u8 *out, u32 outsz); int unzip(u8 *in, u32 insz, u8 *out, u32 outsz); void l2n_daa(daa_t *daa); void l2n_16(u16 *num); void l2n_32(u32 *num); void l2n_64(u64 *num); u32 crc32(u8 *data, int size); void std_err(void); int fgetz(u8 *data, int size, FILE *fd); void myexit(FILE *fdo); static void *SzAlloc(void *p, size_t size) { return(malloc(size)); } static void SzFree(void *p, void *address) { free(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; int multi = 0, multinum, endian, daagbi = TYPE_DAA, swapped_btype[3] = { 0, 1, 2 }; char *multi_filename; int main(int argc, char *argv[]) { CLzmaDec lzma; daa_data_t *daa_data; daa_t daa; FILE *fdi, *fdo; u64 tot; u32 daa_type, i, len, insz, outsz, pwdtype, pwdcrc, daacrc, daas, // amount of elements in the index table daas_mem, // size of the memory containing the index table last_chunk, ver110_x, ver110_y, daa_dataz; int ztype, // for 110 bitpos, // for 110 bitsize, // for 110 bittype, // for 110 dolame, dolzma, ver110_btype, dolamebits, lzma_filter; u8 ans[66], // password goes from 1 to 64 chars pwdkey[128], daakey[128], *filei, *fileo, *in, *out, *p; setbuf(stdout, NULL); fputs("\n" "DAA2ISO / GBI2ISO "VER"\n" "by Luigi Auriemma\n" "e-mail: aluigi@autistici.org\n" "web: aluigi.org\n" "\n", stdout); fdo = NULL; endian = 1; if(*(char *)&endian) endian = 0; #ifdef WIN32 mywnd = GetForegroundWindow(); if(GetWindowLong(mywnd, GWL_WNDPROC)) { p = argv[1]; argv = malloc(sizeof(char *) * 3); if(argc < 2) { argv[1] = get_file(); } else { argv[1] = p; } argv[2] = put_file(argv[1]); argc = 3; p = strrchr(argv[2], '.'); if(!p || (p && (strlen(p) != 4))) strcat(argv[2], ".iso"); } #endif if(argc < 3) { printf("\n" "Usage: %s \n" "\n", argv[0]); myexit(NULL); } filei = argv[1]; fileo = argv[2]; printf("- open %s\n", filei); fdi = fopen(filei, "rb"); if(!fdi) std_err(); printf("- create %s\n", fileo); fdo = fopen(fileo, "rb"); if(fdo) { fclose(fdo); printf("- the output file already exists, do you want to overwrite it (y/N)? "); fgetz(ans, sizeof(ans), stdin); if((ans[0] != 'y') && (ans[0] != 'Y')) myexit(NULL); } fdo = fopen(fileo, "wb"); if(!fdo) std_err(); ztype = 1; // INFLATE default bitpos = 0; bitsize = 0; bittype = 0; dolame = 0; dolzma = 0; ver110_btype = 0; dolamebits = 0; lzma_filter = 0; daa_dataz = 0; in = out = NULL; insz = outsz = 0; myfr(fdi, &daa, sizeof(daa)); daacrc = crc32((u8 *)&daa, sizeof(daa) - 4); l2n_daa(&daa); if(!strncmp(daa.sign, "DAA", 16) || !strncmp(daa.sign, "\xb8\xbd\xb6", 16)) { daagbi = TYPE_DAA; } else if(!strncmp(daa.sign, "GBI", 16)) { daagbi = TYPE_GBI; } else { if(!strncmp(daa.sign, "DAA VOL", 16) || !strncmp(daa.sign, "GBI VOL", 16)) { printf("\n" "Error: you must choose the first DAA file (*.part01.daa, *.part001.daa or\n" " *.daa) because this is a splitted archive\n"); myexit(fdo); } else { printf("\n" "Error: wrong DAA signature (%.16s)\n" " do you want to continue handling it as a normal DAA file (y/N)?\n" " ", daa.sign); fgetz(ans, sizeof(ans), stdin); if((ans[0] == 'y') || (ans[0] == 'Y')) { daagbi = TYPE_DAA; } else if(!stricmp(ans, "daa")) { daagbi = TYPE_DAA; } else if(!stricmp(ans, "gbi")) { daagbi = TYPE_GBI; } else { myexit(fdo); } } } if(daacrc != daa.crc) { printf("- Alert: the CRC of the DAA header differs\n"); } if(((daa.version != 0x100) && (daa.version != 0x110)) || (daa.b1 != 1)) { printf("- Alert: unknown DAA version (%08x %08x %08x)\n", daa.version, daa.b1, daa.b0); } if(daa.version == 0x100) { daas_mem = daa.data_offset - daa.size_offset; daa_data = malloc(daas_mem); if(!daa_data) std_err(); daas = daas_mem / 3; } else { ver110_x = daa.data_offset; ver110_y = daa.chunksize; daa.data_offset &= 0xffffff; daa.chunksize = (daa.chunksize & 0xfff) << 14; bittype = daa.hdata[5] & 7; bitsize = daa.hdata[5] >> 3; if(bitsize) bitsize += 10; if(!bitsize) { for(bitsize = 0, len = daa.chunksize; len > bittype; bitsize++, len >>= 1); } printf("- bits reader %d %d\n", bittype, bitsize); daas_mem = daa.data_offset - daa.size_offset; daas = (daas_mem << 3) / (bittype + bitsize); daas_mem = (((bitsize + bittype) * daas) + 7) >> 3; if(ver110_y & 0x4000) { daas_mem += 0x10000; daa_dataz = *(u32 *)(daa.hdata + 1); l2n_32(&daa_dataz); } daa_data = malloc(daas_mem); if(!daa_data) std_err(); // seems that most of these fields are not supported by PowerISO too if(ver110_x & 0x80000000) { printf("- Alert: ver110_x 0x80000000 not supported yet, contact me if doesn't work!\n"); if(ver110_y & 0x4000) { // daa.daasize -= daa_dataz; } else { // daa.daasize -= daas_mem; } } if(ver110_x & 0x10000000) { printf("- Alert: ver110_x 0x10000000 not supported yet, contact me if doesn't work!\n"); // esi[8948] = 1; // seems that if it's 1 the readbit function is not used and at its place is returned an error... senseless } if(ver110_y & 0x20000) { printf("- activate the lame decryption of the read bits\n"); dolamebits = 1; } if(ver110_y & 0x8000000) { printf("- activate the lame decryption of the index table\n"); dolame = 1; } if(ver110_y & 0x80000) { printf("- Alert: ver110_y & 0x80000 not supported yet, contact me if doesn't work!\n"); } if(ver110_y & 0x100000) { printf("- activate LZMA\n"); dolzma = 1; } ver110_btype = (ver110_y >> 0x17) & 3; if(daagbi == TYPE_GBI) ver110_btype ^= 1; if(dolzma) { lzma_filter = daa.hdata[6]; // this one comes from Pismo of Joe Lowe LzmaDec_Construct(&lzma); LzmaDec_Allocate(&lzma, daa.hdata + 7, LZMA_PROPS_SIZE, &g_Alloc); } } switch(ver110_btype) { case 0: { swapped_btype[0] = 0; swapped_btype[1] = 1; swapped_btype[2] = 2; break; } case 1: { swapped_btype[0] = 1; swapped_btype[1] = 2; swapped_btype[2] = 0; break; } case 2: { swapped_btype[0] = 0; swapped_btype[1] = 2; swapped_btype[2] = 1; break; } case 3: { swapped_btype[0] = 1; swapped_btype[1] = 0; swapped_btype[2] = 2; break; } } printf("- inflate swapped btypes: %d %d %d\n", swapped_btype[0], swapped_btype[1], swapped_btype[2]); printf("\n" " version %08x %08x %08x\n" " size offset %08x\n" " data offset %08x\n" " chunk size %08x\n" " ISO size %08x%08x\n" " DAA size %08x%08x\n" " header data %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n" " header CRC %08x\n" "\n", daa.version, daa.b1, daa.b0, daa.size_offset, daa.data_offset, daa.chunksize, PRINTF64(daa.isosize), PRINTF64(daa.daasize), daa.hdata[0], daa.hdata[1], daa.hdata[2], daa.hdata[3], daa.hdata[4], daa.hdata[5], daa.hdata[6], daa.hdata[7], daa.hdata[8], daa.hdata[9], daa.hdata[10], daa.hdata[11], daa.hdata[12], daa.hdata[13], daa.hdata[14], daa.hdata[15], daa.crc); while(ftell(fdi) < daa.size_offset) { myfr(fdi, &daa_type, 4); l2n_32(&daa_type); myfr(fdi, &len, 4); l2n_32(&len); if(daa_type == 1) { multi = 1; // multi volume, not needed but I want to be sure to catch it in any case } else if(daa_type == 3) { myfr(fdi, &pwdtype, 4); l2n_32(&pwdtype); myfr(fdi, &pwdcrc, 4); l2n_32(&pwdcrc); myfr(fdi, daakey, 128); if(pwdtype != 0) { // ??? printf("- Alert: this type of encryption/password (%d) seems not supported\n", pwdtype); } printf("- the input file is protected by password, insert it: "); fgetz(ans, sizeof(ans), stdin); daa_crypt_init(pwdkey, ans, daakey); if(pwdcrc != crc32(pwdkey, 128)) { printf("\nError: wrong password\n"); myexit(fdo); } } if(fseek(fdi, len - 8, SEEK_CUR)) std_err(); } fseek(fdi, 0, SEEK_END); tot = ftell(fdi); if(multi || (tot != daa.daasize)) { printf("- multi volume file\n"); if((p = find_ext(filei, "001.daa"))) { multi = 1; multinum = 2; // the number of the next archive } else if((p = find_ext(filei, "01.daa"))) { multi = 2; multinum = 2; // if the current is 1 the next is 2 } else { multi = 3; multinum = 0; p = strrchr(filei, '.'); if(!p) p = filei + strlen(filei); } len = p - filei; multi_filename = malloc(len + 16); memcpy(multi_filename, filei, len); multi_filename[len] = 0; } tot = 0; if(fseek(fdi, daa.size_offset, SEEK_SET)) std_err(); if(daa_dataz) { // solution never tested, just a blind conversion from 0045ed7c myalloc(&in, daa_dataz, &insz); myfr(fdi, in, daa_dataz); daas_mem = unzip(in, daa_dataz, (u8 *)daa_data, daas_mem); daas = (daas_mem << 3) / (bittype + bitsize); daas_mem = (((bitsize + bittype) * daas) + 7) >> 3; } else { myfr(fdi, daa_data, daas_mem); } if(daagbi == TYPE_GBI) gburner_lame((u8 *)daa_data, daas_mem, daa.crc & 0xff); if(dolame) poweriso_lame((u8 *)daa_data, daas_mem, daa.isosize); if(fseek(fdi, daa.data_offset, SEEK_SET)) std_err(); printf("- start unpacking:\n"); myalloc(&out, daa.chunksize, &outsz); last_chunk = daas - 1; for(i = 0; i < daas; i++) { printf(" %03d%%\r", (i * 100) / daas); if(daa.version == 0x100) { len = (daa_data[i].n1 << 16) | (daa_data[i].n2) | (daa_data[i].n3 << 8); } else { len = daa2iso_read_bits(bitsize, (u8 *)daa_data, bitpos, dolamebits, 0); bitpos += bitsize; len += LZMA_PROPS_SIZE; ztype = daa2iso_read_bits(bittype, (u8 *)daa_data, bitpos, dolamebits, 1); bitpos += bittype; if(len >= daa.chunksize) ztype = -1; } myalloc(&in, len, &insz); myfr(fdi, in, len); if(daa_type == 3) daa_crypt(in, len); switch(ztype) { case -1: { // no compression (this ztype is used only in this tool) len = daa.chunksize; memcpy(out, in, len); break; } case 0: { // LZMA len = unlzma(&lzma, in, len, out, outsz); if(lzma_filter) poweriso_is_shit(out, len); break; } case 1: { // INFLATE len = unzip(in, len, out, outsz); break; } default: { printf("\nError: unknown compression type (%d)\n", ztype); myexit(fdo); break; } } if(i == last_chunk) { // last chunk if((tot + len) > daa.isosize) len = daa.isosize - tot; } else { // other chunks if(len != daa.chunksize) { printf("\nError: the uncompressed size doesn't match the chunksize (%08x %08x)\n", len, daa.chunksize); myexit(fdo); } } myfw(fdo, out, len); tot += len; } printf(" 100%%\n" "- 0x%08x%08x bytes written\n", PRINTF64(tot)); if(tot != daa.isosize) { printf("- Alert: the size of the ISO should be 0x%08x%08x bytes!\n", PRINTF64(daa.isosize)); } fclose(fdi); fclose(fdo); if(in) free(in); if(out) free(out); if(daa.version == 0x100) { } else { LzmaDec_Free(&lzma, &g_Alloc); } printf("- finished\n"); myexit(NULL); return(0); } unsigned int daa2iso_read_bits(unsigned int bits, unsigned char *in, unsigned int in_bits, unsigned int lame, int lame_increase) { static const u8 powerisux[] = "\x0A\x35\x2D\x3F\x08\x33\x09\x15"; static int powerisuxn = 0; unsigned int seek_bits, rem, seek = 0, ret = 0, mask = 0xffffffff; if(bits > 32) return(0); if(bits < 32) mask = (1 << bits) - 1; for(;;) { seek_bits = in_bits & 7; ret |= ((in[in_bits >> 3] >> seek_bits)) << seek; rem = 8 - seek_bits; if(rem >= bits) break; bits -= rem; in_bits += rem; seek += rem; } if(lame) { ret ^= ((powerisuxn ^ powerisux[powerisuxn & 7]) & 0xff) * 0x01010101; if(lame_increase) powerisuxn++; } return(ret & mask); } void gburner_lame(u8 *data, int size, u8 crc8) { int i; u8 d; d = size >> 2; for(i = 0; i < size; i++) { data[i] -= crc8; data[i] ^= d; } } void poweriso_lame(u8 *data, int size, u64 isosize) { int i; u8 a, c; isosize /= 0x800; a = (isosize >> 8) & 0xff; c = isosize & 0xff; for(i = 0; i < size; i++) { data[i] -= c; c += a; } } // this function is x86_Convert function of the LZMA SDK (thanx to Joe Lowe for the info) void poweriso_is_shit(u8 *chunk, int chunksize) { u32 num, bp, e10, e20, e28; int i; u8 shit[8] = { 0, 1, 2, 2, 3, 3, 3, 3 }, shiz[8] = { 1, 1, 1, 0, 1, 0, 0, 0 }, tmp; bp = 0; e10 = -1; e20 = 5; // add esi,5 e28 = 0; for(i = 0; (i + 5) <= chunksize; i++) { if((chunk[i] & 0xfe) != 0xe8) continue; if((i - e10) <= 3) { bp = (bp << ((i - e10 - 1) & 0xff)) & 7; } else { bp = 0; } if(bp) { tmp = chunk[i - shit[bp] + 4]; if(!shiz[bp] || !tmp || (tmp == 0xff)) { bp = ((bp & 3) << 1) | 1; e10 = i; continue; } } e10 = i; if((chunk[i + 4] != 0) && (chunk[i + 4] != 0xff)) { bp = ((bp & 3) << 1) | 1; continue; } num = (chunk[i + 4] << 24) | (chunk[i + 3] << 16) | (chunk[i + 2] << 8) | chunk[i + 1]; for(;;) { if(!e28) { num -= i + e20; } else { num += i + e20; } if(!bp) break; tmp = num >> (24 - (shit[bp] << 3)); if((tmp != 0) && (tmp != 0xff)) break; num ^= ((1 << (32 - (shit[bp] << 3))) - 1); } chunk[++i] = num; chunk[++i] = num >> 8; chunk[++i] = num >> 16; chunk[++i] = ~(((num >> 24) & 1) - 1); } } #ifdef WIN32 char *get_file(void) { OPENFILENAME ofn; static char filename[4096]; static const char filter[] = "DAA/GBI file\0" "*.daa;*.gbi\0" "(*.*)\0" "*.*\0" "\0" "\0"; filename[0] = 0; memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename); ofn.lpstrTitle = "Select the input DAA file (or the first multipart) to convert"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY; printf("- %s\n", ofn.lpstrTitle); if(!GetOpenFileName(&ofn)) exit(1); return(filename); } char *put_file(char *suggested) { OPENFILENAME ofn; char *p; static char filename[4096 + 10]; static const char filter[] = "ISO file\0" "*.iso\0" "(*.*)\0" "*.*\0" "\0" "\0"; if(!suggested) { filename[0] = 0; } else { p = strrchr(suggested, '.'); if(!p) p = suggested + strlen(suggested); if((p - suggested) >= 4096) p = suggested + 4096 - 1; memcpy(filename, suggested, p - suggested); filename[p - suggested] = 0; strcat(filename, ".iso"); } memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename); ofn.lpstrTitle = "Choose the name of the output ISO file to create"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY; printf("- %s\n", ofn.lpstrTitle); if(!GetSaveFileName(&ofn)) exit(1); return(filename); } #endif u8 *find_ext(u8 *fname, u8 *ext) { int len, extlen; u8 *ret; len = strlen(fname); extlen = strlen(ext); ret = fname + len - extlen; if((len >= extlen) && !stricmp(ret, ext)) { return(ret); } return(NULL); } FILE *daa_next(void) { daa_t daa; FILE *fd; static char *toadd = NULL, *fmt; if(!toadd) { toadd = multi_filename + strlen(multi_filename); switch(multi) { case 1: fmt = "%03d.daa"; break; case 2: fmt = "%02d.daa"; break; default: fmt = ".d%02d"; break; } } sprintf(toadd, fmt, multinum); printf(" open %s\n", multi_filename); fd = fopen(multi_filename, "rb"); if(!fd) std_err(); myfr(fd, &daa, sizeof(daa)); l2n_daa(&daa); if(strncmp(daa.sign, "DAA VOL", 16) && strncmp(daa.sign, "GBI VOL", 16)) { printf("\nError: wrong DAA VOL signature (%.16s)\n", daa.sign); myexit(NULL); } if(fseek(fd, daa.size_offset, SEEK_SET)) std_err(); multinum++; return(fd); } void myalloc(u8 **data, unsigned wantsize, unsigned *currsize) { if(wantsize <= *currsize) return; *data = realloc(*data, wantsize); if(!*data) std_err(); *currsize = wantsize; } void myfr(FILE *fd, void *data, unsigned size) { int len; len = fread(data, 1, size, fd); if(len == size) return; if(!multi) { printf("\nError: incomplete input file, can't read %u bytes\n", size); myexit(NULL); } fclose(fd); fd = daa_next(); myfr(fd, data + len, size - len); } void myfw(FILE *fd, void *data, unsigned size) { if(fwrite(data, 1, size, fd) == size) return; printf("\nError: problems during the writing of the output file, check your disk space\n"); myexit(fd); } int unlzma(CLzmaDec *lzma, u8 *in, u32 insz, u8 *out, u32 outsz) { ELzmaStatus status; SizeT inlen, outlen; LzmaDec_Init(lzma); inlen = insz; outlen = outsz; if(LzmaDec_DecodeToBuf(lzma, out, &outlen, in, &inlen, LZMA_FINISH_END, &status) != SZ_OK) { printf("\nError: the compressed LZMA input is wrong or incomplete (%d)\n", status); myexit(NULL); } return(outlen); } int unzip(u8 *in, u32 insz, u8 *out, u32 outsz) { tinf_init(); if(tinf_uncompress(out, &outsz, in, insz, swapped_btype) != TINF_OK) { printf("\nError: the compressed INFLATE input is wrong or incomplete\n"); myexit(NULL); } return(outsz); } void l2n_daa(daa_t *daa) { if(!endian) return; l2n_32(&daa->size_offset); l2n_32(&daa->version); l2n_32(&daa->data_offset); l2n_32(&daa->b1); l2n_32(&daa->b0); l2n_32(&daa->chunksize); l2n_64(&daa->isosize); l2n_64(&daa->daasize); l2n_32(&daa->crc); } void l2n_16(u16 *num) { u16 tmp; if(!endian) return; tmp = *num; *num = ((tmp & 0xff00) >> 8) | ((tmp & 0x00ff) << 8); } void l2n_32(u32 *num) { u32 tmp; if(!endian) return; tmp = *num; *num = ((tmp & 0xff000000) >> 24) | ((tmp & 0x00ff0000) >> 8) | ((tmp & 0x0000ff00) << 8) | ((tmp & 0x000000ff) << 24); } void l2n_64(u64 *num) { u64 tmp; if(!endian) return; tmp = *num; *num = (u64)((u64)(tmp & (u64)0xff00000000000000ULL) >> (u64)56) | (u64)((u64)(tmp & (u64)0x00ff000000000000ULL) >> (u64)40) | (u64)((u64)(tmp & (u64)0x0000ff0000000000ULL) >> (u64)24) | (u64)((u64)(tmp & (u64)0x000000ff00000000ULL) >> (u64)8) | (u64)((u64)(tmp & (u64)0x00000000ff000000ULL) << (u64)8) | (u64)((u64)(tmp & (u64)0x0000000000ff0000ULL) << (u64)24) | (u64)((u64)(tmp & (u64)0x000000000000ff00ULL) << (u64)40) | (u64)((u64)(tmp & (u64)0x00000000000000ffULL) << (u64)56); } u32 crc32(u8 *data, int size) { static const u32 crctable[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; u32 crc = 0xffffffff; u8 *limit; for(limit = data + size; data < limit; data++) { crc = crctable[*data ^ (crc & 0xff)] ^ (crc >> 8); } return(~crc); } void std_err(void) { perror("\nError"); myexit(NULL); } int fgetz(u8 *data, int size, FILE *fd) { u8 *p; fflush(fd); if(!fgets(data, size, fd)) { data[0] = 0; return(0); } for(p = data; *p && (*p != '\n') && (*p != '\r'); p++); *p = 0; return(p - data); } void myexit(FILE *fdo) { if(fdo) fclose(fdo); // a bit useless #ifdef WIN32 u8 ans[8]; if(GetWindowLong(mywnd, GWL_WNDPROC)) { printf("\nPress RETURN to quit"); fgetz(ans, sizeof(ans), stdin); } #endif exit(1); } daa2iso-0.1.7e/src/Types.h0000644000175000017500000001137511254275040013361 0ustar jamjam/* Types.h -- Basic types 2009-08-14 : Igor Pavlov : Public domain */ #ifndef __7Z_TYPES_H #define __7Z_TYPES_H #include #ifdef _WIN32 #include #endif #ifndef EXTERN_C_BEGIN #ifdef __cplusplus #define EXTERN_C_BEGIN extern "C" { #define EXTERN_C_END } #else #define EXTERN_C_BEGIN #define EXTERN_C_END #endif #endif EXTERN_C_BEGIN #define SZ_OK 0 #define SZ_ERROR_DATA 1 #define SZ_ERROR_MEM 2 #define SZ_ERROR_CRC 3 #define SZ_ERROR_UNSUPPORTED 4 #define SZ_ERROR_PARAM 5 #define SZ_ERROR_INPUT_EOF 6 #define SZ_ERROR_OUTPUT_EOF 7 #define SZ_ERROR_READ 8 #define SZ_ERROR_WRITE 9 #define SZ_ERROR_PROGRESS 10 #define SZ_ERROR_FAIL 11 #define SZ_ERROR_THREAD 12 #define SZ_ERROR_ARCHIVE 16 #define SZ_ERROR_NO_ARCHIVE 17 typedef int SRes; #ifdef _WIN32 typedef DWORD WRes; #else typedef int WRes; #endif #ifndef RINOK #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } #endif typedef unsigned char Byte; typedef short Int16; typedef unsigned short UInt16; #ifdef _LZMA_UINT32_IS_ULONG typedef long Int32; typedef unsigned long UInt32; #else typedef int Int32; typedef unsigned int UInt32; #endif #ifdef _SZ_NO_INT_64 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. NOTES: Some code will work incorrectly in that case! */ typedef long Int64; typedef unsigned long UInt64; #else #if defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 Int64; typedef unsigned __int64 UInt64; #else typedef long long int Int64; typedef unsigned long long int UInt64; #endif #endif #ifdef _LZMA_NO_SYSTEM_SIZE_T typedef UInt32 SizeT; #else typedef size_t SizeT; #endif typedef int Bool; #define True 1 #define False 0 #ifdef _MSC_VER #if _MSC_VER >= 1300 #define MY_NO_INLINE __declspec(noinline) #else #define MY_NO_INLINE #endif #define MY_CDECL __cdecl #define MY_STD_CALL __stdcall #define MY_FAST_CALL MY_NO_INLINE __fastcall #else #define MY_CDECL #define MY_STD_CALL #define MY_FAST_CALL #endif /* The following interfaces use first parameter as pointer to structure */ typedef struct { SRes (*Read)(void *p, void *buf, size_t *size); /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. (output(*size) < input(*size)) is allowed */ } ISeqInStream; /* it can return SZ_ERROR_INPUT_EOF */ SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); typedef struct { size_t (*Write)(void *p, const void *buf, size_t size); /* Returns: result - the number of actually written bytes. (result < size) means error */ } ISeqOutStream; typedef enum { SZ_SEEK_SET = 0, SZ_SEEK_CUR = 1, SZ_SEEK_END = 2 } ESzSeek; typedef struct { SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); } ISeekInStream; typedef struct { SRes (*Look)(void *p, void **buf, size_t *size); /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. (output(*size) > input(*size)) is not allowed (output(*size) < input(*size)) is allowed */ SRes (*Skip)(void *p, size_t offset); /* offset must be <= output(*size) of Look */ SRes (*Read)(void *p, void *buf, size_t *size); /* reads directly (without buffer). It's same as ISeqInStream::Read */ SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); } ILookInStream; SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); /* reads via ILookInStream::Read */ SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); #define LookToRead_BUF_SIZE (1 << 14) typedef struct { ILookInStream s; ISeekInStream *realStream; size_t pos; size_t size; Byte buf[LookToRead_BUF_SIZE]; } CLookToRead; void LookToRead_CreateVTable(CLookToRead *p, int lookahead); void LookToRead_Init(CLookToRead *p); typedef struct { ISeqInStream s; ILookInStream *realStream; } CSecToLook; void SecToLook_CreateVTable(CSecToLook *p); typedef struct { ISeqInStream s; ILookInStream *realStream; } CSecToRead; void SecToRead_CreateVTable(CSecToRead *p); typedef struct { SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); /* Returns: result. (result != SZ_OK) means break. Value (UInt64)(Int64)-1 for size means unknown value. */ } ICompressProgress; typedef struct { void *(*Alloc)(void *p, size_t size); void (*Free)(void *p, void *address); /* address can be 0 */ } ISzAlloc; #define IAlloc_Alloc(p, size) (p)->Alloc((p), size) #define IAlloc_Free(p, a) (p)->Free((p), a) EXTERN_C_END #endif daa2iso-0.1.7e/src/Makefile0000644000175000017500000000046611107403544013542 0ustar jamjamEXE = daa2iso CFLAGS += -O2 -s PREFIX = /usr/local BINDIR = $(PREFIX)/bin SRC = $(EXE).c all: $(CC) $(CFLAGS) -c LzmaDec.c $(CC) $(CFLAGS) -c tinflate.c $(CC) $(SRC) $(CFLAGS) -o $(EXE) LzmaDec.o tinflate.o install: install -m 755 -d $(BINDIR) install -m 755 $(EXE) $(BINDIR)/$(EXE) .PHONY: install daa2iso-0.1.7e/src/tinf.h0000644000175000017500000000143211140216714013203 0ustar jamjam/* * tinf - tiny inflate library (inflate, gzip, zlib) * * version 1.00 * * Copyright (c) 2003 by Joergen Ibsen / Jibz * All Rights Reserved * * http://www.ibsensoftware.com/ */ #ifndef TINF_H_INCLUDED #define TINF_H_INCLUDED /* calling convention */ #ifndef TINFCC #ifdef __WATCOMC__ #define TINFCC __cdecl #else #define TINFCC #endif #endif #ifdef __cplusplus extern "C" { #endif #define TINF_OK 0 #define TINF_DATA_ERROR (-3) /* function prototypes */ void TINFCC tinf_init(); int TINFCC tinf_uncompress(void *dest, unsigned int *destLen, const void *source, unsigned int sourceLen, const unsigned int swapped_btype[3]); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* TINF_H_INCLUDED */ daa2iso-0.1.7e/src/LzmaDec.h0000644000175000017500000001532111254275040013567 0ustar jamjam/* LzmaDec.h -- LZMA Decoder 2009-02-07 : Igor Pavlov : Public domain */ #ifndef __LZMA_DEC_H #define __LZMA_DEC_H #include "Types.h" #ifdef __cplusplus extern "C" { #endif /* #define _LZMA_PROB32 */ /* _LZMA_PROB32 can increase the speed on some CPUs, but memory usage for CLzmaDec::probs will be doubled in that case */ #ifdef _LZMA_PROB32 #define CLzmaProb UInt32 #else #define CLzmaProb UInt16 #endif /* ---------- LZMA Properties ---------- */ #define LZMA_PROPS_SIZE 5 typedef struct _CLzmaProps { unsigned lc, lp, pb; UInt32 dicSize; } CLzmaProps; /* LzmaProps_Decode - decodes properties Returns: SZ_OK SZ_ERROR_UNSUPPORTED - Unsupported properties */ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); /* ---------- LZMA Decoder state ---------- */ /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ #define LZMA_REQUIRED_INPUT_MAX 20 typedef struct { CLzmaProps prop; CLzmaProb *probs; Byte *dic; const Byte *buf; UInt32 range, code; SizeT dicPos; SizeT dicBufSize; UInt32 processedPos; UInt32 checkDicSize; unsigned state; UInt32 reps[4]; unsigned remainLen; int needFlush; int needInitState; UInt32 numProbs; unsigned tempBufSize; Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; } CLzmaDec; #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } void LzmaDec_Init(CLzmaDec *p); /* There are two types of LZMA streams: 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ typedef enum { LZMA_FINISH_ANY, /* finish at any point */ LZMA_FINISH_END /* block must be finished at the end */ } ELzmaFinishMode; /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! You must use LZMA_FINISH_END, when you know that current output buffer covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, and output value of destLen will be less than output buffer size limit. You can check status result also. You can use multiple checks to test data integrity after full decompression: 1) Check Result and "status" variable. 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. You must use correct finish mode in that case. */ typedef enum { LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ } ELzmaStatus; /* ELzmaStatus is used only as output value for function call */ /* ---------- Interfaces ---------- */ /* There are 3 levels of interfaces: 1) Dictionary Interface 2) Buffer Interface 3) One Call Interface You can select any of these interfaces, but don't mix functions from different groups for same object. */ /* There are two variants to allocate state for Dictionary Interface: 1) LzmaDec_Allocate / LzmaDec_Free 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs You can use variant 2, if you set dictionary buffer manually. For Buffer Interface you must always use variant 1. LzmaDec_Allocate* can return: SZ_OK SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties */ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); /* ---------- Dictionary Interface ---------- */ /* You can use it, if you want to eliminate the overhead for data copying from dictionary to some other external buffer. You must work with CLzmaDec variables directly in this interface. STEPS: LzmaDec_Constr() LzmaDec_Allocate() for (each new stream) { LzmaDec_Init() while (it needs more decompression) { LzmaDec_DecodeToDic() use data from CLzmaDec::dic and update CLzmaDec::dicPos } } LzmaDec_Free() */ /* LzmaDec_DecodeToDic The decoding to internal dictionary buffer (CLzmaDec::dic). You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! finishMode: It has meaning only if the decoding reaches output limit (dicLimit). LZMA_FINISH_ANY - Decode just dicLimit bytes. LZMA_FINISH_END - Stream must be finished after dicLimit. Returns: SZ_OK status: LZMA_STATUS_FINISHED_WITH_MARK LZMA_STATUS_NOT_FINISHED LZMA_STATUS_NEEDS_MORE_INPUT LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK SZ_ERROR_DATA - Data error */ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); /* ---------- Buffer Interface ---------- */ /* It's zlib-like interface. See LzmaDec_DecodeToDic description for information about STEPS and return results, but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need to work with CLzmaDec variables manually. finishMode: It has meaning only if the decoding reaches output limit (*destLen). LZMA_FINISH_ANY - Decode just destLen bytes. LZMA_FINISH_END - Stream must be finished after (*destLen). */ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); /* ---------- One Call Interface ---------- */ /* LzmaDecode finishMode: It has meaning only if the decoding reaches output limit (*destLen). LZMA_FINISH_ANY - Decode just destLen bytes. LZMA_FINISH_END - Stream must be finished after (*destLen). Returns: SZ_OK status: LZMA_STATUS_FINISHED_WITH_MARK LZMA_STATUS_NOT_FINISHED LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK SZ_ERROR_DATA - Data error SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). */ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); #ifdef __cplusplus } #endif #endif daa2iso-0.1.7e/src/tinflate.c0000644000175000017500000003016711140222704014047 0ustar jamjam// modified by Luigi Auriemma for: // - daa2iso compatibility (swapping of btype in tinf_uncompress) // - checking of source and destination size /* * tinflate - tiny inflate * * Copyright (c) 2003 by Joergen Ibsen / Jibz * All Rights Reserved * * http://www.ibsensoftware.com/ * * This software is provided 'as-is', without any express * or implied warranty. In no event will the authors be * held liable for any damages arising from the use of * this software. * * Permission is granted to anyone to use this software * for any purpose, including commercial applications, * and to alter it and redistribute it freely, subject to * the following restrictions: * * 1. The origin of this software must not be * misrepresented; you must not claim that you * wrote the original software. If you use this * software in a product, an acknowledgment in * the product documentation would be appreciated * but is not required. * * 2. Altered source versions must be plainly marked * as such, and must not be misrepresented as * being the original software. * * 3. This notice may not be removed or altered from * any source distribution. */ #include "tinf.h" /* ------------------------------ * * -- internal data structures -- * * ------------------------------ */ typedef struct { unsigned short table[16]; /* table of code length counts */ unsigned short trans[288]; /* code -> symbol translation table */ } TINF_TREE; typedef struct { const unsigned char *source; unsigned int tag; unsigned int bitcount; unsigned char *dest; unsigned int *destLen; unsigned int sourceLen; unsigned int sourceSize; unsigned int destSize; TINF_TREE ltree; /* dynamic length/symbol tree */ TINF_TREE dtree; /* dynamic distance tree */ } TINF_DATA; /* --------------------------------------------------- * * -- uninitialized global data (static structures) -- * * --------------------------------------------------- */ TINF_TREE sltree; /* fixed length/symbol tree */ TINF_TREE sdtree; /* fixed distance tree */ /* extra bits and base tables for length codes */ unsigned char length_bits[30]; unsigned short length_base[30]; /* extra bits and base tables for distance codes */ unsigned char dist_bits[30]; unsigned short dist_base[30]; /* special ordering of code length codes */ const unsigned char clcidx[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; /* ----------------------- * * -- utility functions -- * * ----------------------- */ /* build extra bits and base tables */ static void tinf_build_bits_base(unsigned char *bits, unsigned short *base, int delta, int first) { int i, sum; /* build bits table */ for (i = 0; i < delta; ++i) bits[i] = 0; for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta; /* build base table */ for (sum = first, i = 0; i < 30; ++i) { base[i] = sum; sum += 1 << bits[i]; } } /* build the fixed huffman trees */ static void tinf_build_fixed_trees(TINF_TREE *lt, TINF_TREE *dt) { int i; /* build fixed length tree */ for (i = 0; i < 7; ++i) lt->table[i] = 0; lt->table[7] = 24; lt->table[8] = 152; lt->table[9] = 112; for (i = 0; i < 24; ++i) lt->trans[i] = 256 + i; for (i = 0; i < 144; ++i) lt->trans[24 + i] = i; for (i = 0; i < 8; ++i) lt->trans[24 + 144 + i] = 280 + i; for (i = 0; i < 112; ++i) lt->trans[24 + 144 + 8 + i] = 144 + i; /* build fixed distance tree */ for (i = 0; i < 5; ++i) dt->table[i] = 0; dt->table[5] = 32; for (i = 0; i < 32; ++i) dt->trans[i] = i; } /* given an array of code lengths, build a tree */ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num) { unsigned short offs[16]; unsigned int i, sum; /* clear code length count table */ for (i = 0; i < 16; ++i) t->table[i] = 0; /* scan symbol lengths, and sum code length counts */ for (i = 0; i < num; ++i) t->table[lengths[i]]++; t->table[0] = 0; /* compute offset table for distribution sort */ for (sum = 0, i = 0; i < 16; ++i) { offs[i] = sum; sum += t->table[i]; } /* create code->symbol translation table (symbols sorted by code) */ for (i = 0; i < num; ++i) { if (lengths[i]) t->trans[offs[lengths[i]]++] = i; } } /* ---------------------- * * -- decode functions -- * * ---------------------- */ /* get one bit from source stream */ static int tinf_getbit(TINF_DATA *d) { unsigned int bit; /* check if tag is empty */ if (!d->bitcount--) { /* load next tag */ if((d->sourceLen + 1) > d->sourceSize) return 0; // better than ignoring it d->tag = *d->source++; d->sourceLen++; d->bitcount = 7; } /* shift bit out of tag */ bit = d->tag & 0x01; d->tag >>= 1; return bit; } /* read a num bit value from a stream and add base */ static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) { unsigned int val = 0; /* read num bits */ if (num) { unsigned int limit = 1 << (num); unsigned int mask; for (mask = 1; mask < limit; mask <<= 1) if (tinf_getbit(d)) val += mask; } return val + base; } /* given a data stream and a tree, decode a symbol */ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) { int sum = 0, cur = 0, len = 0; /* get more bits while code value is above sum */ do { cur = 2*cur + tinf_getbit(d); ++len; sum += t->table[len]; cur -= t->table[len]; } while (cur >= 0); return t->trans[sum + cur]; } /* given a data stream, decode dynamic trees from it */ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) { TINF_TREE code_tree; unsigned char lengths[288+32]; unsigned int hlit, hdist, hclen; unsigned int i, num, length; /* get 5 bits HLIT (257-286) */ hlit = tinf_read_bits(d, 5, 257); /* get 5 bits HDIST (1-32) */ hdist = tinf_read_bits(d, 5, 1); /* get 4 bits HCLEN (4-19) */ hclen = tinf_read_bits(d, 4, 4); for (i = 0; i < 19; ++i) lengths[i] = 0; /* read code lengths for code length alphabet */ for (i = 0; i < hclen; ++i) { /* get 3 bits code length (0-7) */ unsigned int clen = tinf_read_bits(d, 3, 0); lengths[clcidx[i]] = clen; } /* build code length tree */ tinf_build_tree(&code_tree, lengths, 19); /* decode code lengths for the dynamic trees */ for (num = 0; num < hlit + hdist; ) { int sym = tinf_decode_symbol(d, &code_tree); switch (sym) { case 16: /* copy previous code length 3-6 times (read 2 bits) */ { unsigned char prev = lengths[num - 1]; length = tinf_read_bits(d, 2, 3); if((num + length) > (288+32)) return TINF_DATA_ERROR; for (; length; --length) { lengths[num++] = prev; } } break; case 17: /* repeat code length 0 for 3-10 times (read 3 bits) */ length = tinf_read_bits(d, 3, 3); if((num + length) > (288+32)) return TINF_DATA_ERROR; for (; length; --length) { lengths[num++] = 0; } break; case 18: /* repeat code length 0 for 11-138 times (read 7 bits) */ length = tinf_read_bits(d, 7, 11); if((num + length) > (288+32)) return TINF_DATA_ERROR; for (; length; --length) { lengths[num++] = 0; } break; default: /* values 0-15 represent the actual code lengths */ if((num + 1) > (288+32)) return TINF_DATA_ERROR; lengths[num++] = sym; break; } } /* build dynamic trees */ tinf_build_tree(lt, lengths, hlit); tinf_build_tree(dt, lengths + hlit, hdist); return TINF_OK; } /* ----------------------------- * * -- block inflate functions -- * * ----------------------------- */ /* given a stream and two trees, inflate a block of data */ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) { while (1) { int sym = tinf_decode_symbol(d, lt); /* check for end of block */ if (sym == 256) break; if (sym < 256) { if ((*d->destLen + 1) > d->destSize) return TINF_DATA_ERROR; *d->dest++ = sym; *d->destLen += 1; } else { int length, dist, offs; int i; sym -= 257; /* possibly get more bits from length code */ length = tinf_read_bits(d, length_bits[sym], length_base[sym]); dist = tinf_decode_symbol(d, dt); /* possibly get more bits from distance code */ offs = tinf_read_bits(d, dist_bits[dist], dist_base[dist]); /* copy match */ if ((*d->destLen + length) > d->destSize) return TINF_DATA_ERROR; for (i = 0; i < length; ++i) { d->dest[i] = d->dest[i - offs]; } d->dest += length; *d->destLen += length; } } return TINF_OK; } /* inflate an uncompressed block of data */ static int tinf_inflate_uncompressed_block(TINF_DATA *d) { unsigned int length, invlength; unsigned int i; if((d->sourceLen + 4) > d->sourceSize) return TINF_DATA_ERROR; /* get length */ length = d->source[1]; length = (length << 8) + d->source[0]; /* get one's complement of length */ invlength = d->source[3]; invlength = (invlength << 8) + d->source[2]; /* check length */ if (length != (~invlength & 0x0000ffff)) return TINF_DATA_ERROR; d->source += 4; d->sourceLen += 4; /* copy block */ if ((d->sourceLen + length) > d->sourceSize) return TINF_DATA_ERROR; if ((*d->destLen + length) > d->destSize) return TINF_DATA_ERROR; for (i = length; i; --i) *d->dest++ = *d->source++; /* make sure we start next block on a byte boundary */ d->bitcount = 0; d->sourceLen += length; *d->destLen += length; return TINF_OK; } /* inflate a block of data compressed with fixed huffman trees */ static int tinf_inflate_fixed_block(TINF_DATA *d) { /* decode block using fixed trees */ return tinf_inflate_block_data(d, &sltree, &sdtree); } /* inflate a block of data compressed with dynamic huffman trees */ static int tinf_inflate_dynamic_block(TINF_DATA *d) { /* decode trees from stream */ if(tinf_decode_trees(d, &d->ltree, &d->dtree) != TINF_OK) return TINF_DATA_ERROR; /* decode block using decoded trees */ return tinf_inflate_block_data(d, &d->ltree, &d->dtree); } /* ---------------------- * * -- public functions -- * * ---------------------- */ /* initialize global (static) data */ void tinf_init() { /* build fixed huffman trees */ tinf_build_fixed_trees(&sltree, &sdtree); /* build extra bits and base tables */ tinf_build_bits_base(length_bits, length_base, 4, 3); tinf_build_bits_base(dist_bits, dist_base, 2, 1); /* fix a special case */ length_bits[28] = 0; length_base[28] = 258; } /* inflate stream from source to dest */ int tinf_uncompress(void *dest, unsigned int *destLen, const void *source, unsigned int sourceLen, const unsigned int swapped_btype[3]) { TINF_DATA d; int bfinal; /* initialise data */ d.source = (const unsigned char *)source; d.bitcount = 0; d.dest = (unsigned char *)dest; d.destLen = destLen; d.sourceLen = 0; d.sourceSize = sourceLen; d.destSize = *destLen; *destLen = 0; do { unsigned int btype; int res; /* read final block flag */ bfinal = tinf_getbit(&d); /* read block type (2 bits) */ btype = tinf_read_bits(&d, 2, 0); /* decompress block */ if(btype == swapped_btype[0]) { /* decompress uncompressed block */ res = tinf_inflate_uncompressed_block(&d); } else if(btype == swapped_btype[1]) { /* decompress block with fixed huffman trees */ res = tinf_inflate_fixed_block(&d); } else if(btype == swapped_btype[2]) { /* decompress block with dynamic huffman trees */ res = tinf_inflate_dynamic_block(&d); } else { return TINF_DATA_ERROR; } if (res != TINF_OK) return TINF_DATA_ERROR; } while (!bfinal); return TINF_OK; } daa2iso-0.1.7e/COPYING0000644000175000017500000004310311070673630012345 0ustar jamjam GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. daa2iso-0.1.7e/daa2iso.txt0000644000175000017500000001211311215323350013362 0ustar jamjam###################################################################### Title: DAA2ISO / GBI2ISO Author: Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org DAA2ISO homepage: http://aluigi.org/mytoolz.htm#daa2iso ###################################################################### 1) Introduction 2) Usage on Windows 3) Usage on *nix/MacOSX 4) Features and known bugs 5) Technical info about the format 6) Comments about the DAA format ###################################################################### =============== 1) Introduction =============== DAA2ISO is an open source command-line/GUI tool for converting single and multipart DAA and GBI images to the original ISO format. The DAA image (Direct Access Archive) in fact is just a compressed CD/DVD ISO which can be created through the commercial program PowerISO. ###################################################################### =================== 2) Usage on Windows =================== Using DAA2ISO on Windows is really a joke, just double click on DAA2ISO.exe and the tool will open a DOS-like window which contains all the needed informations about the status of conversion, then you will need to choose the input DAA file you want to convert and subsequently the name of the ISO file you want to create. The tool automatically supports multipart files so it's enough that you select only the first one (like file.part01.daa). If you want to use the tool from the command-line, so specifying the input and output files manually as in the older versions of the tool, you can do it too since DAA2ISO automatically recognizes if it has been launched from the console (cmd.exe) or through double-click. Just specify the input DAA file and the output ISO file you want to create like in the examples of the subsequent section. Remember that you can also associate the DAA extension to DAA2ISO, so when you will double-click on these files DAA2ISO will popup and will allow you to choose the output ISO immediately or you can also drag'n'drop the DAA file directly on DAA2ISO.EXE. Note that DAA2ISO is a stand-alone program, so all you need to have is just DAA2ISO.EXE and you can place it everywhere you want. ###################################################################### ======================= 3) Usage on *nix/MacOSX ======================= Compile the source code using 'make', this will generate the DAA2ISO executable. If you want to install it type 'make install' or just copy the executable where you want since it's the only file you need. Using it then it's simple, just specify the input file and the ISO file you want to create like the following example: daa2iso "my file.daa" output.iso or daa2iso "my file.part01.daa" output.iso ###################################################################### ========================== 4) Features and known bugs ========================== The tool supports password/encryption, multiple volumes, little/big endian architectures and should work on many platforms (Windows, Linux, MacOS, *BSD, Amiga and others). The only known micro-bug is that on Windows 95/98/ME works only the so called GUI version because the method I use to know if the program has been launched from the console or through double-click is not compatible with this OS, anyway this is not a problem since the 99% of the Windows users don't like the command-line 8-) From version 0.1.7 daa2iso is no longer zlib dependent, I have adopted the tinf library of Joergen Ibsen available on http://www.ibsensoftware.com/download.html because it's tiny, simple and was a joke to modify it for adding the needed changes for compatibility with PowerISO. Instead the LZMA decompression library comes from Igor Pavlov of http://www.7-zip.org. I'm available for any comment or feedback, so if you find a compatibility problem with a specific DAA image (and you are sure that the image is perfect) send me a mail. ###################################################################### ================================== 5) Technical info about the format ================================== DAA2ISO is open source so there is nothing better than its source code for explaining in detail this file format. In short DAA is only a simple ISO compressed image, so it can't handle audio or mixed/extra content but only the good old ISO data. ###################################################################### ================================ 6) Comments about the DAA format ================================ I don't like and don't approve the DAA format because it's proprietary and doesn't give benefits. What you can do with DAA can be done better with ZIP or 7zip without the need to be forced to buy a software like PowerISO only for burning an image. Ok exists my tool which can do the job but this is not a valid reason to continue to use this useless format. So if you want to create a CD/DVD image, DO NOT USE DAA! ######################################################################