-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathEMCShell.dpr
More file actions
155 lines (137 loc) · 4.44 KB
/
EMCShell.dpr
File metadata and controls
155 lines (137 loc) · 4.44 KB
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
{ ExecutionMaster component.
Copyright (C) 2018 diversenok
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> }
program EMCShell;
{$WEAKLINKRTTI ON}
{$R *.res}
uses
System.SysUtils,
Winapi.Windows,
IFEO in 'Include\IFEO.pas',
Registry2 in 'Include\Registry2.pas',
CmdUtils in 'Include\CmdUtils.pas',
ProcessUtils in 'Include\ProcessUtils.pas',
ShellExtension in 'Include\ShellExtension.pas',
MessageDialog in 'Include\MessageDialog.pas';
const
PROGRAM_NAME = 'Execution Master shell extension';
procedure ShowStatusMessage(Verb: String; Text: String = '';
Icon: TMessageIcon = miInformation);
begin
ShowMessageOk(PROGRAM_NAME, Verb, Text, Icon);
end;
procedure ActionReset;
var
Core: TImageFileExecutionOptions;
executable: String;
i: integer;
begin
executable := ExtractFileName(ParamStr(2));
try
Core := TImageFileExecutionOptions.Create;
for i := 0 to Core.Count - 1 do
begin
if ParamCount >= 2 then
if Core[i].TreatedFile <> executable then
Continue;
Core.UnregisterDebugger(Core[i].TreatedFile);
Break;
end;
finally
FreeAndNil(Core);
end;
ShowStatusMessage('The action was successfully reset.', executable);
end;
procedure CheckerUI(Text: string);
begin
if ShowMessageYesNo(PROGRAM_NAME, 'Are you sure?', Text, miWarning) <> IDYES
then
raise Exception.Create('The operation was canceled by the user.');
end;
procedure CheckForProblems(Action: TAction; S: String);
var
i: integer;
begin
for i := Low(DangerousProcesses) to High(DangerousProcesses) do
if LowerCase(S) = DangerousProcesses[i] then
begin
CheckerUI(Format(WARN_SYSPROC, [S]));
Break;
end;
if Action in [aAsk..aDisplayOn, aExecuteEx] then
begin
for i := Low(CompatibilityProblems) to High(CompatibilityProblems) do
if LowerCase(S) = CompatibilityProblems[i] then
begin
CheckerUI(Format(WARN_COMPAT, [S]));
Break;
end;
for i := Low(UIAccessPrograms) to High(UIAccessPrograms) do
if LowerCase(S) = UIAccessPrograms[i] then
begin
CheckerUI(Format(WARN_UIACCESS, [S]));
Break;
end;
end;
end;
procedure ActionSet;
var
a: TAction;
Dbg: TIFEORec;
executable: string;
begin
if ParamCount < 3 then
raise Exception.Create('Not enough parameters.');
for a := Low(TAction) to Pred(High(TAction)) do // not including aExecuteEx!
if LowerCase(ParamStr(3)) = ActionShortNames[a] then
Break;
if a = High(TAction) then // for-cycle finished without breaking
raise Exception.Create('Unknown action.');
if a in [Low(TFileBasedAction)..High(TFileBasedAction)] then
if not FileExists(Copy(EMDebuggers[a], 2,
Pos('"', EMDebuggers[a], 2) - 2)) then // Only file without params
raise Exception.Create(ERR_ACTION);
executable := ExtractFileName(ParamStr(2));
CheckForProblems(a, executable);
Dbg := TIFEORec.Create(a, executable);
TImageFileExecutionOptions.RegisterDebugger(Dbg);
ShowStatusMessage('The action was successfully set.', executable + ' → ' +
Dbg.GetCaption);
end;
begin
try
if ParamCount >= 1 then
begin
if LowerCase(ParamStr(1)) = 'set' then
ActionSet
else if LowerCase(ParamStr(1)) = 'reset' then
ActionReset
else if LowerCase(ParamStr(1)) = '/reg' then
begin
RegShellMenu(ParamStr(0));
ShowStatusMessage('Shell extension was successfully registered.');
end
else if LowerCase(ParamStr(1)) = '/unreg' then
begin
UnregShellMenu;
ShowStatusMessage('Shell extension was successfully unregistered.');
end;
end
else
ShowStatusMessage('Usage:',
'EMCShell.exe /reg - register shell extension;'#$D#$A +
'EMCShell.exe /unreg - unregister shell extension.'#$D#$A);
except
on E: Exception do
ShowStatusMessage('The action was not registered:', E.ToString, miError);
end;
end.