Exemplo n.º 1
0
        private int GetRunLengthValue(BeImageReader a5dr, ref int a5repeat)
        {
            // Run length returned is in byte(s).
            // next byte read - see bit pattern from the following table for the return value
            // 0xxxxxxx - 0 - $7F
            // 10xxxxxx - 0 - $3FFF(run length and $3F + next byte, 14 bits)
            // 110xxxxx - 0 - $1FFFFF(run length and $1F + next two bytes, 21 bits)
            // 1110xxxx - next 4 bytes, 32 bits
            // 1111xxxx - get both new runtime length copy in bytes and new runtime length repeat count

            int runLength = a5dr.ReadByte();

            if ((runLength & 0x80) == 0)
            {
                return(runLength);
            }
            if ((runLength & 0x40) == 0)
            {
                runLength = runLength & 0x3F;
                runLength = (runLength << 8) + a5dr.ReadByte();
                return(runLength);
            }
            if ((runLength & 0x20) == 0)
            {
                runLength = runLength & 0x1F;
                runLength = (runLength << 16) + a5dr.ReadBeInt16();
                return(runLength);
            }
            if ((runLength & 0x10) == 0)
            {
                return(a5dr.ReadBeInt32());
            }
            runLength = GetRunLengthValue(a5dr, ref a5repeat);
            a5repeat  = GetRunLengthValue(a5dr, ref a5repeat);
            return(runLength);
        }
Exemplo n.º 2
0
        public void ParseRelocShort(Action <Hunk> h)
        {
            var hunk = new RelocHunk();

            h(hunk);

            var num_relocs = 1;
            var reloc      = new Dictionary <int, List <uint> >();

            hunk.reloc = reloc;
            var total_words = 0;

            while (num_relocs != 0)
            {
                num_relocs = this.read_word(f);
                if (num_relocs < 0)
                {
                    throw new BadImageFormatException(string.Format("{0} has invalid number of relocations.", hunk.HunkType));
                }
                else if (num_relocs == 0)
                {
                    // last relocation found
                    ++total_words;
                    break;
                }
                // build reloc map
                var hunkNo = this.read_word(f);
                if (hunkNo < 0)
                {
                    throw new BadImageFormatException(string.Format("{0} has invalid hunk num.", hunk.HunkType));
                }
                var offsets = new List <uint>();
                var count   = num_relocs & 0xFFFF;
                total_words += count + 2;
                for (var a = 0; a < count; ++a)
                {
                    var offset = f.ReadBeInt16();
                    if (offset < 0)
                    {
                        throw new BadImageFormatException(string.Format(
                                                              "{0} has invalid relocation #{1} offset {2} (num_relocs={3} hunkNo={4}, offset={5}).", hunk.HunkType, a, offset, num_relocs, hunkNo, f.Offset));
                    }
                    offsets.Add((uint)offset);
                }
                reloc[hunkNo] = offsets;
                // padding
            }
            if ((total_words & 1) == 1)
            {
                f.ReadBeInt16();
            }
        }