예제 #1
0
        public void Send(CommandMessage message)
        {
            VerifyConnected();

            var size = Marshal.SizeOf(message);
            IntPtr pnt = Marshal.AllocHGlobal(size);

            try
            {
                IntPtr resultSize;
                Marshal.StructureToPtr(message, pnt, false);
                Marshal.ThrowExceptionForHR(NativeMethods.FilterSendMessage(port, pnt, size, IntPtr.Zero, 0, out resultSize));
            }
            finally
            {
                Marshal.FreeHGlobal(pnt);
            }
        }
예제 #2
0
        public void Send(CommandMessage message, byte[] data)
        {
            VerifyConnected();

            var size = Marshal.SizeOf(message) + data.Length;
            IntPtr pnt = Marshal.AllocHGlobal(size);

            try
            {
                IntPtr resultSize;
                Marshal.StructureToPtr(message, pnt, false);
                IntPtr address = IntPtr.Add(pnt, Marshal.SizeOf(typeof(CommandMessage)));
                Marshal.Copy(data, 0, address, data.Length);
                Marshal.ThrowExceptionForHR(NativeMethods.FilterSendMessage(port, pnt, size, IntPtr.Zero, 0, out resultSize));
            }
            finally
            {
                Marshal.FreeHGlobal(pnt);
            }
        }
예제 #3
0
        private List<FileSystemEvent> GetFileSystemEvents(CommandMessage message, IntPtr buffer)
        {
            IntPtr resultSize;
            HResult hResult = connector.SendAndRead(message, buffer, out resultSize);

            if (hResult.IsError)
            {
                if (hResult.Code != ERROR_NO_MORE_ITEMS)
                {
                    Marshal.ThrowExceptionForHR(hResult.Result);
                }

                return new List<FileSystemEvent>();
            }
            else
            {
                return EventReader.ReadFromBuffer(buffer, resultSize.ToInt64());
            }
        }
예제 #4
0
        private List<FileSystemEvent> GetEvents()
        {
            CommandMessage message = new CommandMessage();
            message.Command = MinispyCommand.GetMiniSpyLog;
            var buffer = Marshal.AllocHGlobal(BUFFER_SIZE);

            try
            {
                return GetFileSystemEvents(message, buffer);
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
예제 #5
0
 public void WatchThread(long threadId)
 {
     CommandMessage message = new CommandMessage();
     message.Command = MinispyCommand.SetWatchThread;
     connector.Send(message, BitConverter.GetBytes(threadId));
 }
예제 #6
0
 public void WatchProcess(long processId)
 {
     CommandMessage message = new CommandMessage();
     message.Command = MinispyCommand.SetWatchProcess;
     connector.Send(message, BitConverter.GetBytes(processId));
 }
예제 #7
0
 public void WatchPath(string path)
 {
     CommandMessage message = new CommandMessage();
     message.Command = MinispyCommand.SetPathFilter;
     connector.Send(message, PathConverter.ReplaceDriveLetter(path));
 }
예제 #8
0
        public DriverVersion GetDriverVersion()
        {
            CommandMessage message = new CommandMessage();
            message.Command = MinispyCommand.GetMiniSpyVersion;

            IntPtr resultSize;
            var buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DriverVersion)));

            HResult hResult = connector.SendAndRead(message, buffer, out resultSize);
            Marshal.ThrowExceptionForHR(hResult.Result);

            var driverVersion = Marshal.PtrToStructure<DriverVersion>(buffer);
            Marshal.FreeHGlobal(buffer);
            return driverVersion;
        }
예제 #9
0
        public HResult SendAndRead(CommandMessage message, IntPtr buffer, out IntPtr resultSize)
        {
            VerifyConnected();

            var size = Marshal.SizeOf(message);
            IntPtr command = Marshal.AllocHGlobal(size);

            try
            {
                Marshal.StructureToPtr(message, command, false);
                return new HResult(NativeMethods.FilterSendMessage(port, command, size, buffer, 4069, out resultSize));
            }
            finally
            {
                Marshal.FreeHGlobal(command);
            }
        }
예제 #10
0
 public void Send(CommandMessage message, string path)
 {
     Send(message, Encoding.Unicode.GetBytes(path + '\0'));
 }