Esempio n. 1
0
        private static libtysila.tydb.Function GetFunction(ref string symbol_name, ulong pc, ref ulong offset)
        {
            if (Program.functions.ContainsKey(symbol_name) && (Program.functions[symbol_name].GetILOffsetFromCompiledOffset((int)offset) != -1))
            {
                return(Program.functions[symbol_name]);
            }

            if (Program.functions_from_text_offset.ContainsKey(pc))
            {
                return(Program.functions_from_text_offset[pc]);
            }

            Program.functions_from_text_offset.Add(pc, new libtysila.tydb.Function());
            int idx = Program.functions_from_text_offset.IndexOfKey(pc);

            Program.functions_from_text_offset.RemoveAt(idx);

            if (idx == 0)
            {
                return(null);
            }

            libtysila.tydb.Function ret = Program.functions_from_text_offset.Values[idx - 1];
            offset      = offset - ret.TextOffset;
            symbol_name = ret.MangledName;
            return(ret);
        }
Esempio n. 2
0
        internal static state get_state()
        {
            bool cont = true;

            s = new state();

            while (cont)
            {
                string msg = comm.gdb_read_message();

                if (msg.StartsWith("T"))
                {
                    interpret_t_message(msg, s);
                    cont = false;
                }
                else if (msg.StartsWith("S"))
                {
                    interpret_s_message(msg, s);
                    cont = false;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Invalid message: " + msg);
                }
            }

            ulong?pc = get_register(s, Program.arch.PC_id);

            if (pc.HasValue)
            {
                s.pc = pc.Value;

                string symbol_name;
                ulong  offset;
                symbol_name = mem.get_symbol(pc.Value, out offset);

                s.offset   = offset;
                s.sym_name = symbol_name;

                // provide a dissassembly
                if (Program.arch.disasm != null)
                {
                    s.disasm = Program.arch.disasm.GetNextLine(new RemoteByteProvider(pc.Value));
                }

                // get the source
                libtysila.tydb.Function t_f = GetFunction(ref s.sym_name, pc.Value, ref s.offset);
                if (t_f != null)
                {
                    s.pefile = t_f.MetadataFileName;
                    int  il_offset = t_f.GetILOffsetFromCompiledOffset((int)s.offset);
                    uint m_tok     = t_f.MetadataToken;

                    s.ty_f      = t_f;
                    s.il_offset = il_offset;
                    s.m_tok     = m_tok;
                    if (Program.cci_int != null)
                    {
                        s.source = Program.cci_int.GetSourceLineFromToken(m_tok, (uint)il_offset);
                    }
                }
            }

            return(s);
        }
Esempio n. 3
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);
        }