diff options
author | Tor Lillqvist <tml@iki.fi> | 2010-09-03 02:10:43 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2010-09-03 02:15:07 +0300 |
commit | 0f01668251d7d9344f2130e128c230ad332ebf42 (patch) | |
tree | 9158b70e0abc022c336d69d1ddcdaed6ae21b3b7 /gdk-pixbuf/io-gdip-utils.c | |
parent | eedc4a3d373671ac62e38ad0d1161f58cd76a31b (diff) | |
download | gdk-pixbuf-0f01668251d7d9344f2130e128c230ad332ebf42.tar.gz |
Link directly to GDI+ API avoiding LoadLibrary
Avoid potential DLL hijacking risks by not calling LoadLibrary() to
load gdiplus.dll. As gdiplus.dll is a WinSxS (side-by-side) DLL we
couldn't use the full path anyway as we don't know it.
So just link to the GDI+ functions directly. Gdiplus.dll should be
present on all Windows versions we support anyway. Some complexity
added as MinGW doesn't come with an import library for gdiplus.dll, so
we have to create one ourselves. But we call relatively few functions
from gdiplus.dll so that is not a big deal.
Diffstat (limited to 'gdk-pixbuf/io-gdip-utils.c')
-rw-r--r-- | gdk-pixbuf/io-gdip-utils.c | 84 |
1 files changed, 3 insertions, 81 deletions
diff --git a/gdk-pixbuf/io-gdip-utils.c b/gdk-pixbuf/io-gdip-utils.c index b8fa72bea..8f62d75d8 100644 --- a/gdk-pixbuf/io-gdip-utils.c +++ b/gdk-pixbuf/io-gdip-utils.c @@ -43,38 +43,6 @@ struct _GdipContext { }; typedef struct _GdipContext GdipContext; -static GdiplusStartupFunc GdiplusStartup; -static GdipCreateBitmapFromStreamFunc GdipCreateBitmapFromStream; -static GdipBitmapGetPixelFunc GdipBitmapGetPixel; -static GdipGetImageHeightFunc GdipGetImageHeight; -static GdipDisposeImageFunc GdipDisposeImage; -static GdipGetImageFlagsFunc GdipGetImageFlags; -static GdipGetImageWidthFunc GdipGetImageWidth; -static GdipImageGetFrameCountFunc GdipImageGetFrameCount; -static GdipImageSelectActiveFrameFunc GdipImageSelectActiveFrame; -static GdipGetPropertyItemSizeFunc GdipGetPropertyItemSize; -static GdipGetPropertyItemFunc GdipGetPropertyItem; -static GdipGetPropertyCountFunc GdipGetPropertyCount; -static GdipGetPropertyIdListFunc GdipGetPropertyIdList; -static GdipCreateBitmapFromScan0Func GdipCreateBitmapFromScan0; -static GdipSaveImageToStreamFunc GdipSaveImageToStream; -static GdipBitmapSetPixelFunc GdipBitmapSetPixel; -static GdipDrawImageIFunc GdipDrawImageI; -static GdipGetImageGraphicsContextFunc GdipGetImageGraphicsContext; -static GdipFlushFunc GdipFlush; -static GdipGraphicsClearFunc GdipGraphicsClear; -static GdipBitmapSetResolutionFunc GdipBitmapSetResolution; -static GdipGetImageHorizontalResolutionFunc GdipGetImageHorizontalResolution; -static GdipGetImageVerticalResolutionFunc GdipGetImageVerticalResolution; -static GdipLoadImageFromStreamFunc GdipLoadImageFromStream; -static GdipDeleteGraphicsFunc GdipDeleteGraphics; -static GdipGetImageEncodersFunc GdipGetImageEncoders; -static GdipGetImageEncodersSizeFunc GdipGetImageEncodersSize; -static GdipBitmapLockBitsFunc GdipBitmapLockBits; -static GdipBitmapUnlockBitsFunc GdipBitmapUnlockBits; -static GdipGetImagePixelFormatFunc GdipGetImagePixelFormat; -static GdipCloneBitmapAreaIFunc GdipCloneBitmapAreaI; - DEFINE_GUID(FrameDimensionTime, 0x6aedbd6d,0x3fb5,0x418a,0x83,0xa6,0x7f,0x45,0x22,0x9d,0xc8,0x72); DEFINE_GUID(FrameDimensionPage, 0x7462dc86,0x6180,0x4c7e,0x8e,0x3f,0xee,0x73,0x33,0xa7,0xa4,0x83); @@ -131,58 +99,12 @@ gdip_init (void) { GdiplusStartupInput input; ULONG_PTR gdiplusToken = 0; - static HINSTANCE gdipluslib = NULL; + static gboolean beenhere = FALSE; - if (!gdipluslib) - gdipluslib = LoadLibrary ("gdiplus.dll"); - else + if (beenhere) return TRUE; /* gdip_init() is idempotent */ - if (!gdipluslib) - return FALSE; - -#define LOOKUP(func) \ - G_STMT_START { \ - func = (func##Func) GetProcAddress (gdipluslib, #func); \ - if (!func) {\ - g_warning ("Couldn't find GDI+ function %s\n", #func); \ - return FALSE; \ - } \ - } G_STMT_END - - LOOKUP (GdiplusStartup); - LOOKUP (GdipCreateBitmapFromStream); - LOOKUP (GdipBitmapGetPixel); - LOOKUP (GdipGetImageHeight); - LOOKUP (GdipDisposeImage); - LOOKUP (GdipGetImageFlags); - LOOKUP (GdipGetImageWidth); - LOOKUP (GdipImageGetFrameCount); - LOOKUP (GdipImageSelectActiveFrame); - LOOKUP (GdipGetPropertyItemSize); - LOOKUP (GdipGetPropertyItem); - LOOKUP (GdipGetPropertyCount); - LOOKUP (GdipGetPropertyIdList); - LOOKUP (GdipCreateBitmapFromScan0); - LOOKUP (GdipSaveImageToStream); - LOOKUP (GdipBitmapSetPixel); - LOOKUP (GdipDrawImageI); - LOOKUP (GdipGetImageGraphicsContext); - LOOKUP (GdipFlush); - LOOKUP (GdipGraphicsClear); - LOOKUP (GdipBitmapSetResolution); - LOOKUP (GdipGetImageHorizontalResolution); - LOOKUP (GdipGetImageVerticalResolution); - LOOKUP (GdipLoadImageFromStream); - LOOKUP (GdipDeleteGraphics); - LOOKUP (GdipGetImageEncoders); - LOOKUP (GdipGetImageEncodersSize); - LOOKUP (GdipBitmapLockBits); - LOOKUP (GdipBitmapUnlockBits); - LOOKUP (GdipGetImagePixelFormat); - LOOKUP (GdipCloneBitmapAreaI); - -#undef LOOKUP + beenhere = TRUE; input.GdiplusVersion = 1; input.DebugEventCallback = NULL; |