Skip to content

Conversation

@bravosierra99
Copy link

This is the error I was getting
`
$file = Get-NtFile <some_path> -win32path
$file.read(5)
Exception calling "Read" with "1" argument(s): "(0xC000000D) - An invalid parameter was passed to a service or
function."
At line:1 char:187

  • ... t-NtFile C:\Users\ben\Documents\desktop.ini -Win32Path; $file.read(3)
  •                                                         ~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : NtException
      `

I'm not a c# person and I didn't dive into if there are underlying problems beyond where I made my fix. While I would have expected null and 0 to be the same, they don't appear to be so I just made the lowest level fix that made sense to me.

let me know if you have any questions.

@google-cla
Copy link

google-cla bot commented Apr 4, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bravosierra99
Copy link
Author

added CLA

@tyranid
Copy link
Collaborator

tyranid commented Apr 4, 2024

Thanks for that, however the behavior is intentional. By default the code opens the file in asynchronous mode. In this mode the kernel does not track the current position of the file pointer so you must always explicitly specify the offset you want to read the bytes from. The reason there's a difference between null and 0 is in synchronous mode you don't need to specify the offset at all. That parameter is optional so it's okay to pass null, however you can specify it if you wanted to. For async you must specify the offset regardless, but the Read method does not try and help you here as it doesn't even know what offset you want to read from.

Therefore you'd need to do one of two things to correctly read data, either pass the position e.g. $file.Read(5, 0) or open the file in synchronous mode e.g. $file = Get-NtFile <some path> -Win32Path -Options SynchronousIoNonAlert -Access GenericAll,Synchronize

@tyranid tyranid closed this Apr 4, 2024
@bravosierra99
Copy link
Author

Got it! Thanks for the response! Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants