ReactOS  0.4.14-dev-49-gfb4591c
isotest.c
Go to the documentation of this file.
1 /*
2  * isotest - display cdrom information
3  */
4 
5 #define WIN32_NO_STATUS
6 #include <windows.h>
7 #define NTOS_MODE_USER
8 #include <ndk/ntndk.h>
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <wchar.h>
15 
16 
17 void HexDump(char *buffer, ULONG size)
18 {
19  ULONG offset = 0;
20  unsigned char *ptr;
21 
22  while (offset < (size & ~15))
23  {
24  ptr = (unsigned char*)((ULONG_PTR)buffer + offset);
25  printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx",
26  offset,
27  ptr[0],
28  ptr[1],
29  ptr[2],
30  ptr[3],
31  ptr[4],
32  ptr[5],
33  ptr[6],
34  ptr[7],
35  ptr[8],
36  ptr[9],
37  ptr[10],
38  ptr[11],
39  ptr[12],
40  ptr[13],
41  ptr[14],
42  ptr[15]);
43 
44  printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
45  isprint(ptr[0])?ptr[0]:'.',
46  isprint(ptr[1])?ptr[1]:'.',
47  isprint(ptr[2])?ptr[2]:'.',
48  isprint(ptr[3])?ptr[3]:'.',
49  isprint(ptr[4])?ptr[4]:'.',
50  isprint(ptr[5])?ptr[5]:'.',
51  isprint(ptr[6])?ptr[6]:'.',
52  isprint(ptr[7])?ptr[7]:'.',
53  isprint(ptr[8])?ptr[8]:'.',
54  isprint(ptr[9])?ptr[9]:'.',
55  isprint(ptr[10])?ptr[10]:'.',
56  isprint(ptr[11])?ptr[11]:'.',
57  isprint(ptr[12])?ptr[12]:'.',
58  isprint(ptr[13])?ptr[13]:'.',
59  isprint(ptr[14])?ptr[14]:'.',
60  isprint(ptr[15])?ptr[15]:'.');
61 
62  offset += 16;
63  }
64 
65  ptr = (unsigned char*)((ULONG_PTR)buffer + offset);
66  if (offset < size)
67  {
68  printf("%08lx ", offset);
69  while (offset < size)
70  {
71  printf(" %02hx", *ptr);
72  offset++;
73  ptr++;
74  }
75  }
76 
77  printf("\n\n");
78 }
79 
80 
81 #ifndef EVENT_ALL_ACCESS
82 #define EVENT_ALL_ACCESS (0x1f0003L)
83 #endif
84 
85 BOOL
87  PVOID Buffer,
89  ULONG Length,
91 {
96 
98  NULL, 0, NULL, NULL);
99 
103  TRUE,
104  FALSE);
105  if (!NT_SUCCESS(Status))
106  {
107  printf("NtCreateEvent() failed\n");
108  return(FALSE);
109  }
110 
112  EventHandle,
113  NULL,
114  NULL,
115  &IoStatusBlock,
116  Buffer,
117  Length,
118  Offset,
119  NULL);
120  if (Status == STATUS_PENDING)
121  {
124  }
125 
127 
128  if (Status != STATUS_PENDING && BytesRead != NULL)
129  {
131  }
133  {
134  printf("ReadBlock() failed (Status: %lx)\n", Status);
135  return(FALSE);
136  }
137 
138  return(TRUE);
139 }
140 
141 
142 
143 int main (int argc, char *argv[])
144 {
145  HANDLE hDisk;
146  DWORD dwRead;
147  char *Buffer;
148  CHAR Filename[80];
149  LARGE_INTEGER FilePosition;
150 
151  if (argc != 2)
152  {
153  printf("Usage: isotest [Drive:]\n");
154  return 0;
155  }
156 
157  strcpy(Filename, "\\\\.\\");
158  strcat(Filename, argv[1]);
159 
160  hDisk = CreateFile(Filename,
161  GENERIC_READ,
163  NULL,
165  0,
166  NULL);
167  if (hDisk == INVALID_HANDLE_VALUE)
168  {
169  printf("CreateFile(): Invalid disk handle!\n");
170  return 0;
171  }
172 
173  Buffer = (char*)malloc(2048);
174  if (Buffer == NULL)
175  {
176  CloseHandle(hDisk);
177  printf("Out of memory!\n");
178  return 0;
179  }
180  memset(Buffer, 0, 2048);
181 
182 
183  FilePosition.QuadPart = 16 * 2048;
184 #if 0
186  SetFilePointer(hDisk,
187  FilePosition.u.LowPart,
188  &FilePosition.u.HighPart,
189  FILE_BEGIN);
190  if (GetLastError() != NO_ERROR)
191  {
192  CloseHandle(hDisk);
193  free(Buffer);
194  printf("SetFilePointer() failed!\n");
195  return 0;
196  }
197 
198  if (ReadFile(hDisk,
199  Buffer,
200  2048,
201  &dwRead,
202  NULL) == FALSE)
203  {
204  CloseHandle(hDisk);
205  free(Buffer);
206  printf("ReadFile() failed!\n");
207  return 0;
208  }
209 #endif
210 
211  if (ReadBlock(hDisk,
212  Buffer,
213  &FilePosition,
214  2048,
215  &dwRead) == FALSE)
216  {
217  CloseHandle(hDisk);
218  free(Buffer);
219 #if 0
220  printf("ReadBlock() failed!\n");
221 #endif
222  return 0;
223  }
224 
225  HexDump(Buffer, 128);
226 
227  CloseHandle(hDisk);
228 
229  free(Buffer);
230 
231  return 0;
232 }
233 
234 /* EOF */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char CHAR
Definition: xmlstorage.h:175
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLuint buffer
Definition: glext.h:5915
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define argv
Definition: mplay32.c:18
#define NO_ERROR
Definition: dderror.h:5
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:925
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define STATUS_END_OF_FILE
Definition: shellext.h:62
uint32_t ULONG_PTR
Definition: typedefs.h:63
HANDLE FileHandle
Definition: stats.c:38
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL ReadBlock(HANDLE FileHandle, PVOID Buffer, PLARGE_INTEGER Offset, ULONG Length, PULONG BytesRead)
Definition: isotest.c:86
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
struct _LARGE_INTEGER::@2201 u
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define OPEN_EXISTING
Definition: compat.h:426
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
#define FILE_BEGIN
Definition: winbase.h:112
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
int main(int argc, char *argv[])
Definition: isotest.c:143
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
void HexDump(char *buffer, ULONG size)
Definition: isotest.c:17
#define isprint(c)
Definition: acclib.h:73
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define malloc
Definition: debug_ros.c:4
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define memset(x, y, z)
Definition: compat.h:39
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
LONGLONG QuadPart
Definition: typedefs.h:112
#define printf
Definition: config.h:203
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)