void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) { int num_frames = 0; int has_buttons = 0; TAG*tag=swf->firstTag; void*md5 = initialize_md5(); while(tag) { if(tag->id == ST_SHOWFRAME) num_frames++; if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) has_buttons = 1; update_md5(md5, tag->data, tag->len); tag = tag->next; } int t = time(0); update_md5(md5, (unsigned char*)&t, sizeof(t)); unsigned char h[16]; unsigned char file_signature[33]; finish_md5(md5, h); sprintf((char*)file_signature, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", h[0],h[1],h[2],h[3], h[4],h[5],h[6],h[7], h[8],h[9],h[10],h[11], h[12],h[13],h[14],h[15]); char scenename1[80], scenename2[80]; sprintf(scenename1, "rfx.MainTimeline_%s", file_signature); sprintf(scenename2, "rfx::MainTimeline_%s", file_signature); abc_file_t*file = abc_file_new(); abc_method_body_t*c = 0; abc_class_t*cls = abc_class_new2(file, scenename2, "flash.display::MovieClip"); TAG*abctag = swf_InsertTagBefore(swf, swf->firstTag, ST_DOABC); tag = swf_InsertTag(abctag, ST_SYMBOLCLASS); swf_SetU16(tag, 1); swf_SetU16(tag, 0); swf_SetString(tag, scenename1); c = abc_class_getstaticconstructor(cls, 0)->body; c->old.max_stack = 1; c->old.local_count = 1; c->old.init_scope_depth = 9; c->old.max_scope_depth = 10; __ getlocal_0(c); __ pushscope(c); __ returnvoid(c); c = abc_class_getconstructor(cls, 0)->body; c->old.max_stack = 3; c->old.local_count = 1; c->old.init_scope_depth = 10; c->old.max_scope_depth = 11; debugfile(c, "constructor.as"); __ getlocal_0(c); __ pushscope(c); __ getlocal_0(c); __ constructsuper(c,0); __ getlex(c, "[package]flash.system::Security"); __ pushstring(c, "*"); __ callpropvoid(c, "[package]::allowDomain", 1); if(stop_each_frame || has_buttons) { int frame = 0; tag = swf->firstTag; abc_method_body_t*f = 0; //frame script while(tag && tag->id!=ST_END) { char framename[80]; char needs_framescript=0; char buttonname[80]; char functionname[80]; sprintf(framename, "[packageinternal]rfx::frame%d_%s", frame, file_signature); if(!f && (tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2 || stop_each_frame)) { /* make the contructor add a frame script */ __ findpropstrict(c,"[package]::addFrameScript"); __ pushuint(c,frame); __ getlex(c,framename); __ callpropvoid(c,"[package]::addFrameScript",2); f = abc_class_method(cls, 0, multiname_fromstring(framename))->body; f->old.max_stack = 3; f->old.local_count = 1; f->old.init_scope_depth = 10; f->old.max_scope_depth = 11; __ debugfile(f, "framescript.as"); __ debugline(f, 1); __ getlocal_0(f); __ pushscope(f); if(stop_each_frame) { __ findpropstrict(f, "[package]::stop"); __ callpropvoid(f, "[package]::stop", 0); } } if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { U16 id = swf_GetDefineID(tag); sprintf(buttonname, "::button%d", swf_GetDefineID(tag)); __ getlex(f,buttonname); __ getlex(f,"flash.events::MouseEvent"); __ getproperty(f, "::CLICK"); sprintf(functionname, "::clickbutton%d_%s", swf_GetDefineID(tag), file_signature); __ getlex(f,functionname); __ callpropvoid(f, "::addEventListener" ,2); needs_framescript = 1; abc_method_body_t*h = abc_class_method(cls, 0, multiname_fromstring(functionname))->body; list_append(h->method->parameters, multiname_fromstring("flash.events::MouseEvent")); h->old.max_stack = 6; h->old.local_count = 2; h->old.init_scope_depth = 10; h->old.max_scope_depth = 11; __ getlocal_0(h); __ pushscope(h); ActionTAG*oldaction = swf_ButtonGetAction(tag); if(oldaction && oldaction->op == ACTION__GOTOFRAME) { int framenr = GET16(oldaction->data); if(!events) { __ findpropstrict(h,"[package]::gotoAndStop"); __ pushuint(h,framenr+1); __ callpropvoid(h,"[package]::gotoAndStop", 1); } else { char framename[80]; sprintf(framename, "frame%d_%s", framenr, file_signature); __ getlocal_0(h); //this __ findpropstrict(h, "[package]flash.events::TextEvent"); __ pushstring(h, "link"); __ pushtrue(h); __ pushtrue(h); __ pushstring(h, framename); __ constructprop(h,"[package]flash.events::TextEvent", 4); __ callpropvoid(h,"[package]::dispatchEvent", 1); } } else if(oldaction && oldaction->op == ACTION__GETURL) { if(!events) { __ findpropstrict(h,"flash.net::navigateToURL"); __ findpropstrict(h,"flash.net::URLRequest"); // TODO: target _blank __ pushstring(h,(char*)oldaction->data); //url __ constructprop(h,"flash.net::URLRequest", 1); __ callpropvoid(h,"flash.net::navigateToURL", 1); } else { __ getlocal_0(h); //this __ findpropstrict(h, "[package]flash.events::TextEvent"); __ pushstring(h, "link"); __ pushtrue(h); __ pushtrue(h); __ pushstring(h,(char*)oldaction->data); //url __ constructprop(h,"[package]flash.events::TextEvent", 4); __ callpropvoid(h,"[package]::dispatchEvent", 1); } } else if(oldaction) { fprintf(stderr, "Warning: Couldn't translate button code of button %d to flash 9 abc action\n", id); } __ returnvoid(h); swf_ActionFree(oldaction); } if(tag->id == ST_SHOWFRAME) { if(f) { __ returnvoid(f); f = 0; } frame++; } tag = tag->next; } if(f) { __ returnvoid(f); } } __ returnvoid(c); tag = swf->firstTag; while(tag) { if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { char buttonname[80]; sprintf(buttonname, "::button%d", swf_GetDefineID(tag)); multiname_t*s = multiname_fromstring(buttonname); //abc_class_slot(cls, multiname_fromstring(buttonname), s); abc_class_slot(cls, multiname_fromstring(buttonname), multiname_fromstring("flash.display::SimpleButton")); } tag = tag->next; } abc_script_t*s = abc_initscript(file); c = s->method->body; c->old.max_stack = 2; c->old.local_count = 1; c->old.init_scope_depth = 1; c->old.max_scope_depth = 9; __ getlocal_0(c); __ pushscope(c); __ getscopeobject(c, 0); __ getlex(c,"::Object"); __ pushscope(c); __ getlex(c,"flash.events::EventDispatcher"); __ pushscope(c); __ getlex(c,"flash.display::DisplayObject"); __ pushscope(c); __ getlex(c,"flash.display::InteractiveObject"); __ pushscope(c); __ getlex(c,"flash.display::DisplayObjectContainer"); __ pushscope(c); __ getlex(c,"flash.display::Sprite"); __ pushscope(c); __ getlex(c,"flash.display::MovieClip"); __ pushscope(c); __ getlex(c,"flash.display::MovieClip"); __ newclass(c,cls); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ initproperty(c,scenename2); __ returnvoid(c); //abc_method_body_addClassTrait(c, "rfx:MainTimeline", 1, cls); multiname_t*classname = multiname_fromstring(scenename2); abc_initscript_addClassTrait(s, classname, cls); multiname_destroy(classname); swf_WriteABC(abctag, file); }
void NSISCALL pushint(int value) { char buffer[1024]; wsprintf(buffer, "%d", value); pushstring(buffer); }
void NSISCALL pushint(int value) { TCHAR buffer[1024]; wsprintf(buffer, _T("%d"), value); pushstring(buffer); }
static void claygetfilekindstring (const tybrowserinfo *info, bigstring bs) { // FSSpec appspec; if ((*info).flvolume) { setstringlength (bs, 0); if ((*info).flejectable) pushadjective (BIGSTRING ("\x09" "Removable"), bs); if ((*info).flhardwarelock) pushadjective (BIGSTRING ("\x09" "Read-only"), bs); if ((*info).flremotevolume) pushadjective (BIGSTRING ("\x06" "Shared"), bs); if (stringlength (bs) > 0) pushstring (BIGSTRING ("\x05" " disk"), bs); else copystring (BIGSTRING ("\x04" "Disk"), bs); return; } if ((*info).flfolder) { copystring (BIGSTRING ("\x06" "Folder"), bs); return; } if ((*info).flalias) { copystring (BIGSTRING ("\x05" "Alias"), bs); return; } switch ((*info).filecreator) { case 'DMGR': case 'ERIK': copystring (BIGSTRING ("\x14" "Desktop Manager file"), bs); return; case 'MACS': copystring (BIGSTRING ("\x0f" "System Software"), bs); return; } /*switch*/ switch ((*info).filetype) { case 'APPL': copystring (BIGSTRING ("\x13" "Application program"), bs); return; case 'cdev': copystring (BIGSTRING ("\x0d" "Control Panel"), bs); return; case 'INIT': case 'appe': case 'fext': case 'adev': copystring (BIGSTRING ("\x10" "System Extension"), bs); return; case 'thng': copystring (BIGSTRING ("\x10" "System Component"), bs); return; case 'PRER': case 'PRES': copystring (BIGSTRING ("\x11" "Chooser Extension"), bs); return; case 'FFIL': copystring (BIGSTRING ("\x0d" "Font Suitcase"), bs); return; case 'dbgr': copystring (BIGSTRING ("\x08" "Debugger"), bs); return; case 'dfil': copystring (BIGSTRING ("\x0e" "Desk Accessory"), bs); return; } /*switch*/ #if 0 if (clayfindapp ((*info).filecreator, &appspec, (*info).vnum)) { if (stringlength (appspec.name) > 0) { copystring (appspec.name, bs); pushstring (BIGSTRING ("\x09" " document"), bs); return; } } else { /*DW 9/14/93 -- add it to the cache -- avoid future delays*/ addapptocache ((*info).filecreator, nil); } #endif copystring (BIGSTRING ("\x08" "document"), bs); } /*claygetfilekindstring*/
__declspec(dllexport) void download (HWND parent, int string_size, char *variables, nsis_stack_t **stacktop) { char buf[1024]; char url[1024]; char filename[1024]; static char proxy[1024]; BOOL bSuccess=FALSE; int timeout_ms=30000; int getieproxy=1; int manualproxy=0; int translation_version; char *error=NULL; // translation version 2 & 1 static char szDownloading[1024]; // "Downloading %s" static char szConnecting[1024]; // "Connecting ..." static char szSecond[1024]; // " (1 second remaining)" for v2 // "second" for v1 static char szMinute[1024]; // " (1 minute remaining)" for v2 // "minute" for v1 static char szHour[1024]; // " (1 hour remaining)" for v2 // "hour" for v1 static char szProgress[1024]; // "%skB (%d%%) of %skB at %u.%01ukB/s" for v2 // "%dkB (%d%%) of %dkB at %d.%01dkB/s" for v1 // translation version 2 only static char szSeconds[1024]; // " (%u seconds remaining)" static char szMinutes[1024]; // " (%u minutes remaining)" static char szHours[1024]; // " (%u hours remaining)" // translation version 1 only static char szPlural[1024]; // "s"; static char szRemaining[1024]; // " (%d %s%s remaining)"; EXDLL_INIT(); popstring(url); if (!lstrcmpi(url, "/TRANSLATE2")) { popstring(szDownloading); popstring(szConnecting); popstring(szSecond); popstring(szMinute); popstring(szHour); popstring(szSeconds); popstring(szMinutes); popstring(szHours); popstring(szProgress); popstring(url); translation_version=2; } else if (!lstrcmpi(url, "/TRANSLATE")) { popstring(szDownloading); popstring(szConnecting); popstring(szSecond); popstring(szMinute); popstring(szHour); popstring(szPlural); popstring(szProgress); popstring(szRemaining); popstring(url); translation_version=1; } else { lstrcpy(szDownloading, "Downloading %s"); lstrcpy(szConnecting, "Connecting ..."); lstrcpy(szSecond, " (1 second remaining)"); lstrcpy(szMinute, " (1 minute remaining)"); lstrcpy(szHour, " (1 hour remaining)"); lstrcpy(szSeconds, " (%u seconds remaining)"); lstrcpy(szMinutes, " (%u minutes remaining)"); lstrcpy(szHours, " (%u hours remaining)"); lstrcpy(szProgress, "%skB (%d%%) of %skB at %u.%01ukB/s"); translation_version=2; } lstrcpyn(buf, url, 10); if (!lstrcmpi(buf, "/TIMEOUT=")) { timeout_ms=my_atoi(url+9); popstring(url); } if (!lstrcmpi(url, "/PROXY")) { getieproxy=0; manualproxy=1; popstring(proxy); popstring(url); } if (!lstrcmpi(url, "/NOIEPROXY")) { getieproxy=0; popstring(url); } popstring(filename); HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); if (hFile == INVALID_HANDLE_VALUE) { wsprintf(buf, "Unable to open %s", filename); error = buf; } else { if (parent) { uMsgCreate = RegisterWindowMessage("nsisdl create"); lpWndProcOld = (void *)SetWindowLong(parent,GWL_WNDPROC,(long)ParentWndProc); SendMessage(parent, uMsgCreate, TRUE, (LPARAM) parent); // set initial text char *p = filename; while (*p) p++; while (*p != '\\' && p != filename) p = CharPrev(filename, p); wsprintf(buf, szDownloading, p != filename ? p + 1 : p); SetDlgItemText(childwnd, 1006, buf); SetWindowText(g_hwndStatic, szConnecting); } { WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); JNL_HTTPGet *get = 0; static char main_buf[8192]; char *buf=main_buf; char *p=NULL; HKEY hKey; if (getieproxy && RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) { DWORD l = 4; DWORD t; DWORD v; if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v) { l=8192; if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ) { p=strstr(buf,"http="); if (!p) p=buf; else { p+=5; } char *tp=strstr(p,";"); if (tp) *tp=0; char *p2=strstr(p,"="); if (p2) p=0; // we found the wrong proxy } } buf[8192-1]=0; RegCloseKey(hKey); } if (manualproxy == 1) { p = proxy; } DWORD start_time=GetTickCount(); get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); int st; int has_printed_headers = 0; __int64 cl = 0; int len; __int64 sofar = 0; DWORD last_recv_time=start_time; get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)"); get->addheader ("Accept: */*"); get->connect (url); while (1) { if (g_cancelled) error = "cancel"; if (error) { if (parent) { SendMessage(parent, uMsgCreate, FALSE, (LPARAM) parent); SetWindowLong(parent, GWL_WNDPROC, (long)lpWndProcOld); } break; } st = get->run (); if (st == -1) { lstrcpyn(url, get->geterrorstr(), sizeof(url)); error = url; } else if (st == 1) { if (sofar < cl || get->get_status () != 2) error="download incomplete"; else { bSuccess=TRUE; error = "success"; } } else { if (get->get_status () == 0) { // progressFunc ("Connecting ...", 0); if (last_recv_time+timeout_ms < GetTickCount()) error = "Timed out on connecting."; else Sleep(10); // don't busy-loop while connecting } else if (get->get_status () == 1) { progress_callback("Reading headers", 0); if (last_recv_time+timeout_ms < GetTickCount()) error = "Timed out on getting headers."; else Sleep(10); // don't busy-loop while reading headers } else if (get->get_status () == 2) { if (! has_printed_headers) { has_printed_headers = 1; last_recv_time=GetTickCount(); cl = get->content_length (); if (cl == 0) error = "Server did not specify content length."; else if (g_hwndProgressBar) { SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 30000)); g_file_size = cl; } } int data_downloaded = 0; while ((len = get->bytes_available ()) > 0) { data_downloaded++; if (len > 8192) len = 8192; len = get->get_bytes (buf, len); if (len > 0) { last_recv_time=GetTickCount(); DWORD dw; WriteFile(hFile,buf,len,&dw,NULL); sofar += len; int time_sofar=(GetTickCount()-start_time)/1000; int bps = (int)(sofar/(time_sofar?time_sofar:1)); int remain = MulDiv64(time_sofar, cl, sofar) - time_sofar; if (translation_version == 2) { char *rtext=remain==1?szSecond:szSeconds;; if (remain >= 60) { remain/=60; rtext=remain==1?szMinute:szMinutes; if (remain >= 60) { remain/=60; rtext=remain==1?szHour:szHours; } } char sofar_str[128]; char cl_str[128]; myitoa64(sofar/1024, sofar_str); myitoa64(cl/1024, cl_str); wsprintf (buf, szProgress, //%skB (%d%%) of %skB @ %u.%01ukB/s sofar_str, MulDiv64(100, sofar, cl), cl_str, bps/1024,((bps*10)/1024)%10 ); if (remain) wsprintf(buf+lstrlen(buf),rtext, remain ); } else if (translation_version == 1) { char *rtext=szSecond; if (remain >= 60) { remain/=60; rtext=szMinute; if (remain >= 60) { remain/=60; rtext=szHour; } } wsprintf (buf, szProgress, //%dkB (%d%%) of %dkB @ %d.%01dkB/s int(sofar/1024), MulDiv64(100, sofar, cl), int(cl/1024), bps/1024,((bps*10)/1024)%10 ); if (remain) wsprintf(buf+lstrlen(buf),szRemaining, remain, rtext, remain==1?"":szPlural ); } progress_callback(buf, sofar); } else { if (sofar < cl) error = "Server aborted."; } } if (GetTickCount() > last_recv_time+timeout_ms) { if (sofar != cl) { error = "Downloading timed out."; } else { // workaround for bug #1713562 // buggy servers that wait for the client to close the connection. // another solution would be manually stopping when cl == sofar, // but then buggy servers that return wrong content-length will fail. bSuccess = TRUE; error = "success"; } } else if (!data_downloaded) Sleep(10); } else { error = "Bad response status."; } } } // Clean up the connection then release winsock if (get) delete get; WSACleanup(); } CloseHandle(hFile); } if (g_cancelled || !bSuccess) { DeleteFile(filename); } pushstring(error); }
/** * Retrieves a file's architecture (x86 or amd64). * Outputs "x86", "amd64" or an error message (if not found/invalid) on stack. * * @param hwndParent Window handle of parent. * @param string_size Size of variable string. * @param variables The actual variable string. * @param stacktop Pointer to a pointer to the current stack. */ VBOXINSTALLHELPER_EXPORT FileGetArchitecture(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { NOREF(hwndParent); EXDLL_INIT(); TCHAR szFile[MAX_PATH + 1]; HRESULT hr = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); if (SUCCEEDED(hr)) { /* See: http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx */ FILE *pFh = fopen(szFile, "rb"); if (pFh) { /* Assume the file is invalid. */ hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); BYTE offPeHdr = 0; /* Absolute offset of PE signature. */ /* Do some basic validation. */ /* Check for "MZ" header (DOS stub). */ BYTE byBuf[255]; if ( fread(&byBuf, sizeof(BYTE), 2, pFh) == 2 && !memcmp(&byBuf, "MZ", 2)) { /* Seek to 0x3C to get the PE offset. */ if (!fseek(pFh, 60L /*0x3C*/, SEEK_SET)) { /* Read actual offset of PE signature. */ /** @todo r=bird: You've obviously no clue about the structure you're messing with here. The field is NOT a BYTE * field but a int32_t/uint32_t! The MZ header is defined as IMAGE_DOS_HEADER by windows.h (well, winnt.h), and the * field you're accessing is e_lfanew. Please rewrite this hack to use the structures! (Also, the MZ structure is * OPTIONAL, just in case you didn't know.) */ #ifdef DEBUG_andy # error "Fix this" #endif if (fread(&offPeHdr, sizeof(BYTE), 1, pFh) == 1) { /* ... and seek to it. */ if (!fseek(pFh, offPeHdr, SEEK_SET)) { /* Validate PE signature. */ if (fread(byBuf, sizeof(BYTE), 4, pFh) == 4) { if (!memcmp(byBuf, "PE\0\0", 4)) hr = S_OK; } } } } } /* Validation successful? */ if (SUCCEEDED(hr)) { BYTE offFileHeaderMachineField = offPeHdr + 0x4; /* Skip PE signature. */ /** @todo When we need to do more stuff here, we probably should * mmap the file w/ a struct so that we easily could access * all the fixed size stuff. Later. */ /* Jump to machine type (first entry, 2 bytes): * Use absolute PE offset retrieved above. */ if (!fseek(pFh, offFileHeaderMachineField, SEEK_SET)) { WORD wMachineType; if (fread(&wMachineType, 1, sizeof(wMachineType), pFh) == 2) { switch (wMachineType) { case 0x14C: /* Intel 86 */ pushstring("x86"); break; case 0x8664: /* AMD64 / x64 */ pushstring("amd64"); break; default: hr = __HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); break; } } else hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); } else hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); } fclose(pFh); } else hr = __HRESULT_FROM_WIN32(ERROR_NOT_FOUND); } if (FAILED(hr)) vboxPushResultAsString(hr); }
/** * Retrieves a file's architecture (x86 or amd64). * Outputs "x86", "amd64" or an error message (if not found/invalid) on stack. * * @param hwndParent Window handle of parent. * @param string_size Size of variable string. * @param variables The actual variable string. * @param stacktop Pointer to a pointer to the current stack. */ VBOXINSTALLHELPER_EXPORT FileGetArchitecture(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); TCHAR szFile[MAX_PATH + 1]; HRESULT hr = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); if (SUCCEEDED(hr)) { /* See: http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx */ FILE *pFh = fopen(szFile, "rb"); if (pFh) { /* Assume the file is invalid. */ hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); BYTE byOffsetPE; /* Absolute offset of PE signature. */ /* Do some basic validation. */ /* Check for "MZ" header (DOS stub). */ BYTE byBuf[255]; if ( fread(&byBuf, sizeof(BYTE), 2, pFh) == 2 && !memcmp(&byBuf, "MZ", 2)) { /* Seek to 0x3C to get the PE offset. */ if (!fseek(pFh, 60L /*0x3C*/, SEEK_SET)) { /* Read actual offset of PE signature. */ if (fread(&byOffsetPE, sizeof(BYTE), 1, pFh) == 1) { /* ... and seek to it. */ if (!fseek(pFh, byOffsetPE, SEEK_SET)) { /* Validate PE signature. */ if (fread(byBuf, sizeof(BYTE), 4, pFh) == 4) { if (!memcmp(byBuf, "PE\0\0", 4)) hr = S_OK; } } } } } /* Validation successful? */ if (SUCCEEDED(hr)) { BYTE byOffsetCOFF = byOffsetPE + 0x4; /* Skip PE signature. */ /** @todo When we need to do more stuff here, we probably should * mmap the file w/ a struct so that we easily could access * all the fixed size stuff. Later. */ /* Jump to machine type (first entry, 2 bytes): * Use absolute PE offset retrieved above. */ if (!fseek(pFh, byOffsetCOFF, SEEK_SET)) { WORD wMachineType; if (fread(&wMachineType, 1, sizeof(wMachineType), pFh) == 2) { switch (wMachineType) { case 0x14C: /* Intel 86 */ pushstring("x86"); break; case 0x8664: /* AMD64 / x64 */ pushstring("amd64"); break; default: hr = __HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); break; } } else hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); } else hr = __HRESULT_FROM_WIN32(ERROR_FILE_INVALID); } fclose(pFh); } else hr = __HRESULT_FROM_WIN32(ERROR_NOT_FOUND); } if (FAILED(hr)) vboxPushResultAsString(hr); }
void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { OPENFILENAME ofn={0,}; // XXX WTF int save; TCHAR type[5]; static TCHAR path[1024]; static TCHAR filter[1024]; static TCHAR currentDirectory[1024]; static TCHAR initialDir[1024]; DWORD gfa; EXDLL_INIT(); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwndParent; ofn.lpstrFilter = filter; ofn.lpstrFile = path; ofn.nMaxFile = sizeof(path); //ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER); ofn.Flags = OFN_CREATEPROMPT | OFN_EXPLORER; popstringn(type, sizeof(type)); popstringn(path, sizeof(path)); popstringn(filter, sizeof(filter)); save = !lstrcmpi(type, _T("save")); // Check if the path given is a folder. If it is we initialize the // ofn.lpstrInitialDir parameter gfa = GetFileAttributes(path); if ((gfa != INVALID_FILE_ATTRIBUTES) && (gfa & FILE_ATTRIBUTE_DIRECTORY)) { lstrcpy(initialDir, path); ofn.lpstrInitialDir = initialDir; path[0] = _T('\0'); // disable initial file selection as path is actually a directory } if (!filter[0]) { lstrcpy(filter, _T("All Files|*.*")); } { // Convert the filter to the format required by Windows: NULL after each // item followed by a terminating NULL TCHAR *p = filter; while (*p) // XXX take care for 1024 { if (*p == _T('|')) { *p++ = 0; } else { p = CharNext(p); } } p++; *p = 0; } GetCurrentDirectory(sizeof(currentDirectory), currentDirectory); // save working dir if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn))) { pushstring(path); } else if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) { *path = _T('\0'); if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn))) { pushstring(path); } else { pushstring(_T("")); } } else { pushstring(_T("")); } // restore working dir // OFN_NOCHANGEDIR doesn't always work (see MSDN) SetCurrentDirectory(currentDirectory); }
static boolean browsercollisiondialog (hdlheadrecord hdest, ptrdraginfo draginfo) { #pragma unused (hdest) /* 2005-09-26 creedon: changed default order of buttons, default is Duplicate which is the safe option, checks user.prefs.flReplaceDialogExpertMode and if true Replace is the default option */ bigstring bs, bscollided, prompt; bigstring nobutton, yesbutton; short itemhit; boolean fl, flExpertMode = false; if ((*draginfo).collisiontype == nocollisions) /*no confirmation or deletions needed*/ return (true); if ((*draginfo).ctcollisions > 1) { copystring (dialogstrings [ixsomeitems], prompt); pushstring (actionstrings [(*draginfo).action], prompt); pushchar ('.', prompt); } else { copystring (dialogstrings [ixan], prompt); switch ((*draginfo).collisiontype) { case collidewithnewer: copystring (dialogstrings [ixanewer], prompt); break; case collidewitholder: copystring (dialogstrings [ixanolder], prompt); break; } /*switch*/ pushstring (dialogstrings [ixitemnamed], prompt); opgetheadstring ((*draginfo).hcollided, bscollided); pushstring (bscollided, prompt); pushstring (dialogstrings [ixalreadyexists], prompt); } getsystemtablescript (idreplacedialogexpertmode, bs); // "user.prefs.flReplaceDialogExpertMode" disablelangerror (); fl = langrunstring (bs, bs); enablelangerror (); if (fl) stringisboolean (bs, &flExpertMode); if (flExpertMode) { copystring (duplicatebuttontext, nobutton); copystring (replacebuttontext, yesbutton); } else { copystring (duplicatebuttontext, yesbutton); copystring (replacebuttontext, nobutton); } itemhit = threewaydialog (prompt, yesbutton, nobutton, cancelbuttontext); if (flExpertMode) switch (itemhit) { case 1: itemhit = 2; break; case 2: itemhit = 1; break; } switch (itemhit) { case 1: opcleartmpbits (); /*caller should rename items where conflicts occur*/ return (true); case 2: /*caller should delete all files with their tmpbit set*/ return (true); default: opcleartmpbits (); return (false); } /* switch */ } /*browsercollisiondialog*/
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { int i, size; char *selected_language = NULL; static HFONT font; switch (uMsg) { case WM_INITDIALOG: // add languages for (i = visible_langs_num - 1; i >= 0; i--) { int cbi; cbi = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM) langs[i].name); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SETITEMDATA, cbi, (LPARAM) langs[i].id); // remember selected language if (!lstrcmp(langs[i].id, getuservariable(INST_LANG))) { selected_language = langs[i].name; } } // select the current language if (selected_language) SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) selected_language); else SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SETCURSEL, 0, 0); // set texts SetDlgItemText(hwndDlg, IDC_TEXT, g_wndtext); SetWindowText(hwndDlg, g_wndtitle); SendDlgItemMessage(hwndDlg, IDC_APPICON, STM_SETICON, (LPARAM)LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(103)), 0); // set font if (dofont && !popstring(temp)) { size = myatou(temp); if (!popstring(temp)) { LOGFONT f = {0,}; if (lstrcmp(temp, "MS Shell Dlg")) { f.lfHeight = -MulDiv(size, GetDeviceCaps(GetDC(hwndDlg), LOGPIXELSY), 72); lstrcpy(f.lfFaceName, temp); font = CreateFontIndirect(&f); SendMessage(hwndDlg, WM_SETFONT, (WPARAM)font, 1); SendDlgItemMessage(hwndDlg, IDOK, WM_SETFONT, (WPARAM)font, 1); SendDlgItemMessage(hwndDlg, IDCANCEL, WM_SETFONT, (WPARAM)font, 1); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, WM_SETFONT, (WPARAM)font, 1); SendDlgItemMessage(hwndDlg, IDC_TEXT, WM_SETFONT, (WPARAM)font, 1); } } } // show window ShowWindow(hwndDlg, SW_SHOW); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: // push result on the stack i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0); i = SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETITEMDATA, i, 0); if (i != CB_ERR && i) { pushstring((char *) i); } else { // ?! pushstring("cancel"); } // end dialog EndDialog(hwndDlg, 0); break; case IDCANCEL: // push "cancel" on the stack pushstring("cancel"); // end dialog EndDialog(hwndDlg, 0); break; } break; case WM_DESTROY: // clean up if (font) DeleteObject(font); break; default: return FALSE; // message not processed } return TRUE; // message processed }
void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { BROWSEINFO bi; TCHAR result[MAX_PATH]; TCHAR initial[MAX_PATH]; TCHAR title[1024]; LPITEMIDLIST resultPIDL; EXDLL_INIT(); if (popstringn(title, COUNTOF(initial))) { pushstring(_T("error")); return; } if (popstringn(initial, COUNTOF(title))) { pushstring(_T("error")); return; } bi.hwndOwner = hwndParent; bi.pidlRoot = NULL; bi.pszDisplayName = result; bi.lpszTitle = title; #ifndef BIF_NEWDIALOGSTYLE #define BIF_NEWDIALOGSTYLE 0x0040 #endif bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; bi.lpfn = BrowseCallbackProc; bi.lParam = (LPARAM) initial; bi.iImage = 0; /*if (pField->pszRoot) { LPSHELLFOLDER sf; ULONG eaten; LPITEMIDLIST root; int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2; LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot); MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot); SHGetDesktopFolder(&sf); sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL); bi.pidlRoot = root; sf->Release(); FREE(pwszRoot); }*/ resultPIDL = SHBrowseForFolder(&bi); if (!resultPIDL) { pushstring(_T("error")); return; } if (SHGetPathFromIDList(resultPIDL, result)) { pushstring(result); } else { pushstring(_T("error")); } CoTaskMemFree(resultPIDL); }
void __declspec(dllexport) LangDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { int i; int doauto = 0; BOOL pop_empty_string = FALSE; // get texts if (popstring(g_wndtitle)) return; if (popstring(g_wndtext)) return; // get flags if (popstring(temp)) return; // parse flags { char *p=temp; while (*p) { if (*p == 'A') doauto=1; // parse auto count flag if (*p == 'F') dofont=1; // parse font flag if (*p == 'C') docp=1; // parse codepage flag p++; } } if (doauto) { // automatic language count stack_t *th; langs_num=0; th=(*g_stacktop); while (th && th->text[0]) { langs_num++; th = th->next; } if (!th) return; if (docp) langs_num /= 3; else langs_num /= 2; pop_empty_string = TRUE; } else { // use counts languages langs_num = myatou(temp); } // zero languages? if (!langs_num) return; // initialize visible languages count visible_langs_num = 0; // allocate language struct langs = (struct lang *)GlobalAlloc(GPTR, langs_num*sizeof(struct lang)); if (!langs) return; // fill language struct for (i = 0; i < langs_num; i++) { if (popstring(temp)) { visible_langs_num = 0; break; } langs[visible_langs_num].name = GlobalAlloc(GPTR, lstrlen(temp)+1); if (!langs[visible_langs_num].name) { visible_langs_num = 0; break; } lstrcpy(langs[visible_langs_num].name, temp); if (popstring(temp)) { visible_langs_num = 0; break; } langs[visible_langs_num].id = GlobalAlloc(GPTR, lstrlen(temp)+1); if (!langs[visible_langs_num].id) { visible_langs_num = 0; break; } lstrcpy(langs[visible_langs_num].id, temp); if (docp) { if (popstring(temp)) { visible_langs_num = 0; break; } langs[visible_langs_num].cp = myatou(temp); } if (!docp || langs[visible_langs_num].cp == GetACP() || langs[visible_langs_num].cp == 0) { visible_langs_num++; } else { GlobalFree(langs[visible_langs_num].name); GlobalFree(langs[visible_langs_num].id); } } // pop the empty string to keep the stack clean if (pop_empty_string) { if (popstring(temp)) { visible_langs_num = 0; } } // start dialog if (visible_langs_num > 1) { DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG), 0, DialogProc); } else if (visible_langs_num == 0) { pushstring(""); } else { pushstring(langs[0].id); } // free structs for (i = 0; i < visible_langs_num; i++) { if (langs[i].name) GlobalFree(langs[i].name); if (langs[i].id) GlobalFree(langs[i].id); } GlobalFree(langs); } }
void __declspec(dllexport) GetAccountType(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); pushstring(GetAccountTypeHelper(TRUE)); }
extern int main(int argc, char *argv[], char *envp[]) { char *dashsee[2], *dollarzero, *null[1]; int c; initprint(); dashsee[0] = dashsee[1] = NULL; dollarzero = argv[0]; rc_pid = getpid(); dashell = (*argv[0] == '-'); /* Unix tradition */ while ((c = rc_getopt(argc, argv, "c:deiIlnopsvx")) != -1) switch (c) { case 'c': dashsee[0] = rc_optarg; goto quitopts; case 'd': dashdee = TRUE; break; case 'e': dashee = TRUE; break; case 'I': dashEYE = TRUE; interactive = FALSE; break; case 'i': dasheye = interactive = TRUE; break; case 'l': dashell = TRUE; break; case 'n': dashen = TRUE; break; case 'o': dashoh = TRUE; break; case 'p': dashpee = TRUE; break; case 's': dashess = TRUE; break; case 'v': dashvee = TRUE; break; case 'x': dashex = TRUE; break; case '?': exit(1); } quitopts: argv += rc_optind; /* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */ if (!dasheye && !dashEYE && dashsee[0] == NULL && (dashess || *argv == NULL)) interactive = isatty(0); if (!dashoh) { checkfd(0, rFrom); checkfd(1, rCreate); checkfd(2, rCreate); } initsignal(); inithash(); initparse(); assigndefault("ifs", " ", "\t", "\n", (void *)0); #ifdef DEFAULTPATH assigndefault("path", DEFAULTPATH, (void *)0); #endif assigndefault("pid", nprint("%d", rc_pid), (void *)0); assigndefault("prompt", "; ", "", (void *)0); assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " DESCRIPTION " $", (void *)0 ); initenv(envp); initinput(); null[0] = NULL; starassign(dollarzero, null, FALSE); /* assign $0 to $* */ inithandler(); if (dashell) { char *rcrc; int fd; rcrc = concat(varlookup("home"), word("/.rcrc", NULL))->w; fd = rc_open(rcrc, rFrom); if (fd == -1) { if (errno != ENOENT) uerror(rcrc); } else { bool push_interactive; pushfd(fd); push_interactive = interactive; interactive = FALSE; doit(TRUE); interactive = push_interactive; close(fd); } } applylocale(); if (dashsee[0] != NULL || dashess) { /* input from -c or -s? */ if (*argv != NULL) starassign(dollarzero, argv, FALSE); if (dashess) pushfd(0); else pushstring(dashsee, TRUE); } else if (*argv != NULL) { /* else from a file? */ b_dot(--argv); rc_exit(getstatus()); } else { /* else stdin */ pushfd(0); } dasheye = FALSE; doit(TRUE); rc_exit(getstatus()); return 0; /* Never really reached. */ }
void __declspec(dllexport) CreateControl(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { char *className; char *text; HWND hwItem; int x, y, width, height; DWORD style, exStyle; size_t id; // get info from stack className = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, g_stringsize * 2); text = &className[g_stringsize]; if (!className) { pushstring("error"); return; } if (popstring(className, 0)) { pushstring("error"); HeapFree(GetProcessHeap(), 0, className); return; } style = (DWORD) popint(); exStyle = (DWORD) popint(); PopPlacement(&x, &y, &width, &height); if (popstring(text, 0)) { pushstring("error"); HeapFree(GetProcessHeap(), 0, className); return; } // create item descriptor id = g_dialog.controlCount; g_dialog.controlCount++; g_dialog.controls = (struct nsControl*) HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, g_dialog.controls, g_dialog.controlCount * sizeof(struct nsControl)); if (!lstrcmpi(className, "BUTTON")) g_dialog.controls[id].type = NSCTL_BUTTON; else if (!lstrcmpi(className, "EDIT")) g_dialog.controls[id].type = NSCTL_EDIT; else if (!lstrcmpi(className, "COMBOBOX")) g_dialog.controls[id].type = NSCTL_COMBOBOX; else if (!lstrcmpi(className, "LISTBOX")) g_dialog.controls[id].type = NSCTL_LISTBOX; else if (!lstrcmpi(className, "RichEdit")) g_dialog.controls[id].type = NSCTL_RICHEDIT; else if (!lstrcmpi(className, "RICHEDIT_CLASS")) g_dialog.controls[id].type = NSCTL_RICHEDIT2; else if (!lstrcmpi(className, "STATIC")) g_dialog.controls[id].type = NSCTL_STATIC; else g_dialog.controls[id].type = NSCTL_UNKNOWN; // apply rtl to style ConvertStyleToRTL(g_dialog.controls[id].type, &style, &exStyle); // create item's window hwItem = CreateWindowEx( exStyle, className, text, style, x, y, width, height, g_dialog.hwDialog, (HMENU) (1200 + id), g_hInstance, NULL); g_dialog.controls[id].window = hwItem; // remember id SetProp(hwItem, NSCONTROL_ID_PROP, (HANDLE) (id + 1)); // set font SendMessage(hwItem, WM_SETFONT, SendMessage(g_dialog.hwParent, WM_GETFONT, 0, 0), TRUE); // push back result pushint((int) hwItem); // done HeapFree(GetProcessHeap(), 0, className); }
void __declspec(dllexport) Init(HWND hwndParent, int string_size, char *variables, nsis_stack_t **stacktop, extra_parameters *extra) { HWND hwStartMenuSelect; hwParent = hwndParent; validate_filename = extra->validate_filename; EXDLL_INIT(); extra->RegisterPluginCallback(g_hInstance, PluginCallback); g_done = 0; noicon = 0; rtl = 0; autoadd = 0; text[0] = 0; progname[0] = 0; lastused[0] = 0; checkbox[0] = 0; g_hwStartMenuSelect = NULL; { hwChild = GetDlgItem(hwndParent, 1018); if (!hwChild) { pushstring("error finding childwnd"); return; } popstring(buf); while (buf[0] == '/') { if (!lstrcmpi(buf+1, "noicon")) { noicon = 1; } else if (!lstrcmpi(buf+1, "rtl")) { rtl = 1; } else if (!lstrcmpi(buf+1, "text")) { popstring(text); } else if (!lstrcmpi(buf+1, "autoadd")) { autoadd = 1; } else if (!lstrcmpi(buf+1, "lastused")) { popstring(lastused); } else if (!lstrcmpi(buf+1, "checknoshortcuts")) { popstring(checkbox); } if (popstring(buf)) { *buf = 0; } } if (*buf) { lstrcpy(progname, buf); } else { pushstring("error reading parameters"); return; } hwStartMenuSelect = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG), hwndParent, dlgProc); g_hwStartMenuSelect = hwStartMenuSelect; if (!hwStartMenuSelect) { pushstring("error creating dialog"); return; } else { lpWndProcOld = (void *) SetWindowLong(hwndParent, DWL_DLGPROC, (long) ParentWndProc); wsprintf(buf, "%u", hwStartMenuSelect); pushstring(buf); } } }
static void persistproto(PersistInfo *pi) { /* perms reftbl ... proto */ Proto *p = toproto(pi->L, -1); lua_checkstack(pi->L, 2); /* Persist constant refs */ { int i; pi->writer(pi->L, &p->sizek, sizeof(int), pi->ud); for(i=0; i<p->sizek; i++) { LIF(A,pushobject)(pi->L, &p->k[i]); /* perms reftbl ... proto const */ persist(pi); lua_pop(pi->L, 1); /* perms reftbl ... proto */ } } /* perms reftbl ... proto */ /* serialize inner Proto refs */ { int i; pi->writer(pi->L, &p->sizep, sizeof(int), pi->ud); for(i=0; i<p->sizep; i++) { pushproto(pi->L, p->p[i]); /* perms reftbl ... proto subproto */ persist(pi); lua_pop(pi->L, 1); /* perms reftbl ... proto */ } } /* perms reftbl ... proto */ /* Serialize code */ { pi->writer(pi->L, &p->sizecode, sizeof(int), pi->ud); pi->writer(pi->L, p->code, sizeof(Instruction) * p->sizecode, pi->ud); } /* Serialize upvalue names */ { int i; pi->writer(pi->L, &p->sizeupvalues, sizeof(int), pi->ud); for(i=0; i<p->sizeupvalues; i++) { pushstring(pi->L, p->upvalues[i]); persist(pi); lua_pop(pi->L, 1); } } /* Serialize local variable infos */ { int i; pi->writer(pi->L, &p->sizelocvars, sizeof(int), pi->ud); for(i=0; i<p->sizelocvars; i++) { pushstring(pi->L, p->locvars[i].varname); persist(pi); lua_pop(pi->L, 1); pi->writer(pi->L, &p->locvars[i].startpc, sizeof(int), pi->ud); pi->writer(pi->L, &p->locvars[i].endpc, sizeof(int), pi->ud); } } /* Serialize source string */ pushstring(pi->L, p->source); persist(pi); lua_pop(pi->L, 1); /* Serialize line numbers */ { pi->writer(pi->L, &p->sizelineinfo, sizeof(int), pi->ud); if (p->sizelineinfo) { pi->writer(pi->L, p->lineinfo, sizeof(int) * p->sizelineinfo, pi->ud); } } /* Serialize linedefined and lastlinedefined */ pi->writer(pi->L, &p->linedefined, sizeof(int), pi->ud); pi->writer(pi->L, &p->lastlinedefined, sizeof(int), pi->ud); /* Serialize misc values */ { pi->writer(pi->L, &p->nups, sizeof(lu_byte), pi->ud); pi->writer(pi->L, &p->numparams, sizeof(lu_byte), pi->ud); pi->writer(pi->L, &p->is_vararg, sizeof(lu_byte), pi->ud); pi->writer(pi->L, &p->maxstacksize, sizeof(lu_byte), pi->ud); } /* We do not currently persist upvalue names, local variable names, * variable lifetimes, line info, or source code. */ }
int WINAPI createCfgDlg() { g_is_back=0; g_is_cancel=0; HWND mainwnd = hMainWindow; if (!mainwnd) { popstring(NULL); pushstring("error finding mainwnd"); return 1; // cannot be used in silent mode unfortunately. } if (!g_stacktop || !*g_stacktop || !(pszFilename = (*g_stacktop)->text) || !pszFilename[0] || !ReadSettings()) { popstring(NULL); pushstring("error finding config"); return 1; } HWND childwnd=GetDlgItem(mainwnd,nRectId); if (!childwnd) { popstring(NULL); pushstring("error finding childwnd"); return 1; } hCancelButton = GetDlgItem(mainwnd,IDCANCEL); hNextButton = GetDlgItem(mainwnd,IDOK); hBackButton = GetDlgItem(mainwnd,3); mySetWindowText(hCancelButton,pszCancelButtonText); mySetWindowText(hNextButton,pszNextButtonText); mySetWindowText(hBackButton,pszBackButtonText); if (bBackEnabled!=-1) EnableWindow(hBackButton,bBackEnabled); if (bCancelEnabled!=-1) EnableWindow(hCancelButton,bCancelEnabled); if (bCancelShow!=-1) old_cancel_visible=ShowWindow(hCancelButton,bCancelShow?SW_SHOWNA:SW_HIDE); HFONT hFont = (HFONT)mySendMessage(mainwnd, WM_GETFONT, 0, 0); // Prevent WM_COMMANDs from being processed while we are building g_done = 1; int mainWndWidth, mainWndHeight; hConfigWindow=CreateDialog(m_hInstance,MAKEINTRESOURCE(IDD_DIALOG1),mainwnd,cfgDlgProc); if (hConfigWindow) { RECT dialog_r; GetWindowRect(childwnd,&dialog_r); MapWindowPoints(0, mainwnd, (LPPOINT) &dialog_r, 2); mainWndWidth = dialog_r.right - dialog_r.left; mainWndHeight = dialog_r.bottom - dialog_r.top; SetWindowPos( hConfigWindow, 0, dialog_r.left, dialog_r.top, mainWndWidth, mainWndHeight, SWP_NOZORDER|SWP_NOACTIVATE ); // Sets the font of IO window to be the same as the main window mySendMessage(hConfigWindow, WM_SETFONT, (WPARAM)hFont, TRUE); } else { popstring(NULL); pushstring("error creating dialog"); return 1; } BOOL fFocused = FALSE; #define DEFAULT_STYLES (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS) #define RTL_EX_STYLES (WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR) for (int nIdx = 0; nIdx < nNumFields; nIdx++) { static struct { char* pszClass; DWORD dwStyle; DWORD dwRTLStyle; DWORD dwExStyle; DWORD dwRTLExStyle; } ClassTable[] = { { "STATIC", // FIELD_LABEL DEFAULT_STYLES, DEFAULT_STYLES | SS_RIGHT, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, { "STATIC", // FIELD_ICON DEFAULT_STYLES | SS_ICON, DEFAULT_STYLES | SS_ICON, 0, RTL_EX_STYLES }, { "STATIC", // FIELD_BITMAP DEFAULT_STYLES | SS_BITMAP, DEFAULT_STYLES | SS_BITMAP, 0, RTL_EX_STYLES }, { "BUTTON", // FIELD_BROWSEBUTTON DEFAULT_STYLES | WS_TABSTOP, DEFAULT_STYLES | WS_TABSTOP, 0, RTL_EX_STYLES }, { "BUTTON", // FIELD_LINK DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW, DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW | BS_RIGHT, 0, RTL_EX_STYLES }, { "BUTTON", // FIELD_BUTTON DEFAULT_STYLES | WS_TABSTOP, DEFAULT_STYLES | WS_TABSTOP, 0, RTL_EX_STYLES }, { "BUTTON", // FIELD_GROUPBOX DEFAULT_STYLES | BS_GROUPBOX, DEFAULT_STYLES | BS_GROUPBOX | BS_RIGHT, WS_EX_TRANSPARENT, WS_EX_TRANSPARENT | RTL_EX_STYLES }, { "BUTTON", // FIELD_CHECKBOX DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE, DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT, 0, RTL_EX_STYLES }, { "BUTTON", // FIELD_RADIOBUTTON DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE, DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE | BS_RIGHT | BS_LEFTTEXT, 0, RTL_EX_STYLES }, { "EDIT", // FIELD_TEXT DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, { "EDIT", // FIELD_FILEREQUEST DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, { "EDIT", // FIELD_DIRREQUEST DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL, DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL | ES_RIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | RTL_EX_STYLES }, { "COMBOBOX", // FIELD_COMBOBOX DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS, DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_RIGHT | RTL_EX_STYLES }, { "LISTBOX", // FIELD_LISTBOX DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT, DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_RIGHT | RTL_EX_STYLES } }; FieldType *pField = pFields + nIdx; #undef DEFAULT_STYLES if (pField->nType < 1 || pField->nType > (sizeof(ClassTable) / sizeof(ClassTable[0]))) continue; DWORD dwStyle, dwExStyle; if (bRTL) { dwStyle = ClassTable[pField->nType - 1].dwRTLStyle; dwExStyle = ClassTable[pField->nType - 1].dwRTLExStyle; } else { dwStyle = ClassTable[pField->nType - 1].dwStyle; dwExStyle = ClassTable[pField->nType - 1].dwExStyle; } // Convert from dialog units RECT rect = pField->rect; // MapDialogRect uses the font used when a dialog is created, and ignores // any subsequent WM_SETFONT messages (like we used above); so use the main // NSIS window for the conversion, instead of this one. MapDialogRect(mainwnd, &rect); if (pField->rect.left < 0) rect.left += mainWndWidth; if (pField->rect.right < 0) rect.right += mainWndWidth; if (pField->rect.top < 0) rect.top += mainWndHeight; if (pField->rect.bottom < 0) rect.bottom += mainWndHeight; if (bRTL) { int right = rect.right; rect.right = mainWndWidth - rect.left; rect.left = mainWndWidth - right; } char *title = pField->pszText; switch (pField->nType) { case FIELD_ICON: case FIELD_BITMAP: title = NULL; // otherwise it is treated as the name of a resource break; case FIELD_CHECKBOX: case FIELD_RADIOBUTTON: dwStyle ^= pField->nFlags & BS_LEFTTEXT; break; case FIELD_TEXT: case FIELD_FILEREQUEST: case FIELD_DIRREQUEST: if (pField->nFlags & FLAG_PASSWORD) dwStyle |= ES_PASSWORD; if (pField->nFlags & FLAG_ONLYNUMBERS) dwStyle |= ES_NUMBER; if (pField->nFlags & FLAG_WANTRETURN) dwStyle |= ES_WANTRETURN; if (pField->nFlags & FLAG_READONLY) dwStyle |= ES_READONLY; title = pField->pszState; if (pField->nFlags & FLAG_MULTILINE) { dwStyle |= ES_MULTILINE | ES_AUTOVSCROLL; // Enable word-wrap unless we have a horizontal scroll bar // or it has been explicitly disallowed if (!(pField->nFlags & (WS_HSCROLL | FLAG_NOWORDWRAP))) dwStyle &= ~ES_AUTOHSCROLL; ConvertNewLines(pField->pszState); // If multiline-readonly then hold the text back until after the // initial focus has been set. This is so the text is not initially // selected - useful for License Page look-a-likes. if (pField->nFlags & FLAG_READONLY) title = NULL; } break; case FIELD_COMBOBOX: dwStyle |= (pField->nFlags & FLAG_DROPLIST) ? CBS_DROPDOWNLIST : CBS_DROPDOWN; title = pField->pszState; break; case FIELD_LISTBOX: dwStyle |= pField->nFlags & (LBS_NOTIFY | LBS_MULTIPLESEL | LBS_EXTENDEDSEL); break; } dwStyle |= pField->nFlags & (WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_DISABLED); if (pField->nFlags & WS_TABSTOP) dwStyle &= ~WS_TABSTOP; HWND hwCtrl = pField->hwnd = CreateWindowEx( dwExStyle, ClassTable[pField->nType - 1].pszClass, title, dwStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, hConfigWindow, (HMENU)pField->nControlID, m_hInstance, NULL ); if (hwCtrl) { // Sets the font of IO window to be the same as the main window mySendMessage(hwCtrl, WM_SETFONT, (WPARAM)hFont, TRUE); // make sure we created the window, then set additional attributes switch (pField->nType) { case FIELD_TEXT: case FIELD_FILEREQUEST: case FIELD_DIRREQUEST: mySendMessage(hwCtrl, EM_LIMITTEXT, (WPARAM)pField->nMaxLength, (LPARAM)0); break; case FIELD_CHECKBOX: case FIELD_RADIOBUTTON: if (pField->pszState[0] == '1') mySendMessage(hwCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); break; case FIELD_COMBOBOX: case FIELD_LISTBOX: // if this is a listbox or combobox, we need to add the list items. if (pField->pszListItems) { UINT nAddMsg, nFindMsg, nSetSelMsg; if (pField->nType == FIELD_COMBOBOX) { nAddMsg = CB_ADDSTRING; nFindMsg = CB_FINDSTRINGEXACT; nSetSelMsg = CB_SETCURSEL; } else { nAddMsg = LB_ADDSTRING; nFindMsg = LB_FINDSTRINGEXACT; nSetSelMsg = LB_SETCURSEL; } char *pszStart, *pszEnd, *pszList; pszStart = pszEnd = pszList = STRDUP(pField->pszListItems); // pszListItems has a trailing pipe while (*pszEnd) { if (*pszEnd == '|') { *pszEnd = '\0'; if (*pszStart) mySendMessage(hwCtrl, nAddMsg, 0, (LPARAM) pszStart); pszStart = ++pszEnd; } else pszEnd = CharNext(pszEnd); } FREE(pszList); if (pField->pszState) { if (pField->nFlags & (LBS_MULTIPLESEL|LBS_EXTENDEDSEL) && nFindMsg == LB_FINDSTRINGEXACT) { mySendMessage(hwCtrl, LB_SETSEL, FALSE, -1); pszStart = pszEnd = pField->pszState; for (;;) { char c = *pszEnd; if (c == '|' || c == '\0') { *pszEnd = '\0'; if (*pszStart) { int nItem = mySendMessage(hwCtrl, LB_FINDSTRINGEXACT, -1, (LPARAM)pszStart); if (nItem != LB_ERR) mySendMessage(hwCtrl, LB_SETSEL, TRUE, nItem); } if (!c) break; pszStart = ++pszEnd; } else pszEnd = CharNext(pszEnd); } } else { int nItem = mySendMessage(hwCtrl, nFindMsg, -1, (LPARAM)pField->pszState); if (nItem != CB_ERR) { // CB_ERR == LB_ERR == -1 mySendMessage(hwCtrl, nSetSelMsg, nItem, 0); } } } } break; case FIELD_ICON: case FIELD_BITMAP: { WPARAM nImageType = pField->nType == FIELD_BITMAP ? IMAGE_BITMAP : IMAGE_ICON; LPARAM nImage = 0; if (pField->pszText) { pField->hImage = LoadImage( m_hInstance, pField->pszText, nImageType, (pField->nFlags & FLAG_RESIZETOFIT) ? (rect.right - rect.left) : 0, (pField->nFlags & FLAG_RESIZETOFIT) ? (rect.bottom - rect.top) : 0, LR_LOADFROMFILE ); nImage = (LPARAM)pField->hImage; } else nImage = (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103)); if ((pField->nFlags & TRANSPARENT_BMP) && nImageType == IMAGE_BITMAP) { // based on AdvSplash's SetTransparentRegion BITMAP bm; HBITMAP hBitmap = (HBITMAP) nImage; if (GetObject(hBitmap, sizeof(bm), &bm)) { HDC dc; int x, y; HRGN region, cutrgn; BITMAPINFO bmi; int size = bm.bmWidth * bm.bmHeight * sizeof(int); int *bmp = (int *) MALLOC(size); if (bmp) { bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biHeight = bm.bmHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = bm.bmWidth; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; dc = CreateCompatibleDC(NULL); SelectObject(dc, hBitmap); x = GetDIBits(dc, hBitmap, 0, bm.bmHeight, bmp, &bmi, DIB_RGB_COLORS); region = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight); int keycolor = *bmp & 0xFFFFFF; // Search for transparent pixels for (y = bm.bmHeight - 1; y >= 0; y--) { for (x = 0; x < bm.bmWidth;) { if ((*bmp & 0xFFFFFF) == keycolor) { int j = x; while ((x < bm.bmWidth) && ((*bmp & 0xFFFFFF) == keycolor)) { bmp++, x++; } // Cut transparent pixels from the original region cutrgn = CreateRectRgn(j, y, x, y + 1); CombineRgn(region, region, cutrgn, RGN_XOR); DeleteObject(cutrgn); } else { bmp++, x++; } } } // Set resulting region. SetWindowRgn(hwCtrl, region, TRUE); DeleteObject(region); DeleteObject(dc); FREE(bmp); } } } mySendMessage( hwCtrl, STM_SETIMAGE, nImageType, nImage ); if (pField->nType == FIELD_BITMAP) { // Centre the image in the requested space. // Cannot use SS_CENTERIMAGE because it behaves differently on XP to // everything else. (Thank you Microsoft.) RECT bmp_rect; GetClientRect(hwCtrl, &bmp_rect); bmp_rect.left = (rect.left + rect.right - bmp_rect.right) / 2; bmp_rect.top = (rect.top + rect.bottom - bmp_rect.bottom) / 2; SetWindowPos(hwCtrl, NULL, bmp_rect.left, bmp_rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); } break; } #ifdef IO_ENABLE_LINK case FIELD_LINK: pField->nParentIdx = SetWindowLong(hwCtrl, GWL_WNDPROC, (long)StaticLINKWindowProc); break; #endif } // Set initial focus to the first appropriate field if (!fFocused && (dwStyle & (WS_TABSTOP | WS_DISABLED)) == WS_TABSTOP && pField->nType >= FIELD_SETFOCUS) { fFocused = TRUE; mySetFocus(hwCtrl); } // If multiline-readonly then hold the text back until after the // initial focus has been set. This is so the text is not initially // selected - useful for License Page look-a-likes. if ((pField->nFlags & (FLAG_MULTILINE | FLAG_READONLY)) == (FLAG_MULTILINE | FLAG_READONLY)) mySetWindowText(hwCtrl, pField->pszState); } } if (!fFocused) mySetFocus(hNextButton); mySetWindowText(mainwnd,pszTitle); pFilenameStackEntry = *g_stacktop; *g_stacktop = (*g_stacktop)->next; static char tmp[32]; wsprintf(tmp,"%d",hConfigWindow); pushstring(tmp); return 0; }
/** * Shows a balloon message using VBoxTray's notification area in the * Windows task bar. * * @param hwndParent Window handle of parent. * @param string_size Size of variable string. * @param variables The actual variable string. * @param stacktop Pointer to a pointer to the current stack. */ VBOXINSTALLHELPER_EXPORT VBoxTrayShowBallonMsg(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { NOREF(hwndParent); EXDLL_INIT(); char szMsg[256]; char szTitle[128]; HRESULT hr = vboxPopString(szMsg, sizeof(szMsg) / sizeof(char)); if (SUCCEEDED(hr)) hr = vboxPopString(szTitle, sizeof(szTitle) / sizeof(char)); /** @todo Do we need to restore the stack on failure? */ if (SUCCEEDED(hr)) { RTR3InitDll(0); uint32_t cbMsg = sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG) + strlen(szMsg) + 1 /* Include terminating zero */ + strlen(szTitle) + 1; /* Dito. */ Assert(cbMsg); PVBOXTRAYIPCMSG_SHOWBALLOONMSG pIpcMsg = (PVBOXTRAYIPCMSG_SHOWBALLOONMSG)RTMemAlloc(cbMsg); if (pIpcMsg) { /* Stuff in the strings. */ memcpy(pIpcMsg->szMsgContent, szMsg, strlen(szMsg) + 1); memcpy(pIpcMsg->szMsgTitle, szTitle, strlen(szTitle) + 1); /* Pop off the values in reverse order from the stack. */ if (SUCCEEDED(hr)) hr = vboxPopULong((ULONG*)&pIpcMsg->uType); if (SUCCEEDED(hr)) hr = vboxPopULong((ULONG*)&pIpcMsg->uShowMS); if (SUCCEEDED(hr)) { RTLOCALIPCSESSION hSession = 0; int rc = vboxConnectToVBoxTray(&hSession); if (RT_SUCCESS(rc)) { VBOXTRAYIPCHEADER ipcHdr = { VBOXTRAY_IPC_HDR_MAGIC, 0 /* Header version */, VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG, cbMsg }; rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); if (RT_SUCCESS(rc)) rc = RTLocalIpcSessionWrite(hSession, pIpcMsg, cbMsg); int rc2 = RTLocalIpcSessionClose(hSession); if (RT_SUCCESS(rc)) rc = rc2; } if (RT_FAILURE(rc)) hr = __HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE); } RTMemFree(pIpcMsg); } else hr = __HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); } /* Push simple return value on stack. */ SUCCEEDED(hr) ? pushstring("0") : pushstring("1"); }
void __declspec(dllexport) GetOriginalAccountType(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { EXDLL_INIT(); pushstring(GetAccountTypeHelper(FALSE)); }
boolean pathtofilespec ( bigstring bspath, ptrfilespec fs ) { // // 2010-01-24 creedon: fix for relative paths not working on mac, // bsfullpath was ending up with :: in it as well as // the full path to the application, see initfsdefault // function // // 2009-08-30 aradke: refactored mac version to make it easier to understand. // fixed bug where a bspath containing a non-existing volume name was accepted as valid, // e.g. filespec("foobar:"), thus deviating from previous behaviour. // // 2006-10-16 creedon: for Mac, FSRef-ized // // 5.0d8 dmb: clear fs first thing // // 2.1b2 dmb: use new fsdefault for building filespec. note that if bspath // isn't a partial path, the vref and dirid will be ignored. // // 2.1b2 dmb: added special case for empty string. also, added drive // number interpretation here. // // 1993-06-11 dmb: if FSMakeFSSpec returns fnfErr, the spec is cool (but // file doesn't exist) // // 1991-012-17 dmb: dont append path to default directory if it's a full // path // // 1991-07-05 dmb: use FSMakeFSSpec if it's available. since it only // returns noErr if the file exists, and we want to handle // non-existant files, we don't give up right away. // #ifdef MACVERSION FSRef fsr; bigstring bspathtmp, bsfullpath, bsfile, bsfolder; short ix = 1; boolean flvolume = false; #endif #ifdef WIN95VERSION bigstring bsfolder; #endif clearbytes ( fs, sizeof ( *fs ) ); if ( isemptystring ( bspath ) ) return ( true ); #ifdef MACVERSION // create cleaned-up full path representation of our input suitable for pathtosref copystring ( bspath, bspathtmp ); cleanendoffilename ( bspathtmp ); if ( scanstring ( ':', bspath, &ix ) && ( ix > 1 ) ) { // contains a colon but doesn't start with one, so it must be a full path if ( ix == stringlength ( bspath ) ) // the colon we found is the last char, so bspath is a volume name flvolume = true; copystring ( bspathtmp, bsfullpath ); } else { // it's a partial path, prefix with default directory (see initfsdefault) if ( ! filespectopath ( &fsdefault, bsfullpath ) ) // get path of default directory return ( false ); // delete first path separator if partial path begins with one because bsfullpath always ends with one if ( bspathtmp [ 1 ] == chpathseparator ) deletefirstchar ( bspathtmp ); pushstring ( bspathtmp, bsfullpath ); // append partial path } // now see if the full path resolves if ( pathtofsref ( bsfullpath, &fsr ) == noErr ) { return ( macmakefilespec ( &fsr, fs ) == noErr ); } // full path did not resolve but we actually only require the parent folder to exist if ( ! flvolume ) { // volumes don't have a parent folder filefrompath ( bsfullpath, bsfile ); folderfrompath ( bsfullpath, bsfolder ); if ( pathtofsref ( bsfolder, &fsr ) == noErr ) { clearfilespec ( fs ); fs->ref = fsr; bigstringtofsname ( bsfile, &fs->name ); return ( true ); } } return ( false ); #endif #ifdef WIN95VERSION copystring (bspath, fsname (fs)); folderfrompath (bspath, bsfolder); if ((isemptystring (bsfolder)) && (! fileisvolume(fs))) { filegetdefaultpath (fs); pushstring (bspath, fsname (fs)); } nullterminate (fsname (fs)); return (true); #endif } // pathtofilespec
void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); { TCHAR source[MAX_PATH]; TCHAR dest[MAX_PATH]; TCHAR exename[MAX_PATH]; HANDLE hPatch, hSource, hDest; int result; popstring(exename); popstring(source); popstring(dest); hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hPatch == INVALID_HANDLE_VALUE) { pushstring(_T("Unable to open patch file")); return; } hSource = CreateFile(source, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hSource == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); pushstring(_T("Unable to open source file")); return; } hDest = CreateFile(dest, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hDest == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); CloseHandle(hSource); pushstring(_T("Unable to open output file")); return; } result = DoPatch(hPatch, hSource, hDest); CloseHandle(hDest); CloseHandle(hSource); CloseHandle(hPatch); if ((result != PATCH_SUCCESS)) { if (result == PATCH_ERROR) pushstring(_T("An error occured while patching")); else if (result == PATCH_CORRUPT) pushstring(_T("Patch data is invalid or corrupt")); else if (result == PATCH_NOMATCH) pushstring(_T("No suitable patches were found")); else if (result == PATCH_UPTODATE) pushstring(_T("OK, new version already installed")); DeleteFile(dest); } else { pushstring(_T("OK")); } return; } }
void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { TCHAR fn[MAX_PATH]; TCHAR temp[64]; TCHAR *sleep=temp; EXDLL_INIT(); popstring(sleep); popstring(fn); sleep_val=0; while (*sleep >= _T('0') && *sleep <= _T('9')) { sleep_val*=10; sleep_val+=*sleep++-_T('0'); } if (fn[0] && sleep_val>0) { MSG msg; TCHAR classname[4]=_T("_sp"); static WNDCLASS wc; wc.lpfnWndProc = WndProc; wc.hInstance = g_hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = classname; if (RegisterClass(&wc)) { TCHAR fn2[MAX_PATH]; lstrcpy(fn2,fn); lstrcat(fn,_T(".bmp")); lstrcat(fn2,_T(".wav")); g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); if (g_hbm) { HWND myWnd; PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT); myWnd = CreateWindowEx(WS_EX_TOOLWINDOW,classname,classname, 0,0,0,0,0,(HWND)hwndParent,NULL,g_hInstance,NULL); while (IsWindow(myWnd) && GetMessage(&msg,myWnd,0,0)) { DispatchMessage(&msg); } // Stop currently playing wave, we want to exit PlaySound(0,0,0); DeleteObject(g_hbm); UnregisterClass(classname, g_hInstance); } } } wsprintf(temp,_T("%d"),g_rv); pushstring(temp); }
/* --- NSIS SCRIPTABLE FUNCTION --- DESC: Find out if the user (the owner of the current process) is a member of DESC: the administrators group on the local computer (not on the domain!). ARGS: Push the service name onto the stack. RETN: Pop the result string from the stack. RETN: The result will be 'Yes' or 'No' if there were no problems, otherwise RETN: the reason for the failure will be in the result string. USGE: Use it like this :- USGE: USGE: CallInstDLL x18Services.dll IsProcessUserAdministrator USGE: Pop $0 USGE: ; $0 now contains either 'Yes', 'No' or an error description */ void __declspec(dllexport) IsProcessUserAdministrator( HWND hwndParent, int string_size, char* variables, stack_t** stacktop) { BOOL fAdmin; HANDLE hThread; TOKEN_GROUPS* ptg = NULL; DWORD cbTokenGroups; DWORD dwGroup; PSID psidAdmin; SID_IDENTIFIER_AUTHORITY SystemSidAuthority= SECURITY_NT_AUTHORITY; g_hwndParent = hwndParent; g_stringsize = string_size; g_stacktop = stacktop; g_variables = variables; // First we must open a handle to the access token for this thread. if (!OpenThreadToken(GetCurrentThread(),TOKEN_QUERY,FALSE,&hThread)) { if (GetLastError() == ERROR_NO_TOKEN) { // If the thread does not have an access token, we'll examine the // access token associated with the process. if (!OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hThread)) { PushLastError(); return; } } else { PushLastError(); return; } } // Then we must query the size of the group information associated with // the token. Note that we expect a FALSE result from GetTokenInformation // because we've given it a NULL buffer. On exit cbTokenGroups will tell // the size of the group information. if (GetTokenInformation(hThread,TokenGroups,NULL,0,&cbTokenGroups)) { PushLastError(); return; } // Here we verify that GetTokenInformation failed for lack of a large // enough buffer. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { PushLastError(); return; } // Now we allocate a buffer for the group information. // Since _alloca allocates on the stack, we don't have // to explicitly deallocate it. That happens automatically // when we exit this function. __try { if (!(ptg = _alloca(cbTokenGroups))) { pushstring("Memory allocation failure"); return; } } __except (pushstring("Memory allocation exception"),1) { } // Now we ask for the group information again. // This may fail if an administrator has added this account // to an additional group between our first call to // GetTokenInformation and this one. if (!GetTokenInformation( hThread, TokenGroups, ptg, cbTokenGroups, &cbTokenGroups)) { PushLastError(); return; } // Now we must create a System Identifier for the Admin group. if (!AllocateAndInitializeSid( &SystemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0,0,0,0,0,0, &psidAdmin)) { PushLastError(); return; } // Finally we'll iterate through the list of groups for this access // token looking for a match against the SID we created above. fAdmin = FALSE; for (dwGroup = 0; dwGroup < ptg->GroupCount; dwGroup++) { if (EqualSid(ptg->Groups[dwGroup].Sid,psidAdmin)) { fAdmin = TRUE; break; } } // Before we exit we must explicity deallocate the SID we created. FreeSid(psidAdmin); if (TRUE == fAdmin) pushstring("Yes"); else pushstring("No"); }
void ExecScript(int log) { char szRet[128] = ""; char *pExec; int nComSpecSize; char meDLLPath[MAX_PATH]; char *p; char *executor; char *g_exec; unsigned int g_to; nComSpecSize = GetModuleFileName(g_hInst, meDLLPath, MAX_PATH) + 2; // 2 chars for quotes p = meDLLPath + nComSpecSize - 2; // point p at null char of meDLLPath g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+nComSpecSize+2); // 1 for space, 1 for null *g_exec = '"'; executor = g_exec + 1; do { if (*p == '\\') break; p = CharPrev(meDLLPath, p); } while (p > meDLLPath); if (p == meDLLPath) { // bad path lstrcpy(szRet, "error"); goto done; } *p = 0; GetTempFileName(meDLLPath, "ns", 0, executor); *p = '\\'; if (CopyFile(meDLLPath, executor, FALSE)) { HANDLE hFile, hMapping; LPBYTE pMapView; PIMAGE_NT_HEADERS pNTHeaders; hFile = CreateFile(executor, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,0, 0); hMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); pMapView = MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0); if (pMapView) { pNTHeaders = (PIMAGE_NT_HEADERS)(pMapView + ((PIMAGE_DOS_HEADER)pMapView)->e_lfanew); pNTHeaders->FileHeader.Characteristics = IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_LOCAL_SYMS_STRIPPED | IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE; pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI; pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)WinMain - (DWORD)g_hInst; UnmapViewOfFile(pMapView); } CloseHandle(hMapping); CloseHandle(hFile); } lstrcat(g_exec, "\""); g_to = 0; // default is no timeout g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL); // add space pExec = g_exec + lstrlen(g_exec); *pExec = ' '; pExec++; popstring(pExec); if (my_strstr(pExec, "/TIMEOUT=")) { char *szTimeout = pExec + 9; g_to = my_atoi(szTimeout); popstring(pExec); } if (!g_exec[0]) { lstrcpy(szRet, "error"); goto done; } { STARTUPINFO si={sizeof(si),}; SECURITY_ATTRIBUTES sa={sizeof(sa),}; SECURITY_DESCRIPTOR sd={0,}; PROCESS_INFORMATION pi={0,}; OSVERSIONINFO osv={sizeof(osv)}; HANDLE newstdout=0,read_stdout=0; HANDLE newstdin=0,read_stdin=0; DWORD dwRead = 1; DWORD dwExit = !STILL_ACTIVE; DWORD dwLastOutput; static char szBuf[1024]; HGLOBAL hUnusedBuf; char *szUnusedBuf = 0; if (log) { hUnusedBuf = GlobalAlloc(GHND, log & 2 ? g_stringsize : sizeof(szBuf)*4); if (!hUnusedBuf) { lstrcpy(szRet, "error"); goto done; } szUnusedBuf = (char *)GlobalLock(hUnusedBuf); } GetVersionEx(&osv); if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd,true,NULL,false); sa.lpSecurityDescriptor = &sd; } else sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = true; if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) { lstrcpy(szRet, "error"); goto done; } if (!CreatePipe(&read_stdin,&newstdin,&sa,0)) { lstrcpy(szRet, "error"); goto done; } GetStartupInfo(&si); si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.hStdInput = newstdin; si.hStdOutput = newstdout; si.hStdError = newstdout; if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) { lstrcpy(szRet, "error"); goto done; } dwLastOutput = GetTickCount(); while (dwExit == STILL_ACTIVE || dwRead) { PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); if (dwRead) { dwLastOutput = GetTickCount(); ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL); szBuf[dwRead] = 0; if (log) { char *p, *p2; SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf); if (GlobalSize(hUnusedBuf) < iReqLen && (iReqLen < g_stringsize || !(log & 2))) { GlobalUnlock(hUnusedBuf); hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND); if (!hUnusedBuf) { lstrcpy(szRet, "error"); break; } szUnusedBuf = (char *)GlobalLock(hUnusedBuf); } p = szUnusedBuf; // get the old left overs if (iReqLen < g_stringsize || !(log & 2)) lstrcat(p, szBuf); else { lstrcpyn(p + lstrlen(p), szBuf, g_stringsize - lstrlen(p)); } if (!(log & 2)) { while (p = my_strstr(p, "\t")) { if ((int)(p - szUnusedBuf) > (int)(GlobalSize(hUnusedBuf) - TAB_REPLACE_SIZE - 1)) { *p++ = ' '; } else { int len = lstrlen(p); char *c_out=(char*)p+TAB_REPLACE_SIZE+len; char *c_in=(char *)p+len; while (len-- > 0) { *c_out--=*c_in--; } lstrcpy(p, TAB_REPLACE); p += TAB_REPLACE_SIZE; *p = ' '; } } p = szUnusedBuf; // get the old left overs for (p2 = p; *p2;) { if (*p2 == '\r') { *p2++ = 0; continue; } if (*p2 == '\n') { *p2 = 0; while (!*p && p != p2) p++; LogMessage(p); p = ++p2; continue; } p2 = CharNext(p2); } // If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf if (p != szUnusedBuf) { char *p2 = szUnusedBuf; while (*p) *p2++ = *p++; *p2 = 0; } } } } else { if (g_to && GetTickCount() > dwLastOutput+g_to) { TerminateProcess(pi.hProcess, -1); lstrcpy(szRet, "timeout"); } else Sleep(LOOPTIMEOUT); } GetExitCodeProcess(pi.hProcess, &dwExit); if (dwExit != STILL_ACTIVE) { PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL); } } done: if (log & 2) pushstring(szUnusedBuf); if (log & 1 && *szUnusedBuf) LogMessage(szUnusedBuf); if ( dwExit == STATUS_ILLEGAL_INSTRUCTION ) lstrcpy(szRet, "error"); if (!szRet[0]) wsprintf(szRet,"%d",dwExit); pushstring(szRet); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(newstdout); CloseHandle(read_stdout); CloseHandle(newstdin); CloseHandle(read_stdin); *(pExec-2) = '\0'; // skip space and quote DeleteFile(executor); GlobalFree(g_exec); if (log) { GlobalUnlock(hUnusedBuf); GlobalFree(hUnusedBuf); } } }
void __declspec(dllexport) vpatchfile(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { g_hwndParent=hwndParent; EXDLL_INIT(); // note if you want parameters from the stack, pop them off in order. // i.e. if you are called via exdll::myFunction file.dat poop.dat // calling popstring() the first time would give you file.dat, // and the second time would give you poop.dat. // you should empty the stack of your parameters, and ONLY your // parameters. // do your stuff here { static char source[1024]; static char dest[1024]; static char exename[1024]; HANDLE hPatch, hSource, hDest; int result; popstring(exename); popstring(source); popstring(dest); hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hPatch == INVALID_HANDLE_VALUE) { pushstring("Unable to open patch file"); return; } hSource = CreateFile(source, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hSource == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); pushstring("Unable to open source file"); return; } hDest = CreateFile(dest, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hDest == INVALID_HANDLE_VALUE) { CloseHandle(hPatch); CloseHandle(hSource); pushstring("Unable to open output file"); return; } result = DoPatch(hPatch, hSource, hDest); CloseHandle(hDest); CloseHandle(hSource); CloseHandle(hPatch); if ((result != PATCH_SUCCESS)) { if (result == PATCH_ERROR) pushstring("An error occured while patching"); else if (result == PATCH_CORRUPT) pushstring("Patch data is invalid or corrupt"); else if (result == PATCH_NOMATCH) pushstring("No suitable patches were found"); else if (result == PATCH_UPTODATE) pushstring("OK, new version already installed"); DeleteFile(dest); } else { pushstring("OK"); } return; } }
BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwLocation = GetDlgItem(hwndDlg, IDC_LOCATION); HWND hwDirList = GetDlgItem(hwndDlg, IDC_DIRLIST); HWND hwCheckBox = GetDlgItem(hwndDlg, IDC_CHECK); switch (uMsg) { case WM_INITDIALOG: { HWND hwIcon; HWND hwText; RECT dialog_r, temp_r; HFONT hFont = (HFONT) SendMessage(hwParent, WM_GETFONT, 0, 0); int y_offset = 0; int width, height; int baseUnitY; // Init dialog unit conversion { TEXTMETRIC tm; HDC hDC; hDC = GetDC(hwndDlg); SelectObject(hDC, hFont); GetTextMetrics(hDC, &tm); baseUnitY = tm.tmHeight; ReleaseDC(hwndDlg, hDC); } GetWindowRect(hwChild, &dialog_r); ScreenToClient(hwParent, (LPPOINT) &dialog_r); ScreenToClient(hwParent, ((LPPOINT) &dialog_r) + 1); width = dialog_r.right - dialog_r.left; height = dialog_r.bottom - dialog_r.top; MoveWindow( hwndDlg, dialog_r.left, dialog_r.top, width, height, FALSE ); hwIcon = GetDlgItem(hwndDlg, IDC_NSISICON); hwText = GetDlgItem(hwndDlg, IDC_TEXT); g_hwDirList = hwDirList; SendMessage(hwndDlg, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwIcon, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwText, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwLocation, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwDirList, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwCheckBox, WM_SETFONT, (WPARAM) hFont, TRUE); if (rtl) { AddRTLStyle(hwText, SS_RIGHT); AddRTLStyle(hwLocation, ES_RIGHT); AddRTLStyle(hwDirList, 0); AddRTLStyle(hwCheckBox, BS_RIGHT | BS_LEFTTEXT); } GetClientRect(hwIcon, &temp_r); if (!noicon) { SendMessage( hwIcon, STM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103)) ); MoveWindow( hwIcon, rtl ? width - temp_r.right : 0, 0, temp_r.right, temp_r.bottom, FALSE ); temp_r.right += 3; } else { ShowWindow(hwIcon, SW_HIDE); temp_r.right = 0; } if (rtl) { ProgressiveSetWindowPos( hwText, 0, width - temp_r.right, 3 * baseUnitY //MulDiv(24, baseUnitY, 8); ); } else { ProgressiveSetWindowPos( hwText, temp_r.right, width - temp_r.right + 3, 3 * baseUnitY //MulDiv(24, baseUnitY, 8); ); } SetWindowText(hwText, *text ? text : "Select the Start Menu folder in which you would like to create the program's shortcuts:"); ProgressiveSetWindowPos( hwLocation, 0, width, MulDiv(12, baseUnitY, 8) ); if (*lastused == '>') { CheckDlgButton(hwndDlg, IDC_CHECK, BST_CHECKED); lstrcpy(lastused, lstrcpy(buf, lastused) + 1); EnableWindow(hwDirList, FALSE); EnableWindow(hwLocation, FALSE); } SetWindowText(hwLocation, *lastused ? lastused : progname); temp_r.bottom = MulDiv(8, baseUnitY, 8); ProgressiveSetWindowPos( hwDirList, 0, width, height - y_offset - (*checkbox ? temp_r.bottom + 3 : 0) ); if (*checkbox) { ProgressiveSetWindowPos( hwCheckBox, 0, width, temp_r.bottom ); ShowWindow(hwCheckBox, SW_SHOWNA); SetWindowText(hwCheckBox, checkbox); } AddFolderFromReg(CSIDL_COMMON_PROGRAMS); AddFolderFromReg(CSIDL_PROGRAMS); // Tell NSIS to remove old inner dialog and pass handle of the new inner dialog SendMessage(hwParent, WM_NOTIFY_CUSTOM_READY, (WPARAM)hwndDlg, 0); ShowWindow(hwndDlg, SW_SHOWNA); if (IsDlgButtonChecked(hwndDlg, IDC_CHECK) == BST_CHECKED) SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) hwCheckBox, TRUE); else SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) hwLocation, TRUE); } break; case WM_COMMAND: if (LOWORD(wParam) == IDC_DIRLIST && HIWORD(wParam) == LBN_SELCHANGE) { SendMessage(hwDirList, LB_GETTEXT, SendMessage(hwDirList, LB_GETCURSEL, 0, 0), (WPARAM)buf); if (autoadd) lstrcat(lstrcat(buf, "\\"), progname); SetWindowText(hwLocation, buf); } else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED) { BOOL bEnable = IsDlgButtonChecked(hwndDlg, IDC_CHECK) != BST_CHECKED; EnableWindow(hwDirList, bEnable); EnableWindow(hwLocation, bEnable); } else if (LOWORD(wParam) == IDC_LOCATION && HIWORD(wParam) == EN_CHANGE) { GetWindowText(hwLocation, buf, MAX_PATH); validate_filename(buf); EnableWindow(GetDlgItem(hwParent, IDOK), *buf != '\0'); } break; case WM_USER+666: g_done = 1; if (wParam == NOTIFY_BYE_BYE) pushstring("cancel"); else { GetWindowText(hwLocation, buf + 1, MAX_PATH); validate_filename(buf); if (IsDlgButtonChecked(hwndDlg, IDC_CHECK) == BST_CHECKED) { buf[0] = '>'; pushstring(buf); } else { pushstring(buf + 1); } pushstring("success"); } case WM_CTLCOLORSTATIC: case WM_CTLCOLOREDIT: case WM_CTLCOLORDLG: case WM_CTLCOLORBTN: case WM_CTLCOLORLISTBOX: // let the NSIS window handle colors, it knows best return SendMessage(hwParent, uMsg, wParam, lParam); break; } return 0; }
} PLUGINFUNCTIONEND PLUGINFUNCTION(Call) { // Prepare input SystemProc *proc = PrepareProc(TRUE); SYSTEM_LOG_ADD("Call "); SYSTEM_LOG_ADD(proc->DllName); SYSTEM_LOG_ADD("::"); SYSTEM_LOG_ADD(proc->ProcName); SYSTEM_LOG_ADD("\n"); if (proc->ProcResult != PR_CALLBACK) ParamAllocate(proc); ParamsIn(proc); // Make the call if (proc->ProcResult != PR_ERROR) { switch (proc->ProcType) { case PT_NOTHING: if (proc->ProcResult == PR_CALLBACK) proc = CallBack(proc); break; case PT_PROC: case PT_VTABLEPROC: proc = CallProc(proc); break; case PT_STRUCT: CallStruct(proc); break; } } // Process output if ((proc->Options & POPT_ALWRETURN) != 0) { // Always return flag set - return separate return and result ParamsOut(proc); GlobalFree(pushstring(GetResultStr(proc))); } else { if (proc->ProcResult != PR_OK) { ProcParameter pp; // Save old return param pp = proc->Params[0]; // Return result instead of return value proc->Params[0].Value = (int) GetResultStr(proc); proc->Params[0].Type = PAT_STRING; // Return all params ParamsOut(proc); // Restore old return param proc->Params[0] = pp; } else ParamsOut(proc); } if (proc->ProcResult != PR_CALLBACK) { // Deallocate params if not callback ParamsDeAllocate(proc); // if not callback - check for unload library option if ((proc->Options & POPT_UNLOAD) && (proc->ProcType == PT_PROC) && (proc->Dll != NULL)) FreeLibrary(proc->Dll); // and unload it :) // In case of POPT_ERROR - first pop will be proc error if ((proc->Options & POPT_ERROR) != 0) pushint(LastError); } // If proc is permanent? if ((proc->Options & POPT_PERMANENT) == 0) GlobalFree((HANDLE) proc); // No, free it } PLUGINFUNCTIONEND