Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
 public virtual void show_reloc_hunk(RelocHunk hunk)
 {
     var reloc = hunk.reloc;
     foreach (var hunkNo in reloc.Keys)
     {
         var offsets = reloc[hunkNo];
         if (this.show_relocs)
         {
             foreach (var offset in offsets)
             {
                 this.print_symbol(offset, String.Format("Segment {0}", hunkNo), "");
             }
         }
         else
         {
             this.print_extra_sub(String.Format("To Segment #{0}: {1,4} entries", hunkNo, offsets));
         }
     }
 }
Ejemplo n.º 3
0
 public RelocHunk ParseReloc(Action<Hunk> fn)
 {
     var hunk = new RelocHunk();
     fn(hunk);
     var num_relocs = 1;
     var reloc = new Dictionary<int, List<uint>>();
     hunk.reloc = reloc;
     while (num_relocs != 0)
     {
         num_relocs = this.read_long();
         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
             break;
         }
         // build reloc map
         var hunkNo = this.read_long();
         if (hunkNo < 0)
             throw new BadImageFormatException(string.Format("{0} has invalid hunk num.", hunk.HunkType));
         Debug.WriteLineIf(trace.TraceVerbose, string.Format("  hunk: {0}, relocs: {1}", hunkNo, num_relocs));
         var offsets = new List<uint>();
         num_relocs &= 0xFFFF;
         for (var a = 0; a < num_relocs; ++a)
         {
             var offset = this.read_long();
             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;
     }
     return hunk;
 }