New exec plugin (broke)
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@920 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
8dcb0e237f
commit
a659c508b1
6 changed files with 378 additions and 0 deletions
85
Contrib/nsExec/nsExec.dsp
Normal file
85
Contrib/nsExec/nsExec.dsp
Normal file
|
@ -0,0 +1,85 @@
|
|||
# Microsoft Developer Studio Project File - Name="nsExec" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=NSEXEC - WIN32 RELEASE
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "nsExec.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "nsExec.mak" CFG="NSEXEC - WIN32 RELEASE"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "nsExec - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSEXEC_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSEXEC_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /nodefaultlib /out:"../../Plugins/nsExec.dll"
|
||||
# Begin Target
|
||||
|
||||
# Name "nsExec - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\nsexec.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\nsis.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\nsexec.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\nsis.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
29
Contrib/nsExec/nsExec.dsw
Normal file
29
Contrib/nsExec/nsExec.dsw
Normal file
|
@ -0,0 +1,29 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "nsExec"=".\nsExec.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
188
Contrib/nsExec/nsexec.c
Normal file
188
Contrib/nsExec/nsexec.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include "nsexec.h"
|
||||
|
||||
#ifndef true
|
||||
#define true TRUE
|
||||
#endif
|
||||
#ifndef false
|
||||
#define false FALSE
|
||||
#endif
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
HWND g_hwndParent;
|
||||
HWND g_hwndList;
|
||||
HWND g_hwndDlg;
|
||||
char g_exec[MAX_PATH];
|
||||
BOOL g_done;
|
||||
BOOL g_foundto;
|
||||
int g_to;
|
||||
|
||||
int LogMessage(const char *pStr);
|
||||
char *my_strstr(const char *string, const char *strCharSet);
|
||||
int my_atoi(char *s);
|
||||
|
||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||
g_hwndParent=hwndParent;
|
||||
g_stringsize=string_size;
|
||||
g_stacktop=stacktop;
|
||||
g_variables=variables;
|
||||
{
|
||||
g_to = 100000;
|
||||
g_foundto = FALSE;
|
||||
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
||||
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
||||
|
||||
if (!g_foundto&&!popstring(g_exec)) {
|
||||
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;
|
||||
DWORD dwRead = 1;
|
||||
DWORD dwExit = !STILL_ACTIVE;
|
||||
HGLOBAL memory;
|
||||
char *szBuf;
|
||||
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)) {
|
||||
pushstring("");
|
||||
pushstring("error");
|
||||
return;
|
||||
}
|
||||
GetStartupInfo(&si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdOutput = newstdout;
|
||||
si.hStdError = newstdout;
|
||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
pushstring("");
|
||||
pushstring("error");
|
||||
}
|
||||
WaitForSingleObject(pi.hProcess,INFINITE);
|
||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||
memory = GlobalAlloc(GMEM_MOVEABLE,dwRead+1);
|
||||
szBuf = (char *)GlobalLock(memory);
|
||||
ReadFile(read_stdout, szBuf, dwRead, &dwRead, NULL);
|
||||
pushstring(szBuf);
|
||||
pushstring("success");
|
||||
if (my_strstr(szBuf,"\r\n")) {
|
||||
while (szBuf&&*szBuf) {
|
||||
char *i = my_strstr(szBuf,"\r\n");
|
||||
if (!i) {
|
||||
LogMessage(szBuf);
|
||||
break;
|
||||
}
|
||||
*i=0;
|
||||
LogMessage(szBuf);
|
||||
szBuf = i+2;
|
||||
}
|
||||
}
|
||||
else if (my_strstr(szBuf,"\n")) {
|
||||
MessageBox(0,"n","n",MB_OK);
|
||||
}
|
||||
else {
|
||||
LogMessage(szBuf);
|
||||
}
|
||||
GlobalFree(szBuf);
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(newstdout);
|
||||
CloseHandle(read_stdout);
|
||||
}
|
||||
pushstring("");
|
||||
pushstring("error");
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||
g_hInstance=hInst;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// code I stole (err borrowed) from Tim Kosse
|
||||
// all credits/problems are his
|
||||
int LogMessage(const char *pStr) {
|
||||
LVITEM item={0};
|
||||
int nItemCount;
|
||||
if (!g_hwndList) return -1;
|
||||
nItemCount=SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
|
||||
item.mask=LVIF_TEXT;
|
||||
item.pszText=(char *)pStr;
|
||||
item.cchTextMax=6;
|
||||
item.iItem=nItemCount;
|
||||
ListView_InsertItem(g_hwndList, &item);
|
||||
ListView_EnsureVisible(g_hwndList, item.iItem, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char *my_strstr(const char *string, const char *strCharSet) {
|
||||
char *s1, *s2;
|
||||
size_t chklen;
|
||||
size_t i;
|
||||
if (!*strCharSet) return (char*)string;
|
||||
chklen=lstrlen(string)-lstrlen(strCharSet);
|
||||
for (i = 0; i < chklen; i++) {
|
||||
s1=&((char*)string)[i];
|
||||
s2=(char*)strCharSet;
|
||||
while (*s1++ == *s2++)
|
||||
if (!*s2)
|
||||
return &((char*)string)[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int my_atoi(char *s)
|
||||
{
|
||||
unsigned int v=0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
{
|
||||
s+=2;
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++;
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') { s++; sign++; }
|
||||
for (;;)
|
||||
{
|
||||
int c=*s++ - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) return -(int) v;
|
||||
}
|
||||
return (int)v;
|
||||
}
|
4
Contrib/nsExec/nsexec.h
Normal file
4
Contrib/nsExec/nsexec.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#ifndef nsexec_h
|
||||
#define nsexec_h
|
||||
#include "nsis.h"
|
||||
#endif
|
26
Contrib/nsExec/nsis.c
Normal file
26
Contrib/nsExec/nsis.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <windows.h>
|
||||
#include "nsis.h"
|
||||
|
||||
int popstring(char *str) {
|
||||
stack_t *th;
|
||||
if (!g_stacktop||!*g_stacktop) return 1;
|
||||
th=(*g_stacktop);
|
||||
lstrcpy(str,th->text);
|
||||
*g_stacktop = th->next;
|
||||
GlobalFree((HGLOBAL)th);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pushstring(char *str) {
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return;
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
||||
lstrcpyn(th->text,str,g_stringsize);
|
||||
th->next=*g_stacktop;
|
||||
*g_stacktop=th;
|
||||
}
|
||||
|
||||
char *getuservariable(int varnum) {
|
||||
if (varnum<0||varnum >= __INST_LAST) return NULL;
|
||||
return g_variables+varnum*g_stringsize;
|
||||
}
|
46
Contrib/nsExec/nsis.h
Normal file
46
Contrib/nsExec/nsis.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef nsis_h
|
||||
#define nsis_h
|
||||
|
||||
typedef struct _stack_t {
|
||||
struct _stack_t *next;
|
||||
char text[1];
|
||||
} stack_t;
|
||||
|
||||
enum {
|
||||
INST_0, // $0
|
||||
INST_1, // $1
|
||||
INST_2, // $2
|
||||
INST_3, // $3
|
||||
INST_4, // $4
|
||||
INST_5, // $5
|
||||
INST_6, // $6
|
||||
INST_7, // $7
|
||||
INST_8, // $8
|
||||
INST_9, // $9
|
||||
INST_R0, // $R0
|
||||
INST_R1, // $R1
|
||||
INST_R2, // $R2
|
||||
INST_R3, // $R3
|
||||
INST_R4, // $R4
|
||||
INST_R5, // $R5
|
||||
INST_R6, // $R6
|
||||
INST_R7, // $R7
|
||||
INST_R8, // $R8
|
||||
INST_R9, // $R9
|
||||
INST_CMDLINE, // $CMDLINE
|
||||
INST_INSTDIR, // $INSTDIR
|
||||
INST_OUTDIR, // $OUTDIR
|
||||
INST_EXEDIR, // $EXEDIR
|
||||
INST_LANG, // $LANGUAGE
|
||||
__INST_LAST
|
||||
};
|
||||
|
||||
int g_stringsize;
|
||||
stack_t ** g_stacktop;
|
||||
char * g_variables;
|
||||
|
||||
int popstring(char *str);
|
||||
void pushstring(char *str);
|
||||
char * getuservariable(int varnum);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue