public PkLiteUnpacker(IServiceProvider services, string filename, byte [] rawImg) : base(services, filename, rawImg) { var exe = new ExeImageLoader(services, filename, rawImg); arch = new IntelArchitecture(ProcessorMode.Real); platform = new MsdosPlatform(services, arch); uint pkLiteHdrOffset = (uint) (exe.e_cparHeader * 0x10); if (RawImage[pkLiteHdrOffset] != 0xB8) throw new ApplicationException(string.Format("Expected MOV AX,XXXX at offset 0x{0:X4}.", pkLiteHdrOffset)); uint cparUncompressed = LoadedImage.ReadLeUInt16(RawImage, pkLiteHdrOffset + 1); abU = new byte[cparUncompressed * 0x10U]; if (RawImage[pkLiteHdrOffset + 0x04C] != 0x83) throw new ApplicationException(string.Format("Expected ADD BX,+XX at offset 0x{0:X4}.", pkLiteHdrOffset + 0x04C)); uint offCompressedData = pkLiteHdrOffset + RawImage[pkLiteHdrOffset + 0x04E] * 0x10u - PspSize; bitStm = new BitStream(RawImage, (int) offCompressedData); }
public PkLiteUnpacker(IServiceProvider services, string filename, byte [] rawImg) : base(services, filename, rawImg) { var exe = new ExeImageLoader(services, filename, rawImg); var cfgSvc = services.RequireService<IConfigurationService>(); this.arch = cfgSvc.GetArchitecture("x86-real-16"); platform = cfgSvc.GetEnvironment("ms-dos") .Load(services, arch); uint pkLiteHdrOffset = (uint) (exe.e_cparHeader * 0x10); if (RawImage[pkLiteHdrOffset] != 0xB8) throw new ApplicationException(string.Format("Expected MOV AX,XXXX at offset 0x{0:X4}.", pkLiteHdrOffset)); uint cparUncompressed = MemoryArea.ReadLeUInt16(RawImage, pkLiteHdrOffset + 1); abU = new byte[cparUncompressed * 0x10U]; if (RawImage[pkLiteHdrOffset + 0x04C] != 0x83) throw new ApplicationException(string.Format("Expected ADD BX,+XX at offset 0x{0:X4}.", pkLiteHdrOffset + 0x04C)); uint offCompressedData = pkLiteHdrOffset + RawImage[pkLiteHdrOffset + 0x04E] * 0x10u - PspSize; bitStm = new BitStream(RawImage, (int) offCompressedData); }
public uint CopyDictionaryWord2(byte [] abU, int BX, int bytes, BitStream stm, uint dst) { BX = (ushort) (ab022C[BX] << 8); return CopyDictionaryWord(abU, BX, bytes, stm, dst); }
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; }
public MemoryArea 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 MemoryArea(addrLoad, abU); this.segmentMap = new SegmentMap( addrLoad, new ImageSegment("", this.imgLoaded, AccessMode.ReadWriteExecute)); return imgLoaded; }