Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook Read calls #4

Open
ShakedGold opened this issue Mar 18, 2024 · 0 comments
Open

Hook Read calls #4

ShakedGold opened this issue Mar 18, 2024 · 0 comments

Comments

@ShakedGold
Copy link

I tried hooking a Read call which does work:

//export detourReadFile
func DetourReadFile(hFile C.HANDLE, lpBuffer C.LPVOID, nNumberOfBytesToRead C.DWORD, lpNumberOfBytesRead C.LPDWORD, lpOverlapped C.LPOVERLAPPED) C.BOOL {
	result, _, lastErr := syscall.SyscallN(
		uintptr(unsafe.Pointer(readTrampoline)),
		uintptr(unsafe.Pointer(hFile)),
		uintptr(unsafe.Pointer(lpBuffer)),
		uintptr(C.DWORD(uint(nNumberOfBytesToRead))),
		uintptr(unsafe.Pointer(lpNumberOfBytesRead)),
		uintptr(unsafe.Pointer(lpOverlapped)),
	)
	if result == 0 {
		fmt.Println("Error reading file: ", lastErr)
		return C.BOOL(0)
	}
        return C.BOOL(result)
}

The hooking most of the time works but sometimes I get an error:
Error reading file: The pipe has been ended

Also the program freezes and refuses to continue (If I remove the read hooking, It is not freezing anymore), Am I doing something wrong here?

I don't know if this the error related to the freezing.

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

No branches or pull requests

1 participant