ReactOS 0.4.16-dev-197-g92996da
dump.c File Reference
#include "diskpart.h"
#include <debug.h>
Include dependency graph for dump.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID HexDump (_In_ UCHAR *addr, _In_ int len)
 
BOOL DumpDisk (_In_ INT argc, _In_ LPWSTR *argv)
 
BOOL DumpPartition (_In_ INT argc, _In_ LPWSTR *argv)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file dump.c.

Function Documentation

◆ DumpDisk()

BOOL DumpDisk ( _In_ INT  argc,
_In_ LPWSTR argv 
)

Definition at line 48 of file dump.c.

51{
58 PUCHAR pSectorBuffer = NULL;
60 LONGLONG Sector;
61 LPWSTR endptr = NULL;
62
63#if 0
64 if (argc == 2)
65 {
66 ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
67 return TRUE;
68 }
69#endif
70
71 if (CurrentDisk == NULL)
72 {
74 return TRUE;
75 }
76
77 Sector = _wcstoi64(argv[2], &endptr, 0);
78 if (((Sector == 0) && (endptr == argv[2])) ||
79 (Sector < 0))
80 {
82 return TRUE;
83 }
84
85 pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
86 if (pSectorBuffer == NULL)
87 {
88 DPRINT1("\n");
89 /* Error message */
90 goto done;
91 }
92
94 L"\\Device\\Harddisk%d\\Partition0",
97 Buffer);
98
100 &Name,
101 0,
102 NULL,
103 NULL);
104
108 &Iosb,
111 if (!NT_SUCCESS(Status))
112 {
113 DPRINT1("\n");
114 goto done;
115 }
116
117 FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
119 NULL,
120 NULL,
121 NULL,
122 &Iosb,
123 (PVOID)pSectorBuffer,
125 &FileOffset,
126 NULL);
127 if (!NT_SUCCESS(Status))
128 {
129 DPRINT1("NtReadFile failed, status=%x\n", Status);
130 goto done;
131 }
132
133 HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
134
135done:
136 if (FileHandle)
138
139 RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
140
141 return TRUE;
142}
static int argc
Definition: ServiceArgs.c:12
struct NameRec_ * Name
Definition: cdprocs.h:460
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static VOID HexDump(_In_ UCHAR *addr, _In_ int len)
Definition: dump.c:18
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:187
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
PDISKENTRY CurrentDisk
Definition: partlist.c:74
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define swprintf
Definition: precomp.h:40
return Iosb
Definition: create.c:4402
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define argv
Definition: mplay32.c:18
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define L(x)
Definition: ntvdm.h:50
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)
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
int64_t LONGLONG
Definition: typedefs.h:68
unsigned char * PUCHAR
Definition: typedefs.h:53
__int64 CDECL _wcstoi64(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: wtoi64.c:121
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ DumpPartition()

BOOL DumpPartition ( _In_ INT  argc,
_In_ LPWSTR argv 
)

Definition at line 146 of file dump.c.

149{
156 PUCHAR pSectorBuffer = NULL;
158 LONGLONG Sector;
159 LPWSTR endptr = NULL;
160
161
162#if 0
163 if (argc == 2)
164 {
165 ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
166 return TRUE;
167 }
168#endif
169
170 if (CurrentDisk == NULL)
171 {
173 return TRUE;
174 }
175
176 if (CurrentPartition == NULL)
177 {
179 return TRUE;
180 }
181
182 Sector = _wcstoi64(argv[2], &endptr, 0);
183 if (((Sector == 0) && (endptr == argv[2])) ||
184 (Sector < 0))
185 {
187 return TRUE;
188 }
189
190 pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
191 if (pSectorBuffer == NULL)
192 {
193 DPRINT1("\n");
194 /* Error message */
195 goto done;
196 }
197
199 L"\\Device\\Harddisk%d\\Partition%d",
203 Buffer);
204
206 &Name,
207 0,
208 NULL,
209 NULL);
210
214 &Iosb,
217 if (!NT_SUCCESS(Status))
218 {
219 DPRINT1("\n");
220 goto done;
221 }
222
223 FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
225 NULL,
226 NULL,
227 NULL,
228 &Iosb,
229 (PVOID)pSectorBuffer,
231 &FileOffset,
232 NULL);
233 if (!NT_SUCCESS(Status))
234 {
235 DPRINT1("NtReadFile failed, status=%x\n", Status);
236 goto done;
237 }
238
239 HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
240
241done:
242 if (FileHandle)
244
245 RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
246
247 return TRUE;
248}
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:88
ULONG PartitionNumber
Definition: partlist.h:75
static PPARTENTRY CurrentPartition
Definition: usetup.c:78

◆ HexDump()

static VOID HexDump ( _In_ UCHAR addr,
_In_ int  len 
)
static

Definition at line 18 of file dump.c.

21{
22 WCHAR Buffer[17];
23 UCHAR *pc;
24 int i;
25
26 Buffer[16] = L'\0';
27
28 pc = addr;
29 for (i = 0; i < len; i++)
30 {
31 if ((i % 16) == 0)
32 ConPrintf(StdOut, L" %04x ", i);
33
34 ConPrintf(StdOut, L" %02x", pc[i]);
35
36 if ((pc[i] < 0x20) || (pc[i] > 0x7e))
37 Buffer[i % 16] = L'.';
38 else
39 Buffer[i % 16] = (WCHAR)(USHORT)pc[i];
40
41 if ((i % 16) == (16 - 1))
42 ConPrintf(StdOut, L" %s\n", Buffer);
43 }
44}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DumpDisk(), and DumpPartition().