コード例 #1
0
        public void ParseExt(Action <Hunk> h)
        {
            var hunk = new ExtHunk();

            h(hunk);
            var ext_def    = new List <ExtObject>();
            var ext_ref    = new List <ExtObject>();
            var ext_common = new List <ExtObject>();

            hunk.ext_def    = ext_def;
            hunk.ext_ref    = ext_ref;
            hunk.ext_common = ext_common;
            var ext_size = 1;

            while (ext_size > 0)
            {
                // ext type | size
                var ext_type_size = this.read_long();
                var ext_type      = (ExtType)(byte)(ext_type_size >> (int)ExtType.EXT_TYPE_SHIFT);
                ext_size = ext_type_size & (int)ExtType.EXT_TYPE_SIZE_MASK;
                if (ext_size < 0)
                {
                    throw new BadImageFormatException(string.Format("{0} has invalid size.", hunk.HunkType));
                }
                // ext name
                string ext_name = this.ReadSizedString(ext_size);
                if (ext_name == null)
                {
                    throw new BadImageFormatException(string.Format("{0} has invalid name.", hunk.HunkType));
                }
                else if (ext_name.Length == 0)
                {
                    break;
                }

                // create local ext object
                var ext = new ExtObject {
                    type = ext_type, name = ext_name
                };

                // check and setup type name
                if (!ext_names.ContainsKey(ext_type))
                {
                    throw new BadImageFormatException(string.Format("{0} has unspported ext entry {1}.", hunk.HunkType, ext_type));
                }
                // ext common
                if (ext_type == ExtType.EXT_ABSCOMMON || ext_type == ExtType.EXT_RELCOMMON)
                {
                    ext.common_size = (uint)this.read_long();
                    ext_common.Add(ext);
                    // ext def
                }
                else if (ext_type == ExtType.EXT_DEF || ext_type == ExtType.EXT_ABS || ext_type == ExtType.EXT_RES)
                {
                    ext.def = f.ReadBeUInt32();
                    ext_def.Add(ext);
                }
                else
                {
                    // ext ref
                    var num_refs = this.read_long();
                    if (num_refs == 0)
                    {
                        num_refs = 1;
                    }
                    var refs = new List <uint>();
                    for (int a = 0; a < num_refs; ++a)
                    {
                        var @ref = f.ReadBeUInt32();
                        refs.Add(@ref);
                    }
                    ext.refs = refs;
                    ext_ref.Add(ext);
                }
            }
        }
コード例 #2
0
ファイル: HunkFileParser.cs プロジェクト: gitter-badger/reko
        public void ParseExt(Action<Hunk> h)
        {
            var hunk = new ExtHunk();
            h(hunk);
            var ext_def = new List<ExtObject>();
            var ext_ref = new List<ExtObject>();
            var ext_common = new List<ExtObject>();
            hunk.ext_def = ext_def;
            hunk.ext_ref = ext_ref;
            hunk.ext_common = ext_common;
            var ext_type_size = 1;
            while (ext_type_size > 0)
            {
                // ext type | size
                ext_type_size = this.read_long();
                if (ext_type_size < 0)
                    throw new BadImageFormatException(string.Format("{0} has invalid size.", hunk.HunkType));
                var ext_type = (ExtType) (ext_type_size >> (int) ExtType.EXT_TYPE_SHIFT);
                var ext_size = ext_type_size & (int) ExtType.EXT_TYPE_SIZE_MASK;
                // ext name
                string ext_name = this.ReadSizedString(ext_size);
                if (ext_name == null)
                    throw new BadImageFormatException(string.Format("{0} has invalid name.", hunk.HunkType));
                else if (ext_name.Length == 0)
                    break;
                
                // create local ext object
                var ext = new ExtObject { type = ext_type, name = ext_name };

                // check and setup type name
                if (!ext_names.ContainsKey(ext_type))
                    throw new BadImageFormatException(string.Format("{0} has unspported ext entry {1}.", hunk.HunkType, ext_type));
                // ext common
                if (ext_type == ExtType.EXT_ABSCOMMON || ext_type == ExtType.EXT_RELCOMMON)
                {
                    ext.common_size = (uint) this.read_long();
                    ext_common.Add(ext);
                    // ext def
                }
                else if (ext_type == ExtType.EXT_DEF || ext_type == ExtType.EXT_ABS || ext_type == ExtType.EXT_RES)
                {
                    ext.def = f.ReadBeUInt32();
                    ext_def.Add(ext);
                }
                else
                {
                    // ext ref
                    var num_refs = this.read_long();
                    if (num_refs == 0)
                    {
                        num_refs = 1;
                    }
                    var refs = new List<uint>();
                    for (int a = 0; a < num_refs; ++a)
                    {
                        var @ref = f.ReadBeUInt32();
                        refs.Add(@ref);
                    }
                    ext.refs = refs;
                    ext_ref.Add(ext);
                }
            }
        }