Exemple #1
0
        public List <MinSym> Enum(string arg)
        {
            IDiaEnumSymbols EnumSymbols    = null;
            IDiaSymbol      Master         = null;
            int             level          = 2;
            uint            compileFetched = 0;

            var rv = new List <MinSym>();

            var foo = new Dia2Lib.DiaSource();

            foo.loadDataForExe(arg, SymPath, null);
            foo.openSession(out Session);

            if (Session == null)
            {
                return(null);
            }

            Session.loadAddress = 0;

            var GlobalScope = Session.globalScope;



#if BLAH_FIX_SOMETIME
            // reflection & CCW not exactally match made in heaven?


            //do
            //{
            //    try
            //    {
            //        Session.findChildren(Session.globalScope, SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
            //        var tot1 = EnumSymbols.count;
            //        uint curr1 = 0;
            //        do
            //        {
            //            EnumSymbols.Next(1, out Master, out compileFetched);
            //            if (Master == null)
            //                continue;
            //            ForegroundColor = ConsoleColor.White;
            //            foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
            //            {
            //                WriteLine($"{pr.Name} = {pr.GetValue(Master)}");
            //            }
            //            //foreach (var fn in typeof(IDiaSymbol).LinqPublicFunctions())
            //            //{
            //            //    //if (fn.Name.Contains("get"))
            //            //        WriteLine($"{fn.Name} = {fn.Invoke(Master, null)}");
            //            //}
            //            // DumpSymbol<IDiaSymbol>(Master, ref level);
            //        } while (curr1++ < tot1);
            //        //foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
            //        //    WriteLine($"{pr.Name} = {pr.GetValue(Master)}");
            //    }
            //    catch { }
            //    finally
            //    {
            //        if (Master != null)
            //            rva += (uint)(Master.length == 0 ? 1 : Master.length);
            //    }

            //} while (Master != null);


            IDiaEnumDebugStreams DebugStreams;

            /*
             * Session.getEnumDebugStreams(out DebugStreams);
             * for (int i = 0; i < DebugStreams.count; i++)
             * {
             *  var ds = DebugStreams.Item(i);
             * //    foreach (var pr in typeof(IDiaEnumDebugStreamData).LinqPublicProperties())
             * //        WriteLine($"{pr.Name} = {pr.GetValue(ds)}");
             * }
             *
             * Session.getEnumTables(out tables);
             * for (int i = 0; i < tables.count; i++)
             * {
             *  var ds = tables.Item(i);
             * //    foreach (var pr in typeof(IDiaTable).LinqPublicProperties())
             * //        WriteLine($"{pr.Name} = {pr.GetValue(ds)}");
             * }
             */
#endif

            GlobalScope.findChildren(SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
            var tot = EnumSymbols.count;
            do
            {
                EnumSymbols.Next(1, out Master, out compileFetched);
                if (Master == null)
                {
                    continue;
                }

                ForegroundColor = ConsoleColor.White;

                foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                {
                    WriteLine($"{pr.Name} = {pr.GetValue(Master)}");
                }

                var subList = DumpSymbol <IDiaSymbol>(Master, level);
                rv.AddRange(subList);
            } while (compileFetched == 1);

            rv.Sort();

            return(rv);
        }
Exemple #2
0
        public int Enum(string arg)
        {
            IDiaEnumSymbols EnumSymbols    = null;
            IDiaSymbol      Master         = null;
            IDiaEnumTables  tables         = null;
            int             level          = 2;
            uint            compileFetched = 0;

            //DebugHelp.SymFindDebugInfoFile(hCurrentProcess, SymPath, arg, )

            var foo = new Dia2Lib.DiaSource();

            foo.loadDataForExe(arg, SymPath, null);
            //foo.loadDataFromPdb(arg);
            foo.openSession(out Session);

            if (Session == null)
            {
                return(-1);
            }

            Session.loadAddress = 0;
            uint rva = 0;

            //do
            //{
            //    try
            //    {
            //        Session.findChildren(Session.globalScope, SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
            //        var tot1 = EnumSymbols.count;
            //        uint curr1 = 0;
            //        do
            //        {
            //            EnumSymbols.Next(1, out Master, out compileFetched);
            //            if (Master == null)
            //                continue;

            //            ForegroundColor = ConsoleColor.White;

            //            foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
            //            {
            //                WriteLine($"{pr.Name} = {pr.GetValue(Master)}");
            //            }

            //            //foreach (var fn in typeof(IDiaSymbol).LinqPublicFunctions())
            //            //{
            //            //    //if (fn.Name.Contains("get"))
            //            //        WriteLine($"{fn.Name} = {fn.Invoke(Master, null)}");
            //            //}
            //            // DumpSymbol<IDiaSymbol>(Master, ref level);

            //        } while (curr1++ < tot1);



            //        //foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
            //        //    WriteLine($"{pr.Name} = {pr.GetValue(Master)}");
            //    }
            //    catch { }
            //    finally
            //    {
            //        if (Master != null)
            //            rva += (uint)(Master.length == 0 ? 1 : Master.length);
            //    }

            //} while (Master != null);



            var GlobalScope = Session.globalScope;

            IDiaEnumDebugStreams DebugStreams;

            Session.getEnumDebugStreams(out DebugStreams);
            for (int i = 0; i < DebugStreams.count; i++)
            {
                var ds = DebugStreams.Item(i);
                foreach (var pr in typeof(IDiaEnumDebugStreamData).LinqPublicProperties())
                {
                    WriteLine($"{pr.Name} = {pr.GetValue(ds)}");
                }
            }

            Session.getEnumTables(out tables);
            for (int i = 0; i < tables.count; i++)
            {
                var ds = tables.Item(i);
                foreach (var pr in typeof(IDiaTable).LinqPublicProperties())
                {
                    WriteLine($"{pr.Name} = {pr.GetValue(ds)}");
                }
            }
            GlobalScope.findChildren(SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
            var tot  = EnumSymbols.count;
            var curr = 0;

            do
            {
                EnumSymbols.Next(1, out Master, out compileFetched);
                if (Master == null)
                {
                    continue;
                }

                ForegroundColor = ConsoleColor.White;

                //foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                //WriteLine($"{pr.Name} = {pr.GetValue(Master)}");

                DumpSymbol <IDiaSymbol>(Master, level);
            } while (curr++ < tot);

            return(0);
        }
Exemple #3
0
        public List <MinSym> EnumSymsInFileWithVAOrder(string arg, ulong BaseVA, ulong Length)
        {
            IDiaSymbol Master = null;
            var        rv     = new List <MinSym>();

            var foo = new Dia2Lib.DiaSource();

            foo.loadDataForExe(arg, SymPath, null);
            foo.openSession(out Session);

            if (Session == null)
            {
                return(null);
            }

            Session.loadAddress = BaseVA;

            var    CurrVA = BaseVA;
            var    End    = BaseVA + Length;
            MinSym last   = null;

            do
            {
                Session.findSymbolByVA(CurrVA, SymTagEnum.SymTagNull, out Master);
                var len = Master.length > 0 ? Master.length : 8;


                var s = new MinSym()
                {
                    Address = CurrVA,
                    Length  = len,
                    Name    = Master.name,
                    ID      = Master.symIndexId,
                    UDName  = (!string.IsNullOrWhiteSpace(Master.undecoratedName) && Master.name != Master.undecoratedName) ? Master.undecoratedName : string.Empty,
                };


                if (last != null
                    &&
                    // if the ID is the same
                    ((last.ID == s.ID)
                     ||
                     // also if the name and the last name are empty even if the ID is diff, treat them as the same
                     (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(last.Name))))
                {
                    // grow the length if the most recent symbol in the list
                    last.Length += s.Length;
                }
                else
                {
                    // otherwise add the new thing to the list
                    rv.Add(s);
                    last = s;
                }

                CurrVA += len;

#if DEBUGGING_STUFF
                /* DEBUGGING
                 * ForegroundColor = ConsoleColor.Cyan;
                 *
                 * Write($"Name: [{Master.name}] Address: [{CurrVA:X}] Length: [{Master.length}] ");
                 * if (string.IsNullOrWhiteSpace(Master.name) && Master.name != Master.undecoratedName)
                 * {
                 *  ForegroundColor = ConsoleColor.White;
                 *  WriteLine($"UDName: [{Master.undecoratedName}]");
                 * }
                 * else
                 *  WriteLine(String.Empty);
                 */
                //foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                //    WriteLine($"{pr.Name} = {pr.GetValue(Master)}");

                /*
                 * Session.findChildren(Master, SymTagEnum.SymTagNull, null, 0, out EnumSymbols);
                 * if (EnumSymbols == null)
                 *  continue;
                 *
                 * var tot1 = EnumSymbols.count;
                 * int cnt = 0;
                 *
                 * ForegroundColor = ConsoleColor.White;
                 *
                 * do {
                 *  cnt++;
                 *  EnumSymbols.Next(1, out Sub, out compileFetched);
                 *  if (Sub == null)
                 *      continue;
                 *
                 *  WriteLine($"Name: [{Sub.name}] UName: [{Sub.undecoratedName}] Length: [{Sub.length}]");
                 *
                 *  foreach (var pr in typeof(IDiaSymbol).LinqPublicProperties())
                 *      WriteLine($"{pr.Name} = {pr.GetValue(Sub)}");
                 *  foreach (var fn in typeof(IDiaSymbol).LinqPublicFunctions())
                 *  {
                 *     if (fn.Name.Contains("get"))
                 *      WriteLine($"{fn.Name} = {fn.Invoke(Sub, null)}");
                 *  }
                 * } while (cnt < tot1);
                 */
#endif
            } while (CurrVA < End);

            return(rv);
        }