public uint CopyDictionaryWord(byte [] abU, int offset, int bytes, BitStream stm, uint dst) { offset |= stm.GetByte(); var src = dst - offset; do { abU[dst++] = abU[src++]; } while (--bytes != 0); return(dst); }
public ByteMemoryArea Unpack(byte [] abC, Address addrLoad) { // Extract the LZ stuff. EndianImageReader rdr = new LeImageReader(abC, (uint)lzHdrOffset); lzIp = rdr.ReadLeUInt16(); lzCs = rdr.ReadLeUInt16(); ushort lzSp = rdr.ReadLeUInt16(); ushort lzSs = rdr.ReadLeUInt16(); ushort lzcpCompressed = rdr.ReadLeUInt16(); ushort lzcpDecompressed = rdr.ReadLeUInt16(); // Find the start of the compressed stream. int ifile = lzHdrOffset - (lzcpCompressed << 4); // Allocate space for the decompressed goo. int cbUncompressed = ((int)lzcpDecompressed + lzcpDecompressed) << 4; byte [] abU = new byte[cbUncompressed]; // Decompress this sorry mess. int len; int span; int p = 0; BitStream bits = new BitStream(abC, ifile); for (;;) { if (bits.GetBit() != 0) { // 1.... abU[p++] = bits.GetByte(); continue; } if (bits.GetBit() == 0) { // 00..... len = bits.GetBit() << 1; len |= bits.GetBit(); len += 2; span = bits.GetByte() | ~0xFF; } else { // 01..... span = bits.GetByte(); len = bits.GetByte();; span |= ((len & ~0x07) << 5) | ~0x1FFF; len = (len & 0x07) + 2; if (len == 2) { len = bits.GetByte(); if (len == 0) { break; // end mark of compressed load module } if (len == 1) { continue; // segment change } else { ++len; } } } for ( ; len > 0; --len, ++p) { abU[p] = abU[p + span]; } } // Create a new image based on the uncompressed data. this.imgLoaded = new ByteMemoryArea(addrLoad, abU); this.segmentMap = new SegmentMap( addrLoad, new ImageSegment("", this.imgLoaded, AccessMode.ReadWriteExecute)); return(imgLoaded); }
public override Program Load(Address addrLoad) { uint dst = PspSize; for (;;) { if (bitStm.GetBit() == 0) { abU[dst++] = bitStm.GetByte(); continue; } // Read span length int CX = 0; int BX = bitStm.AccumulateBit(0); // bx= [0-1] BX = bitStm.AccumulateBit(BX); // bx= [0-3] if (BX < 0x02) { BX = bitStm.AccumulateBit(BX); // bx=[0-3] if (BX != 0) { BX = bitStm.AccumulateBit(BX); // bx=[2-7] if (BX >= 0x05) { BX = bitStm.AccumulateBit(BX); // bx=[0xA - 0xF] if (BX > 0x0C) { BX &= 0x03; BX = bitStm.AccumulateBit(BX); if (BX >= 0x05) { BX = bitStm.AccumulateBit(BX); if (BX > 0x0C) { BX = BX & 0x03; BX = bitStm.AccumulateBit(BX); if (BX >= 0x05) { BX = bitStm.AccumulateBit(BX); } CX = ab0211[BX + 0x0B]; goto l00C5; } } CX = ab0211[BX]; if (CX != 0x19) { goto l00C5; } byte AL = bitStm.GetByte(); CX += AL; if (AL < 0xFE) { goto l00C5; } /* * ES = ES + ((DI - 0x2000) >> 4); * DI = (DI & 0F) + 0x2000; * * DS = DS + (SI >> 4); * SI = SI & 0x0F; * DS = DS + BX; * */ if (AL == 0xFF) // done! { goto l01C8; } continue; } } } BX = ab0206[BX]; } CX = BX; // Read offset in dictionary. l00C5: BX = 0; if (CX == +02) { dst = CopyDictionaryWord(abU, BX, CX, bitStm, dst); continue; } if (bitStm.GetBit() != 0) { dst = CopyDictionaryWord(abU, BX, CX, bitStm, dst); continue; } BX = bitStm.AccumulateBit(BX); // bx: [0-1] BX = bitStm.AccumulateBit(BX); // bx: [0-3] BX = bitStm.AccumulateBit(BX); // bx: [0-7] if (BX < 02) { dst = CopyDictionaryWord2(abU, BX, CX, bitStm, dst); continue; } BX = bitStm.AccumulateBit(BX); if (BX < 08) { dst = CopyDictionaryWord2(abU, BX, CX, bitStm, dst); continue; } BX = bitStm.AccumulateBit(BX); if (BX < 0x17) { dst = CopyDictionaryWord2(abU, BX, CX, bitStm, dst); continue; } BX = bitStm.AccumulateBit(BX); BX = (BX & 0x00DF) << 8; dst = CopyDictionaryWord(abU, BX, CX, bitStm, dst); continue; } /* * l01C8: * 5B POP BX * 2DE9:01C9 8BEB MOV BP,BX // unpackedBase * 2DE9:01CB 83C310 ADD BX,+10 // BX => unpackedBase + 0x100 */ l01C8: imgU = new ByteMemoryArea(addrLoad, abU); segmentMap = new SegmentMap(imgU.BaseAddress, new ImageSegment("image", imgU, AccessMode.ReadWriteExecute)); return(new Program(segmentMap, arch, platform)); }
public uint CopyDictionaryWord(byte [] abU, int offset, int bytes, BitStream stm, uint dst) { offset |= stm.GetByte(); var src = dst - offset; do { abU[dst++] = abU[src++]; } while (--bytes != 0); return dst; }
public LoadedImage Unpack(byte [] abC, Address addrLoad) { // Extract the LZ stuff. ImageReader rdr = new LeImageReader(abC, (uint) lzHdrOffset); lzIp = rdr.ReadLeUInt16(); lzCs = rdr.ReadLeUInt16(); ushort lzSp = rdr.ReadLeUInt16(); ushort lzSs = rdr.ReadLeUInt16(); ushort lzcpCompressed = rdr.ReadLeUInt16(); ushort lzcpDecompressed = rdr.ReadLeUInt16(); // Find the start of the compressed stream. int ifile = lzHdrOffset - (lzcpCompressed << 4); // Allocate space for the decompressed goo. int cbUncompressed = ((int) lzcpDecompressed + lzcpDecompressed) << 4; byte [] abU = new byte[cbUncompressed]; // Decompress this sorry mess. int len; int span; int p = 0; BitStream bits = new BitStream(abC, ifile); for (;;) { if (bits.GetBit() != 0) { // 1.... abU[p++] = bits.GetByte(); continue; } if (bits.GetBit() == 0) { // 00..... len = bits.GetBit() << 1; len |= bits.GetBit(); len += 2; span = bits.GetByte() | ~0xFF; } else { // 01..... span = bits.GetByte(); len = bits.GetByte();; span |= ((len & ~0x07)<<5) | ~0x1FFF; len = (len & 0x07) + 2; if (len == 2) { len = bits.GetByte(); if (len == 0) break; // end mark of compressed load module if (len == 1) continue; // segment change else ++len; } } for( ;len > 0; --len, ++p) { abU[p] = abU[p+span]; } } // Create a new image based on the uncompressed data. this.imgLoaded = new LoadedImage(addrLoad, abU); this.imageMap = imgLoaded.CreateImageMap(); return imgLoaded; }