-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathprecomp.h
235 lines (186 loc) · 3.83 KB
/
precomp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*++
Copyright (c) Alex Ionescu. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED UNDER THE LESSER GNU PUBLIC LICENSE.
PLEASE READ THE FILE "COPYING" IN THE TOP LEVEL DIRECTORY.
Module Name:
precomp.h
Abstract:
The Native Command Line Interface (NCLI) is the command shell for the
TinyKRNL OS.
Environment:
Native mode
Revision History:
Alex Ionescu - Started Implementation - 23-Mar-06
--*/
#define WIN32_NO_STATUS
#define NTOS_MODE_USER
#include <stdio.h>
#include <stdarg.h>
#include <excpt.h>
#include <windef.h>
#include <winnt.h>
#include <ntndk.h>
#include <ntddkbd.h>
#include "ntfile.h"
#include "ntreg.h"
//
// Device type for input/output
//
typedef enum _CON_DEVICE_TYPE
{
KeyboardType,
MouseType
} CON_DEVICE_TYPE;
//
// Display functions
//
NTSTATUS
__cdecl
RtlCliDisplayString(
IN PCH Message,
...
);
NTSTATUS
RtlCliPrintString(
IN PUNICODE_STRING Message
);
NTSTATUS
RtlCliPutChar(
IN WCHAR Char
);
//
// Input functions
//
NTSTATUS
RtlCliOpenInputDevice(
OUT PHANDLE Handle,
IN CON_DEVICE_TYPE Type
);
CHAR
RtlCliGetChar(
IN HANDLE hDriver
);
PCHAR
RtlCliGetLine(
IN HANDLE hDriver
);
//
// System information functions
//
NTSTATUS
RtlCliListDrivers(
VOID
);
NTSTATUS
RtlCliListProcesses(
VOID
);
NTSTATUS
RtlCliDumpSysInfo(
VOID
);
NTSTATUS
RtlCliShutdown(
VOID
);
NTSTATUS
RtlCliReboot(
VOID
);
NTSTATUS
RtlCliPowerOff(
VOID
);
//
// Hardware functions
//
NTSTATUS
RtlCliListHardwareTree(
VOID
);
//
// File functions
//
NTSTATUS
RtlCliListDirectory(
VOID
);
NTSTATUS
RtlCliSetCurrentDirectory(
PCHAR Directory
);
ULONG
RtlCliGetCurrentDirectory(
IN OUT PWSTR CurrentDirectory
);
// Keyboard:
HANDLE hKeyboard;
typedef struct _KBD_RECORD {
WORD wVirtualScanCode;
DWORD dwControlKeyState;
UCHAR AsciiChar;
BOOL bKeyDown;
} KBD_RECORD, *PKBD_RECORD;
void IntTranslateKey(PKEYBOARD_INPUT_DATA InputData, KBD_RECORD *kbd_rec);
#define RIGHT_ALT_PRESSED 0x0001 // the right alt key is pressed.
#define LEFT_ALT_PRESSED 0x0002 // the left alt key is pressed.
#define RIGHT_CTRL_PRESSED 0x0004 // the right ctrl key is pressed.
#define LEFT_CTRL_PRESSED 0x0008 // the left ctrl key is pressed.
#define SHIFT_PRESSED 0x0010 // the shift key is pressed.
#define NUMLOCK_ON 0x0020 // the numlock light is on.
#define SCROLLLOCK_ON 0x0040 // the scrolllock light is on.
#define CAPSLOCK_ON 0x0080 // the capslock light is on.
#define ENHANCED_KEY 0x0100 // the key is enhanced.
// Process:
NTSTATUS CreateNativeProcess(IN PCWSTR file_name, IN PCWSTR cmd_line, OUT PHANDLE hProcess);
#define BUFFER_SIZE 1024
// Command processing:
UINT StringToArguments(CHAR *str);
char *xargv[BUFFER_SIZE];
unsigned int xargc;
BOOL GetFullPath(IN PCSTR filename, OUT PWSTR out, IN BOOL add_slash);
BOOL FileExists(PCWSTR fname);
// Registry
NTSTATUS OpenKey(OUT PHANDLE pHandle, IN PWCHAR key);
NTSTATUS RegWrite(HANDLE hKey, INT type, PWCHAR key_name, PVOID data, DWORD size);
NTSTATUS RegReadValue(HANDLE hKey, PWCHAR key_name, OUT PULONG type, OUT PVOID data, IN ULONG buf_size, OUT PULONG out_size);
// Misc
void FillUnicodeStringWithAnsi(OUT PUNICODE_STRING us, IN PCHAR as);
//===========================================================
//
// Helper Functions for ntreg.c
//
//===========================================================
BOOLEAN SetUnicodeString (
UNICODE_STRING* pustrRet,
WCHAR* pwszData
);
BOOLEAN
DisplayString (
WCHAR* pwszData
);
HANDLE
InitHeapMemory (void);
BOOLEAN
DeinitHeapMemory (
HANDLE hHeap
);
PVOID
kmalloc (
HANDLE hHeap,
int nSize
);
BOOLEAN
kfree (
HANDLE hHeap,
PVOID pMemory
);
BOOLEAN
AppendString(
WCHAR* pszInput,
WCHAR* pszAppend
);
UINT
GetStringLength(
WCHAR* pszInput
);