/
flashutils.h
210 lines (193 loc) · 6.93 KB
/
flashutils.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
/**************************************************************************
Lightspark, a free flash player implementation
Copyright (C) 2009,2010 Alessandro Pignotti (a.pignotti@sssup.it)
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/>.
**************************************************************************/
#ifndef _FLASH_UTILS_H
#define _FLASH_UTILS_H
#include "swftypes.h"
#include "flashevents.h"
#include "thread_pool.h"
#include <map>
namespace lightspark
{
const tiny_string flash_proxy="http://www.adobe.com/2006/actionscript/flash/proxy";
class ByteArray: public ASObject
{
friend class Loader;
friend class URLLoader;
protected:
uint8_t* bytes;
unsigned int len;
unsigned int position;
ByteArray(const ByteArray& b);
public:
ByteArray();
~ByteArray();
ASFUNCTION(_getBytesAvailable);
ASFUNCTION(_getLength);
ASFUNCTION(_getPosition);
ASFUNCTION(_setPosition);
ASFUNCTION(readBytes);
void acquireBuffer(uint8_t* buf, int bufLen);
uint8_t* getBuffer(unsigned int size);
static void sinit(Class_base* c);
static void buildTraits(ASObject* o);
objAndLevel getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
{
assert_and_throw(implEnable);
throw UnsupportedException("getVariableByName not supported for ByteArray");
return objAndLevel(NULL,0);
}
objAndLevel getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true);
intptr_t getVariableByMultiname_i(const multiname& name);
void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool find_back=true, bool skip_impl=false);
void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true);
void setVariableByMultiname_i(const multiname& name, intptr_t value);
bool isEqual(ASObject* r);
};
class Timer: public EventDispatcher, public IThreadJob
{
private:
void execute();
void threadAbort();
protected:
uint32_t delay;
uint32_t repeatCount;
bool running;
public:
Timer():delay(0),repeatCount(0),running(false){};
static void sinit(Class_base* c);
ASFUNCTION(_constructor);
ASFUNCTION(start);
ASFUNCTION(reset);
};
class Dictionary: public ASObject
{
friend class ABCVm;
private:
std::map<ASObject*,ASObject*> data;
public:
Dictionary(){}
virtual ~Dictionary();
static void sinit(Class_base*);
static void buildTraits(ASObject* o);
ASFUNCTION(_constructor);
objAndLevel getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
{
assert_and_throw(implEnable);
throw UnsupportedException("getVariableByQName not supported for Dictionary");
return objAndLevel(NULL,0);
}
objAndLevel getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true);
intptr_t getVariableByMultiname_i(const multiname& name)
{
assert_and_throw(implEnable);
throw UnsupportedException("getVariableByMultiName_i not supported for Dictionary");
}
void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool find_back=true, bool skip_impl=false)
{
assert_and_throw(implEnable);
throw UnsupportedException("setVariableByQName not supported for Dictionary");
}
void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true);
void setVariableByMultiname_i(const multiname& name, intptr_t value);
void deleteVariableByMultiname(const multiname& name);
tiny_string toString(bool debugMsg=false)
{
if(debugMsg)
return ASObject::toString(debugMsg);
else
throw UnsupportedException("Dictionary::toString");
return "";
}
bool isEqual(ASObject* r)
{
assert_and_throw(implEnable);
throw UnsupportedException("isEqual not supported for Dictionary");
}
bool hasNext(unsigned int& index, bool& out);
bool nextName(unsigned int index, ASObject*& out);
bool nextValue(unsigned int index, ASObject*& out);
};
class Proxy: public ASObject
{
friend class ABCVm;
public:
static void sinit(Class_base*);
// static void buildTraits(ASObject* o);
// ASFUNCTION(_constructor);
objAndLevel getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
{
if(!implEnable || skip_impl)
return ASObject::getVariableByQName(name,ns,skip_impl);
throw RunTimeException("Proxy::getVariableByQName");
return objAndLevel(NULL,0);
}
objAndLevel getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true);
intptr_t getVariableByMultiname_i(const multiname& name)
{
assert_and_throw(implEnable);
throw UnsupportedException("getVariableByMultiName_i not supported for Proxy");
}
void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool find_back=true, bool skip_impl=false)
{
if(!implEnable || skip_impl)
ASObject::setVariableByQName(name,ns,o,find_back,skip_impl);
else
throw RunTimeException("Proxy::setVariableByQName");
}
void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true);
void setVariableByMultiname_i(const multiname& name, intptr_t value)
{
assert_and_throw(implEnable);
throw UnsupportedException("setVariableByMultiName_i not supported for Proxy");
}
void deleteVariableByMultiname(const multiname& name)
{
assert_and_throw(implEnable);
throw UnsupportedException("deleteVariableByMultiName not supported for Proxy");
}
tiny_string toString(bool debugMsg=false)
{
if(debugMsg)
return ASObject::toString(debugMsg);
else
throw UnsupportedException("Proxy is missing some stuff");
}
bool isEqual(ASObject* r)
{
assert_and_throw(implEnable);
throw UnsupportedException("Proxy is missing some stuff");
}
bool hasNext(unsigned int& index, bool& out)
{
assert_and_throw(implEnable);
throw UnsupportedException("Proxy is missing some stuff");
}
bool nextName(unsigned int index, ASObject*& out)
{
assert_and_throw(implEnable);
throw UnsupportedException("Proxy is missing some stuff");
}
bool nextValue(unsigned int index, ASObject*& out)
{
assert_and_throw(implEnable);
throw UnsupportedException("Proxy is missing some stuff");
}
};
ASObject* getQualifiedClassName(ASObject*, ASObject* const* args, const unsigned int len);
ASObject* getQualifiedSuperclassName(ASObject*, ASObject* const* args, const unsigned int len);
ASObject* getDefinitionByName(ASObject*, ASObject* const* args, const unsigned int len);
ASObject* getTimer(ASObject* obj,ASObject* const* args, const unsigned int argslen);
};
#endif