Example #1
0
        private static IEnumerable <T> EnumFilter <T, U>(FindFirst find_first, FindNext find_next,
                                                         FindClose find_close, GetNextOffset <U> get_next, CreateObject <T, U> create) where U : struct
        {
            using (var buffer = new SafeStructureInOutBuffer <U>(128 * 1024, true))
            {
                NtStatus          no_more_hresult = Win32Error.ERROR_NO_MORE_ITEMS.ToHresult();
                NtResult <IntPtr> handle          = new NtResult <IntPtr>(no_more_hresult, IntPtr.Zero);
                var list = new List <T>();
                try
                {
                    handle = find_first(buffer);
                    var status = handle.Status;
                    while (status != no_more_hresult)
                    {
                        if (status != NtStatus.STATUS_SUCCESS)
                        {
                            throw new NtException(status);
                        }

                        var next_buffer = buffer;
                        do
                        {
                            list.Add(create(next_buffer));
                            int offset = get_next(next_buffer);
                            if (offset == 0)
                            {
                                break;
                            }
                            next_buffer = next_buffer.GetStructAtOffset <U>(offset);
                        }while (true);

                        status = find_next(handle.Result, buffer);
                    }
                }
                finally
                {
                    if (handle.IsSuccess)
                    {
                        find_close(handle.Result);
                    }
                }
                return(list.AsReadOnly());
            }
        }
 private void InitializeDelegates()
 {
     _createFileDelegate                 = new CreateFileADelegate(CreateFileHook);
     _createDirectoryDelegate            = new CreateDirectoryDelegate(CreateDirectoryHook);
     _deleteFileDelegate                 = new DeleteFileDelegate(DeleteFileHook);
     _removeDirectoryDelegate            = new RemoveDirectoryDelegate(RemoveDirectoryHook);
     _moveFileDelegate                   = new MoveFileDelegate(MoveFileHook);
     _readFileDelegate                   = new ReadFileDelegate(ReadFileHook);
     _closeHandleDelegate                = new CloseHandleDelegate(CloseHandleHook);
     _getFileAttributesDelegate          = new GetFileAttributesDelegate(GetFileAttributesHook);
     _getFileTypeDelegate                = new GetFileTypeDelegate(GetFileTypeHook);
     _setFilePointerDelegate             = new SetFilePointerDelegate(SetFilePointerHook);
     _getFileInformationByHandleDelegate = new GetFileInformationByHandleDelegate(GetFileInformationByHandleHook);
     _setEndOfFileDelegate               = new SetEndOfFileDelegate(SetEndOfFileHook);
     _findFirstFile = new FindFirstFile(FindFirstFileHook);
     _findNextFile  = new FindNextFile(FindNextFileHook);
     _findClose     = new FindClose(FindCloseHook);
     _tioPathAdd    = new TioPathAdd(TioPathAddHook);
 }