Exemplo n.º 1
0
BOOL read_appkey(LPCWSTR lpappname,              /* 区段名 */
                 LPCWSTR lpkey,					 /* 键名  */
                 LPWSTR  prefstring,			 /* 保存值缓冲区 */
                 DWORD   bufsize				 /* 缓冲区大小 */
                )
{
    DWORD  res = 0;
    LPWSTR lpstring;
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return res;
        }
    }
    lpstring = (LPWSTR)SYS_MALLOC(bufsize);
    res = GetPrivateProfileStringW(lpappname, lpkey ,L"", lpstring, bufsize, profile_path);
    if (res == 0 && GetLastError() != 0x0)
    {
        SYS_FREE(lpstring);
        return FALSE;
    }
    wcsncpy(prefstring,lpstring,bufsize/sizeof(WCHAR)-1);
    prefstring[res] = '\0';
    SYS_FREE(lpstring);
    return ( res>0 );
}
Exemplo n.º 2
0
void RTAudioDriver::CloseDriver() {

	audio_.closeStream();

	if (miniBlank_)
  {
		SYS_FREE(miniBlank_);
		miniBlank_=0 ;
	}

	if (unalignedMain_) 
  {
		SYS_FREE (unalignedMain_);
		unalignedMain_=0;
	} ; 
} ;
Exemplo n.º 3
0
BOOL WINAPI WaitWriteFile(LPCWSTR ap_path)
{
	BOOL  ret = FALSE;
	WCHAR profile_path[MAX_PATH+1] = {0};
	BOOL  pname = is_thunderbird();
	if (pname)
	{
		_snwprintf(profile_path,MAX_PATH,L"%ls%ls",ap_path,L"\\Thunderbird\\profiles.ini");
	}
	else
	{
		_snwprintf(profile_path,MAX_PATH,L"%ls%ls",ap_path,L"\\Mozilla\\Firefox\\profiles.ini");
	}
	if ( PathFileExistsW(profile_path) )
	{
		if (pname)
		{
			ret = WritePrivateProfileStringW(L"Profile0",L"Path",L"../../",profile_path);
		}
		else
		{
			ret = WritePrivateProfileStringW(L"Profile0",L"Path",L"../../../",profile_path);
		}
	}
	else
	{
		LPWSTR szDir;
		if ( (szDir = (LPWSTR)SYS_MALLOC( sizeof(profile_path) ) ) != NULL )
		{
			wcsncpy (szDir, profile_path, MAX_PATH);
			PathRemoveFileSpecW( szDir );
			SHCreateDirectoryExW(NULL,szDir,NULL);
			SYS_FREE(szDir);
			WritePrivateProfileSectionW(L"General",L"StartWithLastProfile=1\r\n\0",profile_path);
			if (pname)
			{
				ret = WritePrivateProfileSectionW(L"Profile0",L"Name=default\r\nIsRelative=1\r\nPath=../../\r\nDefault=1\r\n\0" \
												,profile_path);
			}
			else
			{
				ret = WritePrivateProfileSectionW(L"Profile0",L"Name=default\r\nIsRelative=1\r\nPath=../../../\r\nDefault=1\r\n\0" \
												,profile_path);
			}
		}
	}
	return ret;
}
Exemplo n.º 4
0
char* WINAPI unicode_ansi(LPCWSTR pwszUnicode)
{
    int iSize; 
    char* pszByte = NULL;
    iSize = WideCharToMultiByte(CP_ACP, 0, pwszUnicode, -1, NULL, 0, NULL, NULL); 
    pszByte = (char*)SYS_MALLOC( iSize+sizeof(char) );
    if ( !pszByte )
    {
        return NULL;
    }
    if ( !WideCharToMultiByte(CP_ACP, 0, pwszUnicode, -1, pszByte, iSize, NULL, NULL) )
    {
        SYS_FREE(pszByte);
    }
    return pszByte;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
void RTAudioDriver::fillBuffer(short *stream,int frameCount)
{
  int len = frameCount*4;

  // Look if we have enough data in main buffer
    
  while (bufferSize_-bufferPos_ < len)
  {
    // First move remaining bytes at the front
    // then get next queued buffer and copy data from it

    if (pool_[poolPlayPosition_].buffer_ == 0)
    { 
    // underrun, let's fill the buffer with blank and bail out
     SYS_MEMSET(stream, 0, len);
     return ;
    }
    else
    {
      memcpy(mainBuffer_,mainBuffer_+bufferPos_,bufferSize_-bufferPos_) ;
		  memcpy(mainBuffer_+bufferSize_-bufferPos_, pool_[poolPlayPosition_].buffer_,pool_[poolPlayPosition_].size_);
    
			MidiService::GetInstance()->Flush() ;

			 // Adapt buffer variables
    
      bufferSize_ = bufferSize_-bufferPos_ + pool_[poolPlayPosition_].size_ ;
      bufferPos_ = 0 ;

      SYS_FREE( pool_[poolPlayPosition_].buffer_) ;

      pool_[poolPlayPosition_].buffer_ = 0 ;
      poolPlayPosition_ = (poolPlayPosition_+1)%SOUND_BUFFER_COUNT ;
      thread_->Notify() ;
     }    	 
  }
  SYS_MEMCPY(stream,(short *)(mainBuffer_+bufferPos_), len); 
  onAudioBufferTick();
  bufferPos_+=len ;	  
}
Exemplo n.º 7
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
    typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
    int				ret = 0;
    HMODULE			hCrt =NULL;
    _pwrite_env		write_env = NULL;
    char			msvc_crt[CRT_LEN+1] = {0};
    LPWSTR			lpstring;
    if ( !find_msvcrt(msvc_crt,CRT_LEN) )
    {
        return (0);
    }
    if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
    {
        return (0);
    }
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return (0);
        }
    }
    write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
    if ( write_env == NULL )
    {
        return (0);
    }
    if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) == NULL )
    {
        return (0);
    }
    if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
    {
        LPWSTR	strKey = lpstring;
        while(*strKey != L'\0')
        {
            if ( stristrW(strKey, L"NpluginPath") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if ( stristrW(strKey, L"VimpPentaHome") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"VimpPentaHome",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    if (lpfile[1] != L':')
                    {
                        WCHAR vimp_path[VALUE_LEN+1] = {0};
                        charTochar(lpfile);
                        if ( PathCombineW(vimp_path,portable_data_path,lpfile) )
                        {
                            int n = _snwprintf(lpfile,VALUE_LEN,L"%ls",vimp_path);
                            lpfile[n] = L'\0';
                        }
                    }
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"HOME=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"MOZ_GMP_PATH"))
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"MOZ_GMP_PATH",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_GMP_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"TmpDataPath"))
            {
                /* the PATH environment variable does not exist */
            }
            else
            {
                ret = write_env( (LPCWSTR)strKey );
            }
            strKey += wcslen(strKey)+1;
        }
    }
    SYS_FREE(lpstring);
    return (1);
}
Exemplo n.º 8
0
 void my_os_free(void *ptr)
 {
   if(ptr) SYS_FREE(ptr);
 }
Exemplo n.º 9
0
/* PIC inject for win8/8.1 */
BOOL pic_inject(void *mpara, LPCWSTR dll_name)
{
    BOOL		exitCode = FALSE;
    CONTEXT		context;
    DWORD_PTR	*returnPointer;
    DWORD_PTR	i;
    PVOID		picBuf;
    LPVOID		funcBuff;
    SIZE_T		cbSize;
    char		dllName[VALUE_LEN+1];
    HMODULE		hNtdll;
    PROCESS_INFORMATION pi = *(LPPROCESS_INFORMATION)mpara;
    _NtAllocateVirtualMemory TrueNtAllocateVirtualMemory = NULL;
    _NtWriteVirtualMemory	 TrueNtWriteVirtualMemory	 = NULL;
    _NtFreeVirtualMemory	 TrueNtFreeVirtualMemory	 = NULL;
    _NtResumeThread			 TrueNtResumeThread			 = NULL;
    hNtdll = GetModuleHandleW(L"ntdll.dll");
    if (!hNtdll)
    {
        return exitCode;
    }
    TrueNtAllocateVirtualMemory = (_NtAllocateVirtualMemory)GetProcAddress(hNtdll, "NtAllocateVirtualMemory");
    TrueNtWriteVirtualMemory = (_NtWriteVirtualMemory)GetProcAddress(hNtdll, "NtWriteVirtualMemory");
    TrueNtFreeVirtualMemory = (_NtFreeVirtualMemory)GetProcAddress(hNtdll, "NtFreeVirtualMemory");
    TrueNtResumeThread = (_NtResumeThread)GetProcAddress(hNtdll, "NtResumeThread");
    if ( !(TrueNtAllocateVirtualMemory &&
           TrueNtWriteVirtualMemory    &&
           TrueNtFreeVirtualMemory     &&
           TrueNtResumeThread)
       )
    {
        return exitCode;
    }
    if ( !WideCharToMultiByte(CP_ACP, 0,dll_name,(int)((wcslen(dll_name)+1)*sizeof(WCHAR)), \
                              dllName, VALUE_LEN,"" , NULL)
       )
    {
        return exitCode;
    }
    /* Get its context, so we know where to return to after redirecting logic flow. */
    context.ContextFlags = CONTEXT_FULL;
    GetThreadContext(pi.hThread, &context);
#ifdef _WIN64
    returnPointer = &context.Rip;
#define PLACEHOLDER 0xDEADBEEFDEADBEEF
#else
    returnPointer = &context.Eip;
#define PLACEHOLDER 0xDEADBEEF
#endif
    cbSize = GetLoaderPicSize();
    /* Make a buffer for the PIC */
    picBuf = SYS_MALLOC(cbSize);
    if ( !picBuf )
    {
        return exitCode;
    }
#ifdef _LOGDEBUG
    logmsg("cbSize = %lu\n",cbSize);
#endif
    /* Have the pic copied into that buffer. */
    GetLoaderPic(picBuf, GetProcAddress(GetModuleHandleA("Kernel32.dll"),"LoadLibraryA"), \
                 dllName, (DWORD_PTR)(strlen(dllName)+1));
    /* Replace deadbeef (return address) in the pic with a pointer to the thread's current position. */
    for(i=0; i < cbSize - sizeof(PVOID); i++)
    {
        DWORD_PTR *deadbeef = (DWORD_PTR*)((DWORD_PTR)picBuf + i);
        if(*deadbeef == PLACEHOLDER) {
            *deadbeef = *returnPointer;
            break;
        }
    }

    /* Create a code funcBuff in the target process. */
    funcBuff = VirtualAllocEx(pi.hProcess, 0, cbSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(pi.hProcess, funcBuff, picBuf, cbSize, NULL);
    *returnPointer = (DWORD_PTR)funcBuff;
    exitCode = SetThreadContext(pi.hThread,&context);
    TrueNtResumeThread(pi.hThread,NULL);
    SYS_FREE(picBuf);
    cbSize = 0;
    TrueNtFreeVirtualMemory(pi.hProcess,funcBuff,&cbSize,MEM_RELEASE);
    return exitCode;
}
Exemplo n.º 10
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
	typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
	int				ret = 0;
	HMODULE			hCrt =NULL;
	_pwrite_env		write_env = NULL;
	char			msvc_crt[CRT_LEN+1] = {0};
	LPWSTR			lpstring;
	if ( !find_msvcrt(msvc_crt,CRT_LEN) )
	{
		return ((unsigned)ret);
	}
	if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
	{
		return ((unsigned)ret);
	}
	if ( profile_path[1] != L':' )
	{
		if (!ini_ready(profile_path,MAX_PATH))
		{
			return ((unsigned)ret);
		}
	}
	write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
	if ( write_env )
	{
		if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) != NULL )
		{
			if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
			{
				LPWSTR	strKey = lpstring;
				while(*strKey != L'\0') 
				{
					if ( stristrW(strKey, L"NpluginPath") )
					{
						WCHAR lpfile[VALUE_LEN+1];
						if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
						{
							WCHAR env_string[VALUE_LEN+1] = {0};
							PathToCombineW(lpfile, VALUE_LEN);
							if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
							{
								ret = write_env( (LPCWSTR)env_string );
							}
						}
					}
					else if	(stristrW(strKey, L"TmpDataPath"))
					{
						;
					}
					else
					{
						ret = write_env( (LPCWSTR)strKey );
					}
					strKey += wcslen(strKey)+1;
				}
			}
			SYS_FREE(lpstring);
		}
	}
	return ( (unsigned)ret );
}