forked from lightspark/lightspark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
232 lines (206 loc) · 6.08 KB
/
main.cpp
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
/**************************************************************************
Lightspark, a free flash player implementation
Copyright (C) 2009,2010 Alessandro Pignotti ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "swf.h"
#include "logger.h"
#include "parsing/streams.h"
#include "backends/netutils.h"
#ifndef WIN32
#include <sys/resource.h>
#include <unistd.h>
#endif
#include <iostream>
#include <fstream>
#include "compat.h"
#ifdef WIN32
#include <windows.h>
#endif
#include <SDL.h>
#ifdef WIN32
#undef main
#endif
using namespace std;
using namespace lightspark;
TLSDATA DLL_PUBLIC SystemState* sys;
TLSDATA DLL_PUBLIC RenderThread* rt=NULL;
TLSDATA DLL_PUBLIC ParseThread* pt=NULL;
int main(int argc, char* argv[])
{
char* fileName=NULL;
char* url=NULL;
char* paramsFileName=NULL;
SecurityManager::SANDBOXTYPE sandboxType=SecurityManager::REMOTE;
bool useInterpreter=true;
bool useJit=false;
LOG_LEVEL log_level=LOG_NOT_IMPLEMENTED;
setlocale(LC_ALL, "");
bindtextdomain("lightspark", "/usr/share/locale");
textdomain("lightspark");
for(int i=1;i<argc;i++)
{
if(strcmp(argv[i],"-u")==0 ||
strcmp(argv[i],"--url")==0)
{
i++;
if(i==argc)
{
fileName=NULL;
break;
}
url=argv[i];
}
else if(strcmp(argv[i],"-ni")==0 || strcmp(argv[i],"--disable-interpreter")==0)
useInterpreter=false;
else if(strcmp(argv[i],"-j")==0 || strcmp(argv[i],"--enable-jit")==0)
useJit=true;
else if(strcmp(argv[i],"-l")==0 || strcmp(argv[i],"--log-level")==0)
{
i++;
if(i==argc)
{
fileName=NULL;
break;
}
log_level=(LOG_LEVEL)atoi(argv[i]);
}
else if(strcmp(argv[i],"-p")==0 ||
strcmp(argv[i],"--parameters-file")==0)
{
i++;
if(i==argc)
{
fileName=NULL;
break;
}
paramsFileName=argv[i];
}
else if(strcmp(argv[i],"-s")==0 ||
strcmp(argv[i],"--security-sandbox")==0)
{
i++;
if(i==argc)
{
fileName=NULL;
break;
}
if(strncmp(argv[i], "remote", 6) == 0)
sandboxType = SecurityManager::REMOTE;
else if(strncmp(argv[i], "local-with-filesystem", 21) == 0)
sandboxType = SecurityManager::LOCAL_WITH_FILE;
else if(strncmp(argv[i], "local-with-networking", 21) == 0)
sandboxType = SecurityManager::LOCAL_WITH_NETWORK;
else if(strncmp(argv[i], "local-trusted", 13) == 0)
sandboxType = SecurityManager::LOCAL_TRUSTED;
}
else if(strcmp(argv[i],"-v")==0 ||
strcmp(argv[i],"--version")==0)
{
cout << "Lightspark version " << VERSION << " Copyright 2009-2010 Alessandro Pignotti" << endl;
exit(0);
}
else
{
//No options flag, so set the swf file name
if(fileName) //If already set, exit in error status
{
fileName=NULL;
break;
}
fileName=argv[i];
}
}
if(fileName==NULL)
{
cout << "Usage: " << argv[0] << " [--url|-u http://loader.url/file.swf]" <<
" [--disable-interpreter|-ni] [--enable-jit|-j] [--log-level|-l 0-4]" <<
" [--parameters-file|-p params-file] [--security-sandbox|-s sandbox] <file.swf>" << endl;
exit(1);
}
#ifndef WIN32
struct rlimit rl;
getrlimit(RLIMIT_AS,&rl);
rl.rlim_cur=400000000;
rl.rlim_max=rl.rlim_cur;
//setrlimit(RLIMIT_AS,&rl);
#endif
Log::initLogging(log_level);
ifstream f(fileName);
f.seekg(0, ios::end);
uint32_t fileSize=f.tellg();
f.seekg(0, ios::beg);
if(!f)
{
cout << argv[0] << ": " << fileName << ": No such file or directory" << endl;
exit(2);
}
f.exceptions ( istream::eofbit | istream::failbit | istream::badbit );
cout.exceptions( ios::failbit | ios::badbit);
cerr.exceptions( ios::failbit | ios::badbit);
ParseThread* pt = new ParseThread(NULL,f);
SystemState::staticInit();
//NOTE: see SystemState declaration
sys=new SystemState(pt, fileSize);
//This setting allows qualifying filename-only paths to fully qualified paths
//When the URL parameter is set, set the root URL to the given parameter
if(url)
{
sys->setOrigin(url, fileName);
}
#ifndef WIN32
//When running in a local sandbox, set the root URL to the current working dir
else if(sandboxType != SecurityManager::REMOTE)
{
char * cwd = get_current_dir_name();
tiny_string cwdStr = tiny_string("file://") + tiny_string(cwd, true);
free(cwd);
cwdStr += "/";
sys->setOrigin(cwdStr, fileName);
}
#endif
else
{
sys->setOrigin(tiny_string("file://") + tiny_string(fileName));
LOG(LOG_NO_INFO, _("Warning: running with no origin URL set."));
}
//One of useInterpreter or useJit must be enabled
if(!(useInterpreter || useJit))
{
LOG(LOG_ERROR,_("No execution model enabled"));
exit(1);
}
sys->useInterpreter=useInterpreter;
sys->useJit=useJit;
if(paramsFileName)
sys->parseParametersFromFile(paramsFileName);
SDL_Init ( SDL_INIT_VIDEO |SDL_INIT_EVENTTHREAD );
sys->setParamsAndEngine(SDL, NULL);
sys->securityManager->setSandboxType(sandboxType);
if(sandboxType == SecurityManager::REMOTE)
LOG(LOG_NO_INFO, _("Running in remote sandbox"));
else if(sandboxType == SecurityManager::LOCAL_WITH_NETWORK)
LOG(LOG_NO_INFO, _("Running in local-with-networking sandbox"));
else if(sandboxType == SecurityManager::LOCAL_WITH_FILE)
LOG(LOG_NO_INFO, _("Running in local-with-filesystem sandbox"));
else if(sandboxType == SecurityManager::LOCAL_TRUSTED)
LOG(LOG_NO_INFO, _("Running in local-trusted sandbox"));
sys->downloadManager=new StandaloneDownloadManager();
//Start the parser
sys->addJob(pt);
sys->wait();
delete sys;
delete pt;
SystemState::staticDeinit();
SDL_Quit();
return 0;
}