Beispiel #1
0
 private void write(List<byte> lines, libtysila.tydb.Line line)
 {
     byte[] buf = new byte[8];
     write(buf, 0, line.ILOffset);
     write(buf, 4, line.CompiledOffset);
     lines.AddRange(buf);
 }
Beispiel #2
0
        public static TyDbFile Read(Stream s)
        {
            TyDbFile ret = new TyDbFile();

            reader_s = s;

            uint magic = ReadUInt(s);

            if (magic != 0x42445954)
            {
                throw new Exception("Invalid magic number");
            }

            uint version = ReadUInt(s);

            if (version != 0x00000001)
            {
                throw new Exception("Invalid version");
            }

            int funcs_offset   = ReadInt(s);
            int lines_offset   = ReadInt(s);
            int varargs_offset = ReadInt(s);

            reader_strings_offset = ReadInt(s);
            int locs_offset = ReadInt(s);
            int func_count  = ReadInt(s);

            ret.CompiledFileName = ReadString(s);

            s.Seek((long)funcs_offset, SeekOrigin.Begin);
            for (int i = 0; i < func_count; i++)
            {
                long f_offset = s.Position;

                libtysila.tydb.Function f = new libtysila.tydb.Function();
                f.MetadataFileName = ReadString(s);
                f.MetadataToken    = ReadUInt(s);
                f.MangledName      = ReadString(s);
                f.TextOffset       = ReadUInt(s);

                int line_start = ReadInt(s);
                int line_count = ReadInt(s);
                int var_start  = ReadInt(s);
                int var_count  = ReadInt(s);
                int arg_start  = ReadInt(s);
                int arg_count  = ReadInt(s);

                for (int j = 0; j < line_count; j++)
                {
                    s.Seek((long)(lines_offset + line_start + j * 8), SeekOrigin.Begin);

                    libtysila.tydb.Line l = new libtysila.tydb.Line();
                    l.ILOffset       = ReadInt(s);
                    l.CompiledOffset = ReadInt(s);
                    f.Lines.Add(l);

                    if (!f.compiled_to_il.ContainsKey(l.CompiledOffset))
                    {
                        f.compiled_to_il[l.CompiledOffset] = l.ILOffset;
                    }
                }

                for (int j = 0; j < var_count; j++)
                {
                    s.Seek((long)(varargs_offset + var_start + j * 8), SeekOrigin.Begin);

                    libtysila.tydb.VarArg v = new libtysila.tydb.VarArg();
                    v.Name     = ReadString(s);
                    v.Location = ReadLocation(s, locs_offset, ReadInt(s));
                    f.Vars.Add(v);
                }

                for (int j = 0; j < arg_count; j++)
                {
                    s.Seek((long)(varargs_offset + arg_start + j * 8), SeekOrigin.Begin);

                    libtysila.tydb.VarArg a = new libtysila.tydb.VarArg();
                    a.Name     = ReadString(s);
                    a.Location = ReadLocation(s, locs_offset, ReadInt(s));
                    f.Args.Add(a);
                }

                ret.Functions.Add(f);

                s.Seek(f_offset + 40, SeekOrigin.Begin);
            }

            return(ret);
        }