/* * SfExtractDropper * * Purpose: * * Extract Sirefef/ZeroAccess from image resource. * * CNG variant * */ UINT SfExtractDropper( LPWSTR lpCommandLine ) { BOOL cond = FALSE, bSuccess = FALSE; ULONG c, uKey = 0, imagesz; WCHAR szInputFile[MAX_PATH + 1]; WCHAR szOutputFile[MAX_PATH + 1]; WCHAR szKey[MAX_PATH]; PVOID ImageBase = NULL, EncryptedData = NULL, DecryptedData = NULL; IStream *pImageStream = NULL; ULONG_PTR gdiplusToken = 0; GdiplusStartupInput input; GdiplusStartupOutput output; PVOID BitmapPtr = NULL; GdiPlusBitmapData BitmapData; GdiPlusRect rect; SIZE_T sz; PULONG ptr, i_ptr; //input file c = 0; RtlSecureZeroMemory(szInputFile, sizeof(szInputFile)); GetCommandLineParam(lpCommandLine, 1, (LPWSTR)&szInputFile, MAX_PATH, &c); if (c == 0) { SfcuiPrintText(g_ConOut, T_SFEXTRACTUSAGE, g_ConsoleOutput, FALSE); return (UINT)-1; } //output file c = 0; RtlSecureZeroMemory(&szOutputFile, sizeof(szOutputFile)); GetCommandLineParam(lpCommandLine, 2, (LPWSTR)&szOutputFile, MAX_PATH, &c); if (c == 0) { _strcpy(szOutputFile, TEXT("extracted.bin")); } //key c = 0; RtlSecureZeroMemory(&szKey, sizeof(szKey)); GetCommandLineParam(lpCommandLine, 3, (LPWSTR)&szKey, MAX_PATH, &c); if ((c == 0) || (c > 10)) { SfcuiPrintText(g_ConOut, T_SFEXTRACTUSAGE, g_ConsoleOutput, FALSE); return (UINT)-1; } c = 0; if (locase_w(szKey[1]) == 'x') { c = 2; } uKey = hextoul(&szKey[c]); do { ImageBase = SfuCreateFileMappingNoExec(szInputFile); if (ImageBase == NULL) break; c = 0; EncryptedData = SfLdrQueryResourceData(1, ImageBase, &c); if ((EncryptedData == NULL) || (c == 0)) break; pImageStream = SHCreateMemStream((BYTE *)EncryptedData, (UINT)c); if (pImageStream == NULL) break; RtlSecureZeroMemory(&input, sizeof(input)); RtlSecureZeroMemory(&output, sizeof(output)); input.GdiplusVersion = 1; if (GdiplusStartup(&gdiplusToken, &input, &output) != GdiplusOk) break; BitmapPtr = NULL; if (GdipCreateBitmapFromStream(pImageStream, &BitmapPtr) != GdiplusOk) break; RtlSecureZeroMemory(&rect, sizeof(rect)); if ( (GdipGetImageWidth(BitmapPtr, (UINT *)&rect.Width) == GdiplusOk) && (GdipGetImageHeight(BitmapPtr, (UINT *)&rect.Height) == GdiplusOk) ) { RtlSecureZeroMemory(&BitmapData, sizeof(BitmapData)); if (GdipBitmapLockBits(BitmapPtr, &rect, ImageLockModeRead, PixelFormat32bppARGB, &BitmapData) == GdiplusOk) { c = (rect.Width * rect.Height); imagesz = sizeof(ULONG) * c; sz = imagesz; DecryptedData = NULL; NtAllocateVirtualMemory(NtCurrentProcess(), &DecryptedData, 0, &sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (DecryptedData) { i_ptr = (PULONG)BitmapData.Scan0; ptr = DecryptedData; while (c > 0) { *ptr = *i_ptr ^ uKey; ptr++; i_ptr++; c--; } bSuccess = (SfuWriteBufferToFile(szOutputFile, DecryptedData, imagesz, FALSE, FALSE) == imagesz); sz = 0; NtFreeVirtualMemory(NtCurrentProcess(), &DecryptedData, &sz, MEM_RELEASE); } GdipBitmapUnlockBits(BitmapPtr, &BitmapData); } } } while (cond); if (bSuccess == FALSE) { SfcuiPrintText(g_ConOut, T_SFEXTRACTFAIL, g_ConsoleOutput, FALSE); } else { SfcuiPrintText(g_ConOut, szOutputFile, g_ConsoleOutput, TRUE); SfcuiPrintText(g_ConOut, T_SFEXTRACTED, g_ConsoleOutput, TRUE); } if (BitmapPtr != NULL) { GdipDisposeImage(&BitmapPtr); } if (gdiplusToken != 0) { GdiplusShutdown(gdiplusToken); } if (pImageStream != NULL) { pImageStream->lpVtbl->Release(pImageStream); } if (ImageBase != NULL) { NtUnmapViewOfSection(NtCurrentProcess(), ImageBase); } return 0; }
int CLayeredApp::ExitInstance() { GdiplusShutdown(m_GdiplusToken); return CWinApp::ExitInstance(); }
int CDataLoggerApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class GdiplusShutdown(m_pGdiToken); return CWinApp::ExitInstance(); }
CHTMLViewCapView::~CHTMLViewCapView() { ::CloseHandle(m_hDocCompleteEvent); GdiplusShutdown(m_gdiplusToken); }
int CCugWorkSpaceApp::ExitInstance() { BCGCBProCleanUp(); GdiplusShutdown(m_gdiplusToken); return CWinApp::ExitInstance(); }
CGifAnimUI::~CGifAnimUI(void) { DeleteGif(); m_pManager->KillTimer( this, EVENT_TIEM_ID ); GdiplusShutdown( m_gdiplusToken ); // 卸载GDI接口 }
LONG WINAPI ImageView_CreateWindow(HWND hwnd, LPWSTR szFileName) { struct GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; WNDCLASS WndClass = {0}; TCHAR szBuf[512]; HWND hMainWnd; MSG msg; if (!ImageView_LoadSettings()) { shiSettings.Maximized = FALSE; shiSettings.Left = 0; shiSettings.Top = 0; shiSettings.Right = 520; shiSettings.Bottom = 400; } // Initialize GDI+ gdiplusStartupInput.GdiplusVersion = 1; gdiplusStartupInput.DebugEventCallback = NULL; gdiplusStartupInput.SuppressBackgroundThread = FALSE; gdiplusStartupInput.SuppressExternalCodecs = FALSE; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); pLoadImage(szFileName); // Create the window WndClass.lpszClassName = _T("shimgvw_window"); WndClass.lpfnWndProc = (WNDPROC)ImageView_WndProc; WndClass.hInstance = hInstance; WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); WndClass.hCursor = LoadCursor(hInstance, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)COLOR_WINDOW; if (!RegisterClass(&WndClass)) return -1; LoadString(hInstance, IDS_APPTITLE, szBuf, sizeof(szBuf) / sizeof(TCHAR)); hMainWnd = CreateWindow(_T("shimgvw_window"), szBuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL); // Show it ShowWindow(hMainWnd, SW_SHOW); UpdateWindow(hMainWnd); // Message Loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessageW(&msg); } if (image) GdipDisposeImage(image); GdiplusShutdown(gdiplusToken); return -1; }
// In a windows program, instead of main(), we use WinMain() // Refer to earlier lessons for comments and more detail. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow ) { // Setup a console consoleCreate() ; consoleWhite() ; consoleMove( 32, 500 ) ; consoleRowsAndCols( 10, 120 ) ; // Start up the log. logStartup() ; // Put these after log start up, b/c start up inits them with some init values logOutputsForConsole = LOG_ERROR | LOG_WARNING | LOG_INFO ; // See ERROR and WARNING messages at Console. logOutputsForFile = LOG_ERROR | LOG_WARNING | LOG_INFO ; // See all types of messages in file logOutputsForDebugStream = LOG_ERROR | LOG_WARNING ; // See all ERROR and WARNING messages at debugstream. Suppress 'info()' messages. // Start up GDI+, which we use to draw // For GDI+, used only for shape render GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // Setup the window window = new GameWindow( hInstance, TEXT( "eternity engine base" ), 32, 32, // x pos, y pos 640, 480 // width, height ) ; // After the window comes up, we call Init // to load the game's content Init() ; MSG message ; while( 1 ) { if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) { if( message.message == WM_QUIT ) // if we got a WM_QUIT message.. { break ; // ..then end the program by jumping out of the while(1) loop. } // Send the message over to WndProc for // further processing. TranslateMessage( &message ) ; DispatchMessage( &message ) ; } else { // Run our game, one frame Update() ; window->step() ; // ^^ update fmod engine, grab updated keystates, etc. // Draw the game out, all at once if( window->beginDrawing() ) // only continue if beginDrawing() succeeds { Draw() ; window->endDrawing() ; } } } info( "Game over!" ) ; logShutdown() ; GdiplusShutdown(gdiplusToken); //system( "pause" ) ; // uncomment to make it pause before exit return 0 ; }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case ID_HELP_SPLASHSCREEN: ghDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SPLASH), 0, Splash); ShowWindow(ghDlg, SW_SHOW); break; case ID_CONTROL_YIELD: if (!eval_null()){ MessageBoxA(0, "You could only yield before a game start.", "Yield", 0); break; } mainboard[7][7] = 1; paint_board(hWnd); break; case ID_CONTROL_RESTART: clear_board(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT:{ Graphics *myGraphics; Pen *myPen; hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... myGraphics = new Graphics(hdc); myPen = new Pen(Color(255, 0, 0, 0), 1); myGraphics->DrawRectangle(myPen, Rect(400, 20, 20, 20)); for (int i = 0; i < 375; i += 25) myGraphics->DrawLine(myPen, 20, 20 + i, 370, 20 + i); for (int i = 0; i < 375; i += 25) myGraphics->DrawLine(myPen, 20 + i, 20, 20 + i, 370); delete myGraphics; delete myPen; EndPaint(hWnd, &ps); paint_board(hWnd); } break; case WM_DESTROY: GdiplusShutdown(gdiplusToken); PostQuitMessage(0); break; case WM_LBUTTONDOWN: board_clicked(hWnd, LOWORD(lParam), HIWORD(lParam)); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT uie_albumart::on_message(HWND wnd1,UINT msg,WPARAM wp,LPARAM lp) { switch(msg) { case WM_CREATE: { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); m_sources_control.register_foo_callbacks(); m_sources_control.register_sources_control_callback(this); m_sources_control.setup_sources_control(m_config, m_sources); m_wheel_accum = 0; } break; case WM_DESTROY: { m_sources_control.unregister_sources_control_callback(this); m_sources_control.unregister_foo_callbacks(); m_bufold.release(); m_bufnew.release(); m_bufanim.release(); m_bmpnew.release(); m_bmp.release(); GdiplusShutdown(gdiplusToken); } break; case WM_LBUTTONDOWN: { POINTS pts = MAKEPOINTS(lp); POINT pt; POINTSTOPOINT(pt, pts); if (m_panning_enabled) { m_dragging = true; SetCursor(LoadCursor(NULL, IDC_SIZEALL)); SetCapture(wnd1); m_drag_start = pt; m_orig_dx = m_pan_dx; m_orig_dy = m_pan_dy; } } break; case WM_MOUSEMOVE: { if (m_dragging) { POINTS pts = MAKEPOINTS(lp); m_pan_dx = m_orig_dx + pts.x - m_drag_start.x; m_pan_dy = m_orig_dy + pts.y - m_drag_start.y; redraw(); } } break; case WM_CANCELMODE: if (m_dragging) { ReleaseCapture(); SetCursor(LoadCursor(NULL, IDC_ARROW)); m_dragging = false; } break; case WM_LBUTTONDBLCLK: click_func(m_config.dblclickfunc); b_dblclick = true; break; case WM_LBUTTONUP: if (m_dragging) { ReleaseCapture(); SetCursor(LoadCursor(NULL, IDC_ARROW)); m_dragging = false; // if the mouse didn't move much, it probably wasn't // a drag, so trigger the mouse action POINTS pts = MAKEPOINTS(lp); POINT pt; POINTSTOPOINT(pt, pts); int cxdrag = GetSystemMetrics(SM_CXDRAG); int cydrag = GetSystemMetrics(SM_CYDRAG); RECT rect; SetRect(&rect, -1*cxdrag/2, -1*cydrag/2, cxdrag/2, cydrag/2); OffsetRect(&rect, m_drag_start.x, m_drag_start.y); if (PtInRect(&rect, pt)) click_func(m_config.lftclickfunc); } else if (!b_dblclick) { click_func(m_config.lftclickfunc); } b_dblclick = false; break; case WM_MBUTTONUP: click_func(m_config.mdlclickfunc); break; case WM_MOUSEWHEEL: { short delta = GET_WHEEL_DELTA_WPARAM(wp); m_wheel_accum += delta; while (m_wheel_accum <= -WHEEL_DELTA) { m_wheel_accum += WHEEL_DELTA; func_NextSource(true); } while (m_wheel_accum >= WHEEL_DELTA) { m_wheel_accum -= WHEEL_DELTA; func_PreviousSource(); } } break; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(m_hWnd, &ps); paint(hdc); EndPaint(m_hWnd, &ps); return 0; } break; case WM_TIMER: switch (wp) { case animation_timer_id: KillTimer(m_hWnd, animation_timer_id); redraw(); return 0; break; case cycle_timer_id: if (static_api_ptr_t<ui_control>()->is_visible()) { func_NextSource(false); } else { start_cycle_timer(); } return 0; break; } break; case WM_GETMINMAXINFO: { LPMINMAXINFO mmi = LPMINMAXINFO(lp); mmi->ptMinTrackSize.y = m_config.minheight; mmi->ptMinTrackSize.x = m_config.minwidth; } break; } return uDefWindowProc(wnd1, msg, wp, lp); }
AndGate::~AndGate() { GdiplusShutdown(g_GdiPlusTokenBoxData_AND); }
BOOL CPuzzleGameApp::ExitInstance() { GdiplusShutdown(m_gdiplusToken); return CWinApp::ExitInstance(); }
int CFloatApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class GdiplusShutdown(m_gdiplusToken); return CWinApp::ExitInstance(); }
int ReadTextureFromFile( struct Texture * t, const char * filename ) { int i; HGLOBAL hMem; LPVOID pMemImage; IStream *pStm; struct GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GpBitmap *pImg; PixelFormat PixelFormat; //Read in data FILE * f = fopen( filename, "rb"); if( !f ) { fprintf( stderr, "Error: Could not open %s\n", filename ); return -1; } fseek(f,0,SEEK_END); int l = ftell( f ); unsigned char * buffer = malloc( l ); fseek(f,0,SEEK_SET); fread(buffer, l, 1, f ); fclose( f ); //Prepare GDI+ imaging hMem = GlobalAlloc( GMEM_MOVEABLE, l ); pMemImage = GlobalLock( hMem); memcpy( pMemImage, buffer, l ); GlobalUnlock( hMem ); //XXX: This requries OLE32, do we really want it? CreateStreamOnHGlobal( hMem, TRUE, &pStm ); gdiplusStartupInput.GdiplusVersion = 1; gdiplusStartupInput.DebugEventCallback = NULL; gdiplusStartupInput.SuppressBackgroundThread = FALSE; gdiplusStartupInput.SuppressExternalCodecs = FALSE; GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ); if( GdipCreateBitmapFromStream( pStm, &pImg ) ) { fprintf( stderr, "Error: cannot decode: %s\n", filename ); return -2; } GdipGetImagePixelFormat( (GpImage *)pImg, &PixelFormat ); UINT width; UINT height; GdipGetImageHeight( (GpImage *)pImg, &height ); GdipGetImageWidth( (GpImage *)pImg, &width ); GpRect r; r.X = 0; r.Y = 0; r.Width = width; r.Height = height; BitmapData bd; enum TextureType format; GLenum type; //Almost always GL_TEXTURE_2D (Could be GL_TEXTURE_3D) GLuint texture; int slot; //which texture slot (For multi-texturing) uint8_t * rawdata; //May be other types, too! t->width = width; t->height = height; t->type = GL_TEXTURE_2D; //Detect if has alpha or not... int ps; if( PixelFormat & PixelFormatAlpha ) { GdipBitmapLockBits(pImg,&r,ImageLockModeRead,PixelFormat32bppARGB,&bd); ps = 4; t->format = TTRGBA; } else { GdipBitmapLockBits(pImg,&r,ImageLockModeRead,PixelFormat24bppRGB,&bd); ps = 3; t->format = TTRGB; } t->rawdata = malloc( ps * width * height ); int x, y; if( ps == 3 ) { for( y = 0; y < height; y++ ) for( x = 0; x < width; x++ ) { t->rawdata[(x+y*width)*3+0] = ((unsigned char*)bd.Scan0)[x*3+y*bd.Stride+2]; t->rawdata[(x+y*width)*3+1] = ((unsigned char*)bd.Scan0)[x*3+y*bd.Stride+1]; t->rawdata[(x+y*width)*3+2] = ((unsigned char*)bd.Scan0)[x*3+y*bd.Stride+0]; } } else //ps = 4 { for( y = 0; y < height; y++ ) for( x = 0; x < width; x++ ) { t->rawdata[(x+y*width)*4+0] = ((unsigned char*)bd.Scan0)[x*4+y*bd.Stride+2]; t->rawdata[(x+y*width)*4+1] = ((unsigned char*)bd.Scan0)[x*4+y*bd.Stride+1]; t->rawdata[(x+y*width)*4+2] = ((unsigned char*)bd.Scan0)[x*4+y*bd.Stride+0]; t->rawdata[(x+y*width)*4+3] = ((unsigned char*)bd.Scan0)[x*4+y*bd.Stride+3]; } } GdipBitmapUnlockBits(pImg, &bd ); GdipDisposeImage( (GpImage *)pImg ); GdiplusShutdown( gdiplusToken ); return 0; }