コード例 #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            Console.WriteLine("writer starts");
            byte[] one = new byte[100000];
            GenericProxy <CacheStream.IIOHelper> p = null;

            p = new SimpleIPC.GenericProxy <CacheStream.IIOHelper>(new SimpleIPC.Windows.SIPCProxy("cachestreamreader"));
            if (args[0] == "1")
            {
                Console.WriteLine("******System Cache Read Write Demo*******");
                CacheStream.IOHelper ioh = new CacheStream.IOHelper(@"test1.dat");
                Console.WriteLine("created d:\\test1.dat on system cache");
                for (int i = 0; i < one.Length; ++i)
                {
                    one[i] = 1;
                }

                bool bret = ioh.Write(one, 0, one.Length);
                Console.WriteLine("Wrote 100000 bytes with 1");
                Console.WriteLine("Sending IPC call to the Reader");
                p.Proxy.WroteBytes(Process.GetCurrentProcess().Id, ioh.hImageFile, 0, one.Length);
                Console.WriteLine("Sleeping for 5 seconds");
                System.Threading.Thread.Sleep(5000);
                ioh.Read(one, 0, one.Length);
                Console.WriteLine("read {0} bytes with {1}", one.Length, one[0]);
            }
            else
            {
                Console.WriteLine("\n\n******ReadProcessMemory WriteProcessMeory Demo*******");
                for (int i = 0; i < one.Length; ++i)
                {
                    one[i] = 3;
                }
                GCHandle handle = GCHandle.Alloc(one, GCHandleType.Pinned);
                Console.WriteLine("Wrote 100000 bytes with 3");
                Console.WriteLine("Sending IPC call to the Reader");
                p.Proxy.WroteMemBytes(Process.GetCurrentProcess().Id, handle.AddrOfPinnedObject(), one.Length);
                Console.WriteLine("Sleeping for 5 seconds");
                System.Threading.Thread.Sleep(5000);
                Console.WriteLine("Remote Read 100000 bytes with {0}", one[0]);
                handle.Free();
                p.Dispose();
            }
            Console.WriteLine("press any key to stop");
            Console.ReadKey();
            Console.WriteLine("writer stops");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rvvyas/TechBlog
        public void WroteBytes(int pid, IntPtr handle, int offset, int len)
        {
            Console.WriteLine("******System Cache Read Write Demo*******");
            Console.WriteLine("Received IPC call from the writer");
            Console.WriteLine("opened d:\\test1.dat on system cache");
            CacheStream.IOHelper iop = new CacheStream.IOHelper(pid, handle);

            byte[] buffer = new Byte[len];
            iop.Read(buffer, offset, len);
            Console.WriteLine("read {0} bytes with {1}", len, buffer[offset]);

            Console.WriteLine("write {0} bytes with {1}", len, 2);
            for (int i = 0; i < buffer.Length; ++i)
            {
                buffer[i] = 2;
            }
            bool bret = iop.Write(buffer, offset, buffer.Length);

            Console.WriteLine("press any key to stop");
        }