use new plug-in library wherever possible, which is not a lot...

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5840 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2008-12-12 18:24:00 +00:00
parent a924c4d2d3
commit e59407720a
4 changed files with 64 additions and 114 deletions

View file

@ -14,12 +14,12 @@ TempStack *tempstack = NULL;
PLUGINFUNCTIONSHORT(Alloc) PLUGINFUNCTIONSHORT(Alloc)
{ {
int size; int size;
if ((size = popint()) == 0) if ((size = popint64()) == 0)
{ {
pushint(0); system_pushint(0);
return; return;
} }
pushint((int) GlobalAlloc(GPTR, size)); system_pushint((int) GlobalAlloc(GPTR, size));
} }
PLUGINFUNCTIONEND PLUGINFUNCTIONEND
@ -29,16 +29,16 @@ PLUGINFUNCTIONSHORT(Copy)
HANDLE source, dest; HANDLE source, dest;
char *str; char *str;
// Get the string // Get the string
if ((str = popstring()) == NULL) return; if ((str = system_popstring()) == NULL) return;
// Check for size option // Check for size option
if (str[0] == '/') if (str[0] == '/')
{ {
size = (int) myatoi(str+1); size = (int) myatoi64(str+1);
dest = (HANDLE) popint(); dest = (HANDLE) popint64();
} }
else dest = (HANDLE) myatoi(str); else dest = (HANDLE) myatoi64(str);
source = (HANDLE) popint(); source = (HANDLE) popint64();
// Ok, check the size // Ok, check the size
if (size == 0) size = (int) GlobalSize(source); if (size == 0) size = (int) GlobalSize(source);
@ -46,7 +46,7 @@ PLUGINFUNCTIONSHORT(Copy)
if ((int) dest == 0) if ((int) dest == 0)
{ {
dest = GlobalAlloc((GPTR), size); dest = GlobalAlloc((GPTR), size);
pushint((int) dest); system_pushint((int) dest);
} }
// COPY! // COPY!
@ -58,7 +58,7 @@ PLUGINFUNCTIONEND
PLUGINFUNCTIONSHORT(Free) PLUGINFUNCTIONSHORT(Free)
{ {
GlobalFree((HANDLE) popint()); GlobalFree((HANDLE) popint64());
} }
PLUGINFUNCTIONEND PLUGINFUNCTIONEND
@ -67,7 +67,7 @@ PLUGINFUNCTION(Store)
TempStack *tmp; TempStack *tmp;
int size = ((INST_R9+1)*g_stringsize); int size = ((INST_R9+1)*g_stringsize);
char *command, *cmd = command = popstring(); char *command, *cmd = command = system_popstring();
while (*cmd != 0) while (*cmd != 0)
{ {
switch (*(cmd++)) switch (*(cmd++))
@ -97,12 +97,12 @@ PLUGINFUNCTION(Store)
case 'P': case 'P':
*cmd += 10; *cmd += 10;
case 'p': case 'p':
GlobalFree((HANDLE) pushstring(getuservariable(*(cmd++)-'0'))); GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-'0')));
break; break;
case 'R': case 'R':
*cmd += 10; *cmd += 10;
case 'r': case 'r':
GlobalFree((HANDLE) setuservariable(*(cmd++)-'0', popstring())); GlobalFree((HANDLE) system_setuservariable(*(cmd++)-'0', system_popstring()));
break; break;
} }
} }

View file

@ -4,9 +4,6 @@
#include "System.h" #include "System.h"
HWND g_hwndParent; HWND g_hwndParent;
int g_stringsize;
stack_t **g_stacktop;
char *g_variables;
char *AllocString() char *AllocString()
{ {
@ -18,7 +15,7 @@ char *AllocStr(char *str)
return lstrcpy(AllocString(), str); return lstrcpy(AllocString(), str);
} }
char* popstring() char* system_popstring()
{ {
char *str; char *str;
stack_t *th; stack_t *th;
@ -34,7 +31,7 @@ char* popstring()
return str; return str;
} }
char *pushstring(char *str) char *system_pushstring(char *str)
{ {
stack_t *th; stack_t *th;
if (!g_stacktop) return str; if (!g_stacktop) return str;
@ -45,13 +42,13 @@ char *pushstring(char *str)
return str; return str;
} }
char *getuservariable(int varnum) char *system_getuservariable(int varnum)
{ {
if (varnum < 0 || varnum >= __INST_LAST) return AllocString(); if (varnum < 0 || varnum >= __INST_LAST) return AllocString();
return AllocStr(g_variables+varnum*g_stringsize); return AllocStr(g_variables+varnum*g_stringsize);
} }
char *setuservariable(int varnum, char *var) char *system_setuservariable(int varnum, char *var)
{ {
if (var != NULL && varnum >= 0 && varnum < __INST_LAST) { if (var != NULL && varnum >= 0 && varnum < __INST_LAST) {
lstrcpy (g_variables + varnum*g_stringsize, var); lstrcpy (g_variables + varnum*g_stringsize, var);
@ -60,7 +57,7 @@ char *setuservariable(int varnum, char *var)
} }
// Updated for int64 and simple bitwise operations // Updated for int64 and simple bitwise operations
__int64 myatoi(char *s) __int64 myatoi64(char *s)
{ {
__int64 v=0; __int64 v=0;
// Check for right input // Check for right input
@ -107,7 +104,7 @@ __int64 myatoi(char *s)
// Support for simple ORed expressions // Support for simple ORed expressions
if (*s == '|') if (*s == '|')
{ {
v |= myatoi(s+1); v |= myatoi64(s+1);
} }
return v; return v;
@ -135,21 +132,21 @@ void myitoa64(__int64 i, char *buffer)
*buffer = 0; *buffer = 0;
} }
int popint() int popint64()
{ {
int value; int value;
char *str; char *str;
if ((str = popstring()) == NULL) return -1; if ((str = system_popstring()) == NULL) return -1;
value = (int) myatoi(str); value = (int) myatoi64(str);
GlobalFree(str); GlobalFree(str);
return value; return value;
} }
void pushint(int value) void system_pushint(int value)
{ {
char buffer[1024]; char buffer[1024];
wsprintf(buffer, "%d", value); wsprintf(buffer, "%d", value);
pushstring(buffer); system_pushstring(buffer);
} }
char *copymem(char *output, char *input, int size) char *copymem(char *output, char *input, int size)
@ -166,9 +163,9 @@ HANDLE GlobalCopy(HANDLE Old)
return copymem(GlobalAlloc(GPTR, size), Old, (int) size); return copymem(GlobalAlloc(GPTR, size), Old, (int) size);
} }
UINT_PTR NSISCallback(UINT msg) UINT_PTR NSISCallback(enum NSPIM msg)
{ {
return (UINT_PTR) NULL; return 0;
} }
#ifdef _DEBUG #ifdef _DEBUG

View file

@ -1,57 +1,13 @@
#ifndef ___PLUGIN__H___ #ifndef ___PLUGIN__H___
#define ___PLUGIN__H___ #define ___PLUGIN__H___
typedef struct _stack_t { #include <plugin.h> // nsis plug-in...
struct _stack_t *next;
char text[1]; // this should be the length of string_size
} 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
};
typedef UINT_PTR (*NSISPLUGINCALLBACK)(UINT);
typedef struct {
void *exec_flags;
int (__stdcall *ExecuteCodeSegment)(int, HWND);
void (__stdcall *validate_filename)(char *);
BOOL (__stdcall *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK);
} extra_parameters;
#define PLUGINFUNCTION(name) \ #define PLUGINFUNCTION(name) \
void __declspec(dllexport) name( \ void __declspec(dllexport) name( \
HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { \ HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { \
/*g_hwndParent=hwndParent;*/ \ /*g_hwndParent=hwndParent;*/ \
g_stringsize=string_size; \ EXDLL_INIT(); \
g_stacktop=stacktop; \
g_variables=variables; \
extra->RegisterPluginCallback(g_hInstance, NSISCallback); extra->RegisterPluginCallback(g_hInstance, NSISCallback);
#define PLUGINFUNCTIONEND } #define PLUGINFUNCTIONEND }
@ -62,23 +18,20 @@ typedef struct {
extern char *AllocStr(char *str); extern char *AllocStr(char *str);
extern void myitoa64(__int64 i, char *buffer); extern void myitoa64(__int64 i, char *buffer);
extern char *AllocString(); extern char *AllocString();
extern char *getuservariable(int varnum); extern char *system_getuservariable(int varnum);
extern char *setuservariable(int varnum, char *var); extern char *system_setuservariable(int varnum, char *var);
extern char* popstring(); // NULL - stack empty extern char* system_popstring(); // NULL - stack empty
extern char* pushstring(char *str); extern char* system_pushstring(char *str);
extern __int64 myatoi(char *s); extern __int64 myatoi64(char *s);
extern int popint(); // -1 -> stack empty extern int popint64(); // -1 -> stack empty
extern void pushint(int value); extern void system_pushint(int value);
extern HANDLE GlobalCopy(HANDLE Old); extern HANDLE GlobalCopy(HANDLE Old);
extern char *copymem(char *output, char *input, int size); extern char *copymem(char *output, char *input, int size);
extern UINT_PTR NSISCallback(UINT); extern UINT_PTR NSISCallback(enum NSPIM);
extern HWND g_hwndParent; extern HWND g_hwndParent;
extern int g_stringsize;
extern stack_t **g_stacktop;
extern char *g_variables;
extern HINSTANCE g_hInstance; extern HINSTANCE g_hInstance;
#endif #endif

View file

@ -92,7 +92,7 @@ void WriteToLog(char *buffer)
PLUGINFUNCTION(Debug) PLUGINFUNCTION(Debug)
{ {
char *o1; char *o1;
o1 = popstring(); o1 = system_popstring();
if (logfile == NULL) if (logfile == NULL)
if (lstrlen(o1) > 0) if (lstrlen(o1) > 0)
@ -141,7 +141,7 @@ PLUGINFUNCTION(Get)
SystemProc *proc = PrepareProc(FALSE); SystemProc *proc = PrepareProc(FALSE);
if (proc == NULL) if (proc == NULL)
{ {
pushstring("error"); system_pushstring("error");
return; return;
} }
@ -154,20 +154,20 @@ PLUGINFUNCTION(Get)
if ((proc->Options & POPT_ALWRETURN) != 0) if ((proc->Options & POPT_ALWRETURN) != 0)
{ {
// Always return flag set -> return separate proc and result // Always return flag set -> return separate proc and result
pushint((int) proc); system_pushint((int) proc);
GlobalFree(pushstring(GetResultStr(proc))); GlobalFree(system_pushstring(GetResultStr(proc)));
} else } else
{ {
if (proc->ProcResult != PR_OK) if (proc->ProcResult != PR_OK)
{ {
// No always return flag and error result - return result // No always return flag and error result - return result
GlobalFree(pushstring(GetResultStr(proc))); GlobalFree(system_pushstring(GetResultStr(proc)));
// If proc is permanent? // If proc is permanent?
if ((proc->Options & POPT_PERMANENT) == 0) if ((proc->Options & POPT_PERMANENT) == 0)
GlobalFree((HANDLE) proc); // No, free it GlobalFree((HANDLE) proc); // No, free it
} }
else // Ok result, return proc else // Ok result, return proc
pushint((int) proc); system_pushint((int) proc);
} }
} PLUGINFUNCTIONEND } PLUGINFUNCTIONEND
@ -209,7 +209,7 @@ PLUGINFUNCTION(Call)
{ {
// Always return flag set - return separate return and result // Always return flag set - return separate return and result
ParamsOut(proc); ParamsOut(proc);
GlobalFree(pushstring(GetResultStr(proc))); GlobalFree(system_pushstring(GetResultStr(proc)));
} else } else
{ {
if (proc->ProcResult != PR_OK) if (proc->ProcResult != PR_OK)
@ -242,7 +242,7 @@ PLUGINFUNCTION(Call)
FreeLibrary(proc->Dll); // and unload it :) FreeLibrary(proc->Dll); // and unload it :)
// In case of POPT_ERROR - first pop will be proc error // In case of POPT_ERROR - first pop will be proc error
if ((proc->Options & POPT_ERROR) != 0) pushint(LastError); if ((proc->Options & POPT_ERROR) != 0) system_pushint(LastError);
} }
// If proc is permanent? // If proc is permanent?
@ -257,13 +257,13 @@ PLUGINFUNCTIONSHORT(Int64Op)
char buf[128]; char buf[128];
// Get strings // Get strings
o1 = popstring(); op = popstring(); o1 = system_popstring(); op = system_popstring();
i1 = myatoi(o1); // convert first arg to int64 i1 = myatoi64(o1); // convert first arg to int64
if ((*op != '~') && (*op != '!')) if ((*op != '~') && (*op != '!'))
{ {
// get second arg, convert it, free it // get second arg, convert it, free it
o2 = popstring(); o2 = system_popstring();
i2 = myatoi(o2); i2 = myatoi64(o2);
GlobalFree(o2); GlobalFree(o2);
} }
@ -293,7 +293,7 @@ PLUGINFUNCTIONSHORT(Int64Op)
// Output and freedom // Output and freedom
myitoa64(i1, buf); myitoa64(i1, buf);
pushstring(buf); system_pushstring(buf);
GlobalFree(o1); GlobalFree(op); GlobalFree(o1); GlobalFree(op);
} PLUGINFUNCTIONEND } PLUGINFUNCTIONEND
@ -304,7 +304,7 @@ __int64 GetIntFromString(char **p)
while (((**p >= 'a') && (**p <= 'f')) || ((**p >= 'A') && (**p <= 'F')) || ((**p >= '0') && (**p <= '9')) || (**p == 'X') || (**p == '-') || (**p == 'x') || (**p == '|')) *(b++) = *((*p)++); while (((**p >= 'a') && (**p <= 'f')) || ((**p >= 'A') && (**p <= 'F')) || ((**p >= '0') && (**p <= '9')) || (**p == 'X') || (**p == '-') || (**p == 'x') || (**p == '|')) *(b++) = *((*p)++);
*b = 0; *b = 0;
(*p)--; // We should point at last digit (*p)--; // We should point at last digit
return myatoi(buffer); return myatoi64(buffer);
} }
SystemProc *PrepareProc(BOOL NeedForCall) SystemProc *PrepareProc(BOOL NeedForCall)
@ -321,7 +321,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
// Retrieve proc specs // Retrieve proc specs
cb = (cbuf = AllocString()); // Current String buffer cb = (cbuf = AllocString()); // Current String buffer
sbuf = AllocString(); // Safe String buffer sbuf = AllocString(); // Safe String buffer
ib = ibuf = popstring(); // Input string ib = ibuf = system_popstring(); // Input string
// Parse the string // Parse the string
while (SectionType != -1) while (SectionType != -1)
@ -387,7 +387,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
if (proc != NULL) GlobalFree(proc); if (proc != NULL) GlobalFree(proc);
// Get already defined proc // Get already defined proc
proc = (SystemProc *) INT_TO_POINTER(myatoi(cbuf)); proc = (SystemProc *) INT_TO_POINTER(myatoi64(cbuf));
if (!proc) break; if (!proc) break;
// Find the last clone at proc queue // Find the last clone at proc queue
@ -668,7 +668,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
// Use direct system proc address // Use direct system proc address
int addr; int addr;
proc->Dll = (HANDLE) INT_TO_POINTER(myatoi(proc->DllName)); proc->Dll = (HANDLE) INT_TO_POINTER(myatoi64(proc->DllName));
if (proc->Dll == 0) if (proc->Dll == 0)
{ {
@ -689,7 +689,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
addr = *((int *)addr); addr = *((int *)addr);
// now addr contains the pointer to first item at VTABLE // now addr contains the pointer to first item at VTABLE
// add the index of proc // add the index of proc
addr = addr + (int)(myatoi(proc->ProcName)*4); addr = addr + (int)(myatoi64(proc->ProcName)*4);
proc->Proc = *((HANDLE*)addr); proc->Proc = *((HANDLE*)addr);
} }
break; break;
@ -697,7 +697,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
if (*proc->DllName == 0) if (*proc->DllName == 0)
{ {
// Use direct system proc address // Use direct system proc address
if ((proc->Proc = (HANDLE) INT_TO_POINTER(myatoi(proc->ProcName))) == 0) if ((proc->Proc = (HANDLE) INT_TO_POINTER(myatoi64(proc->ProcName))) == 0)
proc->ProcResult = PR_ERROR; proc->ProcResult = PR_ERROR;
} else } else
{ {
@ -720,7 +720,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
} }
break; break;
case PT_STRUCT: case PT_STRUCT:
if (*(proc->ProcName) != 0) proc->Proc = (HANDLE) INT_TO_POINTER(myatoi(proc->ProcName)); if (*(proc->ProcName) != 0) proc->Proc = (HANDLE) INT_TO_POINTER(myatoi64(proc->ProcName));
break; break;
} }
} }
@ -752,9 +752,9 @@ void ParamsIn(SystemProc *proc)
// Step 1: retrive value // Step 1: retrive value
if ((par->Input == IOT_NONE) || (par->Input == IOT_INLINE)) if ((par->Input == IOT_NONE) || (par->Input == IOT_INLINE))
realbuf = AllocStr(""); realbuf = AllocStr("");
else if (par->Input == IOT_STACK) realbuf = popstring(); else if (par->Input == IOT_STACK) realbuf = system_popstring();
else if ((par->Input > 0) && (par->Input <= __INST_LAST)) else if ((par->Input > 0) && (par->Input <= __INST_LAST))
realbuf = getuservariable(par->Input - 1); realbuf = system_getuservariable(par->Input - 1);
else else
{ {
// Inline input, will be freed as realbuf // Inline input, will be freed as realbuf
@ -776,10 +776,10 @@ void ParamsIn(SystemProc *proc)
par->Value = 0; par->Value = 0;
break; break;
case PAT_INT: case PAT_INT:
*((int*) place) = (int) myatoi(realbuf); *((int*) place) = (int) myatoi64(realbuf);
break; break;
case PAT_LONG: case PAT_LONG:
*((__int64*) place) = myatoi(realbuf); *((__int64*) place) = myatoi64(realbuf);
break; break;
case PAT_STRING: case PAT_STRING:
/* if (par->Input == IOT_NONE) /* if (par->Input == IOT_NONE)
@ -802,7 +802,7 @@ void ParamsIn(SystemProc *proc)
case PAT_CALLBACK: case PAT_CALLBACK:
// Generate new or use old callback // Generate new or use old callback
if (lstrlen(realbuf) > 0) if (lstrlen(realbuf) > 0)
par->Value = (int) CreateCallback((SystemProc*) INT_TO_POINTER(myatoi(realbuf))); par->Value = (int) CreateCallback((SystemProc*) INT_TO_POINTER(myatoi64(realbuf)));
break; break;
} }
GlobalFree(realbuf); GlobalFree(realbuf);
@ -863,7 +863,7 @@ void ParamsOut(SystemProc *proc)
break; break;
case PAT_STRING: case PAT_STRING:
{ {
int num = lstrlen(*((char**) place)); unsigned num = lstrlen(*((char**) place));
if (num >= g_stringsize) num = g_stringsize-1; if (num >= g_stringsize) num = g_stringsize-1;
lstrcpyn(realbuf,*((char**) place), num+1); lstrcpyn(realbuf,*((char**) place), num+1);
realbuf[num] = 0; realbuf[num] = 0;
@ -891,8 +891,8 @@ void ParamsOut(SystemProc *proc)
// Step 2: place it // Step 2: place it
if (proc->Params[i].Output == IOT_NONE); if (proc->Params[i].Output == IOT_NONE);
else if (proc->Params[i].Output == IOT_STACK) pushstring(realbuf); else if (proc->Params[i].Output == IOT_STACK) system_pushstring(realbuf);
else if (proc->Params[i].Output > 0) setuservariable(proc->Params[i].Output - 1, realbuf); else if (proc->Params[i].Output > 0) system_setuservariable(proc->Params[i].Output - 1, realbuf);
GlobalFree(realbuf); GlobalFree(realbuf);