Esempio n. 1
0
        //============================================================================
        // load
        //============================================================================
        public bool load(string filename)
        {
            DbgHelp.SymSetOptions(DbgHelp.SymOpt.UNDNAME);

            hProcess = new IntPtr(0);
            if (!DbgHelp.SymInitialize(hProcess, "", false))
            {
                Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                return(false);
            }

            IntPtr pZero = new IntPtr(0);

            DbgHelp.MODLOAD_DATA modLoadDat = new DbgHelp.MODLOAD_DATA();

            pvModuleBase = (UInt64)DbgHelp.SymLoadModuleEx(hProcess, pZero, filename, null, 0, 0, modLoadDat, 0);
            if (pvModuleBase == 0)
            {
                Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                return(false);
            }

            pvModuleBase = (UInt64)((UInt32)(pvModuleBase));


            //enumerate symbols
            DbgHelp.SymEnumSymbolsProc enumSymbolsCB = new DbgHelp.SymEnumSymbolsProc(this.enumSymbolsCallback);

            System.Runtime.InteropServices.GCHandle gch = System.Runtime.InteropServices.GCHandle.Alloc(enumSymbolsCB);
            IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(enumSymbolsCB);

            DbgHelp.SymEnumSymbolsProc cb = null;
            bool OK = true;

            unsafe
            {
                //    cb = (ip.ToPointer() as DbgHelp.SymEnumSymbolsProc);
                //    OK = DbgHelp.SymEnumSymbols(hProcess, pvModuleBase, null, cb, pZero);//pvModuleBase);
            }



            if (!OK)
            {
                Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                return(false);
            }
            while (true)
            {
            }
            ;

            //enumerate lines
            //OK = DbgHelp.SymEnumLines(hProcess, pvModuleBase, null, null, enumLinesCallback, hProcess);
            //if (!OK)
            //{
            //   Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
            //   return false;
            //}


            return(true);
        }
Esempio n. 2
0
        //============================================================================
        // load
        //============================================================================
        public bool init(int procHandle, string filename)
        {
            hProcess = (uint)procHandle;

            bool dointrusive = false;

            if (mDoEnumerate)
            {
                dointrusive = false;
                DbgHelp.SymSetOptions(DbgHelp.SymOpt.UNDNAME);
            }
            else
            {
                dointrusive = false;// true;
                DbgHelp.SymSetOptions(DbgHelp.SymOpt.LOAD_LINES);
            }

            string pathToPDB = Path.GetDirectoryName(filename);

            if (!DbgHelp.SymInitialize(hProcess, pathToPDB, dointrusive))
            {
                Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                return(false);
            }

            IntPtr pZero = new IntPtr(0);

            DbgHelp.MODLOAD_DATA modLoadDat = new DbgHelp.MODLOAD_DATA();

            ///////////////////////////////////////////////
            //load module
            pvModuleBase = (UInt64)DbgHelp.SymLoadModuleEx(hProcess, pZero, filename, null, 0, 0, modLoadDat, 0);
            if (pvModuleBase == 0)
            {
                Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                return(false);
            }

            pvModuleBase = (UInt64)((UInt32)(pvModuleBase));


            /////////////////ENUMERATION

            if (mDoEnumerate)
            {
                ///////////////////////////////////////////////
                //enumerate lines
                bool OK = DbgHelp.SymEnumLines(hProcess, pvModuleBase, null, null, enumLinesCallback, pZero);
                if (!OK)
                {
                    Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                    return(false);
                }

                mAddressHash.sortList();
                ///////////////////////////////////////////////
                //enumerate symbols
                //OK = DbgHelp.SymEnumSymbols(hProcess, pvModuleBase, null, enumSymbolsCallback, pZero);//pvModuleBase);
                //if (!OK)
                //{
                //   Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                //   return false;
                //}
            }



            return(true);
        }