-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDI.dpr
214 lines (186 loc) · 4.49 KB
/
GDI.dpr
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
program GDI;
{$SetPEFlags 1}
{$IF compilerversion >= 21.0}
{$WEAKLINKRTTI on}
{$RTTI EXPLICIT METHODS ([]) PROPERTIES ([]) fields ([])}
{$IFEND}
uses
winapi.windows,
System.SysUtils,
classes,
PsAPI,
SpeechLib_TLB in 'SpeechLib_TLB.pas',
jsTTS in 'jsTTS.pas',
JSfilesystem in 'JSfilesystem.pas',
JSajax in 'JSajax.pas',
JSNatives in 'JSNatives.pas',
jsdb in 'jsdb.pas',
JSCrypt in 'JSCrypt.pas',
jsRuntime in 'jsRuntime.pas',
StringTools in 'StringTools.pas',
jsproc in 'jsproc.pas',
SetupApi in 'setupapi\SetupApi.pas',
ModuleLoader in 'setupapi\ModuleLoader.pas',
DeviceHelper in 'setupapi\DeviceHelper.pas',
Common in 'setupapi\Common.pas',
jshwinfo in 'jshwinfo.pas',
JudithKernel in 'JudithKernel.pas',
mod_keyhook in 'sources\natives\mod_keyhook.pas',
keyhook in 'keyhook.pas',
sndkey32tr in 'sndkey32tr.pas',
psyapi in 'psyapi.pas',
jstcp in 'jstcp.pas',
entrypoint in 'entrypoint.pas',
DeskTools in 'DeskTools.pas',
mod_disk in 'sources\mod_disk\mod_disk.pas',
udputils in 'udputils.pas',
exceptions in 'exceptions.pas',
utils in 'utils.pas',
socket in 'socket.pas',
threads in 'threads.pas',
x64 in 'x64.pas',
console in 'console.pas',
logger in 'logger.pas',
jsdownloader in 'jsdownloader.pas';
var
Mutex: Thandle;
{$R 'resources.RES'}
const
MUTEXstr = 'JudithCore';
apptitle = 'Judith';
procedure duplicatecheck;
begin
Mutex := CreateMutex(NIL, False, pchar(MUTEXstr));
if WaitForSingleObject(Mutex, 3000) = WAIT_TIMEOUT then
TerminateProcess(GetCurrentProcess, 0);
end;
var
msg: Tmsg;
bRet: Boolean;
err: RawByteString;
i: integer;
type
TTickThread = class(TThread)
protected
procedure Execute; override;
public
constructor Create;
end;
constructor TTickThread.Create;
begin
FreeOnTerminate := True;
inherited Create(False);
end;
procedure TTickThread.Execute;
var
start: int64;
begin
start := gettickcount64;
sleep(1000);
while not Terminated do
begin
Synchronize(
procedure
begin
err := judith.engine.FEngine.eval('vm._tick(' + inttostr(gettickcount64 - start) + ');', true);
end);
sleep(1);
end;
end;
begin
{
mode 0: REPL session
mode 1: read only script execution, no input
mode 2: attach to existing console (cmd, conhost, powershell, terminal)
mode 3: hidden mode, no console
}
root := extractfilepath(ParamStr(0));
chdir(root);
mode := 0;
setlength(scripts, 0);
if paramcount > 0 then
begin
mode := 1;
for i := 1 to paramcount do
begin
if paramstr(i) = '--log' then
begin
log := Tlogger.create('engine.log');
log.write('-- app start ' + datetimetostr(now));
log.write('-- GDI.js v' + version_info);
continue;
end;
if paramstr(i) = '--zombie' then
begin
nokill := true;
continue;
end;
if paramstr(i) = '--hide' then
begin
mode := 2;
continue;
end;
if paramstr(i) = '--new' then
begin
mode := 0;
incel := true;
end;
if paramstr(i) = '--update' then
begin
update := true;
end;
if paramstr(i) = '--version' then
begin
printver := true;
end;
if paramstr(i) = '-v' then
begin
printver := true;
end;
if length(paramstr(i)) > 0 then
begin
if paramstr(i)[1] <> '-' then
begin
setlength(scripts, length(scripts) + 1);
scripts[length(scripts) - 1] := paramstr(i);
end;
end;
end;
end;
if mode < 2 then
begin
CreateDebugConsole;
end;
for I := Low(scripts) to High(scripts) do
begin
if not fileexists(scripts[i]) then
begin
debug('-- file not found: ' + scripts[i]);
exit;
end;
end;
judith := TJudith.create;
ahandle := judith.window.handle;
boot := True;
//TTickThread.Create;
repeat
bRet := winapi.windows.GetMessage(msg, 0, 0, 0);
if Int32(bRet) = -1 then
begin
// OutputDebugString(PChar('Error in GetMessage: ' + IntToStr(GetLastError)));
Break;
end
else
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
until not bRet;
__shutdown := True;
judith.free;
if Mutex > 0 then
begin
ReleaseMutex(Mutex);
closehandle(Mutex);
end;
end.