Esempio n. 1
0
        public HeaderHunk ParseHeader(Action <Hunk> h)
        {
            var hunk = new HeaderHunk();

            h(hunk);
            var names = new List <string>();

            hunk.HunkNames = names;
            while (true)
            {
                var t = this.ReadString();
                if (t == null)
                {
                    throw new BadImageFormatException("Error parsing header hunk names.");
                }
                else if (t.Length == 0)
                {
                    break;
                }
                names.Add(t);
            }

            // Table size and hunk range
            var table_size = f.ReadBeInt32();
            var first_hunk = f.ReadBeInt32();
            var last_hunk  = f.ReadBeInt32();

            if (table_size < 0 || first_hunk < 0 || last_hunk < 0)
            {
                throw new BadImageFormatException("Invalid header hunk.");
            }

            hunk.table_size  = table_size;
            hunk.FirstHunkId = first_hunk;
            hunk.LastHunkId  = last_hunk;

            // Determine number of hunks in size table
            int num_hunks = last_hunk - first_hunk + 1;
            var hunkInfos = new List <HunkInfo>();

            for (int a = 0; a < num_hunks; ++a)
            {
                var hunk_info = new HunkInfo();
                int hunk_size = this.read_long();
                hunk_size &= 0x3FFFFFFF;           // Top 2 bits not handled yet.
                if (hunk_size < 0)
                {
                    throw new BadImageFormatException("Head hunk contains invalid hunk_size.");
                }
                int hunk_bytes = (hunk_size & ~Hunk.HUNKF_ALL) * 4;
                hunk_info.Size  = hunk_bytes;
                hunk_info.Flags = this.SetMemoryFlags(hunk_size & Hunk.HUNKF_ALL, 30);
                hunkInfos.Add(hunk_info);
            }
            hunk.HunkInfos = hunkInfos;
            return(hunk);
        }
Esempio n. 2
0
 public HunkFile()
 {
     this.type             = FileType.TYPE_UNKNOWN;
     this.hunks            = new List <Hunk>();
     this.header           = null;
     this.segments         = new List <List <Hunk> >();
     this.overlay          = null;
     this.overlay_headers  = null;
     this.overlay_segments = null;
     this.libs             = null;
     this.units            = null;
 }
Esempio n. 3
0
        public HunkFile()
        {
            this.type = FileType.TYPE_UNKNOWN;
            this.hunks = new List<Hunk>();
            this.header = null;
            this.segments = new List<List<Hunk>>();
            this.overlay = null;
            this.overlay_headers = null;
            this.overlay_segments = null;
            this.libs = null;
            this.units = null;

        }
Esempio n. 4
0
 public HunkShow(HunkFile hunk_file, bool show_relocs = false, bool show_debug = false, bool disassemble = false, uint disassemble_start = 0, bool hexdump = false, bool brief = false, bool use_objdump = false, string cpu = "68000")
 {
     this.hunk_file = hunk_file;
     // clone file refs
     this.header = hunk_file.header;
     this.segments = hunk_file.segments;
     this.overlay = hunk_file.overlay;
     this.overlay_headers = hunk_file.overlay_headers;
     this.overlay_segments = hunk_file.overlay_segments;
     this.libs = hunk_file.libs;
     this.units = hunk_file.units;
     this.show_relocs = show_relocs;
     this.show_debug = show_debug;
     this.disassemble = disassemble;
     this.disassemble_start = disassemble_start;
     this.use_objdump = use_objdump;
     this.cpu = cpu;
     this.hexdump = hexdump;
     this.brief = brief;
 }
Esempio n. 5
0
 public virtual void print_header(HeaderHunk hdr)
 {
     Console.WriteLine("\t      header (segments: first={0}, last={1}, table size={2})", hdr.FirstHunkId, hdr.LastHunkId, hdr.table_size);
 }
Esempio n. 6
0
        public HeaderHunk ParseHeader(Action<Hunk> h)
        {
            var hunk = new HeaderHunk();
            h(hunk);
            var names = new List<string>();
            hunk.HunkNames = names;
            while (true)
            {
                var t = this.ReadString();
                if (t == null)
                    throw new BadImageFormatException("Error parsing header hunk names.");
                else if (t.Length == 0)
                {
                    break;
                }
                names.Add(t);
            }

            // Table size and hunk range
            var table_size = f.ReadBeInt32();
            var first_hunk = f.ReadBeInt32();
            var last_hunk = f.ReadBeInt32();
            if (table_size < 0 || first_hunk < 0 || last_hunk < 0)
                throw new BadImageFormatException("Invalid header hunk.");
            
            hunk.table_size = table_size;
            hunk.FirstHunkId = first_hunk;
            hunk.LastHunkId = last_hunk;

            // Determine number of hunks in size table
            int num_hunks = last_hunk - first_hunk + 1;
            var hunkInfos = new List<HunkInfo>();
            for (int a = 0; a < num_hunks; ++a)
            {
                var hunk_info = new HunkInfo();
                int hunk_size = this.read_long();
                hunk_size &= 0x3FFFFFFF;           // Top 2 bits not handled yet.
                if (hunk_size < 0)
                    throw new BadImageFormatException("Head hunk contains invalid hunk_size.");
                int hunk_bytes = (hunk_size & ~Hunk.HUNKF_ALL) * 4;
                hunk_info.Size = hunk_bytes;
                hunk_info.Flags = this.SetMemoryFlags(hunk_size & Hunk.HUNKF_ALL, 30);
                hunkInfos.Add(hunk_info);
            }
            hunk.HunkInfos = hunkInfos;
            return hunk;
        }