1 /* $Id: RegistryExplorer.cpp,v 1.3 2001/01/10 01:25:29 narnaoud Exp $
3 * regexpl - Console Registry Explorer
5 * Copyright (C) 2000 Nedko Arnaoudov <nedkohome@atia.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 // Registry Explorer.cpp : Defines the entry point for the console application.
27 #include "RegistryExplorer.h"
29 #include "RegistryKey.h"
30 #include "RegistryTree.h"
31 #include "SecurityDescriptor.h"
32 #include "ArgumentParser.h"
33 #include "ShellCommandsLinkedList.h"
34 #include "ShellCommandExit.h"
35 #include "ShellCommandVersion.h"
36 #include "ShellCommandHelp.h"
37 #include "ShellCommandDir.h"
38 #include "ShellCommandChangeKey.h"
39 #include "ShellCommandValue.h"
40 #include "ShellCommandOwner.h"
41 #include "ShellCommandDACL.h"
42 #include "ShellCommandSACL.h"
43 //#include "ShellCommandDOKA.h"
44 #include "ShellCommandConnect.h"
45 #include "ShellCommandNewKey.h"
46 #include "ShellCommandDeleteKey.h"
47 #include "ShellCommandSetValue.h"
48 #include "ShellCommandDeleteValue.h"
50 TCHAR pchCurrentKey
[PROMPT_BUFFER_SIZE
];
55 BOOL blnCommandExecutionInProgress
= FALSE
;
57 BOOL WINAPI
HandlerRoutine(DWORD dwCtrlType
)
62 case CTRL_BREAK_EVENT
:
63 if (blnCommandExecutionInProgress
)
74 Console
.Write(_T("\n"));
75 Console
.DisableWrite();
83 //int _tmain(/*int argc, TCHAR* argv[], TCHAR* envp[]*/)
86 CShellCommandsLinkedList
CommandsList(Console
);
88 CShellCommandExit ExitCommand
;
89 CommandsList
.AddCommand(&ExitCommand
);
91 CShellCommandVersion VersionCommand
;
92 CommandsList
.AddCommand(&VersionCommand
);
94 CShellCommandHelp
HelpCommand(CommandsList
);
95 CommandsList
.AddCommand(&HelpCommand
);
97 CShellCommandDir
DirCommand(Tree
);
98 CommandsList
.AddCommand(&DirCommand
);
100 CShellCommandChangeKey
ChangeKeyCommand(Tree
);
101 CommandsList
.AddCommand(&ChangeKeyCommand
);
103 CShellCommandValue
ValueCommand(Tree
);
104 CommandsList
.AddCommand(&ValueCommand
);
106 CShellCommandOwner
OwnerCommand(Tree
);
107 CommandsList
.AddCommand(&OwnerCommand
);
109 CShellCommandDACL
DACLCommand(Tree
);
110 CommandsList
.AddCommand(&DACLCommand
);
112 CShellCommandSACL
SACLCommand(Tree
);
113 CommandsList
.AddCommand(&SACLCommand
);
115 //CShellCommandDOKA DOKACommand(Tree);
116 //CommandsList.AddCommand(&DOKACommand);
118 CShellCommandConnect
ConnectCommand(Tree
);
119 CommandsList
.AddCommand(&ConnectCommand
);
121 CShellCommandNewKey
NewKeyCommand(Tree
);
122 CommandsList
.AddCommand(&NewKeyCommand
);
124 CShellCommandDeleteKey
DeleteKeyCommand(Tree
);
125 CommandsList
.AddCommand(&DeleteKeyCommand
);
127 CShellCommandSetValue
SetValueCommand(Tree
);
128 CommandsList
.AddCommand(&SetValueCommand
);
130 CShellCommandDeleteValue
DeleteValueCommand(Tree
);
131 CommandsList
.AddCommand(&DeleteValueCommand
);
133 CArgumentParser Parser
;
137 // input buffer size in chars
138 #define INPUT_BUFFER_SIZE 1024
139 //#define INPUT_BUFFER_SIZE 128
140 //#define INPUT_BUFFER_SIZE 10
144 pchCommand
= Console
.Init(INPUT_BUFFER_SIZE
,10);
145 if (pchCommand
== NULL
)
147 _ftprintf(stderr
,_T("Cannot initialize console.\n"));
151 Console
.SetReplaceCompletionCallback(CompletionCallback
);
153 WORD wOldConsoleAttribute
;
154 if (!Console
.GetTextAttribute(wOldConsoleAttribute
)) goto Abort
;
156 Console
.SetTitle(_T("Registry Explorer"));
157 Console
.SetTextAttribute(FOREGROUND_BLUE
|FOREGROUND_GREEN
|FOREGROUND_RED
|FOREGROUND_INTENSITY
);
159 VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE
)HandlerRoutine
,TRUE
));
161 if (!Console
.Write(HELLO_MSG
162 //(_L(__TIMESTAMP__))
165 //Tree.SetDesiredOpenKeyAccess(KEY_READ);
167 const TCHAR
*pszCurrentPath
;
170 // TODO: make prompt user-customizable
171 Console
.EnableWrite();
172 pszCurrentPath
= Tree
.GetCurrentPath();
173 Console
.Write(pszCurrentPath
?pszCurrentPath
:_T("NULL (Internal Error)"));
174 Console
.Write(_T("\n# "));
175 Console
.FlushInputBuffer();
177 blnCommandExecutionInProgress
= FALSE
;
179 // Set command line color
180 // Console.SetTextAttribute(/*FOREGROUND_BLUE|*/FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
181 if (!Console
.ReadLine())
185 // Console.SetTextAttribute(FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
187 Console
.BeginScrollingOperation();
188 blnCommandExecutionInProgress
= TRUE
;
190 // Parse command line (1st step - convert to multi sz)
191 Parser
.SetArgumentList(pchCommand
);
193 int nCommandReturnValue
;
194 switch(CommandsList
.Execute(Parser
,nCommandReturnValue
))
196 case -1: // not recognized command
198 Parser
.ResetArgumentIteration();
199 TCHAR
*pchCommandItself
= Parser
.GetNextArgument();
200 size_t cmdlen
= _tcslen(pchCommandItself
);
202 (pchCommandItself
[cmdlen
-1] != _T('\\'))||
203 (Parser
.GetNextArgument())||
204 (!Tree
.ChangeCurrentKey(pchCommandItself
)))
206 Console
.Write(_T("Unknown command \""));
207 Console
.Write(pchCommandItself
);
208 Console
.Write(_T("\"\n"));
211 case -2: // empty line
213 case 0: // exit command
215 Console
.SetTextAttribute(wOldConsoleAttribute
);
218 Console
.Write(_T("\n"));
223 _ftprintf(stderr
,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL
_T("\n"));