void AddRemoveFonts(TCHAR *location, BOOL add)
{
	int counter = 0;
	TCHAR fontpath[MAX_PATH];
	TCHAR findpath[MAX_PATH];

	WIN32_FIND_DATA fd;

	_stprintf(findpath, _T("%s\\*.ttf"), location);

	HANDLE hFind = FindFirstFile(findpath, &fd);

	if(hFind != INVALID_HANDLE_VALUE) {
		_stprintf(fontpath, _T("%s\\%s"), location, fd.cFileName);
		if (add) {
			counter += AddFontResource(fontpath);
		} else {
			counter += RemoveFontResource(fontpath);
		}

		while(FindNextFile(hFind, &fd)) {
			_stprintf(fontpath, _T("%s\\%s"), location, fd.cFileName);
			if (add) {
				counter += AddFontResource(fontpath);
			} else {
				counter += RemoveFontResource(fontpath);
			}
		}
	}
	FindClose(hFind);

	if (counter > 0) {
		SendMessage(HWND_BROADCAST, WM_FONTCHANGE, NULL, NULL);
	}
}
Exemplo n.º 2
0
int MyApp::OnExit()
{
  if (wxFileExists("fonts/jsMath-cmex10.ttf")) RemoveFontResource(wxT("fonts/jsMath-cmex10.ttf"));
  if (wxFileExists("fonts/jsMath-cmsy10.ttf")) RemoveFontResource(wxT("fonts/jsMath-cmsy10.ttf"));
  if (wxFileExists("fonts/jsMath-cmr10.ttf"))  RemoveFontResource(wxT("fonts/jsMath-cmr10.ttf"));
  if (wxFileExists("fonts/jsMath-cmmi10.ttf")) RemoveFontResource(wxT("fonts/jsMath-cmmi10.ttf"));
  if (wxFileExists("fonts/jsMath-cmti10.ttf")) RemoveFontResource(wxT("fonts/jsMath-cmti10.ttf"));
}
void CGumpEditorDoc::UnInit()
{
	delete m_pGumpLoader;
	m_pGumpLoader = NULL;
//flo:
	delete pVerdataLoader;
	pVerdataLoader = NULL;

	delete m_pHueLoader;
	m_pHueLoader = NULL;
	
	LOGFONT lf;
	memset(&lf, 0, sizeof(lf));

	CString strFontName;
	for (font_iter iter = m_fonts.begin(); iter != m_fonts.end(); iter++)
	{
		delete iter->second.font;
		RemoveFontResource(iter->second.file.c_str());
	}
	m_fonts.clear();

	m_bInitUOData = false;
	g_pGumpEditorDoc = NULL;
}
Exemplo n.º 4
0
    ~BitmapDC()
    {
        prepareBitmap(0, 0);
        if (m_hDC)
        {
            DeleteDC(m_hDC);
        }
        HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
        if (hDefFont != m_hFont)
        {
            DeleteObject(m_hFont);
            m_hFont = hDefFont;
        }
		// release temp font resource	
		if (m_curFontPath.size() > 0)
		{
			wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
			if (pwszBuffer)
			{
				RemoveFontResource(pwszBuffer);
				SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
				delete [] pwszBuffer;
				pwszBuffer = NULL;
			}
		}
    }
RRESULT OnDestroy(void *pParam)
{
	cclog("Destroy gunz\n");

	g_App.OnDestroy();

	SAFE_DELETE(g_pDefFont); 

	g_Core.Finalize();

	cclog("interface finalize.\n");

	SAFE_DELETE(g_pInput);
	g_DInput.Destroy();

	cclog("game input destroy.\n");

//	RGetShaderMgr()->Release();

	ZGetConfiguration()->Destroy();

	cclog("game gonfiguration destroy.\n");

	delete g_pDC;

	struct _finddata_t c_file;
	intptr_t hFile;
	char szFileName[256];
#define FONT_DIR	"Font/"
#define FONT_EXT	"ttf"
	if( (hFile = _findfirst(FONT_DIR"*."FONT_EXT, &c_file )) != -1L ){
		do{
			strcpy(szFileName, FONT_DIR);
			strcat(szFileName, c_file.name);
			RemoveFontResource(szFileName);
		}while( _findnext( hFile, &c_file ) == 0 );
		_findclose(hFile);
	}

	CCFontManager::Destroy();
	CCBitmapManager::Destroy();
	CCBitmapManager::DestroyAniBitmap();

	cclog("Bitmap manager destroy Animation bitmap.\n");


//	ZBasicInfoItem::Release(); 
//	ZGetStencilLight()->Destroy();
//	LightSource::Release();
	RBspObject::DestroyShadeMap();
	RDestroyLenzFlare();
	RAnimationFileMgr::GetInstance()->Destroy();
	ZStringResManager::ResetInstance();
	cclog("destroy gunz finish.\n");

	return R_OK;
}
Exemplo n.º 6
0
void StartmenuDestroy()
{
	DeleteObject(hCopyrightFont);
	DeleteObject(hDescriptionFont);
	DeleteObject(hTitleFont);
	DeleteObject(hMenuSelectedFont);
	DeleteObject(hMenuFont);
	RemoveFontResource(FONTNAME TEXT(".ttf"));
}
Exemplo n.º 7
0
bool QFontDatabase::removeApplicationFont(int handle)
{
    QMutexLocker locker(fontDatabaseMutex());

    QFontDatabasePrivate *db = privateDb();
    if (handle < 0 || handle >= db->applicationFonts.count())
        return false;

    const QFontDatabasePrivate::ApplicationFont font = db->applicationFonts.at(handle);
    db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont();
    if (font.memoryFont) {
#ifdef Q_OS_WINCE
        bool removeSucceeded = RemoveFontResource((LPCWSTR)font.fileName.utf16());
        QFile tempfile(font.fileName);
        tempfile.remove();
        if (!removeSucceeded)
            return false;
#else
        PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                                              "RemoveFontMemResourceEx");
        if (!ptrRemoveFontMemResourceEx
            || !ptrRemoveFontMemResourceEx(font.handle))
            return false;
#endif // Q_OS_WINCE
    } else {
#ifdef Q_OS_WINCE
        if (!RemoveFontResource((LPCWSTR)font.fileName.utf16()))
            return false;
#else
        PtrRemoveFontResourceExW ptrRemoveFontResourceExW = (PtrRemoveFontResourceExW)QSystemLibrary::resolve(QLatin1String("gdi32"),
                                                                                                        "RemoveFontResourceExW");
        if (!ptrRemoveFontResourceExW
            || !ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0))
            return false;
#endif // Q_OS_WINCE
    }

    db->invalidate();
    return true;
}
Exemplo n.º 8
0
void CFontMgr::Release()
{
	for (int i=0; i<fontreslist.Size(); i++)
	{
		RemoveFontResource( fontreslist[i].c_str() );		
	}

	for (int i=0;i<MAX_FONTS;i++)
		if (fonts[i]!=NULL)
		{
			fonts[i]->Release();
			fonts[i] = NULL;
		}
}
Exemplo n.º 9
0
C4VectorFont::~C4VectorFont()
	{
	CStdFont::DestroyFont(pFont);
	// temp file loaded?
	if (*FileName)
		{
		// release font
#if defined(_WIN32) && !defined(HAVE_FREETYPE)
		//RemoveFontResourceEx(FileName, FR_PRIVATE, NULL); requires win2k
		RemoveFontResource(FileName);
#endif
		if (fIsTempFile) EraseFile(FileName);
		}
	}
Exemplo n.º 10
0
void manager::deinit() const
{
#ifdef CAIRO_HAS_FT_FONT
	FcConfigAppFontClear(FcConfigGetCurrent());
#endif

#if CAIRO_HAS_WIN32_FONT
	foreach(const std::string& path, get_binary_paths("fonts")) {
		std::vector<std::string> files;
		get_files_in_dir(path, &files, NULL, ENTIRE_FILE_PATH);
		foreach(const std::string& file, files)
			if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
				RemoveFontResource(file.c_str());
	}
#endif
}
Exemplo n.º 11
0
BOOL CVCheckerApp::InitInstance()
{

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));

	//AfxSetResourceHandle(g_hMod);
	g_hResDll = LoadLibrary(_T("VCheckerResZhCn.dll"));		
	if (g_hResDll == NULL)
	{
		AfxMessageBox(_T("加载资源库文件失败!"));
	}

	CVCheckerClsGlobal clsGlobal;
	if (NULL != AddFontResource(clsGlobal.fGetAppPath() + _T("\\font\\ARLRDBD.TTF")))		// AddFontResource(CUSTOM_FONT))
	{
		::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
	}

	CVCheckerDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: 在此处放置处理何时用“确定”来关闭
		//  对话框的代码
	}

	if(RemoveFontResource(clsGlobal.fGetAppPath() + _T("\\font\\ARLRDBD.ttf")))
	{
		::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
	}

	FreeLibrary(g_hResDll);

	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	return FALSE;
}
Exemplo n.º 12
0
    ~BitmapDC()
    {
        prepareBitmap(0, 0);
        if (m_hDC)
        {
            DeleteDC(m_hDC);
        }
        HFONT hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
        if (hDefFont != m_hFont)
        {
            DeleteObject(m_hFont);
            m_hFont = hDefFont;
        }
		// release temp font resource	
		if (m_curFontPath.size() > 0)
		{
			RemoveFontResource(m_curFontPath.c_str());
			SendMessage(m_hWnd, WM_FONTCHANGE, 0, 0);
		}
    }
Exemplo n.º 13
0
gxGraphics::~gxGraphics(){
	if( _gamma ) _gamma->Release();
#ifdef PRO
	while( scene_set.size() ) freeScene( *scene_set.begin() );
#endif
	while( movie_set.size() ) closeMovie( *movie_set.begin() );
	while( font_set.size() ) freeFont( *font_set.begin() );
	while( canvas_set.size() ) freeCanvas( *canvas_set.begin() );

	set<string>::iterator it;
	for( it=font_res.begin();it!=font_res.end();++it ) RemoveFontResource( (*it).c_str() );
	font_res.clear();

	delete back_canvas;
	delete front_canvas;

	ds_dirDraw->Release();

	dirDraw->RestoreDisplayMode();
	dirDraw->Release();
}
Exemplo n.º 14
0
int 	CWedApp::ExitInstance()
{
#if 0
	if(!RemoveFontResource("sample.fnt"))
		MessageBox(NULL, "Cannot remove font", "Wed", 0);
#endif

	//P2N("Terminated Application: %s %s\r\n",
	//				m_pszAppName, approot);

	//if(wait_exit)
	//	{
	//	for(int loop = 0; loop < 10; loop++)
	//		{
	//		YieldToWin(); Sleep(20);
	//		}
	//	}

	P2N("Exited Wed\r\n");

 	return CWinApp::ExitInstance();
}
Exemplo n.º 15
0
//////////////////////////////////////////////////////////////////////////////
//CLEANUP
//////////////////////////////////////////////////////////////////////////////
void Prog_Done()
{

   // sub block for managing a Device Context
   {
      ManageDC aDC(hWndMain);
      HDC hdc = aDC.borrowedDC();

      // slap the old on back into the DC
      SelectObject(hdc,hfntOld);
      SelectObject(hdc,hpenOld);
      
      // make sure we clean up after ourselves..
      DeleteObject(hfntNew);
      DeleteObject(hpenNew);
      
      RemoveFontResource(FONTNAME);
   }
   //////////////////////////
   //clean up code goes here
   //////////////////////////
}
Exemplo n.º 16
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_CREATE:
		WindowInit(hWnd, wParam, lParam);
		break;
	case WM_PAINT:
		Render(hWnd);
		break;
	case WM_KEYDOWN:
		KeyDown(hWnd, wParam, lParam);
		break;
	case WM_KEYUP:
		break;
	case WM_MOUSEMOVE:
		MouseMove(hWnd, wParam, lParam);
		break;
	case WM_LBUTTONDOWN:
		LButtonDown(hWnd, wParam, lParam);
		break;
	case WM_TOUCH:
		return TouchEvent(hWnd, message, wParam, lParam);
	case WM_TIMER:
		TimerUpdate(hWnd, wParam, lParam);
		break;
	case WM_DESTROY:
		RemoveFontResource(_T("res/font/fantiquefour.ttf"));
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}
Exemplo n.º 17
0
    bool setFont(const char * pFontName = NULL, int nSize = 0)
    {
        bool bRet = false;
        do 
        {
			std::string fontName = pFontName;
			std::string fontPath;
            HFONT       hDefFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            LOGFONTA    tNewFont = {0};
            LOGFONTA    tOldFont = {0};
            GetObjectA(hDefFont, sizeof(tNewFont), &tNewFont);
            if (fontName.c_str())
            {	
				// create font from ttf file
				int nFindttf = fontName.find(".ttf");
				int nFindTTF = fontName.find(".TTF");
				if (nFindttf >= 0 || nFindTTF >= 0)
				{
					fontPath = CCFileUtils::fullPathFromRelativePath(fontName.c_str());
					int nFindPos = fontName.rfind("/");
					fontName = &fontName[nFindPos+1];
					nFindPos = fontName.rfind(".");
					fontName = fontName.substr(0,nFindPos);				
				}
				tNewFont.lfCharSet = DEFAULT_CHARSET;
                strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str());
            }
            if (nSize)
            {
                tNewFont.lfHeight = -nSize;
            }
            GetObjectA(m_hFont,  sizeof(tOldFont), &tOldFont);

            if (tOldFont.lfHeight == tNewFont.lfHeight
                && ! strcpy(tOldFont.lfFaceName, tNewFont.lfFaceName))
            {
                // already has the font 
                bRet = true;
                break;
            }

            // delete old font
            if (m_hFont != hDefFont)
            {
                DeleteObject(m_hFont);
				// release old font register
				if (m_curFontPath.size() > 0)
				{
					wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
					if (pwszBuffer)
					{
						if(RemoveFontResource(pwszBuffer))
						{
							SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
						}						
						delete [] pwszBuffer;
						pwszBuffer = NULL;
					}
				}
				fontPath.size()>0?(m_curFontPath = fontPath):(m_curFontPath.clear());
				// register temp font
				if (m_curFontPath.size() > 0)
				{
					wchar_t * pwszBuffer = utf8ToUtf16(m_curFontPath);
					if (pwszBuffer)
					{
						if(AddFontResource(pwszBuffer))
						{
							SendMessage( m_hWnd, WM_FONTCHANGE, 0, 0);
						}						
						delete [] pwszBuffer;
						pwszBuffer = NULL;
					}
				}
            }
            m_hFont = NULL;

            // disable Cleartype
            tNewFont.lfQuality = ANTIALIASED_QUALITY;

            // create new font
            m_hFont = CreateFontIndirectA(&tNewFont);
            if (! m_hFont)
            {
                // create failed, use default font
                m_hFont = hDefFont;
                break;
            }
            
            bRet = true;
        } while (0);
        return bRet;
    }
Exemplo n.º 18
0
void PinFont::UnRegister()
	{
	/*const BOOL fFoo =*/ RemoveFontResource(m_szTempFile);

	DeleteFile(m_szTempFile);
	}
Exemplo n.º 19
0
BOOL bTestLoadFOT (
    HDC     hdc
    )
{
    HFONT   hfont;
    HFONT   hfontOriginal;
    LOGFONT lfnt;
    TEXTMETRIC  tm;

// Clear the screen to black.

    BitBlt(hdc, 0, 0, CX, CY, (HDC) 0, 0, 0, 0);

    DbgPrint("ft!bTestLoadFOT(): check gcTrueTypeFonts\n");
    DbgBreakPoint();

// Add a TrueType .FOT font file.

    if ( !AddFontResource("lcallig.fot") )
    {
        DbgPrint("ft!bTestLoadFOT(): failed to load .FOT file\n");
        return FALSE;
    }
    GdiFlush();
    DbgPrint("ft!bTestLoadFOT(): check gcTrueTypeFonts (it should be 1 bigger)\n");
    DbgBreakPoint();

// Get a font.

    memset(&lfnt, 0, sizeof(lfnt));
    lstrcpy(lfnt.lfFaceName, "Lucida Calligraphy");
    lfnt.lfHeight = -14;
    lfnt.lfWeight = 400;

    if ((hfont = CreateFontIndirect(&lfnt)) == NULL)
    {
        DbgPrint("ft!bTestLoadFOT(): Logical font creation failed.\n");
        return FALSE;
    }

    hfontOriginal = SelectObject(hdc, hfont);

// Get metrics.

    if ( GetTextMetrics(hdc, &tm) )
        vPrintTM(hdc, &tm);
    else
        DbgPrint("ft!bTestLoadFOT(): GetTextMetrics call failed\n");

// Restore the font.

    SelectObject(hdc, hfontOriginal);
    DeleteObject(hfont);

// Remove the TrueType .FOT font file.

    if ( !RemoveFontResource("lcallig.fot") )
    {
        DbgPrint("ft!bTestLoadFOT(): error removing .FOT file\n");
        return FALSE;
    }
    GdiFlush();
    DbgPrint("ft!bTestLoadFOT(): check gcTrueTypeFonts (it should be 1 smaller)\n");
    DbgBreakPoint();

    return TRUE;
}
Exemplo n.º 20
0
//--------------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{    
    m_hInstance = (HINSTANCE)GetModuleHandle(NULL);

    if (argc >= 3)
    {
        m_lpFontPath = argv[2];
        m_lpFontName = argv[1];
        printf(__FUNCTION__"(): Using external font %ws \"%ws\"\n", m_lpFontName, m_lpFontPath);
    }
    else
    {
        printf("USAGE: MsFontsFuzz.exe <font_name> <font_file> [options]\n");
        goto end;
    }    

    _stprintf_s(m_TmpFontPath, _T("__TMP__%s"), _tGetNameFromFullPath(m_lpFontPath));
    DbgMsg(__FILE__, __LINE__, "[+] Temporary font file is \"%ws\"\n", m_TmpFontPath);

    if (_tcslen(m_TmpFontPath) >= 4)
    {
        _tcslwr(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4);
        if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".otf")))
        {
            m_dwFontType = FONT_TYPE_OTF;
            DbgMsg(__FILE__, __LINE__, "[+] Font type is .OTF\n");
        }
        else if (!_tcscmp(m_TmpFontPath + _tcslen(m_TmpFontPath) - 4, _T(".ttf")))
        {
            m_dwFontType = FONT_TYPE_TTF;
            DbgMsg(__FILE__, __LINE__, "[+] Font type is .TTF\n");
        }
    }    

    RemoveFontResource(m_TmpFontPath);

#ifdef USE_BOADCAST_MESSAGES

    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

#endif

    char ch = 0;
    memset(m_szTable, '.', sizeof(m_szTable) - 1);
    
    for (int i = 0; i < sizeof(m_szTable); i++)
    {
        if (i != 0 && i % 16 == 0)
        {
            m_szTable[i] = '\n';
            continue;
        }

        if (ch >= 0x20)
        {
            m_szTable[i] = ch;
        }

        if (ch == 0x7f)
        {
            m_szTable[i] = 0;
            break;
        }

        ch += 1;
    }

    if (argc > 3)
    {
        // enumerate additional parameters
        for (int i = 3; i < argc; i++)
        {
            if (!_tcscmp(argv[i], _T("--test")))
            {
                // single launch mode
                m_bTest = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--resume")))
            {
                // resume fuzzing in the new process
                m_bResume = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--noisy")))
            {
                // show lot of output information
                m_bNoisy = TRUE;
            }
            else if (!_tcscmp(argv[i], _T("--text")) && argc - i > 1)
            {
#ifdef UNICODE
                // use caller-specified text for display
                WideCharToMultiByte(
                    CP_ACP, 0, 
                    argv[i + 1], 
                    -1, 
                    m_szTable,
                    sizeof(m_szTable) - 1, 
                    NULL, NULL
                );
#else
                strcpy_s(m_szTable, argv[i + 1]);
#endif
                i++;
            }
            else if (!_tcscmp(argv[i], _T("--fix-crcs")))
            {
                // fix incorrect checksums for the original font file
                m_bFixCrcs = TRUE;
            }
            else if (argc - i > 1 && argv[i][0] == '-')
            {
                /**
                 * Process data generation options.
                 */

                LPCTSTR lpParam = argv[i] + 1;
                DWORD dwValue = 0;
                BOOL bFound = FALSE;

                if (!StrToIntEx(argv[i + 1], STIF_SUPPORT_HEX, (int *)&dwValue))
                {
                    DbgMsg(__FILE__, __LINE__, "[!] ERROR: Invalid value for parameter \"%ws\"\n", argv[i]);
                    continue;
                }

                for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++)
                {
                    // search parameter by name
                    if (!_tcscmp(m_Params[i_n].lpName, lpParam))
                    {
                        *(m_Params[i_n].pdwValue) = dwValue;
                        bFound = TRUE;
                        break;
                    }
                }

                if (!bFound)
                {
                    DbgMsg(__FILE__, __LINE__, "[!] ERROR: Unknown parameter \"%ws\"\n", argv[i]);
                }

                i++;
            }            
        }
    }

    DbgInit(LOG_FILE_NAME);

    // check block size and range
    if (BLOCK_SIZE == 1)
    {
        if (BLOCK_RANGE_START >= 0xFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFF)\n");
            goto end;
        }
    }
    else if (BLOCK_SIZE == 2)
    {
        if (BLOCK_RANGE_START >= 0xFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFF)\n");
            goto end;
        }
    }
    else if (BLOCK_SIZE == 4)
    {
        if (BLOCK_RANGE_START >= 0xFFFFFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_START value (it must be <0xFFFFFFFF)\n");
            goto end;
        }

        if (BLOCK_RANGE_END > 0xFFFFFFFF)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_END value (it must be <=0xFFFFFFFF)\n");
            goto end;
        }
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_SIZE value (it must be 1, 2 or 4)\n");
        goto end;
    }

    // check step size
    if (BLOCK_RANGE_N > BLOCK_RANGE_END)
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid BLOCK_RANGE_N value (it must be <=BLOCK_RANGE_END)\n");
        goto end;
    }

    WNDCLASSEX wcex;
    ZeroMemory(&wcex, sizeof(wcex));
    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.hInstance = m_hInstance;    
    wcex.lpszClassName = _T(WND_CLASS);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

    m_hWndEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (m_hWndEvent == NULL)
    {
        DbgMsg(__FILE__, __LINE__, "CreateEvent() ERROR %d\n", GetLastError());
        goto end;
    }

    // register window class
    if (RegisterClassEx(&wcex) == NULL)
    {
        DbgMsg(__FILE__, __LINE__, "RegisterClassEx() ERROR %d\n", GetLastError());
        goto end;
    }    
    
    // init random number generator
    init_genrand(GetTickCount());

    SetUnhandledExceptionFilter(UnhandledExceptionError);
        
    // read input file
    if (ReadFromFile(m_lpFontPath, &m_pData, &m_dwDataSize))
    {
        if (FILE_RANGE_START >= m_dwDataSize)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START value (it must be <=FILE_SIZE)\n");
            M_FREE(m_pData);
            return -1;
        }

        if (FILE_RANGE_END > m_dwDataSize)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_END value (it must be <FILE_SIZE)\n");
            M_FREE(m_pData);
            return -1;
        }        

        if (FILE_RANGE_END == 0)
        {
            FILE_RANGE_END = m_dwDataSize;
        }

        if (FILE_RANGE_START >= FILE_RANGE_END)
        {
            DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Invalid FILE_RANGE_START/FILE_RANGE_END values\n");
            M_FREE(m_pData);
            return -1;
        }

        DbgMsg(__FILE__, __LINE__, "[+] %d bytes readed from \"%ws\"\n", m_dwDataSize, m_lpFontPath);

        if (!m_bResume && (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF))
        {
            OTF_TableByOffset(m_pData, (ULONG)-1);
        }

        if (m_bFixCrcs)
        {
            // write fixed checksums into the original file
            if (DumpToFile(m_lpFontPath, m_pData, m_dwDataSize))
            {
                DbgMsg(__FILE__, __LINE__, "[+] Checksums has been fixed for font file \"%ws\"\n", m_lpFontPath);
            }
        }
        else if (m_bTest)
        {
            // single run with the unchanged font file
            if (DumpToFile(m_TmpFontPath, m_pData, m_dwDataSize))
            {
                FuzzIteration();
            }
        }
        else
        {
            DbgMsg(__FILE__, __LINE__, "[+] Fuzzing params:\n\n");

            // print parameters values
            for (int i_n = 0; i_n < sizeof(m_Params) / sizeof(ENGINE_PARAM); i_n++)
            {            
                DbgMsg(__FILE__, __LINE__, " %20ws = 0x%.8x\n", m_Params[i_n].lpName, *(m_Params[i_n].pdwValue));
            }

            DbgMsg(__FILE__, __LINE__, "\n");
            DbgMsg(__FILE__, __LINE__, "[+] Processing cases...\n\n");

            // align buffer size by block size
            m_dwAlignedDataSize = XALIGN_UP(m_dwDataSize, BLOCK_SIZE);

            // allocate output buffer
            if (m_pAlignedData = M_ALLOC(m_dwAlignedDataSize))
            {         
                char *lpszBigBuff = (char *)M_ALLOC(BIG_BUFFER_LENGTH);
                if (lpszBigBuff)
                {
                    FillMemory(lpszBigBuff, BIG_BUFFER_LENGTH, 'A');
                }

                PVOID pBigData = M_ALLOC(m_dwDataSize + BIG_BUFFER_LENGTH);
                
                // for each byte/word/dword of input file...
                for (DWORD i = FILE_RANGE_START; i < FILE_RANGE_END; i += BLOCK_SIZE)
                {                
                    DbgMsg(__FILE__, __LINE__, "Offset=0x%.8x TotalSize=0x%.8x File=%.8x\n", i, m_dwDataSize, m_dwCasesProcessed);

                    POTF_TABLE_HEADER Table = NULL;
                    if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF)
                    {
                        Table = OTF_TableByOffset(m_pData, i);
                        if (Table == NULL)
                        {
                            // skip OTF/TTF data outside the tables
                            continue;
                        }
                    }                    

                    if (BLOCK_RANGE_N > 0)
                    {
                        // fuze each value with the step size == BLOCK_RANGE_N
                        for (DWORD n = XALIGN_DOWN(BLOCK_RANGE_START, BLOCK_RANGE_N); 
                             n < XALIGN_DOWN(BLOCK_RANGE_END, BLOCK_RANGE_N); 
                             n += BLOCK_RANGE_N)
                        {                            
                            // write plain value
                            WriteVal(i, BLOCK_SIZE, n, n, n);                

                            if (BLOCK_SIZE > 1)
                            {
                                // write randomized value
                                WriteVal(i, BLOCK_SIZE, 
                                    n, 
                                    n + getrand(0, BLOCK_RANGE_N - 1), 
                                    n + getrand(0, BLOCK_RANGE_N - 1)
                                );                                    
                            }                    
                        }
                    }

                    // zero-bytes stuff
                    WriteVal(i, BLOCK_SIZE, 0x00, 0x0000, 0x00000000);                

                    // integer overflow stuff
                    WriteVal(i, BLOCK_SIZE, 0xFF, 0xFFFF, 0xFFFFFFFF);

                    // invalid user-mode pointers
                    WriteVal(i, BLOCK_SIZE, 0x0D, 0x0D0D, 0x0D0D0D0D);

                    if (lpszBigBuff && pBigData)
                    {
                        /**
                         * Write big ASCI data after the each byte.
                         */

                        memcpy(pBigData, m_pData, i);
                        memcpy((PUCHAR)pBigData + i, lpszBigBuff, BIG_BUFFER_LENGTH);
                        memcpy((PUCHAR)pBigData + i + BIG_BUFFER_LENGTH, (PUCHAR)m_pData + i, m_dwDataSize - i);

                        if (m_dwFontType == FONT_TYPE_OTF || m_dwFontType == FONT_TYPE_TTF)
                        {
                            POTF_FILE_HEADER Hdr = (POTF_FILE_HEADER)pBigData;
                            POTF_TABLE_HEADER Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER));
                            POTF_TABLE_HEADER CurrentTable = NULL;

                            for (USHORT t = 0; t < htons(Hdr->numTables); t++)
                            {
                                ULONG Offset = htonl(Table->offset), Length = htonl(Table->length);

                                if (i >= Offset &&
                                    i < Offset + Length)
                                {
                                    // fix OTF/TTF table checksum and length
                                    ULONG Sum = OTF_CalcTableChecksum((ULONG *)((PUCHAR)pBigData + Offset), Length);
                                    
                                    Table->checkSum = htonl(Sum);
                                    Table->length = htonl(Length);
                                    CurrentTable = Table;

                                    break;
                                }

                                Table += 1;
                            }

                            if (CurrentTable)
                            {
                                Table = (POTF_TABLE_HEADER)((PUCHAR)pBigData + sizeof(OTF_FILE_HEADER));

                                for (USHORT t = 0; t < htons(Hdr->numTables); t++)
                                {
                                    ULONG Offset = htonl(Table->offset), Length = htonl(Table->length);

                                    if (Offset > htonl(CurrentTable->offset))
                                    {
                                        // fix offsets of the other tables
                                        Table->offset = htonl(Offset + BIG_BUFFER_LENGTH);
                                    }

                                    Table += 1;
                                }
                            }
                        }

                        if (DumpToFile(m_TmpFontPath, pBigData, m_dwDataSize + BIG_BUFFER_LENGTH))
                        {
                            FuzzIteration();
                            m_dwCasesProcessed++;
                        }
                    }

                    if (m_dwCasesProcessed > MAX_CASES_PER_PROCESS)
                    {
                        TCHAR szSelf[MAX_PATH], szCmdLine[MAX_PATH];
                        GetModuleFileName(GetModuleHandle(NULL), szSelf, MAX_PATH);

                        _stprintf_s(
                            szCmdLine, MAX_PATH, 
                            _T("\"%s\" \"%s\" \"%s\" -BLOCK_SIZE 0x%x -BLOCK_RANGE_START 0x%x -BLOCK_RANGE_END 0x%x -BLOCK_RANGE_N 0x%x -FILE_RANGE_START 0x%x --resume Y"),
                            szSelf, m_lpFontName, m_lpFontPath, BLOCK_SIZE, BLOCK_RANGE_START, BLOCK_RANGE_END, BLOCK_RANGE_N, i
                        );

                        if (m_bNoisy)
                        {
                            _tcscat(szCmdLine, _T(" --noisy Y"));
                        }

                        STARTUPINFO si;
                        PROCESS_INFORMATION pi;

                        ZeroMemory(&pi, sizeof(pi));
                        ZeroMemory(&si, sizeof(si));
                        si.cb = sizeof(si);                            

                        // create a new fuzzer instance
                        if (!CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                        {
                            MessageBox(0, _T("CreateProcess() fails"), _T("ERROR"), MB_ICONERROR);
                        }

                        ExitProcess(0);
                    }
                }

                DbgMsg(__FILE__, __LINE__, "Done; %d cases processed\n", m_dwCasesProcessed);

                if (pBigData)
                {
                    M_FREE(pBigData);
                }

                if (lpszBigBuff)
                {
                    M_FREE(lpszBigBuff);
                }

                M_FREE(m_pAlignedData);
            }
        }        

        M_FREE(m_pData);        
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): Error while reading input file\n");
    }

end:

    if (m_hWndEvent)
    {
        CloseHandle(m_hWndEvent);
    }

    printf("Press any key to quit...\n");
    _getch();

	return 0;
}
Exemplo n.º 21
0
void TEMPLATE_CONTROL_API RemoveLoadFont( LPCSTR lpFilePath )
{
	RemoveFontResource(lpFilePath);
	::SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
}
bool CGumpEditorDoc::Init()
{
	if (m_bInitUOData) return true;

	UnInit();

	//fix Mulpath if wrong
	if (nConfig::mulpath.size ())
    {
		char last_char = nConfig::mulpath[nConfig::mulpath.length () - 1];
		if ((last_char != '/') && (last_char != '\\'))
		  nConfig::mulpath +="/";
	}

	std::string mulpath = nConfig::mulpath;
	std::string gumpartfile = mulpath + "gumpart.mul";
	std::string gumpidxfile = mulpath + "gumpidx.mul";
	std::string huesfile = mulpath + "hues.mul";
//flo:
	pVerdataLoader = NULL;

	m_pGumpLoader = new cGumpLoader;
	if (!m_pGumpLoader->load(gumpartfile, gumpidxfile))
	{
		MessageBox(NULL, (gumpartfile + " or\n" + gumpidxfile).c_str(), "Can't Open File", MB_OK|MB_ICONERROR);
		delete m_pGumpLoader;
		m_pGumpLoader = NULL;
		return false;
	}

//flo: New
	std::string filename=mulpath + "verdata.mul";
	std::ifstream verdata; 
	verdata.open(filename.c_str (),  std::ios::in | std::ios::binary);
    if (verdata)
    {
        verdata.close();
		pVerdataLoader = new cVerdataLoader (mulpath + "verdata.mul");
    }
//--------
	m_pHueLoader = new cHueLoader;
	if (!m_pHueLoader->load(huesfile))
	{
		MessageBox(NULL, huesfile.c_str(), "Can't Open File", MB_OK|MB_ICONERROR);
		delete m_pHueLoader;
		m_pHueLoader = NULL;
		return false;
	}


	LOGFONT lf;
	memset(&lf,0,sizeof(lf));

	sMyFont font;

	for (std::vector<nConfig::font_info>::iterator iter = nConfig::fonts.begin(); iter != nConfig::fonts.end(); iter++)
	{	
		if (!AddFontResource(iter->file.c_str())) continue;
	
		strcpy(lf.lfFaceName, iter->name.c_str());
		lf.lfHeight = iter->size;
		//lf.lfWeight = FW_BOLD;
		//lf.lfCharSet = ANSI_CHARSET;
		//lf.lfOutPrecision  = OUT_TT_ONLY_PRECIS;

		CFont* pFont = new CFont;
		//if (!pFont->CreateFontIndirect(&lf)) {
		if (!pFont->CreatePointFont(lf.lfHeight*8, lf.lfFaceName)) {
			delete pFont;
			RemoveFontResource(iter->file.c_str());
			continue;
		}

		font.file = iter->file;
		font.font = pFont;
		font.color = GetHueColor(iter->hue, iter->id);

		m_fonts.insert(std::make_pair(iter->id, font));
	}

	m_bInitUOData = true;

	g_pGumpEditorDoc = this;

	return true;
}
Exemplo n.º 23
0
//--------------------------------------------------------------------------------------
DWORD WINAPI FuzzIterationThread(LPVOID lpParam)
{
    MSG Msg;

    // load fuzzed font
    if (AddFontResource(m_TmpFontPath) == 0)
    {
        DbgMsg(__FILE__, __LINE__, "AddFontResource() fails\n");
        return -1;
    }

#ifdef USE_BOADCAST_MESSAGES

    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

#endif

    int x = (GetSystemMetrics(SM_CXSCREEN) - WND_W) / 2;
    int y = (GetSystemMetrics(SM_CYSCREEN) - WND_H) / 2;

    // create new empty window
    m_hWnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        _T(WND_CLASS), _T(WND_TITLE), 
        WS_OVERLAPPEDWINDOW,
        x, y, WND_W, WND_H, 
        NULL, NULL, 
        m_hInstance, 
        NULL
    );
    if (m_hWnd)
    {
        ShowWindow(m_hWnd, SW_SHOWNORMAL);
        UpdateWindow(m_hWnd);

        SendMessage(m_hWnd, WM_COMMAND, ID_CLOSE, 0);

        // Main message loop
        while (GetMessage(&Msg, NULL, 0, 0))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, "CreateWindow() ERROR %d\n", GetLastError());
    }    

    // unload fuzzed font
    if (!RemoveFontResource(m_TmpFontPath))
    {
        DbgMsg(__FILE__, __LINE__, "RemoveFontResource() fails\n");
    }

#ifdef USE_BOADCAST_MESSAGES

    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

#endif

    return 0;
}
Exemplo n.º 24
0
FrkText::~FrkText(void)
{
	m_hFont->Release();
	RemoveFontResource(DEFAULT_FONTPATH);
}