Exemple #1
0
int main(int argc, char* argv[])
{
  if (argc <= 1)
  {
    std::cout << "Usage: vm executable" << std::endl;
    return -1;
  }

  EXPORT(print);
  EXPORT(fprintln);
  EXPORT(fprint);
  EXPORT(cosf);
  EXPORT(stradd);

  /*
  PEFile pe;
  HMODULE module = pe.openFile("msvcrt.dll");

  DWORD dwRet = GetLastError();
  pe.importBindings(module);
  */

  VirtualMachine::GetSingleton().eip = 0;

  CodeLoader loader;



  if (!loader.load(argv[1]))
  {
    std::cout << "Error opening file \"" << argv[1] 
              <<"\": the file does not exixst or is not a valid VM executable" << std::endl;
    return -1;
  }

  VirtualMachine::GetSingleton().setBaseAddress(loader.getAddress());
  VirtualMachine::GetSingleton().setStackSize(loader.getStackSize());
  
  VirtualMachine::GetSingleton().reserveGlobal();
  VirtualMachine::GetSingleton().setEntryPoint();

  VirtualMachine::GetSingleton().instrStreamSize = loader.getStreamSize();

  VirtualMachine::GetSingleton().dumpDASM("dump.txt");
  VirtualMachine::GetSingleton().exec();

  return 0;
}
Exemple #2
0
void
install_win32_system_utilities (WIN32_SYSTEM_UTILITIES *utils)
{
#define EXPORT(field) utils->field = win32_##field
  EXPORT (under_win32s_p);
  EXPORT (allocate_heap);
  EXPORT (release_heap);
  EXPORT (lock_memory_area);
  EXPORT (unlock_memory_area);
  EXPORT (install_async_timer);
  EXPORT (flush_async_timer);
  EXPORT (alloc_scheme_selectors);
  EXPORT (release_scheme_selectors);
}
Exemple #3
0
static inline void PutGrid(Grid *grid)
{
  unsigned const int slot = EXPORT(vegasgridno) - 1;

  if( slot < MAXGRIDS ) {
    if( gridptr_[slot] == NULL ) Alloc(gridptr_[slot], ndim_);
    griddim_[slot] = ndim_;
    VecCopy(gridptr_[slot], grid);
  }
}
Exemple #4
0
Extern void EXPORT(vegas)(ccount *pndim, ccount *pncomp,
  Integrand integrand,
  creal *pepsrel, creal *pepsabs,
  cint *pflags, cnumber *pmineval, cnumber *pmaxeval,
  cnumber *pnstart, cnumber *pnincrease, 
  number *pneval, int *pfail,
  real *integral, real *error, real *prob)
{
  /* make sure the filename is null-terminated */
  if( *EXPORT(vegasstate) ) {
    char *p;
    EXPORT(vegasstate)[sizeof(EXPORT(vegasstate)) - 1] = 0;
    if( (p = strchr(EXPORT(vegasstate), ' ')) ) *p = 0;
  }

  EXPORT(Vegas)(*pndim, *pncomp,
    integrand,
    *pepsrel, *pepsabs,
    *pflags, *pmineval, *pmaxeval,
    *pnstart, *pnincrease,
    pneval, pfail,
    integral, error, prob);
}
Exemple #5
0
static inline void GetGrid(Grid *grid)
{
  count bin, dim;
  unsigned const int slot = abs(EXPORT(vegasgridno)) - 1;

  if( EXPORT(vegasgridno) < 0 ) {
    EXPORT(vegasgridno) = -EXPORT(vegasgridno);
    if( slot < MAXGRIDS ) griddim_[slot] = 0;
  }

  if( slot < MAXGRIDS && gridptr_[slot] ) {
    if( griddim_[slot] == ndim_ ) {
      VecCopy(grid, gridptr_[slot]);
      return;
    }
    free(gridptr_[slot]);
    gridptr_[slot] = NULL;
  }

  for( bin = 0; bin < NBINS; ++bin )
    grid[0][bin] = (bin + 1)/(real)NBINS;
  for( dim = 1; dim < ndim_; ++dim )
    Copy(&grid[dim], &grid[0], 1);
}
Exemple #6
0
Extern void EXPORT(suave)(ccount *pndim, ccount *pncomp,
  Integrand integrand,
  creal *pepsrel, creal *pepsabs,
  cint *pflags, cnumber *pmineval, cnumber *pmaxeval,
  cnumber *pnnew, creal *pflatness,
  count *pnregions, number *pneval, int *pfail,
  real *integral, real *error, real *prob)
{
  EXPORT(Suave)(*pndim, *pncomp,
    integrand,
    *pepsrel, *pepsabs,
    *pflags, *pmineval, *pmaxeval,
    *pnnew, *pflatness,
    pnregions, pneval, pfail,
    integral, error, prob);
}
Exemple #7
0
Extern void EXPORT(divonne)(ccount *pndim, ccount *pncomp,
  Integrand integrand,
  creal *pepsrel, creal *pepsabs,
  cint *pflags, cnumber *pmineval, cnumber *pmaxeval,
  cint *pkey1, cint *pkey2, cint *pkey3, ccount *pmaxpass,
  creal *pborder, creal *pmaxchisq, creal *pmindeviation,
  cnumber *pngiven, ccount *pldxgiven, real *xgiven,
  cnumber *pnextra, PeakFinder peakfinder,
  int *pnregions, number *pneval, int *pfail,
  real *integral, real *error, real *prob)
{
  EXPORT(Divonne)(*pndim, *pncomp,
    integrand,
    *pepsrel, *pepsabs,
    *pflags, *pmineval, *pmaxeval,
    *pkey1, *pkey2, *pkey3, *pmaxpass,
    *pborder, *pmaxchisq, *pmindeviation,
    *pngiven, *pldxgiven, xgiven,
    *pnextra, peakfinder,
    pnregions, pneval, pfail,
    integral, error, prob);
}
Exemple #8
0
RPSTR_FUNC(Bool32) RPSTR_GetExportData(uint32_t dwType, void * pData)
{
	Bool32 rc = TRUE;
  #define RPSTR_VERSION_CODE 1
    int32_t  vers = RPSTR_VERSION_CODE;
#define EXPORT(name) *(intptr_t*)(pData)=(intptr_t)name;
#define EXPORTNUM(name) *(uint32_t*)(pData)=(uint32_t)name;
  wLowRC = RPSTR_ERR_NO;
	switch(dwType)
	{
//    case    RPSTR_FNCORRECTKEGL: //      post correction kegl
//        EXPORT(RPSTR_CorrectKegl );
//        break;
    case    RPSTR_FNNEWPAGE:    //      init new page
        EXPORT(RPSTR_NewPage);
        break;
    case    RPSTR_FNCORRECTSPELL:    //      init new page
        EXPORT(RPSTR_CorrectSpell);
        break;
    case    RPSTR_FNCORRECTLINESPELL:
        EXPORT(RPSTR_CorrectLineSpell);
        break;
    case    RPSTR_FNCORRECTINCLINE:
        EXPORT(RPSTR_CorrectIncline);
        break;
    case    RPSTR_FNCOLLECTCAPDROP:
        EXPORT( RPSTR_CollectCapDrops);
        break;
    case    RPSTR_FNNORMVERTSTR:
        EXPORT( RPSTR_NormalizeVertStr);
        break;

    default:
        wLowRC = RPSTR_ERR_NOTIMPLEMENT;
        rc = FALSE;
        break;
	}
#undef EXPORT
#undef EXPORTNUM
return rc;
}
PyMODINIT_FUNC
init_zope_security_checker(void)
{
  PyObject* m;

  CheckerType.tp_new = PyType_GenericNew;
  if (PyType_Ready(&CheckerType) < 0)
    return;

  _defaultChecker = PyObject_CallFunction((PyObject*)&CheckerType, "{}");
  if (_defaultChecker == NULL)
    return;

#define INIT_STRING(S) \
if((str_##S = PyString_InternFromString(#S)) == NULL) return

  INIT_STRING(checkPermission);
  INIT_STRING(__Security_checker__);
  INIT_STRING(interaction);

  if ((_checkers = PyDict_New()) == NULL)
    return;

  NoProxy = PyObject_CallObject((PyObject*)&PyBaseObject_Type, NULL);
  if (NoProxy == NULL)
    return;

  if ((m = PyImport_ImportModule("zope.security._proxy")) == NULL) return;
  if ((Proxy = PyObject_GetAttrString(m, "_Proxy")) == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security._definitions")) == NULL) return;
  thread_local = PyObject_GetAttrString(m, "thread_local");
  if (thread_local == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security.interfaces")) == NULL) return;
  ForbiddenAttribute = PyObject_GetAttrString(m, "ForbiddenAttribute");
  if (ForbiddenAttribute == NULL) return;
  Unauthorized = PyObject_GetAttrString(m, "Unauthorized");
  if (Unauthorized == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security.checker")) == NULL) return;
  CheckerPublic = PyObject_GetAttrString(m, "CheckerPublic");
  if (CheckerPublic == NULL) return;
  Py_DECREF(m);

  if ((_available_by_default = PyList_New(0)) == NULL) return;

  m = Py_InitModule3("_zope_security_checker", module_methods,
                     "C optimizations for zope.security.checker");

  if (m == NULL)
    return;

#define EXPORT(N) Py_INCREF(N); PyModule_AddObject(m, #N, N)

  EXPORT(_checkers);
  EXPORT(NoProxy);
  EXPORT(_defaultChecker);
  EXPORT(_available_by_default);

  Py_INCREF(&CheckerType);
  PyModule_AddObject(m, "Checker", (PyObject *)&CheckerType);
}
Exemple #10
0
int
EXPORT(BTIns)(GBTree const btree, GBTObject const obj, GBTObject *ngb)
{
    BTKey               kpromoted;

    BTPage              *newroot;
    BTPage              *ppromoted;

    int                 i;
    int                 retval;

    if (btree == NULL)
    {
        // No tree
        return(BT_INVALID);
    }

    if (btree->root == NULL)
    {
        // Empty tree
        newroot = (BTPage *) EXPORT(AllocPage)(btree->pool);

        if (newroot == NULL)
        {
            return(BT_ALLOC_fail);
        }

        for(i = 0; i < BT_MAXKEY; i++)
        {
            newroot->child[i] = NULL;
            newroot->key[i] = 0;
        }

        // Numbers of children is key+1, so ensure the last child is initialised
        newroot->child[i] = NULL;
        newroot->count = 0;
        newroot->isleaf = 1;
        newroot->child[0] = (BTPage *) obj;
        btree->root = newroot;
        btree->depth = 1;
        (*ngb) = NULL;

        return(BT_OK);
    }

    if ((retval = BTInsert(btree->pool, btree->root, obj,
                           &ppromoted, &kpromoted, ngb)) == BT_PROMOTION)
    {
        newroot = (BTPage *) EXPORT(AllocPage)(btree->pool);

        if (newroot == NULL)
        {
            return(BT_ALLOC_fail);
        }

        for(i = 0; i < BT_MAXKEY; i++)
        {
            newroot->child[i] = NULL;
            newroot->key[i] = 0;
        }

        newroot->child[i] = NULL;
        newroot->count = 1;
        newroot->isleaf = 0;
        newroot->child[0] = btree->root;
        newroot->child[1] = ppromoted;
        newroot->key[0] = kpromoted;
        btree->root = newroot;
        btree->depth++;
        retval = BT_OK;
    }

    return(0);
}
Exemple #11
0
static int
BTInsert(PagePool *pool, BTPage * const current, GBTObject const obj,
         BTPage ** const ppromoted, BTKey * const kpromoted,
         GBTObject *ngb)
{
    BTKey               key;
    BTKey               kmed;

    BTKeyCount          hi;
    BTKeyCount          i;
    BTKeyCount          j;
    BTKeyCount          lo;
    BTKeyCount          mid;

    BTPage              *newpage;

    int                 in_old;
    int                 retval;

    if (current == NULL)
    {
        (*kpromoted) = BTGetObjKey(obj);
        (*ppromoted) = NULL;

        return(BT_PROMOTION);
    }

    key = BTGetObjKey(obj);
    lo = 0;
    hi = current->count;

    while(lo < hi)
    {
        mid = (lo + hi) / 2;

        if (BTKeyEQ(current->key[mid], key))
        {
            return(BT_DUPLICATE);
        }
        else if (BTKeyGT(current->key[mid], key))
        {
            hi = mid;
        }
        else
        {
            lo = mid + 1;
        }
    }

#   ifdef BT_HAVE_INTERVALS
    if ((hi < current->count) && (BTObjMatch(obj,current->key[hi])))
    {
        return(BT_OVERLAP);
    }
#   endif

    if (current->isleaf)
    {
#       ifdef BT_HAVE_INTERVALS
        if (BTObjMatch((GBTObject)(current->child[hi]), key) ||
                (!hi && BTOverlaps(obj,(GBTObject)(current->child[0]))))
        {
            return(BT_OVERLAP);
        }
#       endif

        (*ppromoted) = (BTPage *) obj;
        (*kpromoted) = BTGetObjKey(obj);
        retval = BT_PROMOTION;
        (*ngb) = (GBTObject)(current->child[hi]);

        if (!hi && BTKeyLT(key,BTGetObjKey((GBTObject)(current->child[0]))))
        {
            hi = -1;
        }
    }
    else
    {
        retval = BTInsert(pool, current->child[hi], obj, ppromoted,
                          kpromoted, ngb);
    }

    if (retval == BT_PROMOTION)
    {
        if (current->count < BT_MAXKEY)
        {
            return(BTInsertPage(current, hi, *kpromoted, *ppromoted));
        }

        // split the page BT_MINKEY keys on left (org) and
        // BT_MAXKEY-BT_MINKEY on right

        if ((newpage = (BTPage *) EXPORT(AllocPage)(pool)) == NULL)
        {
            return(BT_ALLOC_fail);
        }

        newpage->isleaf = current->isleaf;
        newpage->count = BT_MAXKEY - BT_MINKEY;
        current->count = BT_MINKEY;

        if ((in_old = (hi < current->count)))
        {
            // insert promoted key in the left (original) page
            current->count--;
            kmed = current->key[current->count];
            current->key[current->count] = 0;
        }
        else
        {
            // insert promoted key in the right (new) page
            newpage->count--;

            if (hi == current->count)
            {
                kmed = *kpromoted;
            }
            else
            {
                kmed = current->key[current->count];
                current->key[current->count] = 0;
            }
        }

        newpage->child[0] = current->child[current->count+1];
        current->child[current->count+1] = NULL;

        for(j = current->count + 1, i = 0; i < newpage->count; i++, j++)
        {
            newpage->key[i] = current->key[j];
            newpage->child[i + 1] = current->child[j + 1];
            current->key[j] = 0;
            current->child[j + 1] = NULL;
        }

        for (; i < BT_MAXKEY; i++)
        {
            newpage->key[i] = 0;
            newpage->child[i + 1] = NULL;
        }

        if (in_old)
        {
            retval = BTInsertPage(current, hi, *kpromoted, *ppromoted);
        }
        else
        {
            hi -= current->count + 1;
            retval = BTInsertPage(newpage, hi, *kpromoted, *ppromoted);
        }

        (*kpromoted) = kmed;
        (*ppromoted) = newpage;

        return(BT_PROMOTION);
    }

    return(retval);
}