2011-07-18 14:57:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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 library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-02 11:16:27 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "ole2.h"
|
2011-09-05 09:14:14 +00:00
|
|
|
#include "dispex.h"
|
2011-07-18 14:57:27 +00:00
|
|
|
#include "activscp.h"
|
2011-09-02 11:16:27 +00:00
|
|
|
|
2011-07-18 14:57:27 +00:00
|
|
|
#include "vbscript_classes.h"
|
|
|
|
|
2011-09-05 09:14:55 +00:00
|
|
|
#include "wine/list.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2011-09-12 10:29:14 +00:00
|
|
|
typedef struct {
|
|
|
|
void **blocks;
|
|
|
|
DWORD block_cnt;
|
|
|
|
DWORD last_block;
|
|
|
|
DWORD offset;
|
|
|
|
struct list custom_blocks;
|
|
|
|
} vbsheap_t;
|
|
|
|
|
|
|
|
void vbsheap_init(vbsheap_t*) DECLSPEC_HIDDEN;
|
|
|
|
void *vbsheap_alloc(vbsheap_t*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
|
|
|
|
void vbsheap_free(vbsheap_t*) DECLSPEC_HIDDEN;
|
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
typedef struct _function_t function_t;
|
|
|
|
typedef struct _vbscode_t vbscode_t;
|
2011-09-08 12:54:37 +00:00
|
|
|
typedef struct _script_ctx_t script_ctx_t;
|
2011-09-07 12:07:12 +00:00
|
|
|
|
2011-09-05 09:14:55 +00:00
|
|
|
typedef struct named_item_t {
|
|
|
|
IDispatch *disp;
|
|
|
|
DWORD flags;
|
|
|
|
LPWSTR name;
|
|
|
|
|
|
|
|
struct list entry;
|
|
|
|
} named_item_t;
|
|
|
|
|
2011-09-05 09:14:14 +00:00
|
|
|
typedef struct {
|
|
|
|
IDispatchEx IDispatchEx_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
} vbdisp_t;
|
|
|
|
|
2011-09-08 12:54:37 +00:00
|
|
|
HRESULT disp_get_id(IDispatch*,BSTR,DISPID*);
|
|
|
|
HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*);
|
2011-09-12 10:33:03 +00:00
|
|
|
HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,VARIANT*);
|
2011-09-08 12:54:37 +00:00
|
|
|
|
2011-09-13 09:36:47 +00:00
|
|
|
typedef struct _dynamic_var_t {
|
|
|
|
struct _dynamic_var_t *next;
|
|
|
|
VARIANT v;
|
|
|
|
const WCHAR *name;
|
|
|
|
} dynamic_var_t;
|
|
|
|
|
2011-09-08 12:54:37 +00:00
|
|
|
struct _script_ctx_t {
|
2011-08-31 09:22:05 +00:00
|
|
|
IActiveScriptSite *site;
|
|
|
|
LCID lcid;
|
2011-09-05 09:14:14 +00:00
|
|
|
|
2011-09-05 09:14:55 +00:00
|
|
|
IDispatch *host_global;
|
|
|
|
|
2011-09-05 09:14:14 +00:00
|
|
|
vbdisp_t *script_obj;
|
2011-09-05 09:14:55 +00:00
|
|
|
|
2011-09-13 09:36:47 +00:00
|
|
|
dynamic_var_t *global_vars;
|
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
struct list code_list;
|
2011-09-05 09:14:55 +00:00
|
|
|
struct list named_items;
|
2011-09-08 12:54:37 +00:00
|
|
|
};
|
2011-08-31 09:22:05 +00:00
|
|
|
|
2011-09-05 09:14:14 +00:00
|
|
|
HRESULT init_global(script_ctx_t*);
|
|
|
|
|
2011-09-07 12:08:47 +00:00
|
|
|
typedef enum {
|
|
|
|
ARG_NONE = 0,
|
2011-09-08 12:54:23 +00:00
|
|
|
ARG_STR,
|
2011-09-08 12:57:16 +00:00
|
|
|
ARG_BSTR,
|
|
|
|
ARG_INT,
|
2011-09-12 10:30:11 +00:00
|
|
|
ARG_UINT,
|
2011-09-13 09:38:38 +00:00
|
|
|
ARG_ADDR,
|
2011-09-12 10:30:11 +00:00
|
|
|
ARG_DOUBLE
|
2011-09-07 12:08:47 +00:00
|
|
|
} instr_arg_type_t;
|
|
|
|
|
|
|
|
#define OP_LIST \
|
2011-09-12 10:31:58 +00:00
|
|
|
X(add, 1, 0, 0) \
|
2011-09-12 10:32:50 +00:00
|
|
|
X(assign_ident, 1, ARG_BSTR, 0) \
|
2011-09-13 09:35:33 +00:00
|
|
|
X(assign_member, 1, ARG_BSTR, 0) \
|
2011-09-08 12:57:16 +00:00
|
|
|
X(bool, 1, ARG_INT, 0) \
|
2011-09-12 10:30:47 +00:00
|
|
|
X(concat, 1, 0, 0) \
|
2011-09-12 10:30:11 +00:00
|
|
|
X(double, 1, ARG_DOUBLE, 0) \
|
2011-09-09 12:49:26 +00:00
|
|
|
X(empty, 1, 0, 0) \
|
2011-09-09 12:48:25 +00:00
|
|
|
X(equal, 1, 0, 0) \
|
2011-09-09 12:48:48 +00:00
|
|
|
X(icall, 1, ARG_BSTR, ARG_UINT) \
|
2011-09-08 12:57:16 +00:00
|
|
|
X(icallv, 1, ARG_BSTR, ARG_UINT) \
|
2011-09-13 09:38:38 +00:00
|
|
|
X(jmp, 0, ARG_ADDR, 0) \
|
|
|
|
X(jmp_false, 0, ARG_ADDR, 0) \
|
2011-09-12 10:30:11 +00:00
|
|
|
X(long, 1, ARG_INT, 0) \
|
2011-09-13 09:39:53 +00:00
|
|
|
X(mod, 1, 0, 0) \
|
2011-09-12 10:31:37 +00:00
|
|
|
X(neg, 1, 0, 0) \
|
2011-09-12 10:32:27 +00:00
|
|
|
X(nequal, 1, 0, 0) \
|
2011-09-09 12:47:45 +00:00
|
|
|
X(not, 1, 0, 0) \
|
2011-09-09 12:49:36 +00:00
|
|
|
X(null, 1, 0, 0) \
|
2011-09-08 12:57:31 +00:00
|
|
|
X(ret, 0, 0, 0) \
|
2011-09-12 10:30:11 +00:00
|
|
|
X(short, 1, ARG_INT, 0) \
|
2011-09-12 10:31:58 +00:00
|
|
|
X(string, 1, ARG_STR, 0) \
|
|
|
|
X(sub, 1, 0, 0)
|
2011-09-07 12:07:12 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-09-07 12:08:47 +00:00
|
|
|
#define X(x,n,a,b) OP_##x,
|
2011-09-07 12:07:12 +00:00
|
|
|
OP_LIST
|
|
|
|
#undef X
|
|
|
|
OP_LAST
|
|
|
|
} vbsop_t;
|
|
|
|
|
2011-09-07 12:08:47 +00:00
|
|
|
typedef union {
|
|
|
|
const WCHAR *str;
|
2011-09-08 12:54:23 +00:00
|
|
|
BSTR bstr;
|
2011-09-08 12:57:16 +00:00
|
|
|
unsigned uint;
|
|
|
|
LONG lng;
|
2011-09-12 10:30:11 +00:00
|
|
|
double *dbl;
|
2011-09-07 12:08:47 +00:00
|
|
|
} instr_arg_t;
|
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
typedef struct {
|
|
|
|
vbsop_t op;
|
2011-09-07 12:08:47 +00:00
|
|
|
instr_arg_t arg1;
|
|
|
|
instr_arg_t arg2;
|
2011-09-07 12:07:12 +00:00
|
|
|
} instr_t;
|
|
|
|
|
|
|
|
struct _function_t {
|
|
|
|
unsigned code_off;
|
|
|
|
vbscode_t *code_ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _vbscode_t {
|
|
|
|
instr_t *instrs;
|
|
|
|
WCHAR *source;
|
|
|
|
|
2011-09-09 12:47:00 +00:00
|
|
|
BOOL option_explicit;
|
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
BOOL global_executed;
|
|
|
|
function_t global_code;
|
|
|
|
|
2011-09-08 12:54:23 +00:00
|
|
|
BSTR *bstr_pool;
|
|
|
|
unsigned bstr_pool_size;
|
|
|
|
unsigned bstr_cnt;
|
2011-09-12 10:29:14 +00:00
|
|
|
vbsheap_t heap;
|
2011-09-08 12:54:23 +00:00
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT compile_script(script_ctx_t*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
|
2011-09-07 12:07:24 +00:00
|
|
|
HRESULT exec_script(script_ctx_t*,function_t*) DECLSPEC_HIDDEN;
|
2011-09-07 12:07:12 +00:00
|
|
|
|
2011-07-18 14:57:27 +00:00
|
|
|
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
|
|
|
|
|
2011-09-13 09:35:50 +00:00
|
|
|
const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;
|
|
|
|
|
2011-07-18 14:57:27 +00:00
|
|
|
static inline void *heap_alloc(size_t len)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *heap_alloc_zero(size_t len)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
|
|
|
}
|
|
|
|
|
2011-09-07 12:07:12 +00:00
|
|
|
static inline void *heap_realloc(void *mem, size_t len)
|
|
|
|
{
|
|
|
|
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
|
|
|
|
}
|
|
|
|
|
2011-07-18 14:57:27 +00:00
|
|
|
static inline BOOL heap_free(void *mem)
|
|
|
|
{
|
|
|
|
return HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
}
|
2011-09-05 09:14:55 +00:00
|
|
|
|
|
|
|
static inline LPWSTR heap_strdupW(LPCWSTR str)
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
|
|
|
|
if(str) {
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
size = (strlenW(str)+1)*sizeof(WCHAR);
|
|
|
|
ret = heap_alloc(size);
|
|
|
|
if(ret)
|
|
|
|
memcpy(ret, str, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|