192: BOOL
193: WINAPI
194: ReadFile(
195: HANDLE hFile,
196: LPVOID lpBuffer,
197: DWORD nNumberOfBytesToRead,
198: LPDWORD lpNumberOfBytesRead,
199: LPOVERLAPPED lpOverlapped
200: )
201:
202: /*++
203:
204: Routine Description:
205:
206: Data can be read from a file using ReadFile.
207:
208: This API is used to read data from a file. Data is read from the
209: file from the position indicated by the file pointer. After the
210: read completes, the file pointer is adjusted by the number of bytes
211: actually read. A return value of TRUE coupled with a bytes read of
212: 0 indicates that the file pointer was beyond the current end of the
213: file at the time of the read.
214:
215: Arguments:
216:
217: hFile - Supplies an open handle to a file that is to be read. The
218: file handle must have been created with GENERIC_READ access to
219: the file.
220:
221: lpBuffer - Supplies the address of a buffer to receive the data read
222: from the file.
223:
224: nNumberOfBytesToRead - Supplies the number of bytes to read from the
225: file.
226:
227: lpNumberOfBytesRead - Returns the number of bytes read by this call.
228: This parameter is always set to 0 before doing any IO or error
229: checking.
230:
231: lpOverlapped - Optionally points to an OVERLAPPED structure to be used with the
232: request. If NULL then the transfer starts at the current file position
233: and ReadFile will not return until the operation completes.
234:
235: If the handle hFile was created without specifying FILE_FLAG_OVERLAPPED
236: the file pointer is moved to the specified offset plus
237: lpNumberOfBytesRead before ReadFile returns. ReadFile will wait for the
238: request to complete before returning (it will not return
239: ERROR_IO_PENDING).
240:
241: When FILE_FLAG_OVERLAPPED is specified, ReadFile may return
242: ERROR_IO_PENDING to allow the calling function to continue processing
243: while the operation completes. The event (or hFile if hEvent is NULL) will
244: be set to the signalled state upon completion of the request.
245:
246: When the handle is created with FILE_FLAG_OVERLAPPED and lpOverlapped
247: is set to NULL, ReadFile will return ERROR_INVALID_PARAMTER because
248: the file offset is required.
249:
250:
251: Return Value:
252:
253: TRUE - The operation was successul.
254:
255: FALSE - The operation failed. Extended error status is available
256: using GetLastError.
257:
258: --*/
259:
260: {
261: NTSTATUS Status;
262: IO_STATUS_BLOCK IoStatusBlock;
263: PPEB Peb;
264: DWORD InputMode;
265:
266: if ( ARGUMENT_PRESENT(lpNumberOfBytesRead) ) {
267: *lpNumberOfBytesRead = 0;
268: }
269:
270: Peb = NtCurrentPeb();
271:
272: switch( HandleToUlong(hFile) ) {
273: case STD_INPUT_HANDLE: hFile = Peb->ProcessParameters->StandardInput;
274: break;
275: case STD_OUTPUT_HANDLE: hFile = Peb->ProcessParameters->StandardOutput;
276: break;
277: case STD_ERROR_HANDLE: hFile = Peb->ProcessParameters->StandardError;
278: break;
279: }
280:
281: if (CONSOLE_HANDLE(hFile)) {
282: if (ReadConsoleA(hFile,
283: lpBuffer,
284: nNumberOfBytesToRead,
285: lpNumberOfBytesRead,
286: lpOverlapped
287: )
288: ) {
289: Status = STATUS_SUCCESS;
290: if (!GetConsoleMode( hFile, &InputMode )) {
291: InputMode = 0;
292: }
293:
294: if (InputMode & ENABLE_PROCESSED_INPUT) {
295: try {
296: if (*(PCHAR)lpBuffer == 0x1A) {
297: *lpNumberOfBytesRead = 0;
298: }
299: }
300: except( EXCEPTION_EXECUTE_HANDLER ) {
301: Status = GetExceptionCode();
302: }
303: }
304:
305: if (NT_SUCCESS(Status)) {
306: return TRUE;
307: }
308: else {
309: BaseSetLastNTError(Status);
310: return FALSE;
311: }
312: }
313: else {
314: return FALSE;
315: }
316: }
317:
318: if ( ARGUMENT_PRESENT( lpOverlapped ) ) {
319: LARGE_INTEGER Li;
320:
321: lpOverlapped->Internal = (DWORD)STATUS_PENDING;
322: Li.LowPart = lpOverlapped->Offset;
323: Li.HighPart = lpOverlapped->OffsetHigh;
324: Status = NtReadFile(
325: hFile,
326: lpOverlapped->hEvent,
327: NULL,
328: (ULONG_PTR)lpOverlapped->hEvent & 1 ? NULL : lpOverlapped,
329: (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
330: lpBuffer,
331: nNumberOfBytesToRead,
332: &Li,
333: NULL
334: );
335:
336:
337: if ( NT_SUCCESS(Status) && Status != STATUS_PENDING) {
338: if ( ARGUMENT_PRESENT(lpNumberOfBytesRead) ) {
339: try {
340: *lpNumberOfBytesRead = (DWORD)lpOverlapped->InternalHigh;
341: }
342: except(EXCEPTION_EXECUTE_HANDLER) {
343: *lpNumberOfBytesRead = 0;
344: }
345: }
346: return TRUE;
347: }
348: else
349: if (Status == STATUS_END_OF_FILE) {
350: if ( ARGUMENT_PRESENT(lpNumberOfBytesRead) ) {
351: *lpNumberOfBytesRead = 0;
352: }
353: BaseSetLastNTError(Status);
354: return FALSE;
355: }
356: else {
357: BaseSetLastNTError(Status);
358: return FALSE;
359: }
360: }
361: else
362: {
363: Status = NtReadFile(
364: hFile,
365: NULL,
366: NULL,
367: NULL,
368: &IoStatusBlock,
369: lpBuffer,
370: nNumberOfBytesToRead,
371: NULL,
372: NULL
373: );
374:
375: if ( Status == STATUS_PENDING) {
376: // Operation must complete before return & IoStatusBlock destroyed
377: Status = NtWaitForSingleObject( hFile, FALSE, NULL );
378: if ( NT_SUCCESS(Status)) {
379: Status = IoStatusBlock.Status;
380: }
381: }
382:
383: if ( NT_SUCCESS(Status) ) {
384: *lpNumberOfBytesRead = (DWORD)IoStatusBlock.Information;
385: return TRUE;
386: }
387: else
388: if (Status == STATUS_END_OF_FILE) {
389: *lpNumberOfBytesRead = 0;
390: return TRUE;
391: }
392: else {
393: if ( NT_WARNING(Status) ) {
394: *lpNumberOfBytesRead = (DWORD)IoStatusBlock.Information;
395: }
396: BaseSetLastNTError(Status);
397: return FALSE;
398: }
399: }
400: }
系统调用 进程 ——> 调用OS API;OS进程管理 ——>... 硬件] 设备驱动] 核心层] 管理层] 系统服务界面,中断入口(不公开)] 系统DLL(公开)] ——>API 用户进程没有调用内核函数(特权指令)...
内核里操作文件 ...在讲解具体的代码之前,先讲解一下文件系统的流程,让大家对整个文件系统有个大概的了解。 假设我们要读写一个文件,无论在 RING3 调用 ReadFile,还是在 RING0 调用
windows7内核分析之x86&x64第二章系统调用 2.1内核与系统调用 上节讲到进入内核五种方式 其中一种就是 系统调用 syscall/sysenter或者int 2e(在 64 位环境里统一使用 syscall/sysret 指令,在 32 位...
用户态进入系统态有以下几种方式: 中断(Interrupt)。在允许中断的情况下,有外部设备的中断请求到达,CPU自动转入系统空间,并从预定地址执行指令。中断只发生在两条指令之间,不会打断正在执行的指令。对CPU而言...
内核里操作文件 RING0操作文件和RING3操作文件在流程...在讲解具体的代码之前,先讲解一下文件系统的流程,让大家对整个文件系统有个大概的了解。 假设我们要读写一个文件,无论在RING3调用ReadFile,还是在RIN...
运行 Windows 的计算机中的处理器有两个不同模式:“用户模式”和“内核模式”。根据处理器上运行的代码的类型,处理器在两个模式之间切换。应用程序在用户模式下运行,核心操作系统组件在内核模式下运行。多个驱动...
由API-系统调用模式探析windows NT内核 0、最常见的疑惑 这个程序是怎么运行的?为什么一双击exe文件就开始运行了呢?程序和操作系统什么关系呢? 其实很多人都有这些问题,如果有人能回答,说不一定这个回答的人...
内核重载需求的产生在内核中有很多HOOK, 例如:KiFastCallEntry, SSDT,IDT,OBJECT HOOK,甚至是内核API的内联HOOK , 有些HOOK很容易找到,并还原, 有些HOOK就很难找到. 在某些时候(例如一个病毒HOOK了int3中断,这样调试...
应用程序->驱动B(Read)->驱动A(Read) // 应用程序 #include <windows.h> #include <stdio.h>... HANDLE hDevice = CreateFile("\\\\.\\HelloDDKB", GENERIC_READ | GENERIC_WRITE, ...
这个表就是一个把 Ring3 的 Win32 API 和 Ring0 的内核 API 联系起来。Ring3下调用的所有函数最终都会先进入到ntdll里面的,比如ReadFile,就会进入ntdll的ZwReadFile SSDT 并不仅仅只包含一个庞大的...
理解Windows NT驱动程序最重要的概念之一就是驱动程序...传统上文件系统开发者最关注这个问题,但所有类型的NT内核模式驱动程序的编写者都能从执行上下文的深刻理解中获益。小心谨慎地使用执行上下文的概念能帮助构建
文章目录Win32API用户篇内核篇参数表...
内核同步对象(上) Windows NT提供了五种内核同步对象(Kernel Dispatcher Object),你可以用它们控制非任意线程(普通线程)的流程。表4-1列出了这些内核同步对象的类型及它们的用途。在任何时刻,任何对象...
对于应用程序而言,操作系统内核的作用体现在一组可以供其调用的函数,称为“系统调用”。系统调用也可以称为“系统服务”。 模式切换: 1、 内核态到用户态很容易,运行于系统态的CPU可以通过一些只允许在系统态...
第8章 键盘的过滤
技术原理 1.预备知识 何为符号链接?符号链接其实就是设备的一个“别名”。在应用程序中想要访问设备一般要通过符号链接来完成,而不是...同名的函数有两个:一个在内核中(ntknos.exe),一个在应用层(ntdll.dll)
xFsRedir是windows平台下的分布式网络文件系统程序。这个软件已经持续比较长的时间了,最近更新了部分功能。完整版本安装和使用请查阅如下链接:https://blog.csdn.net/fanxiushu/article/details/53...
当一个用户线程向一个设备发出了 I/O 函数调用,例如通过调用Win32 的 ReadFile(…) 函数,将产生一个系统服务请求。在 Intel 架构的处理器上,这样的请求依靠通过一个中断门的软中断来实现。中断门把处理器...
内核互斥对象互斥(mutex)就是互相排斥(mutual exclusion)的简写。内核互斥对象为多个竞争线程串行化访问共享资源提供了一种方法(不一定是最好的方法)。如果互斥对象不被某线程所拥有,则它是信号态,反之则是非信号...
转:... 2.1 应用程序如何使用驱动 应用程序中使用 CreateFile,ReadFile,WriteFile,DeviceIoControl,CloseHandle 来指示驱动程序完成某种
A盾是开源的一个功能算是比较多的ARK,对木马,病毒在内核层还是可以拦截的。目前市面上的主动防御,杀毒软件的思路也是这样。但是,毕竟开源的,很多功能考虑的实现很浅,木有在内核里面深层次拦截。 它的开源的...
内核互斥对象为多个竞争线程串行化访问共享资源提供了一种方法(不一定是最好的方法)。如果互斥对象不被某线程所拥有,则它是信号态,反之则是非信号态。当线程为了获得互斥对象的控制权而调用KeWaitXxx例程时,内核...
Windows NT提供了五种内核同步对象(Kernel Dispatcher Object),你可以用它们控制非任意线程(普通线程)的流程。表4-1列出了这些内核同步对象的类型及它们的用途。在任何时刻,任何对象都处于两种状态中的一种:信号...
jdk1.8 64位官方正式版 jdk-8u91-windows
C#入门必看含有100个例字,每个例子都是针对C#的学习关键知识点设计的,是学习C#必须知道的一些程序例子,分享给大家,需要的可以下载
这本面试手册包含了Java基础、Java集合、JVM、Spring、Spring Boot、Spring Cloud、Mysql、Redis、RabbitMQ、Dubbo、Netty、分布式及架构设计等方面的技术点。内容难度参差,满足初中高级Java工程师的面试需求。
xshell6 和 xftp6个人版,直接安装即可使用。
官方的DEV C++ 规范好用的自学C语言工具
七夕节、情人节表白用的HTML源码(两款)
本教程页数不多,7页,主要描述如何使用以太坊ETH挖矿,图文并茂的展示和流程细节的体现,基本看了一遍就肯定能够学会了。