Skip to content

Commit

Permalink
Optimize: Avoid unnecessary dictionary re-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Apr 28, 2024
1 parent 8f2d1bc commit 8aa1ff8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions FileEmulationFramework/FileAccessServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ private static int SetInformationFileHook(IntPtr hfile, IO_STATUS_BLOCK* ioStatu

private static int SetInformationFileImpl(IntPtr hfile, IO_STATUS_BLOCK* ioStatusBlock, byte* fileInformation, uint length, FileInformationClass fileInformationClass)
{
if (fileInformationClass != FileInformationClass.FilePositionInformation || !HandleToInfoMap.ContainsKey(hfile))
if (fileInformationClass != FileInformationClass.FilePositionInformation || !HandleToInfoMap.TryGetValue(hfile, out var info))
return _setFilePointerHook.OriginalFunction.Value.Invoke(hfile, ioStatusBlock, fileInformation, length, fileInformationClass);

var pointer = *(long*)fileInformation;
HandleToInfoMap[hfile].FileOffset = pointer;
info.FileOffset = pointer;
return _setFilePointerHook.OriginalFunction.Value.Invoke(hfile, ioStatusBlock, fileInformation, length, fileInformationClass);
}

Expand All @@ -174,7 +174,7 @@ private static int NtReadFileImpl(IntPtr handle, IntPtr hEvent, IntPtr* apcRouti
// If it is, prepare to hook it.
long requestedOffset = byteOffset != (void*)0 ? *byteOffset : FileUseFilePointerPosition; // -1 means use current location
if (requestedOffset == FileUseFilePointerPosition)
requestedOffset = HandleToInfoMap[handle].FileOffset;
requestedOffset = info.FileOffset;

if (_logger.IsEnabled(LogSeverity.Debug))
_logger.Debug($"[FileAccessServer] Read Request, Buffer: {(long)buffer:X}, Length: {length}, Offset: {requestedOffset}");
Expand Down

0 comments on commit 8aa1ff8

Please sign in to comment.