Example #1
0
void 
send_click(int mouse)
{
    INPUT input[2];
    fzero(&input, sizeof(input));
    input[0].type=input[1].type=INPUT_MOUSE;
    input[0].mi.dwFlags=mouse;
    if (mouse == MOUSEEVENTF_LEFTDOWN)
    {
        input[1].mi.dwFlags=MOUSEEVENTF_LEFTUP;
    }
    else if (mouse == MOUSEEVENTF_MIDDLEDOWN)
    {
        input[1].mi.dwFlags=MOUSEEVENTF_MIDDLEUP;
    }
    else
    {
        return;
    }
    if (mouse == MOUSEEVENTF_LEFTDOWN)
    {
        SendInput(2,input,sizeof(INPUT));
    }
    /* 增加一次点击,避免与双击关闭标签功能冲突 */
    if (double_click)
    {
        SendInput(2,input,sizeof(INPUT));
    }
}
bool path_update()
{
  enigma::object_planar*  const inst = (enigma::object_planar*)enigma::instance_event_iterator->inst;
  enigma::extension_path* const inst_paths = enigma::extension_cast::as_extension_path(inst);

  if (size_t(inst_paths->path_index) >= enigma::path_idmax || fzero(inst_paths->path_speed))
      return false;

  enigma::path *path = enigma::pathstructarray[inst_paths->path_index];
  if (!path)
    return false;

  bool at_end = false;
  cs_scalar pstep = inst_paths->path_speed / path->total_length;
  if (!inst_paths->path_orientation) {
    inst_paths->path_positionprevious = inst_paths->path_position;
    inst_paths->path_position += pstep;
    if ((at_end = inst_paths->path_position >= 1)) {
      inst_paths->path_position = 1;
    }
  } else {
    inst_paths->path_positionprevious = inst_paths->path_position;
    inst_paths->path_position -= pstep;
    if ((at_end = inst_paths->path_position <= 0)) {
      inst_paths->path_position = 0;
    }
  }

  cs_scalar ax, ay;
  path_getXY_scaled(path, ax, ay, inst_paths->path_position, inst_paths->path_scale);
  inst->x = inst_paths->path_xstart + ax;
  inst->y = inst_paths->path_ystart + ay;

  if (at_end) {
    //Give the user some time to intervene
    inst_paths->myevent_pathend();

    switch (inst_paths->path_endaction) {
      case 0: // Stop
          inst_paths->path_index = -1;
        return false;
      case 1: // Restart
          inst_paths->path_position = 0;
        break;
      case 2: { // Continue
          cs_scalar sx, sy;
          path_getXY_scaled(path, sx, sy, 0, inst_paths->path_scale);
          inst_paths->path_xstart = inst->x - sx;
          inst_paths->path_ystart = inst->y - sy;
          inst_paths->path_position = 0;
        break;
      }
      case 3: // Reverse
          inst_paths->path_orientation ^= true;
        break;
    }
  }

  return true;
}
Example #3
0
unsigned WINAPI run_process(void * pParam)
{
    PROCESS_INFORMATION pi;
    STARTUPINFOW si;
    WCHAR wcmd[VALUE_LEN+1] = {0};
    WCHAR wdirectory[VALUE_LEN+1] = {0};
    DWORD dwCreat = 0;
    int flags = get_parameters(wdirectory, wcmd, VALUE_LEN);
    if (flags<0)
    {
        return (0);
    }
    /* 如果是预启动,直接返回 */
    if ( parse_shcommand() )
    {
        return (0);
    }
    if ( GetLastError() == ERROR_ALREADY_EXISTS )
    {
        return (0);
    }
    if ( wcslen(wcmd)>0  && !search_process(wcmd,0) )
    {
        fzero(&si,sizeof(si));
        si.cb = sizeof(si);
        si.dwFlags = STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_MINIMIZE;
        if (!flags)
        {
            si.wShowWindow = SW_HIDE;
            dwCreat |= CREATE_NEW_PROCESS_GROUP;
        }
        if(!CreateProcessW(NULL,
                           (LPWSTR)wcmd,
                           NULL,
                           NULL,
                           FALSE,
                           dwCreat,
                           NULL,
                           (LPCWSTR)wdirectory,
                           &si,&pi))
        {
#ifdef _LOGDEBUG
            logmsg("CreateProcessW error %lu\n",GetLastError());
#endif
            return (0);
        }
        g_handle[0] = pi.hProcess;
        CloseHandle(pi.hThread);
        if ( pi.dwProcessId >4 && (SleepEx(6000,FALSE) == 0) )
        {
            search_process(NULL, pi.dwProcessId);
        }
    }
    return (1);
}
Example #4
0
bool path_update()
{
    #ifndef PATH_EXT_SET
        return false;
    #endif
    return false;  //function can cause crashes atm, until extension variables fixed
    
    enigma::extension_path* const inst_paths = ((enigma::extension_path*)enigma::instance_event_iterator->inst);

    if (inst_paths->path_index == -1 || fzero(inst_paths->path_speed))
        return false;

    return true;
}
    int object_collisions::$bbox_bottom() const
    {
        if (fzero(image_angle))
            return (image_yscale >= 0) ?
                ((mask_index >= 0 ? (sprite_get_bbox_bottom_relative(mask_index) + 1)*image_yscale - 1 : (sprite_index >= 0 ? (sprite_get_bbox_bottom_relative(sprite_index) + 1)*image_yscale - 1: 0)) + y + .5) :
                ((mask_index >= 0 ? sprite_get_bbox_top_relative(mask_index)*image_yscale : (sprite_index >= 0 ? sprite_get_bbox_top_relative(sprite_index)*image_yscale : 0)) + y + .5);

        const double arad = image_angle*(M_PI/180.0);
        const int quad = int(fmod(fmod(image_angle, 360) + 360, 360)/90.0);
        double w, h;
        w = ((image_xscale >= 0)^(quad == 2 || quad == 3)) ?
            (mask_index >= 0 ? sprite_get_bbox_left_relative(mask_index)*image_xscale : (sprite_index >= 0 ? sprite_get_bbox_left_relative(sprite_index)*image_xscale : 0)) :
            (mask_index >= 0 ? (sprite_get_bbox_right_relative(mask_index) + 1)*image_xscale - 1 : (sprite_index >= 0 ? (sprite_get_bbox_right_relative(sprite_index) + 1)*image_xscale - 1: 0));
        h = ((image_yscale >= 0)^(quad == 1 || quad == 2)) ?
            (mask_index >= 0 ? (sprite_get_bbox_bottom_relative(mask_index) + 1)*image_yscale - 1 : (sprite_index >= 0 ? (sprite_get_bbox_bottom_relative(sprite_index) + 1)*image_yscale - 1: 0)) :
            (mask_index >= 0 ? sprite_get_bbox_top_relative(mask_index)*image_yscale : (sprite_index >= 0 ? sprite_get_bbox_top_relative(sprite_index)*image_yscale : 0));

        return cos(arad)*h - sin(arad)*w + y + .5;
    }
Example #6
0
BOOL foreach_section(LPCWSTR cat,						/* ini 区段 */
                     WCHAR (*lpdata)[VALUE_LEN+1],	    /* 二维数组首地址,保存多个段值 */
                     int line							/* 二维数组行数 */
                    )
{
    DWORD	res = 0;
    LPWSTR	lpstring;
    LPWSTR	strKey;
    int		i = 0;
    const	WCHAR delim[] = L"=";
    DWORD	num = VALUE_LEN*sizeof(WCHAR)*line;
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return res;
        }
    }
    if ( (lpstring = (LPWSTR)SYS_MALLOC(num)) != NULL )
    {
        if ( (res = GetPrivateProfileSectionW(cat, lpstring, num, profile_path)) > 0 )
        {
            fzero(*lpdata,num);
            strKey = lpstring;
            while(*strKey != L'\0'&& i < line)
            {
                LPWSTR strtmp;
                WCHAR t_str[VALUE_LEN] = {0};
                wcsncpy(t_str,strKey,VALUE_LEN-1);
                strtmp = StrStrW(t_str, delim);
                if (strtmp)
                {
                    wcsncpy(lpdata[i],&strtmp[1],VALUE_LEN-1);
                }
                strKey += wcslen(strKey)+1;
                ++i;
            }
        }
        SYS_FREE(lpstring);
    }
    return (BOOL)res;
}
Example #7
0
DWORD WINAPI GetOsVersion(void)
{
    OSVERSIONINFOEXA	osvi;
    BOOL				bOs = FALSE;
    DWORD				ver = 0L;
    fzero(&osvi, sizeof(OSVERSIONINFOEXA));

    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
    if( GetVersionExA((OSVERSIONINFOA*)&osvi) )
    {
        if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&
                osvi.dwMajorVersion > 4 )
        {
            char pszOS[4] = {0};
            _snprintf(pszOS, 3, "%lu%d%lu", osvi.dwMajorVersion,0,osvi.dwMinorVersion);
            ver = strtol(pszOS, NULL, 10);
        }
    }
    return ver;
}
Example #8
0
static bool 
init_data(thread_data *pt)
{
    bool    res = false;
    WCHAR   dll_name[VALUE_LEN+1];
    HMODULE nt_handle = GetModuleHandleW(L"ntdll.dll");
    if (NULL == nt_handle)
    {
        return res;
    }    
    fzero(pt, sizeof(thread_data));
    pt->dwFuncAddr   = (uintptr_t)GetProcAddress(nt_handle, "LdrLoadDll");
    pt->dwRtlInitStr = (uintptr_t)GetProcAddress(nt_handle, "RtlInitUnicodeString");
    if (pt->dwFuncAddr && pt->dwRtlInitStr && 
        GetModuleFileNameW(dll_module,dll_name,VALUE_LEN) >0)
    {
        wcsncpy(pt->strDll,dll_name,VALUE_LEN);
        res = true;
    }
    return res;
}
Example #9
0
int
main(int argc, char *argv[])
{
  if (argc != 3) {
    printf("Usage: %s <root-dir> <output-device>\n", argv[0]);
    return 1;
  } 

  outfd = open(argv[2],O_WRONLY);
  if (outfd == -1 && errno == ENOENT) {
    outfd = open(argv[2],O_CREAT|O_WRONLY);
  }
  if (outfd == -1)
    err(2, "open output file");

  // Zero out metadata region and reset filehandle
  fzero(outfd, START_OFFSET);
  lseek(outfd, mseek, SEEK_SET);
  
  start_write(argv[1],"");
  lseek(outfd, mseek, SEEK_SET);
  close(outfd);
  return 0;
}
Example #10
0
int main(int argc, char *argv[]) {
  struct dirent* dirp;
  DIR* d;
  char *dir, *path;
  int outfd, infd;
  struct stat st;
  struct fs_hdr *fsh;
  int mseek = 0;
  int size;
  u_int32_t offset;
  struct fs_ctx *fsc;

  if (argc != 4) {
    usage();
    return -1;
  } 

  outfd = open(argv[2],O_WRONLY);
  if (outfd == -1 && errno == ENOENT) {
    outfd = open(argv[2],O_CREAT|O_WRONLY);
  }
  if (outfd == -1) {
    printf("Failed to open output file\n");
    return -1;
  }
  printf("Opened output file %s\n",argv[2]);

  //Zero out metadata region and reset filehandle
  fzero(outfd, START_OFFSET);
  lseek(outfd,mseek,SEEK_SET);

  //Initialise the blockstore
  fsc = init_fs_ctx();
  printf("Initialising blockstore...\n");
  if (init_blockstore(argv[3],fsc)!=1) {
	  printf("Failed to initialise blockstore\n");
	  return -1;
  }
  fsc->next_fs_block = 1024;
  
  fsc->fsfd = outfd;

  dir = strdup(argv[1]);
  if ((d = opendir(argv[1])) == NULL) {
    return -1;
  }

  while ((dirp = readdir(d)) != NULL) {
    if (dirp->d_type == DT_REG) {
      printf("%s/%s\n", dir, dirp->d_name);
      size = strlen(dir) + strlen(dirp->d_name) + 2;
      path = malloc(size);
      if(!path) {
	printf("Failed to malloc %d bytes\n",size);
	continue;
      }
      snprintf(path,size,"%s/%s", dir, dirp->d_name);

      //Open the file and write to dst
      infd = open(path, O_RDONLY);
      free(path);

      if(fstat(infd, &st)!=0) {
	printf("Failed to stat input file, continuing...\n");
	continue;
      }

      offset = fcopy_to_blockstore(infd,fsc,roundup(st.st_size,PAGE_SIZE));
      close(infd);

      //Seek to location and Write FS metadata
      fsh = init_hdr(dirp->d_name, st.st_size, offset, BLOCKSUM_MAGIC_HDR);
      lseek(outfd,mseek,SEEK_SET);
      write(outfd, fsh, sizeof(struct fs_hdr));

      printf("Wrote Node: %s, size: %llu, offset: %llu\n",
           fsh->filename, fsh->length, fsh->offset);

      //Reset FD pointers
      mseek += SECTOR_SIZE;

      free(fsh);
      close(infd);
    }
  }
  close(outfd);
  closedir(d);
  close_blockstore(fsc);
  return 0;
}
Example #11
0
/// Barks -> Hertz conversion
inline
double bark2hertz( double b )
{
	return fzero( [b](double f){ return hertz2bark(f) - b; }, 0, 25e3 );
}
Example #12
0
// query
DLL_QUERY libmath_query( Chuck_DL_Query * QUERY )
{
    // get global
    Chuck_Env * env = Chuck_Env::instance();
    // name
    QUERY->setname( QUERY, "Math" );

    /*! \example
    math.sin( math.pi /2.0 ) => stdout;
    */

    // register deprecate
    type_engine_register_deprecate( env, "math", "Math" );

    // add class
    QUERY->begin_class( QUERY, "Math", "Object" );
    
    // add abs
    QUERY->add_sfun( QUERY, abs_impl, "int", "abs" );
    QUERY->add_arg( QUERY, "int", "value" );
    
    // add fabs
    QUERY->add_sfun( QUERY, fabs_impl, "float", "fabs" );
    QUERY->add_arg( QUERY, "float", "value" );

    // add sgn
    QUERY->add_sfun( QUERY, sgn_impl, "float", "sgn" );
    QUERY->add_arg( QUERY, "float", "value" );
    
    // sin
    QUERY->add_sfun( QUERY, sin_impl, "float", "sin" );
    QUERY->add_arg( QUERY, "float", "x" );
    
    // cos
    QUERY->add_sfun( QUERY, cos_impl, "float", "cos" );
    QUERY->add_arg( QUERY, "float", "x" );

    // tan
    QUERY->add_sfun( QUERY, tan_impl, "float", "tan" );
    QUERY->add_arg( QUERY, "float", "x" );

    // asin
    QUERY->add_sfun( QUERY, asin_impl, "float", "asin" );
    QUERY->add_arg( QUERY, "float", "x" );

    // acos
    QUERY->add_sfun( QUERY, acos_impl, "float", "acos" );
    QUERY->add_arg( QUERY, "float", "x" );

    // atan
    QUERY->add_sfun( QUERY, atan_impl, "float", "atan" );
    QUERY->add_arg( QUERY, "float", "x" );

    // atan2
    QUERY->add_sfun( QUERY, atan2_impl, "float", "atan2" );
    QUERY->add_arg( QUERY, "float", "y" );
    QUERY->add_arg( QUERY, "float", "x" );

    // sinh
    QUERY->add_sfun( QUERY, sinh_impl, "float", "sinh" );
    QUERY->add_arg( QUERY, "float", "x" );

    // cosh
    QUERY->add_sfun( QUERY, cosh_impl, "float", "cosh" );
    QUERY->add_arg( QUERY, "float", "x" );

    // tanh
    QUERY->add_sfun( QUERY, tanh_impl, "float", "tanh" );
    QUERY->add_arg( QUERY, "float", "x" );

    // hypot
    QUERY->add_sfun( QUERY, hypot_impl, "float", "hypot" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // pow
    QUERY->add_sfun( QUERY, pow_impl, "float", "pow" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // sqrt
    QUERY->add_sfun( QUERY, sqrt_impl, "float", "sqrt" );
    QUERY->add_arg( QUERY, "float", "x" );

    // exp
    QUERY->add_sfun( QUERY, exp_impl, "float", "exp" );
    QUERY->add_arg( QUERY, "float", "x" );

    // log
    QUERY->add_sfun( QUERY, log_impl, "float", "log" );
    QUERY->add_arg( QUERY, "float", "x" );

    // log2
    QUERY->add_sfun( QUERY, log2_impl, "float", "log2" );
    QUERY->add_arg( QUERY, "float", "x" );

    // log10
    QUERY->add_sfun( QUERY, log10_impl, "float", "log10" );
    QUERY->add_arg( QUERY, "float", "x" );

    // floor
    QUERY->add_sfun( QUERY, floor_impl, "float", "floor" );
    QUERY->add_arg( QUERY, "float", "x" );

    // ceil
    QUERY->add_sfun( QUERY, ceil_impl, "float", "ceil" );
    QUERY->add_arg( QUERY, "float", "x" );

    // round
    QUERY->add_sfun( QUERY, round_impl, "float", "round" );
    QUERY->add_arg( QUERY, "float", "x" );

    // trunc
    QUERY->add_sfun( QUERY, trunc_impl, "float", "trunc" );
    QUERY->add_arg( QUERY, "float", "x" );

    // fmod
    QUERY->add_sfun( QUERY, fmod_impl, "float", "fmod" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // remainder
    QUERY->add_sfun( QUERY, remainder_impl, "float", "remainder" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // min
    QUERY->add_sfun( QUERY, min_impl, "float", "min" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // max
    //! see \example powerup.ck
    QUERY->add_sfun( QUERY, max_impl, "float", "max" );
    QUERY->add_arg( QUERY, "float", "x" );
    QUERY->add_arg( QUERY, "float", "y" );

    // isinf
    QUERY->add_sfun( QUERY, isinf_impl, "int", "isinf" );
    QUERY->add_arg( QUERY, "float", "x" );

    // isnan
    QUERY->add_sfun( QUERY, isnan_impl, "int", "isnan" );
    QUERY->add_arg( QUERY, "float", "x" );

    // floatMax
    // QUERY->add_sfun( QUERY, floatMax_impl, "float", "floatMax" );

    // intMax
    // QUERY->add_sfun( QUERY, intMax_impl, "int", "intMax" );

    // nextpow2
    QUERY->add_sfun( QUERY, nextpow2_impl, "int", "nextpow2" );
    QUERY->add_arg( QUERY, "int", "n" );

    // ensurepow2
    QUERY->add_sfun( QUERY, ensurepow2_impl, "int", "ensurePow2" );
    QUERY->add_arg( QUERY, "int", "n" );

    // rand
    QUERY->add_sfun( QUERY, rand_impl, "int", "rand" ); //! return int between 0 and RAND_MAX
    
    // rand2
    QUERY->add_sfun( QUERY, rand2_impl, "int", "rand2" ); //! integer between [min,max]
    QUERY->add_arg( QUERY, "int", "min" ); 
    QUERY->add_arg( QUERY, "int", "max" ); 
    
    // randf
    QUERY->add_sfun( QUERY, randf_impl, "float", "randf" ); //! rand between -1.0,1.0

    // rand2f
    QUERY->add_sfun( QUERY, rand2f_impl, "float", "rand2f" ); //! rand between min and max
    QUERY->add_arg( QUERY, "float", "min" );
    QUERY->add_arg( QUERY, "float", "max" );

    // add mtof
    //! see \example mand-o-matic.ck
    QUERY->add_sfun( QUERY, mtof_impl, "float", "mtof" ); //! midi note to frequency
    QUERY->add_arg( QUERY, "float", "value" );

    // add ftom
    QUERY->add_sfun( QUERY, ftom_impl, "float", "ftom" ); //! frequency to midi note
    QUERY->add_arg( QUERY, "float", "value" );

    // add powtodb
    QUERY->add_sfun( QUERY, powtodb_impl, "float", "powtodb" ); //! linear power to decibel 
    QUERY->add_arg( QUERY, "float", "value" );

    // add rmstodb
    QUERY->add_sfun( QUERY, rmstodb_impl, "float", "rmstodb" ); //! rms to decibel
    QUERY->add_arg( QUERY, "float", "value" );

    // add dbtopow
    QUERY->add_sfun( QUERY, dbtopow_impl, "float", "dbtopow" ); //! decibel to linear
    QUERY->add_arg( QUERY, "float", "value" );

    // add dbtorms
    QUERY->add_sfun( QUERY, dbtorms_impl, "float", "dbtorms" ); //! decibel to rms
    QUERY->add_arg( QUERY, "float", "value" );
    
    // add re
    QUERY->add_sfun( QUERY, re_impl, "float", "re" ); //! real component of complex
    QUERY->add_arg( QUERY, "complex", "value" );
    
    // add im
    QUERY->add_sfun( QUERY, im_impl, "float", "im" ); //! imaginary component of complex
    QUERY->add_arg( QUERY, "complex", "value" );
    
    // add mag
    QUERY->add_sfun( QUERY, modulus_impl, "float", "mag" ); //! mag
    QUERY->add_arg( QUERY, "polar", "value" );
    
    // add phase
    QUERY->add_sfun( QUERY, phase_impl, "float", "phase" ); //! phase
    QUERY->add_arg( QUERY, "polar", "value" );
    
    // add rtop
    QUERY->add_sfun( QUERY, rtop_impl, "int", "rtop" ); // rect to polar
    QUERY->add_arg( QUERY, "complex[]", "from" );
    QUERY->add_arg( QUERY, "polar[]", "to" );
    
    // add ptor
    QUERY->add_sfun( QUERY, ptor_impl, "int", "ptor" ); // polar to rect
    QUERY->add_arg( QUERY, "polar[]", "from" );
    QUERY->add_arg( QUERY, "complex[]", "to" );
    
    // pi
    //! see \example math.ck
    QUERY->add_svar( QUERY, "float", "PI", TRUE, &g_pi );

    // twopi
    QUERY->add_svar( QUERY, "float", "TWO_PI", TRUE, &g_twopi );

    // e
    QUERY->add_svar( QUERY, "float", "E", TRUE, &g_e );
    // e
    QUERY->add_svar( QUERY, "float", "e", TRUE, &g_e );

    // float max
    assert( sizeof(t_CKFLOAT) == sizeof(double) );
    QUERY->add_svar( QUERY, "float", "FLOAT_MAX", TRUE, &g_floatMax );

    // float min
    QUERY->add_svar( QUERY, "float", "FLOAT_MIN_MAG", TRUE, &g_floatMin );

    // int max
    assert( sizeof(t_CKINT) == sizeof(long) );
    QUERY->add_svar( QUERY, "int", "INT_MAX", TRUE, &g_intMax );

    // infinity, using function to avoid potential "smart" compiler warning
    g_inf = 1.0 / fzero();
    QUERY->add_svar( QUERY, "float", "INFINITY", TRUE, &g_inf );

    // i
    QUERY->add_svar( QUERY, "complex", "I", TRUE, &g_i );
    QUERY->add_svar( QUERY, "complex", "i", TRUE, &g_i );

    // j
    QUERY->add_svar( QUERY, "complex", "J", TRUE, &g_i );
    QUERY->add_svar( QUERY, "complex", "j", TRUE, &g_i );

    // done
    QUERY->end_class( QUERY );

    return TRUE;
}
Example #13
0
File: kde.c Project: gulkhan007/kde
void kde(double *data, int length, int n ,double dataMIN, double dataMAX, double **out_density, double **out_x, double *bw)
{
	XML_IN;
/*
 * function [bandwidth,density,xmesh,cdf]=kde(data,n,dataMIN,dataMAX)
 *  Reference: 
 * Kernel density estimation via diffusion
 * Z. I. Botev, J. F. Grotowski, and D. P. Kroese (2010)
 * Annals of Statistics, Volume 38, Number 5, pages 2916-2957.
*/
	
	/* if n is not supplied switch to the default
	n = pow( 2 , 14 ); 
	*/
	n = pow( 2 , ceil(log2(n)) ); // round up n to the next power of 2;
	double tol=1e-6;
	if ( (fabs(dataMIN+1)<tol) && (fabs(dataMAX+1)<tol) )
	{
		printf("using automatic extrema determination\n");
		//define the default  interval [MIN,MAX]
		double maximum,minimum;
		find_max_min_array_doubles(data,length,&maximum,&minimum);
		double Range=maximum-minimum;
		dataMIN=minimum-Range/10.0; dataMAX=maximum+Range/10.0;
		printf("min: %g max: %g\n",dataMIN,dataMAX);
	}

    /*set up the grid over which the density estimate is computed;*/
	double R=dataMAX-dataMIN; 
	double dx=R/(n-1);
	double* xmesh=(double*)malloc(n*sizeof(*xmesh));
	for (int i=0; i<n; i++ ) xmesh[i] = dataMIN+i*dx;

	double N = length; //double N=length(unique(data)); //qsort(data, length, sizeof(double), compare_doubles);
	N=256;	//FIXME: we have emulate the unique matlab function.
	/*bin the data uniformly using the grid defined above;*/
	double initial_data[n];
	histc(data, length, xmesh, n , initial_data);
	double sum_initial_data = 0;
	for(int i=0;i<n;i++){
		initial_data[i]=initial_data[i]/N;
		sum_initial_data+=initial_data[i];
	}
	for(int i=0;i<n;i++)
		initial_data[i]=initial_data[i]/sum_initial_data;

	double a[n];
	kde_dct_fftw(initial_data,n,a); // discrete cosine transform of initial data
	

	/*now compute the optimal bandwidth^2 using the referenced method*/
	double It[n-1];
	for (int i=0;i<n-1;i++)
		It[i]=pow(i+1,2.0);

	double a2[n-1];
	for(int i=0;i<n-1;i++)
		a2[i] = pow(a[i+1]/2.0,2.0);

	double t_star=0;
	/*use  fzero to solve the equation t=zeta*gamma^[5](t)*/
	/*	try
		t_star=fzero(@(t)fixed_point(t,N,I,a2),[0,.1])
		catch
		t_star=.28*N^(-2/5);
		end
		*/

	//test fixed point values
	double t=0;
	double tt;
	tt=fixed_point(0.01,N,It,a2,n);
	printf("tt: %g\n",tt);
	tt=fixed_point(0.0,N,It,a2,n);
	printf("tt: %g\n",tt);
	tt=fixed_point(0.1,N,It,a2,n);
	printf("tt: %g\n",tt);

	int status=fzero(&t_star,N,It,a2,n);
	printf("t_star: %g\n",t_star);
	//t_star=.28*pow(N,-2.0/5.0);
	//printf("t_star: %g\n",t_star);

	/*smooth the discrete cosine transform of initial data using t_star*/
	double a_t[n];
	for(int i=0;i<n;i++)
		a_t[i]=a[i]*exp(-pow(i*M_PI,2.0)*t_star/2.0);


	double *density=(double* )malloc(n*sizeof(*density));
	kde_idct_fftw(a_t,n,density); 

	for(int i=0;i<n;i++)
		density[i]/=R*n*2;

	double bandwidth=sqrt(t_star)*R;

	printf("bandwidth: %g\n",bandwidth);


	if  (verbose>=2 || verbose<=3)
	{
      int range[2]={0,128};
		print_vec(xmesh,"xmesh",0,n);
		print_vec(data,"data",0,length);
		print_vec(initial_data,"initial_data",0,n);
		print_vec(a,"a",0,n);
		print_vec(a_t,"a_t",0,n);
		print_vec(a2,"a_2",0,n-1);
		print_vec(density,"density",0,n);
	}

	if  (verbose>=3)
	{
		array_write_ascii(xmesh,n,"xmesh.txt");
		array_write_ascii(initial_data, n, "initial_data.txt");
		array_write_ascii(data, length, "data.txt");
		array_write_ascii(density, n, "density.txt");
		array_write_ascii(a_t, n, "a_t.txt");
		array_write_ascii(a2, n-1, "a_2.txt");
	}

	//prepare output
	*bw=bandwidth;
	if(!(*out_density))
		*out_density=density;
	if(!(*out_x))
			*out_x=xmesh;

	XML_OUT;
}
Example #14
0
NTSTATUS WINAPI HookNtCreateUserProcess(PHANDLE ProcessHandle,PHANDLE ThreadHandle,
								  ACCESS_MASK ProcessDesiredAccess,ACCESS_MASK ThreadDesiredAccess,
								  POBJECT_ATTRIBUTES ProcessObjectAttributes,
								  POBJECT_ATTRIBUTES ThreadObjectAttributes,
								  ULONG CreateProcessFlags,
								  ULONG CreateThreadFlags,
								  PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
								  PVOID CreateInfo,
								  PNT_PROC_THREAD_ATTRIBUTE_LIST AttributeList)
{
	RTL_USER_PROCESS_PARAMETERS mY_ProcessParameters;
	PROCESS_INFORMATION ProcessInformation;
	NTSTATUS	status;
	BOOL		tohook	= FALSE;
	fzero(&mY_ProcessParameters,sizeof(RTL_USER_PROCESS_PARAMETERS));
	if ( stristrW(ProcessParameters->ImagePathName.Buffer, L"SumatraPDF.exe") || 
		 stristrW(ProcessParameters->ImagePathName.Buffer, L"java.exe") ||
		 stristrW(ProcessParameters->ImagePathName.Buffer, L"jp2launcher.exe"))
	{
		tohook = TRUE;
	}
	else if ( read_appint(L"General",L"EnableWhiteList") > 0 )
	{
		if ( ProcessParameters->ImagePathName.Length > 0 && 
			in_whitelist((LPCWSTR)ProcessParameters->ImagePathName.Buffer) )
		{
		#ifdef _LOGDEBUG
			logmsg("the process %ls in whitelist\n",ProcessParameters->ImagePathName.Buffer);
		#endif
		}
		else
		{
		#ifdef _LOGDEBUG
			logmsg("the process %ls disabled-runes\n",ProcessParameters->ImagePathName.Buffer);
		#endif
			ProcessParameters = &mY_ProcessParameters;
		}
	}
	else if ( in_whitelist((LPCWSTR)ProcessParameters->ImagePathName.Buffer) )
	{
		;
	}
	else
	{
		if ( !IsGUI((LPCWSTR)ProcessParameters->ImagePathName.Buffer) )
			ProcessParameters = &mY_ProcessParameters;
	}
	status = TrueNtCreateUserProcess(ProcessHandle, ThreadHandle,
								  ProcessDesiredAccess, ThreadDesiredAccess,
								  ProcessObjectAttributes, ThreadObjectAttributes,
								  CreateProcessFlags, CreateThreadFlags, ProcessParameters,
								  CreateInfo, AttributeList);
	if ( NT_SUCCESS(status)&&tohook)
	{
		ULONG Suspend = 0;
		fzero(&ProcessInformation,sizeof(PROCESS_INFORMATION));
		ProcessInformation.hProcess = *ProcessHandle;
		ProcessInformation.hThread = *ThreadHandle;
	/* when tcmalloc enabled or MinGW compile time,InjectDll crash on win8/8.1 */
	#if !defined(ENABLE_TCMALLOC) && !defined(__GNUC__) && !defined(LIBPORTABLE_STATIC)
		if ( NT_SUCCESS(TrueNtSuspendThread(ProcessInformation.hThread,&Suspend)) )
		{
		#ifdef _LOGDEBUG
			logmsg("NtInjectDll() run .\n");
		#endif
			InjectDll(&ProcessInformation);
		}
	#endif
	}
	return status;
}
Example #15
0
static void fdfzero(double a,void *params,double *f,double *df)
{
  *f=fzero(a,params);
  *df=dfzero(a,params);
}
Example #16
0
JECT_EXTERN
unsigned WINAPI InjectDll(void *mpara)
{
    BOOL			bRet		= FALSE;
    LPVOID			funcBuff	= NULL;
    HANDLE			hRemote		= NULL;
    LPVOID			pBuff		= NULL;
    SIZE_T			cbSize		= sizeof(RemotePara);
    SIZE_T			cbCodeSize	= (LPBYTE)AfterThreadProc - (LPBYTE)ThreadProc;
    HMODULE			hNtdll;
    WCHAR			dll_name[VALUE_LEN+1];
    RemotePara		myPara;
    DWORD           os	   = GetOsVersion();
    PROCESS_INFORMATION pi = *(LPPROCESS_INFORMATION)mpara;

    if ( GetModuleFileNameW(dll_module,dll_name,VALUE_LEN) <=0 )
    {
        return bRet;
    }
    /* when tcmalloc enabled or MinGW x64 compile time,InjectDll crash on win8/8.1 */
#if !defined(ENABLE_TCMALLOC) && !defined(__MINGW64__)
    if ( os > 601 )
    {
#ifdef _LOGDEBUG
        logmsg("pic inject runing\n");
#endif
        return pic_inject(mpara,dll_name);
    }
#endif
    hNtdll = GetModuleHandleW(L"ntdll.dll");
    if (!hNtdll)
    {
        return bRet;
    }
    fzero(&myPara, sizeof(myPara));
    myPara.dwLoadLibraryAddr = (DWORD_PTR)GetProcAddress(hNtdll, "LdrLoadDll");
    myPara.dwRtlInitUnicodeString = (DWORD_PTR)GetProcAddress(hNtdll, "RtlInitUnicodeString");
    if ( (myPara.dwLoadLibraryAddr)&&(myPara.dwRtlInitUnicodeString) )
    {
        DWORD dwThreadId  = 0;
        wcsncpy(myPara.strDll,dll_name,VALUE_LEN);
        /* 在进程内分配空间 */
        pBuff = VirtualAllocEx(pi.hProcess, 0, cbSize+cbCodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        funcBuff = ((BYTE *)pBuff+cbSize);
        /* 写入参数空间 */
        WriteProcessMemory(pi.hProcess, pBuff, (PVOID)&myPara, cbSize, NULL);
        /* 写入代码空间 */
        WriteProcessMemory(pi.hProcess, funcBuff, (PVOID)ThreadProc, cbCodeSize, NULL);
        hRemote = CreateRemoteThread(pi.hProcess,
                                     NULL,
                                     1024*1024,
                                     (LPTHREAD_START_ROUTINE)funcBuff,
                                     pBuff,
                                     CREATE_SUSPENDED,
                                     &dwThreadId);
        if (hRemote)
        {
            ResumeThread(hRemote);
            WaitForSingleObject(hRemote,1500);
            CloseHandle(hRemote);
        }
        if (pBuff)
        {
            VirtualFreeEx(pi.hProcess, pBuff, 0, MEM_RELEASE);
        }
        if (funcBuff)
        {
            VirtualFreeEx(pi.hProcess, funcBuff, 0, MEM_RELEASE);
        }
    }
    ResumeThread(pi.hThread);
    return bRet;
}
Example #17
0
/* Split plnode along plane. We know that plane really intersects
 * plnode->poly. We also know that plnode->poly is planar and convex.
 *
 * Given this assumptions we know that plnode->poly has to be split
 * into exactly two pieces. 
 */
static inline void SplitPolyNode(PolyListNode *plnode,
				 PolyListNode **front, PolyListNode **back,
				 EdgeIntersection edges[2],
				 struct obstack *scratch)
{
  const void **tagged_app = plnode->tagged_app;
  Poly *poly = plnode->poly, savedp;
  VARARRAY(savedv, Vertex *, poly->n_vertices);
  Vertex *v0, *v1, **vpos;
  int istart[2], iend[2], i, nv[2];
  Vertex *vstart[2], *vend[2];

#if BSPTREE_STATS
  ++n_tree_polys;
#endif

  vstart[0] = vstart[1] = vend[0] = vend[1] = NULL;
  istart[0] = istart[1] = iend[0] = iend[1] = -1;

  /* first point of intersection */
  if (fzero(edges[0].scp[0])) {
    v0 = poly->v[edges[0].v[0]];
    if (fpos(edges[0].scp[1])) {
      istart[0] = edges[0].v[0];
      iend[1]   = edges[0].v[0];
    } else {
      istart[1] = edges[0].v[0];
      iend[0]   = edges[0].v[0]; 
    }
  } else if (fzero(edges[0].scp[1])) {
    v0 = poly->v[edges[0].v[1]];
    if (fpos(edges[0].scp[0])) {
      istart[1] = edges[0].v[1];
      iend[0]   = edges[0].v[1];
    } else {
      istart[0] = edges[0].v[1];
      iend[1]   = edges[0].v[1]; 
    }
  } else {
    HPt3Coord mu0, mu1;
    Vertex *V0 = poly->v[edges[0].v[0]];
    Vertex *V1 = poly->v[edges[0].v[1]];
    
    v0 = obstack_alloc(scratch, sizeof(Vertex));
    mu0 = edges[0].scp[1]/(edges[0].scp[1]-edges[0].scp[0]);
#if 0
    mu1 = edges[0].scp[0]/(edges[0].scp[0]-edges[0].scp[1]);
#else
    mu1 = 1.0 - mu0;
#endif
    /* Use denormalized variant; otherwise textures may come out wrong
     * because the homogeneous divisor is used for perspective
     * corrections.
     */
    if (poly->flags & VERT_ST) {
      v0->st.s = mu0 * V0->st.s + mu1 * V1->st.s;
      v0->st.t = mu0 * V0->st.t + mu1 * V1->st.t;
      HPt3LinSumDenorm(mu0, &V0->pt, mu1, &V1->pt, &v0->pt);
    } else {
      HPt3LinSum(mu0, &V0->pt, mu1, &V1->pt, &v0->pt);
    } 
    if (!finite(v0->pt.x + v0->pt.y + v0->pt.z)){
      abort();
    }
    if (poly->flags & VERT_C) {
      CoLinSum(mu0, &V0->vcol, mu1, &V1->vcol, &v0->vcol);
    }
    if (true || (poly->flags & VERT_N)) {
      /* The averaged vertex normals do not have an orientation, so
       * try to orient them w.r.t. the polygon normal before computing
       * the linear combination.
       */
      if (Pt3Dot(&V0->vn, &poly->pn)*Pt3Dot(&V1->vn, &poly->pn) < 0) {
	Pt3Comb(-mu0, &V0->vn, mu1, &V1->vn, &v0->vn);
      } else {
	Pt3Comb(mu0, &V0->vn, mu1, &V1->vn, &v0->vn);
      }
      Pt3Unit(&v0->vn);
    }

    if (fpos(edges[0].scp[0])) {
      vstart[1] = vend[0] = v0;
      istart[1] = edges[0].v[1];
      iend[0]   = edges[0].v[0];
    } else {
      vstart[0] = vend[1] = v0;
      istart[0] = edges[0].v[1];
      iend[1]   = edges[0].v[0];
    }
  }

  /* second point of intersection */
  if (fzero(edges[1].scp[0])) {
    v1 = poly->v[edges[1].v[0]];
    if (fpos(edges[1].scp[1])) {
      istart[0] = edges[1].v[0];
      iend[1]   = edges[1].v[0];
    } else {
      istart[1] = edges[1].v[0];
      iend[0]   = edges[1].v[0]; 
    }
  } else if (fzero(edges[1].scp[1])) {
    v1 = poly->v[edges[1].v[1]];
    if (fpos(edges[1].scp[0])) {
      istart[1] = edges[1].v[1];
      iend[0]   = edges[1].v[1];
    } else {
      istart[0] = edges[1].v[1];
      iend[1]   = edges[1].v[1]; 
    }
  } else {
    HPt3Coord mu0, mu1;
    Vertex *V0 = poly->v[edges[1].v[0]];
    Vertex *V1 = poly->v[edges[1].v[1]];
    
    v1 = obstack_alloc(scratch, sizeof(Vertex));
    mu0 = edges[1].scp[1]/(edges[1].scp[1]-edges[1].scp[0]);
#if 0
    mu1 = edges[1].scp[0]/(edges[1].scp[0]-edges[1].scp[1]);
#else
    mu1 = 1.0 - mu0;
#endif
    if (poly->flags & VERT_ST) {
      v1->st.s = mu0 * V0->st.s + mu1 * V1->st.s;
      v1->st.t = mu0 * V0->st.t + mu1 * V1->st.t;
      HPt3LinSumDenorm(mu0, &V0->pt, mu1, &V1->pt, &v1->pt);
    } else {
      HPt3LinSum(mu0, &V0->pt, mu1, &V1->pt, &v1->pt);
    }
    if (!finite(v1->pt.x + v1->pt.y + v1->pt.z))
      abort();
    if (poly->flags & VERT_C) {
      CoLinSum(mu0, &V0->vcol, mu1, &V1->vcol, &v1->vcol);
    }
    if (true || (poly->flags & VERT_N)) {
      if (Pt3Dot(&V0->vn, &poly->pn)*Pt3Dot(&V1->vn, &poly->pn) < 0) {
	Pt3Comb(-mu0, &V0->vn, mu1, &V1->vn, &v1->vn);
      } else {
	Pt3Comb(mu0, &V0->vn, mu1, &V1->vn, &v1->vn);
      }
      Pt3Unit(&v1->vn);
    }

    if (fpos(edges[1].scp[0])) {
      vstart[1] = vend[0] = v1;
      istart[1] = edges[1].v[1];
      iend[0]   = edges[1].v[0];
    } else {
      vstart[0] = vend[1] = v1;
      istart[0] = edges[1].v[1];
      iend[1]   = edges[1].v[0];
    }
  }

  ListPush(*front, plnode);
  ListPush(*back, new_poly_list_node(tagged_app, scratch));

  if ((poly->flags & POLY_NONFLAT)) {
    if (!(*front)->pn) {
      /* Compute the normal on the parent element to avoid numerical
       * instabilities on increasingly degenerated polygons.
       */
      (*front)->pn = obstack_alloc(scratch, sizeof(Point3));
      PolyNormal(poly, (*front)->pn,
		 true /* 4d */, false /* evert */, NULL, NULL);
    }
    (*back)->pn = (*front)->pn;
  }

  for (i = 0; i < 2; i++) {
    nv[i] = iend[i] - istart[i] + 1;
    if (nv[i] < 0) {
      nv[i] += poly->n_vertices;
    }
    nv[i] += (vstart[i] != NULL) + (vend[i] != NULL);
  }

  if (poly->flags & POLY_SCRATCH) {

    savedp = *poly;
    memcpy(savedv, poly->v, poly->n_vertices*sizeof(Vertex *));

    if (nv[0] <= poly->n_vertices) {
      poly->n_vertices = nv[0];
      (*front)->poly = poly;
      (*back)->poly  = new_poly(nv[1], NULL, scratch);
    } else {
      if (nv[1] > poly->n_vertices) {
	abort();
      }
      poly->n_vertices = nv[1];
      (*back)->poly = poly;
      (*front)->poly  = new_poly(nv[0], NULL, scratch);
    }
    
    /* Attention: gcc had problems with this code snippet with
     * -fstrict-aliasing, the "#if 1" stuff seems to work. In the
     * "#else" version gcc somehow lost the "savedp.v = savedv"
     * assignment. I think this is a compiler bug.
     */
    poly = &savedp;
#if 1
    poly->v = savedv;
#else
    savedp.v = savedv;
#endif
  } else {
    (*front)->poly  = new_poly(nv[0], NULL, scratch);
    (*back)->poly  = new_poly(nv[1], NULL, scratch);
  }

  for (i = 0; i < 2; i++) {
    PolyListNode *half = (i == 0) ? *front : *back;
    int j;

    vpos = half->poly->v;
    if (vstart[i] != NULL) {
      *vpos++ = vstart[i];
    }
    if (istart[i] <= iend[i]) {
      for (j = istart[i]; j <= iend[i] && j < poly->n_vertices; j++) {
	*vpos++ = poly->v[j];
      }
    } else {
      for (j = istart[i]; j < poly->n_vertices; j++) {
	*vpos++ = poly->v[j];
      }
      for (j = 0; j <= iend[i]; j++) {
	*vpos++ = poly->v[j];
      }
    }
    if (vend[i] != NULL) {
      *vpos++ = vend[i];
    }
    half->poly->pcol  = poly->pcol;
    half->poly->pn    = poly->pn;
    half->poly->flags = poly->flags|POLY_SCRATCH;

    check_poly(half->poly);
  }
}