2011-06-21 16:14:04 +02: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-06-21 16:14:37 +02:00
|
|
|
#include "initguid.h"
|
|
|
|
|
2011-09-02 13:16:27 +02:00
|
|
|
#include "vbscript.h"
|
2011-09-02 13:15:51 +02:00
|
|
|
#include "objsafe.h"
|
2011-09-22 14:25:27 +02:00
|
|
|
#include "mshtmhst.h"
|
2011-06-21 16:14:26 +02:00
|
|
|
#include "rpcproxy.h"
|
2011-06-21 16:14:37 +02:00
|
|
|
#include "vbscript_classes.h"
|
2011-09-19 14:08:38 +02:00
|
|
|
#include "vbsglobal.h"
|
2013-02-15 15:09:28 +01:00
|
|
|
#include "vbsregexp55.h"
|
2011-06-21 16:14:04 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
2013-02-19 12:39:47 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(heap);
|
2011-06-21 16:14:04 +02:00
|
|
|
|
2011-09-08 14:54:37 +02:00
|
|
|
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
|
|
|
|
2011-06-21 16:14:26 +02:00
|
|
|
static HINSTANCE vbscript_hinstance;
|
2019-12-06 13:46:13 +01:00
|
|
|
static ITypeInfo *dispatch_typeinfo;
|
2011-06-21 16:14:26 +02:00
|
|
|
|
2019-10-03 18:18:51 +02:00
|
|
|
BSTR get_vbscript_string(int id)
|
|
|
|
{
|
|
|
|
WCHAR buf[512];
|
|
|
|
if(!LoadStringW(vbscript_hinstance, id, buf, ARRAY_SIZE(buf))) return NULL;
|
|
|
|
return SysAllocString(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
BSTR get_vbscript_error_string(HRESULT error)
|
|
|
|
{
|
|
|
|
BSTR ret;
|
|
|
|
if(HRESULT_FACILITY(error) != FACILITY_VBS || !(ret = get_vbscript_string(HRESULT_CODE(error))))
|
|
|
|
ret = get_vbscript_string(VBS_UNKNOWN_RUNTIME_ERROR);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:29:14 +02:00
|
|
|
#define MIN_BLOCK_SIZE 128
|
2013-02-19 12:39:47 +01:00
|
|
|
#define ARENA_FREE_FILLER 0xaa
|
2011-09-12 12:29:14 +02:00
|
|
|
|
|
|
|
static inline DWORD block_size(DWORD block)
|
|
|
|
{
|
|
|
|
return MIN_BLOCK_SIZE << block;
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
void heap_pool_init(heap_pool_t *heap)
|
2011-09-12 12:29:14 +02:00
|
|
|
{
|
|
|
|
memset(heap, 0, sizeof(*heap));
|
|
|
|
list_init(&heap->custom_blocks);
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
void *heap_pool_alloc(heap_pool_t *heap, size_t size)
|
2011-09-12 12:29:14 +02:00
|
|
|
{
|
|
|
|
struct list *list;
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
size = (size+3)&~3;
|
|
|
|
|
|
|
|
if(!heap->block_cnt) {
|
|
|
|
if(!heap->blocks) {
|
|
|
|
heap->blocks = heap_alloc(sizeof(void*));
|
|
|
|
if(!heap->blocks)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = heap_alloc(block_size(0));
|
|
|
|
if(!tmp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
heap->blocks[0] = tmp;
|
|
|
|
heap->block_cnt = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(heap->offset + size <= block_size(heap->last_block)) {
|
|
|
|
tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
|
|
|
|
heap->offset += size;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(size <= block_size(heap->last_block+1)) {
|
|
|
|
if(heap->last_block+1 == heap->block_cnt) {
|
|
|
|
tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
|
|
|
|
if(!tmp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
heap->blocks = tmp;
|
|
|
|
heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
|
|
|
|
if(!heap->blocks[heap->block_cnt])
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
heap->block_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap->last_block++;
|
|
|
|
heap->offset = size;
|
|
|
|
return heap->blocks[heap->last_block];
|
|
|
|
}
|
|
|
|
|
|
|
|
list = heap_alloc(size + sizeof(struct list));
|
|
|
|
if(!list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
list_add_head(&heap->custom_blocks, list);
|
|
|
|
return list+1;
|
|
|
|
}
|
|
|
|
|
2013-02-19 12:39:47 +01:00
|
|
|
void *heap_pool_grow(heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
|
|
|
|
&& heap->offset+inc < block_size(heap->last_block)) {
|
|
|
|
heap->offset += inc;
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = heap_pool_alloc(heap, size+inc);
|
|
|
|
if(ret) /* FIXME: avoid copying for custom blocks */
|
|
|
|
memcpy(ret, mem, size);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void heap_pool_clear(heap_pool_t *heap)
|
|
|
|
{
|
|
|
|
struct list *tmp;
|
|
|
|
|
|
|
|
if(!heap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while((tmp = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
|
|
|
|
list_remove(tmp);
|
|
|
|
heap_free(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WARN_ON(heap)) {
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for(i=0; i < heap->block_cnt; i++)
|
|
|
|
memset(heap->blocks[i], ARENA_FREE_FILLER, block_size(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
heap->last_block = heap->offset = 0;
|
|
|
|
heap->mark = FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:11:13 +01:00
|
|
|
void heap_pool_free(heap_pool_t *heap)
|
2011-09-12 12:29:14 +02:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
2013-02-19 12:39:47 +01:00
|
|
|
heap_pool_clear(heap);
|
2011-09-12 12:29:14 +02:00
|
|
|
|
|
|
|
for(i=0; i < heap->block_cnt; i++)
|
|
|
|
heap_free(heap->blocks[i]);
|
|
|
|
heap_free(heap->blocks);
|
2013-02-19 12:39:47 +01:00
|
|
|
|
|
|
|
heap_pool_init(heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_pool_t *heap_pool_mark(heap_pool_t *heap)
|
|
|
|
{
|
|
|
|
if(heap->mark)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
heap->mark = TRUE;
|
|
|
|
return heap;
|
2011-09-12 12:29:14 +02:00
|
|
|
}
|
|
|
|
|
2019-12-06 13:46:13 +01:00
|
|
|
HRESULT get_dispatch_typeinfo(ITypeInfo **out)
|
|
|
|
{
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
ITypeLib *typelib;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!dispatch_typeinfo)
|
|
|
|
{
|
|
|
|
hr = LoadRegTypeLib(&IID_StdOle, STDOLE_MAJORVERNUM, STDOLE_MINORVERNUM, STDOLE_LCID, &typelib);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IDispatch, &typeinfo);
|
|
|
|
ITypeLib_Release(typelib);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
if (InterlockedCompareExchangePointer((void**)&dispatch_typeinfo, typeinfo, NULL))
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = dispatch_typeinfo;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-21 16:14:37 +02:00
|
|
|
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
|
|
|
|
*ppv = iface;
|
|
|
|
}else if(IsEqualGUID(&IID_IClassFactory, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
|
|
|
|
*ppv = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%x)\n", iface, fLock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl VBScriptFactoryVtbl = {
|
|
|
|
ClassFactory_QueryInterface,
|
|
|
|
ClassFactory_AddRef,
|
|
|
|
ClassFactory_Release,
|
|
|
|
VBScriptFactory_CreateInstance,
|
|
|
|
ClassFactory_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
static IClassFactory VBScriptFactory = { &VBScriptFactoryVtbl };
|
|
|
|
|
2013-02-15 15:09:28 +01:00
|
|
|
static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl = {
|
|
|
|
ClassFactory_QueryInterface,
|
|
|
|
ClassFactory_AddRef,
|
|
|
|
ClassFactory_Release,
|
|
|
|
VBScriptRegExpFactory_CreateInstance,
|
|
|
|
ClassFactory_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
static IClassFactory VBScriptRegExpFactory = { &VBScriptRegExpFactoryVtbl };
|
|
|
|
|
2011-06-21 16:14:04 +02:00
|
|
|
/******************************************************************
|
|
|
|
* DllMain (vbscript.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
|
|
|
{
|
|
|
|
TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
|
|
|
|
|
|
|
|
switch(fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2011-06-21 16:14:26 +02:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
|
|
|
vbscript_hinstance = hInstDLL;
|
2011-06-21 16:14:04 +02:00
|
|
|
break;
|
2011-09-19 14:08:38 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-15 10:30:04 +02:00
|
|
|
if (lpv) break;
|
2019-12-06 13:46:13 +01:00
|
|
|
if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
|
2013-02-15 15:10:27 +01:00
|
|
|
release_regexp_typelib();
|
2011-06-21 16:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllGetClassObject (vbscript.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2011-06-21 16:14:37 +02:00
|
|
|
if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
|
|
|
|
TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
|
2013-02-15 15:09:28 +01:00
|
|
|
}else if(IsEqualGUID(&CLSID_VBScriptRegExp, rclsid)) {
|
|
|
|
TRACE("(CLSID_VBScriptRegExp %s %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
return IClassFactory_QueryInterface(&VBScriptRegExpFactory, riid, ppv);
|
2011-06-21 16:14:37 +02:00
|
|
|
}
|
|
|
|
|
2011-06-21 16:14:04 +02:00
|
|
|
FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllCanUnloadNow (vbscript.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (vbscript.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
2011-06-21 16:14:26 +02:00
|
|
|
TRACE("()\n");
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_register_resources(vbscript_hinstance);
|
2011-06-21 16:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (vbscript.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
2011-06-21 16:14:26 +02:00
|
|
|
TRACE("()\n");
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_unregister_resources(vbscript_hinstance);
|
2011-06-21 16:14:04 +02:00
|
|
|
}
|