Exemplo n.º 1
0
        public static SModuleEntry32[] ListModule(IntPtr hModule)
        {
            FObjects <SModuleEntry32>  mes       = new FObjects <SModuleEntry32>();
            Nullable <SImageNtHeaders> ntHeaders = GetNtHeaders(hModule);
            SImageDataDirectory        idd       = ntHeaders.Value.OptionalHeader.DataDirectory[(int)EImageDirectoryEntry.Import];

            if (idd.VirtualAddress == 0)
            {
                return(mes.ToArray());
            }
            // Import
            uint   maddress  = (uint)hModule.ToInt32();
            IntPtr pIdHeader = (IntPtr)(maddress + idd.VirtualAddress);
            int    idSize    = Marshal.SizeOf(typeof(SImageImportDescriptor));

            while (true)
            {
                SImageImportDescriptor impDesc = (SImageImportDescriptor)Marshal.PtrToStructure(pIdHeader, typeof(SImageImportDescriptor));
                if (impDesc.Name == 0)
                {
                    break;
                }
                IntPtr         namePtr = (IntPtr)(maddress + impDesc.Name);
                SModuleEntry32 me      = new SModuleEntry32();
                me.modBaseAddr = impDesc.FirstThunk;
                me.szModule    = Marshal.PtrToStringAnsi(namePtr, 260);
                mes.Push(me);
                pIdHeader = (IntPtr)(pIdHeader.ToInt32() + idSize);
            }
            return(mes.ToArray());
        }
Exemplo n.º 2
0
        //============================================================
        // <T>刷新器。</T>
        //============================================================
        private void timRefresh_Tick(object sender, System.EventArgs e)
        {
            FObjects <FTrack> tracks = RMoCore.TrackConsole.Tracks;

            FTrack[] trackItems = null;
            lock (tracks) {
                trackItems = tracks.ToArray();
                tracks.Clear();
            }
            if (trackItems.Length > 0)
            {
                lvwTracks.BeginUpdate();
                foreach (FTrack track in trackItems)
                {
                    if (null != track)
                    {
                        ListViewItem lviTrack = new ListViewItem();
                        lviTrack.Text = track.Datetime.ToString();
                        lviTrack.SubItems.Add(track.Sender);
                        lviTrack.SubItems.Add(track.Message);
                        lvwTracks.Items.Add(lviTrack);
                    }
                }
                lvwTracks.EndUpdate();
                Show();
                BringToFront();
            }
        }
Exemplo n.º 3
0
        public FShellFolder[] ListFolder()
        {
            IntPtr ptr = IntPtr.Zero;

            if (_face.EnumObjects(_handle, EShcontf.Folders | EShcontf.IncludeHidden, out ptr) == RWinShell.S_OK)
            {
                IntPtr pidlSub;
                int    celtFetched;
                FObjects <FShellFolder> folders = new FObjects <FShellFolder>();
                IEnumIDList             list    = (IEnumIDList)Marshal.GetObjectForIUnknown(ptr);
                while (list.Next(1, out pidlSub, out celtFetched) == RWinShell.S_OK)
                {
                    if (celtFetched != RWinShell.S_FALSE)
                    {
                        break;
                    }
                    FShellFolder folder = new FShellFolder();
                    folder.Parent = this;
                    folder.SetHandle(pidlSub);
                    folder.RefreshInfo();
                    folders.Push(folder);
                }
                return(folders.ToArray());
            }
            return(null);
        }
Exemplo n.º 4
0
        public static FProcessInfo[] Fetch()
        {
            IntPtr hSnap = RKernel32.CreateToolhelp32Snapshot(ETh32cs.SnapProcess, 0);

            if (!RApi.IsValidHandle(hSnap))
            {
                return(null);
            }
            FObjects <FProcessInfo> process = new FObjects <FProcessInfo>();
            SProcessEntry32         pe32    = new SProcessEntry32();

            pe32.dwSize = (uint)Marshal.SizeOf(pe32);
            bool next = RKernel32.Process32First(hSnap, ref pe32);

            while (next)
            {
                FProcessInfo info = new FProcessInfo();
                info.Id       = pe32.th32ProcessID;
                info.Threads  = (int)pe32.cntThreads;
                info.FileName = pe32.szExeFile;
                process.Push(info);
                next = RKernel32.Process32Next(hSnap, ref pe32);
            }
            RKernel32.CloseHandle(hSnap);
            return(process.ToArray());
        }
Exemplo n.º 5
0
        public static Encoding[] DetectInputAllCodepages(byte[] input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (input.Length == 0)
            {
                return(new Encoding[] { Encoding.ASCII });
            }
            if (input.Length < 256)
            {
                byte[] newInput = new byte[256];
                int    steps    = 256 / input.Length;
                for (int i = 0; i < steps; i++)
                {
                    Array.Copy(input, 0, newInput, input.Length * i, input.Length);
                }
                int rest = 256 % input.Length;
                if (rest > 0)
                {
                    Array.Copy(input, 0, newInput, steps * input.Length, rest);
                }
                input = newInput;
            }
            IMultiLanguage2 multilang2 = new FMultiLanguageClass();

            if (multilang2 == null)
            {
                throw new System.Runtime.InteropServices.COMException("Failed to get IMultilang2");
            }
            FObjects <Encoding> result = new FObjects <Encoding>();

            try {
                SDetectEncodingInfo[] detectedEncdings = new SDetectEncodingInfo[RInt.SIZE_1K];
                int         scores  = detectedEncdings.Length;
                int         srcLen  = input.Length;
                SMlDetectCp options = SMlDetectCp.MLDETECTCP_NONE;
                multilang2.DetectInputCodepage(options, 0, ref input[0], ref srcLen, ref detectedEncdings[0], ref scores);
                if (scores > 0)
                {
                    for (int i = 0; i < scores; i++)
                    {
                        result.Push(Encoding.GetEncoding((int)detectedEncdings[i].nCodePage));
                    }
                }
            } finally {
                Marshal.FinalReleaseComObject(multilang2);
            }
            return(result.ToArray());
        }
Exemplo n.º 6
0
        public FMethod[] GetAllMethods(BindingFlags flags)
        {
            FObjects <FMethod> methods = new FObjects <FMethod>();
            Type type = _type;

            while (type != null)
            {
                foreach (MethodInfo methodInfo in type.GetMethods(flags))
                {
                    methods.Push(new FMethod(methodInfo));
                }
                type = type.BaseType;
            }
            return(methods.ToArray());
        }
Exemplo n.º 7
0
        public FField[] GetAllFields(BindingFlags flags)
        {
            FObjects <FField> fields = new FObjects <FField>();
            Type type = _type;

            while (type != null)
            {
                foreach (FieldInfo fieldInfo in type.GetFields(flags))
                {
                    fields.Push(new FField(fieldInfo));
                }
                type = type.BaseType;
            }
            return(fields.ToArray());
        }
Exemplo n.º 8
0
        /*public FFieldInfo[] GetFields(object value) {
         *       FObjects<FFieldInfo> infos = new FObjects<FFieldInfo>();
         *       if (value != null) {
         *          Type type = value.GetType();
         *          FieldInfo[] fields = type.GetFields();
         *          foreach (FieldInfo field in fields) {
         *             FFieldInfo fieldInfo = new FFieldInfo();
         *             fieldInfo.Name = field.Name;
         *             fieldInfo.Value = field.GetValue(value);
         *             collection.Push(fieldInfo);
         *          }
         *       }
         *       return collection;
         *    }*/

        public static FField[] GetFields(object value)
        {
            FObjects <FField> infos = new FObjects <FField>();

            if (value != null)
            {
                Type        type   = value.GetType();
                FieldInfo[] fields = type.GetFields();
                foreach (FieldInfo field in fields)
                {
                    FField fieldInfo = new FField();
                    fieldInfo.Name  = field.Name;
                    fieldInfo.Value = field.GetValue(value);
                    infos.Push(fieldInfo);
                }
            }
            return(infos.ToArray());
        }
Exemplo n.º 9
0
        public FShellFile[] ListFile()
        {
            IntPtr ptr = IntPtr.Zero;

            if (_face.EnumObjects(_handle, EShcontf.NonFolders | EShcontf.IncludeHidden, out ptr) == RWinShell.S_OK)
            {
                IntPtr pidlSub;
                int    celtFetched;
                FObjects <FShellFile> files = new FObjects <FShellFile>();
                IEnumIDList           list  = (IEnumIDList)Marshal.GetObjectForIUnknown(ptr);
                while (list.Next(1, out pidlSub, out celtFetched) == RWinShell.S_OK && celtFetched == RWinShell.S_FALSE)
                {
                    FShellFile file = new FShellFile();
                    file.Parent = this;
                    file.SetHandle(pidlSub);
                    file.RefreshInfo();
                    files.Push(file);
                }
                return(files.ToArray());
            }
            return(null);
        }
Exemplo n.º 10
0
        //============================================================
        // <T>设置渲染过程。</T>
        //============================================================
        public override void Setup()
        {
            base.Setup();
            SIntSize size = new SIntSize(2048, 2048);
            FObjects <FDxBufferedTexture> textures = new FObjects <FDxBufferedTexture>();

            // 创建深度检测区
            _depthTexture.Device = _device;
            _depthTexture.Create(size.Width, size.Height);
            // 创建渲染目标纹理区 (标识)
            _textureFlags.Device       = _device;
            _textureFlags.NativeFormat = Format.R32G32B32A32_SInt;
            _textureFlags.Create(size.Width, size.Height);
            textures.Push(_textureFlags);
            // 创建渲染目标纹理区 (颜色,透明度)
            _textureColor.Device       = _device;
            _textureColor.NativeFormat = Format.R8G8B8A8_UNorm;
            _textureColor.Create(size.Width, size.Height);
            textures.Push(_textureColor);
            // 建立纹理列表
            _targets = textures.ToArray();
        }
Exemplo n.º 11
0
        public static SModuleEntry32[] ListAll(int processId)
        {
            IntPtr hSnap = RKernel32.CreateToolhelp32Snapshot(ETh32cs.SnapModule, processId);

            if (!RApi.IsValidHandle(hSnap))
            {
                return(null);
            }
            FObjects <SModuleEntry32> modules = new FObjects <SModuleEntry32>();
            SModuleEntry32            me32    = new SModuleEntry32();

            me32.dwSize = Marshal.SizeOf(me32);
            bool next = RKernel32.Module32First(hSnap, ref me32);

            while (next)
            {
                SModuleEntry32 module = new SModuleEntry32();
                module = me32;
                modules.Push(module);
                next = RKernel32.Module32Next(hSnap, ref me32);
            }
            RKernel32.CloseHandle(hSnap);
            return(modules.ToArray());
        }
Exemplo n.º 12
0
        public static FTrunkInfo[] FetchTrunks(IntPtr hModule)
        {
            Nullable <SImageNtHeaders> ntHeaders = GetNtHeaders(hModule);
            SImageDataDirectory        idd       = ntHeaders.Value.OptionalHeader.DataDirectory[(int)EImageDirectoryEntry.Import];

            if (idd.VirtualAddress == 0)
            {
                return(null);
            }
            // Import
            uint   maddress  = (uint)hModule.ToInt32();
            IntPtr pIdHeader = (IntPtr)(maddress + idd.VirtualAddress);
            SImageImportDescriptor impDesc = (SImageImportDescriptor)Marshal.PtrToStructure(pIdHeader, typeof(SImageImportDescriptor));

            if (impDesc.Name == 0)
            {
                return(null);
            }
            // Get module Name
            // IntPtr moduleNamePtr = (IntPtr)(maddress + impDesc.Name);
            // Trunk
            IntPtr pOrgFt = (IntPtr)(maddress + impDesc.OriginalFirstThunk);
            IntPtr pFt    = (IntPtr)(maddress + impDesc.FirstThunk);
            int    ftSize = Marshal.SizeOf(typeof(SImageThunkData32));
            int    miSize = Marshal.SizeOf(typeof(SMemoryBasicInformation));
            FObjects <FTrunkInfo> infos = new FObjects <FTrunkInfo>();

            while (true)
            {
                SImageThunkData32 origThunk = (SImageThunkData32)Marshal.PtrToStructure(pOrgFt, typeof(SImageThunkData32));
                SImageThunkData32 realThunk = (SImageThunkData32)Marshal.PtrToStructure(pFt, typeof(SImageThunkData32));
                if (origThunk.Function == 0)
                {
                    break;
                }
                if ((origThunk.Ordinal & 0x80000000) == 0x80000000)
                {
                    break;
                }

                /*uint arrd = (uint)(maddress + origThunk.AddressOfData);
                 * if ((arrd & 0x80000000) == 0x80000000) {
                 * break;
                 * }*/
                // Read name
                IntPtr             pName  = (IntPtr)(maddress + origThunk.AddressOfData);
                SImageImportByName byName = (SImageImportByName)Marshal.PtrToStructure(pName, typeof(SImageImportByName));
                if (byName.Name[0] == 0)
                {
                    break;
                }
                // Read memory state
                SMemoryBasicInformation mbi = new SMemoryBasicInformation();
                //RKernel32.VirtualQuery((uint)pFt.ToInt32(), ref mbi, miSize);
                RKernel32.VirtualQuery(realThunk.Function, ref mbi, miSize);
                // TrunkInfo
                FTrunkInfo info = new FTrunkInfo();
                info.Name    = RAscii.GetString(byName.Name);
                info.Address = origThunk.Function;
                //info.Entry = (IntPtr)(maddress + origThunk.Function);
                info.Entry                = (IntPtr)realThunk.Function;
                info.Hint                 = byName.Hint;
                info.MemAllocationBase    = mbi.AllocationBase;
                info.MemAllocationProtect = mbi.AllocationProtect;
                info.MemBaseAddress       = mbi.BaseAddress;
                info.MemProtect           = mbi.Protect;
                info.MemRegionSize        = mbi.RegionSize;
                info.MemState             = mbi.State;
                info.MemType              = mbi.Type;
                infos.Push(info);
                // Loop
                pOrgFt = (IntPtr)(pOrgFt.ToInt32() + ftSize);
                pFt    = (IntPtr)(pFt.ToInt32() + ftSize);
            }
            return(infos.ToArray());
        }