ReactOS  0.4.14-dev-860-gd05f621
vbscript.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #pragma once
20 
21 #include <stdarg.h>
22 #include <stdint.h>
23 
24 #define COBJMACROS
25 
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "dispex.h"
30 #include "activscp.h"
31 #include "activdbg.h"
32 
33 #ifdef __REACTOS__
34 #include <initguid.h>
35 #endif
36 #include "vbscript_classes.h"
37 #include "vbscript_defs.h"
38 
39 #include "wine/heap.h"
40 #include "wine/list.h"
41 
42 typedef struct {
43  void **blocks;
44  DWORD block_cnt;
45  DWORD last_block;
46  DWORD offset;
47  BOOL mark;
48  struct list custom_blocks;
49 } heap_pool_t;
50 
57 
62 
63 typedef struct named_item_t {
64  IDispatch *disp;
65  DWORD flags;
66  LPWSTR name;
67 
68  struct list entry;
69 } named_item_t;
70 
71 typedef enum {
77 
78 typedef struct {
79  unsigned dim_cnt;
81 } array_desc_t;
82 
83 typedef struct {
86  const WCHAR *name;
88 
89 typedef struct {
90  const WCHAR *name;
95 
96 typedef struct _class_desc_t {
97  const WCHAR *name;
99 
102  unsigned func_cnt;
104 
105  unsigned prop_cnt;
107 
108  unsigned array_cnt;
110 
112 
114 } class_desc_t;
115 
116 struct _vbdisp_t {
117  IDispatchEx IDispatchEx_iface;
118 
121  struct list entry;
122 
126 };
127 
128 typedef struct _ident_map_t ident_map_t;
129 
130 typedef struct {
131  IDispatchEx IDispatchEx_iface;
133 
135  unsigned ident_map_cnt;
136  unsigned ident_map_size;
137 
139 } ScriptDisp;
140 
142 
143 typedef struct {
146  size_t member_cnt;
149 } BuiltinDisp;
150 
159 
161 
162 static inline unsigned arg_cnt(const DISPPARAMS *dp)
163 {
164  return dp->cArgs - dp->cNamedArgs;
165 }
166 
167 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
168 {
169  return dp->rgvarg + dp->cArgs-i-1;
170 }
171 
172 typedef struct _dynamic_var_t {
175  const WCHAR *name;
177 } dynamic_var_t;
178 
179 struct _script_ctx_t {
181  LCID lcid;
182 
184  DWORD safeopt;
185 
187 
189 
192 
194 
199 
201 
202  struct list objects;
203  struct list code_list;
205 };
206 
209 
211 
212 typedef enum {
213  ARG_NONE = 0,
221 
222 #define OP_LIST \
223  X(add, 1, 0, 0) \
224  X(and, 1, 0, 0) \
225  X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
226  X(assign_member, 1, ARG_BSTR, ARG_UINT) \
227  X(bool, 1, ARG_INT, 0) \
228  X(catch, 1, ARG_ADDR, ARG_UINT) \
229  X(case, 0, ARG_ADDR, 0) \
230  X(concat, 1, 0, 0) \
231  X(const, 1, ARG_BSTR, 0) \
232  X(dim, 1, ARG_BSTR, ARG_UINT) \
233  X(div, 1, 0, 0) \
234  X(double, 1, ARG_DOUBLE, 0) \
235  X(empty, 1, 0, 0) \
236  X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
237  X(equal, 1, 0, 0) \
238  X(hres, 1, ARG_UINT, 0) \
239  X(errmode, 1, ARG_INT, 0) \
240  X(eqv, 1, 0, 0) \
241  X(exp, 1, 0, 0) \
242  X(gt, 1, 0, 0) \
243  X(gteq, 1, 0, 0) \
244  X(icall, 1, ARG_BSTR, ARG_UINT) \
245  X(icallv, 1, ARG_BSTR, ARG_UINT) \
246  X(idiv, 1, 0, 0) \
247  X(imp, 1, 0, 0) \
248  X(incc, 1, ARG_BSTR, 0) \
249  X(int, 1, ARG_INT, 0) \
250  X(is, 1, 0, 0) \
251  X(jmp, 0, ARG_ADDR, 0) \
252  X(jmp_false, 0, ARG_ADDR, 0) \
253  X(jmp_true, 0, ARG_ADDR, 0) \
254  X(lt, 1, 0, 0) \
255  X(lteq, 1, 0, 0) \
256  X(mcall, 1, ARG_BSTR, ARG_UINT) \
257  X(mcallv, 1, ARG_BSTR, ARG_UINT) \
258  X(me, 1, 0, 0) \
259  X(mod, 1, 0, 0) \
260  X(mul, 1, 0, 0) \
261  X(neg, 1, 0, 0) \
262  X(nequal, 1, 0, 0) \
263  X(new, 1, ARG_STR, 0) \
264  X(newenum, 1, 0, 0) \
265  X(not, 1, 0, 0) \
266  X(nothing, 1, 0, 0) \
267  X(null, 1, 0, 0) \
268  X(or, 1, 0, 0) \
269  X(pop, 1, ARG_UINT, 0) \
270  X(ret, 0, 0, 0) \
271  X(retval, 1, 0, 0) \
272  X(set_ident, 1, ARG_BSTR, ARG_UINT) \
273  X(set_member, 1, ARG_BSTR, ARG_UINT) \
274  X(step, 0, ARG_ADDR, ARG_BSTR) \
275  X(stop, 1, 0, 0) \
276  X(string, 1, ARG_STR, 0) \
277  X(sub, 1, 0, 0) \
278  X(val, 1, 0, 0) \
279  X(xor, 1, 0, 0)
280 
281 typedef enum {
282 #define X(x,n,a,b) OP_##x,
283 OP_LIST
284 #undef X
286 } vbsop_t;
287 
288 typedef union {
289  const WCHAR *str;
290  BSTR bstr;
291  unsigned uint;
292  LONG lng;
293  double *dbl;
294 } instr_arg_t;
295 
296 typedef struct {
300 } instr_t;
301 
302 typedef struct {
303  const WCHAR *name;
305 } arg_desc_t;
306 
307 typedef enum {
316 
317 typedef struct {
318  const WCHAR *name;
319 } var_desc_t;
320 
321 struct _function_t {
323  const WCHAR *name;
326  unsigned arg_cnt;
328  unsigned var_cnt;
330  unsigned array_cnt;
331  unsigned code_off;
334 };
335 
336 struct _vbscode_t {
339 
341 
345 
347  unsigned bstr_pool_size;
348  unsigned bstr_cnt;
350 
351  struct list entry;
352 };
353 
364 
366 
367 static inline BOOL is_int32(double d)
368 {
369  return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
370 }
371 
373 
375 
377 
378 #define FACILITY_VBS 0xa
379 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
380 
383 
386 
388 {
389  LPWSTR ret = NULL;
390 
391  if(str) {
392  DWORD size;
393 
394  size = (lstrlenW(str)+1)*sizeof(WCHAR);
395  ret = heap_alloc(size);
396  if(ret)
397  memcpy(ret, str, size);
398  }
399 
400  return ret;
401 }
402 
403 #define VBSCRIPT_BUILD_VERSION 16978
404 #define VBSCRIPT_MAJOR_VERSION 5
405 #define VBSCRIPT_MINOR_VERSION 8
const WCHAR * name
Definition: vbscript.h:318
#define INT32_MIN
Definition: macro.lex.yy.c:66
vbsop_t op
Definition: vbscript.h:297
disp
Definition: i386-dis.c:3181
instr_arg_type_t
Definition: vbscript.h:212
const WCHAR * name
Definition: vbscript.h:175
void * heap_pool_alloc(heap_pool_t *, size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
Definition: vbscript_main.c:67
heap_pool_t heap
Definition: vbscript.h:200
void clear_ei(EXCEPINFO *) DECLSPEC_HIDDEN
Definition: interp.c:242
BSTR get_vbscript_string(int) DECLSPEC_HIDDEN
Definition: vbscript_main.c:38
#define REFIID
Definition: guiddef.h:118
arg_desc_t * args
Definition: vbscript.h:325
ScriptDisp * script_obj
Definition: vbscript.h:188
heap_pool_t heap
Definition: vbscript.h:349
VARIANT v
Definition: vbscript.h:174
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
SAFEARRAYBOUND * bounds
Definition: vbscript.h:80
vbdisp_invoke_type_t
Definition: vbscript.h:71
HRESULT disp_get_id(IDispatch *, BSTR, vbdisp_invoke_type_t, BOOL, DISPID *) DECLSPEC_HIDDEN
Definition: vbdisp.c:854
HRESULT vbdisp_get_id(vbdisp_t *, BSTR, vbdisp_invoke_type_t, BOOL, DISPID *) DECLSPEC_HIDDEN
Definition: vbdisp.c:59
#define __WINE_ALLOC_SIZE(x)
Definition: winnt_old.h:84
unsigned class_initialize_id
Definition: vbscript.h:100
vbsop_t
Definition: vbscript.h:281
script_ctx_t * ctx
Definition: vbscript.h:138
unsigned bstr_cnt
Definition: vbscript.h:348
struct list objects
Definition: vbscript.h:202
dynamic_var_t * global_vars
Definition: vbscript.h:195
const WCHAR * str
Definition: vbscript.h:289
unsigned code_off
Definition: vbscript.h:331
GLintptr offset
Definition: glext.h:5920
struct named_item_t named_item_t
script_ctx_t * ctx
Definition: vbscript.h:98
unsigned arg_cnt
Definition: vbscript.h:326
class_desc_t * classes
Definition: vbscript.h:197
DWORD LCID
Definition: nls.h:13
OLECHAR * BSTR
Definition: compat.h:1942
unsigned ident_map_size
Definition: vbscript.h:136
#define lstrlenW
Definition: compat.h:415
IDispatch * host_global
Definition: jscript.h:429
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
unsigned array_cnt
Definition: vbscript.h:330
#define INT32_MAX
Definition: macro.lex.yy.c:75
unsigned prop_cnt
Definition: vbscript.h:105
struct _dynamic_var_t dynamic_var_t
HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN
Definition: vbdisp.c:877
struct _class_desc_t class_desc_t
HRESULT get_builtin_id(BuiltinDisp *, const WCHAR *, DISPID *) DECLSPEC_HIDDEN
Definition: global.c:128
heap_pool_t * heap_pool_mark(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:182
function_t * global_funcs
Definition: vbscript.h:196
function_type_t
Definition: vbscript.h:307
IUnknown * create_ax_site(script_ctx_t *) DECLSPEC_HIDDEN
Definition: jscript.c:324
LONG ref
Definition: vbscript.h:119
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HRESULT disp_call(script_ctx_t *, IDispatch *, DISPID, DISPPARAMS *, VARIANT *) DECLSPEC_HIDDEN
Definition: vbdisp.c:938
size_t member_cnt
Definition: vbscript.h:146
const WCHAR * name
Definition: vbscript.h:86
void detach_global_objects(script_ctx_t *) DECLSPEC_HIDDEN
Definition: global.c:2855
unsigned array_cnt
Definition: vbscript.h:108
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
instr_arg_t arg2
Definition: vbscript.h:299
HRESULT get_disp_value(script_ctx_t *, IDispatch *, VARIANT *) DECLSPEC_HIDDEN
Definition: vbdisp.c:967
HRESULT to_int(VARIANT *, int *) DECLSPEC_HIDDEN
Definition: global.c:410
void heap_pool_clear(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:146
function_type_t type
Definition: vbscript.h:322
array_desc_t * array_descs
Definition: vbscript.h:109
IDispatch IDispatch_iface
Definition: vbscript.h:144
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
const WCHAR * str
unsigned ident_map_cnt
Definition: vbscript.h:135
void * heap_pool_grow(heap_pool_t *, void *, DWORD, DWORD) DECLSPEC_HIDDEN
Definition: jsutils.c:130
smooth NULL
Definition: ftsmooth.c:416
unsigned bstr_pool_size
Definition: vbscript.h:347
static LPWSTR heap_strdupW(LPCWSTR str)
Definition: vbscript.h:387
const builtin_prop_t * members
Definition: vbscript.h:147
static int blocks
Definition: mkdosfs.c:527
var_desc_t * vars
Definition: vbscript.h:327
struct list entry
Definition: vbscript.h:351
struct _dynamic_var_t * next
Definition: vbscript.h:173
vbscode_t * code_ctx
Definition: vbscript.h:332
BSTR * bstr_pool
Definition: vbscript.h:346
HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory *, IUnknown *, REFIID, void **) DECLSPEC_HIDDEN
Definition: vbregexp.c:1618
void heap_pool_init(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:71
HRESULT create_vbdisp(const class_desc_t *, vbdisp_t **) DECLSPEC_HIDDEN
Definition: vbdisp.c:470
BSTR get_vbscript_error_string(HRESULT) DECLSPEC_HIDDEN
Definition: vbscript_main.c:45
void heap_pool_free(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:169
GLsizeiptr size
Definition: glext.h:5919
ident_map_t * ident_map
Definition: vbscript.h:134
instr_t * instrs
Definition: vbscript.h:337
static BOOL is_int32(double d)
Definition: vbscript.h:367
class_desc_t * procs
Definition: vbscript.h:198
#define d
Definition: ke_i.h:81
script_ctx_t * ctx
Definition: vbscript.h:148
function_t main_code
Definition: vbscript.h:343
DWORD safeopt
Definition: jscript.h:419
__wchar_t WCHAR
Definition: xmlstorage.h:180
HRESULT compile_procedure(script_ctx_t *, const WCHAR *, const WCHAR *, DWORD, class_desc_t **) DECLSPEC_HIDDEN
Definition: compile.c:1930
LONG HRESULT
Definition: typedefs.h:77
BOOL option_explicit
Definition: vbscript.h:340
#define WINAPI
Definition: msvc.h:6
static VARIANT * get_arg(DISPPARAMS *dp, DWORD i)
Definition: vbscript.h:167
unsigned short WORD
Definition: ntddk_ex.h:93
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *, IUnknown *, REFIID, void **) DECLSPEC_HIDDEN
Definition: vbscript.c:930
function_t * value_func
Definition: vbscript.h:111
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned dim_cnt
Definition: vbscript.h:79
WCHAR * source
Definition: vbscript.h:338
struct _class_desc_t * next
Definition: vbscript.h:113
void release_vbscode(vbscode_t *) DECLSPEC_HIDDEN
Definition: compile.c:1768
const WCHAR * name
Definition: vbscript.h:90
GLbitfield flags
Definition: glext.h:7161
IDispatchEx IDispatchEx_iface
Definition: vbscript.h:117
int ret
HRESULT disp_propput(script_ctx_t *, IDispatch *, DISPID, WORD, DISPPARAMS *) DECLSPEC_HIDDEN
Definition: vbdisp.c:975
vbdisp_funcprop_desc_t * funcs
Definition: vbscript.h:103
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
function_t * next
Definition: vbscript.h:333
unsigned func_cnt
Definition: vbscript.h:102
Definition: _list.h:228
HRESULT exec_script(script_ctx_t *, BOOL, function_t *, vbdisp_t *, DISPPARAMS *, VARIANT *) DECLSPEC_HIDDEN
Definition: interp.c:2086
EXCEPINFO ei
Definition: vbscript.h:193
BuiltinDisp * err_obj
Definition: vbscript.h:191
VARIANT props[1]
Definition: vbscript.h:125
BOOL pending_exec
Definition: vbscript.h:342
HRESULT compile_script(script_ctx_t *, const WCHAR *, const WCHAR *, DWORD, vbscode_t **) DECLSPEC_HIDDEN
Definition: compile.c:1828
struct stdole::EXCEPINFO EXCEPINFO
const class_desc_t * desc
Definition: vbscript.h:123
static VARIANTARG static DISPID
Definition: ordinal.c:49
static unsigned arg_cnt(const DISPPARAMS *dp)
Definition: vbscript.h:162
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
IDispatch * context
Definition: vbscript.h:344
HRESULT create_script_disp(script_ctx_t *, ScriptDisp **) DECLSPEC_HIDDEN
Definition: vbdisp.c:819
array_desc_t * array_descs
Definition: vbscript.h:329
struct list entry
Definition: vbscript.h:121
void release_regexp_typelib(void) DECLSPEC_HIDDEN
Definition: vbregexp.c:1634
IDispatch * lookup_named_item(script_ctx_t *, const WCHAR *, unsigned) DECLSPEC_HIDDEN
Definition: vbscript.c:99
const WCHAR * name
Definition: vbscript.h:303
double * dbl
Definition: vbscript.h:293
IActiveScriptSite * site
Definition: jscript.h:417
struct list code_list
Definition: vbscript.h:203
unsigned class_terminate_id
Definition: vbscript.h:101
BOOL is_public
Definition: vbscript.h:324
IInternetHostSecurityManager * secmgr
Definition: jscript.h:418
IDispatchEx IDispatchEx_iface
Definition: vbscript.h:131
HRESULT init_global(script_ctx_t *) DECLSPEC_HIDDEN
Definition: global.c:1105
HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev) DECLSPEC_HIDDEN
Definition: utils.c:163
void release_dynamic_vars(dynamic_var_t *) DECLSPEC_HIDDEN
Definition: interp.c:2044
LONG ref
Definition: vbscript.h:145
struct stdole::DISPPARAMS DISPPARAMS
named_item_t * named_items
Definition: jscript.h:416
vbdisp_prop_desc_t * props
Definition: vbscript.h:106
instr_arg_t arg1
Definition: vbscript.h:298
#define OP_LIST
Definition: vbscript.h:222
UINT32 uint
Definition: types.h:83
const WCHAR * name
Definition: vbscript.h:97
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned var_cnt
Definition: vbscript.h:328
const WCHAR * name
Definition: vbscript.h:323
BuiltinDisp * global_obj
Definition: vbscript.h:190
HRESULT init_err(script_ctx_t *) DECLSPEC_HIDDEN
HRESULT report_script_error(script_ctx_t *) DECLSPEC_HIDDEN
Definition: vbscript.c:315
void collect_objects(script_ctx_t *) DECLSPEC_HIDDEN
Definition: vbdisp.c:835
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
BOOL by_ref
Definition: vbscript.h:304
BOOL terminator_ran
Definition: vbscript.h:120
LONG ref
Definition: vbscript.h:132
HRESULT create_regexp(IDispatch **) DECLSPEC_HIDDEN
Definition: vbregexp.c:1596
SAFEARRAY ** arrays
Definition: vbscript.h:124
GLuint const GLchar * name
Definition: glext.h:6031