Пример #1
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);
        }