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:
parent
a924c4d2d3
commit
e59407720a
4 changed files with 64 additions and 114 deletions
|
@ -14,12 +14,12 @@ TempStack *tempstack = NULL;
|
|||
PLUGINFUNCTIONSHORT(Alloc)
|
||||
{
|
||||
int size;
|
||||
if ((size = popint()) == 0)
|
||||
if ((size = popint64()) == 0)
|
||||
{
|
||||
pushint(0);
|
||||
system_pushint(0);
|
||||
return;
|
||||
}
|
||||
pushint((int) GlobalAlloc(GPTR, size));
|
||||
system_pushint((int) GlobalAlloc(GPTR, size));
|
||||
}
|
||||
PLUGINFUNCTIONEND
|
||||
|
||||
|
@ -29,16 +29,16 @@ PLUGINFUNCTIONSHORT(Copy)
|
|||
HANDLE source, dest;
|
||||
char *str;
|
||||
// Get the string
|
||||
if ((str = popstring()) == NULL) return;
|
||||
if ((str = system_popstring()) == NULL) return;
|
||||
|
||||
// Check for size option
|
||||
if (str[0] == '/')
|
||||
{
|
||||
size = (int) myatoi(str+1);
|
||||
dest = (HANDLE) popint();
|
||||
size = (int) myatoi64(str+1);
|
||||
dest = (HANDLE) popint64();
|
||||
}
|
||||
else dest = (HANDLE) myatoi(str);
|
||||
source = (HANDLE) popint();
|
||||
else dest = (HANDLE) myatoi64(str);
|
||||
source = (HANDLE) popint64();
|
||||
|
||||
// Ok, check the size
|
||||
if (size == 0) size = (int) GlobalSize(source);
|
||||
|
@ -46,7 +46,7 @@ PLUGINFUNCTIONSHORT(Copy)
|
|||
if ((int) dest == 0)
|
||||
{
|
||||
dest = GlobalAlloc((GPTR), size);
|
||||
pushint((int) dest);
|
||||
system_pushint((int) dest);
|
||||
}
|
||||
|
||||
// COPY!
|
||||
|
@ -58,7 +58,7 @@ PLUGINFUNCTIONEND
|
|||
|
||||
PLUGINFUNCTIONSHORT(Free)
|
||||
{
|
||||
GlobalFree((HANDLE) popint());
|
||||
GlobalFree((HANDLE) popint64());
|
||||
}
|
||||
PLUGINFUNCTIONEND
|
||||
|
||||
|
@ -67,7 +67,7 @@ PLUGINFUNCTION(Store)
|
|||
TempStack *tmp;
|
||||
int size = ((INST_R9+1)*g_stringsize);
|
||||
|
||||
char *command, *cmd = command = popstring();
|
||||
char *command, *cmd = command = system_popstring();
|
||||
while (*cmd != 0)
|
||||
{
|
||||
switch (*(cmd++))
|
||||
|
@ -97,12 +97,12 @@ PLUGINFUNCTION(Store)
|
|||
case 'P':
|
||||
*cmd += 10;
|
||||
case 'p':
|
||||
GlobalFree((HANDLE) pushstring(getuservariable(*(cmd++)-'0')));
|
||||
GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-'0')));
|
||||
break;
|
||||
case 'R':
|
||||
*cmd += 10;
|
||||
case 'r':
|
||||
GlobalFree((HANDLE) setuservariable(*(cmd++)-'0', popstring()));
|
||||
GlobalFree((HANDLE) system_setuservariable(*(cmd++)-'0', system_popstring()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
#include "System.h"
|
||||
|
||||
HWND g_hwndParent;
|
||||
int g_stringsize;
|
||||
stack_t **g_stacktop;
|
||||
char *g_variables;
|
||||
|
||||
char *AllocString()
|
||||
{
|
||||
|
@ -18,7 +15,7 @@ char *AllocStr(char *str)
|
|||
return lstrcpy(AllocString(), str);
|
||||
}
|
||||
|
||||
char* popstring()
|
||||
char* system_popstring()
|
||||
{
|
||||
char *str;
|
||||
stack_t *th;
|
||||
|
@ -34,7 +31,7 @@ char* popstring()
|
|||
return str;
|
||||
}
|
||||
|
||||
char *pushstring(char *str)
|
||||
char *system_pushstring(char *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return str;
|
||||
|
@ -45,13 +42,13 @@ char *pushstring(char *str)
|
|||
return str;
|
||||
}
|
||||
|
||||
char *getuservariable(int varnum)
|
||||
char *system_getuservariable(int varnum)
|
||||
{
|
||||
if (varnum < 0 || varnum >= __INST_LAST) return AllocString();
|
||||
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) {
|
||||
lstrcpy (g_variables + varnum*g_stringsize, var);
|
||||
|
@ -60,7 +57,7 @@ char *setuservariable(int varnum, char *var)
|
|||
}
|
||||
|
||||
// Updated for int64 and simple bitwise operations
|
||||
__int64 myatoi(char *s)
|
||||
__int64 myatoi64(char *s)
|
||||
{
|
||||
__int64 v=0;
|
||||
// Check for right input
|
||||
|
@ -107,7 +104,7 @@ __int64 myatoi(char *s)
|
|||
// Support for simple ORed expressions
|
||||
if (*s == '|')
|
||||
{
|
||||
v |= myatoi(s+1);
|
||||
v |= myatoi64(s+1);
|
||||
}
|
||||
|
||||
return v;
|
||||
|
@ -135,21 +132,21 @@ void myitoa64(__int64 i, char *buffer)
|
|||
*buffer = 0;
|
||||
}
|
||||
|
||||
int popint()
|
||||
int popint64()
|
||||
{
|
||||
int value;
|
||||
char *str;
|
||||
if ((str = popstring()) == NULL) return -1;
|
||||
value = (int) myatoi(str);
|
||||
if ((str = system_popstring()) == NULL) return -1;
|
||||
value = (int) myatoi64(str);
|
||||
GlobalFree(str);
|
||||
return value;
|
||||
}
|
||||
|
||||
void pushint(int value)
|
||||
void system_pushint(int value)
|
||||
{
|
||||
char buffer[1024];
|
||||
wsprintf(buffer, "%d", value);
|
||||
pushstring(buffer);
|
||||
system_pushstring(buffer);
|
||||
}
|
||||
|
||||
char *copymem(char *output, char *input, int size)
|
||||
|
@ -166,9 +163,9 @@ HANDLE GlobalCopy(HANDLE Old)
|
|||
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
|
||||
|
|
|
@ -1,57 +1,13 @@
|
|||
#ifndef ___PLUGIN__H___
|
||||
#define ___PLUGIN__H___
|
||||
|
||||
typedef struct _stack_t {
|
||||
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;
|
||||
#include <plugin.h> // nsis plug-in...
|
||||
|
||||
#define PLUGINFUNCTION(name) \
|
||||
void __declspec(dllexport) name( \
|
||||
HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { \
|
||||
/*g_hwndParent=hwndParent;*/ \
|
||||
g_stringsize=string_size; \
|
||||
g_stacktop=stacktop; \
|
||||
g_variables=variables; \
|
||||
EXDLL_INIT(); \
|
||||
extra->RegisterPluginCallback(g_hInstance, NSISCallback);
|
||||
#define PLUGINFUNCTIONEND }
|
||||
|
||||
|
@ -62,23 +18,20 @@ typedef struct {
|
|||
extern char *AllocStr(char *str);
|
||||
extern void myitoa64(__int64 i, char *buffer);
|
||||
extern char *AllocString();
|
||||
extern char *getuservariable(int varnum);
|
||||
extern char *setuservariable(int varnum, char *var);
|
||||
extern char* popstring(); // NULL - stack empty
|
||||
extern char* pushstring(char *str);
|
||||
extern __int64 myatoi(char *s);
|
||||
extern int popint(); // -1 -> stack empty
|
||||
extern void pushint(int value);
|
||||
extern char *system_getuservariable(int varnum);
|
||||
extern char *system_setuservariable(int varnum, char *var);
|
||||
extern char* system_popstring(); // NULL - stack empty
|
||||
extern char* system_pushstring(char *str);
|
||||
extern __int64 myatoi64(char *s);
|
||||
extern int popint64(); // -1 -> stack empty
|
||||
extern void system_pushint(int value);
|
||||
|
||||
extern HANDLE GlobalCopy(HANDLE Old);
|
||||
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 int g_stringsize;
|
||||
extern stack_t **g_stacktop;
|
||||
extern char *g_variables;
|
||||
extern HINSTANCE g_hInstance;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -92,7 +92,7 @@ void WriteToLog(char *buffer)
|
|||
PLUGINFUNCTION(Debug)
|
||||
{
|
||||
char *o1;
|
||||
o1 = popstring();
|
||||
o1 = system_popstring();
|
||||
|
||||
if (logfile == NULL)
|
||||
if (lstrlen(o1) > 0)
|
||||
|
@ -141,7 +141,7 @@ PLUGINFUNCTION(Get)
|
|||
SystemProc *proc = PrepareProc(FALSE);
|
||||
if (proc == NULL)
|
||||
{
|
||||
pushstring("error");
|
||||
system_pushstring("error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,20 +154,20 @@ PLUGINFUNCTION(Get)
|
|||
if ((proc->Options & POPT_ALWRETURN) != 0)
|
||||
{
|
||||
// Always return flag set -> return separate proc and result
|
||||
pushint((int) proc);
|
||||
GlobalFree(pushstring(GetResultStr(proc)));
|
||||
system_pushint((int) proc);
|
||||
GlobalFree(system_pushstring(GetResultStr(proc)));
|
||||
} else
|
||||
{
|
||||
if (proc->ProcResult != PR_OK)
|
||||
{
|
||||
// No always return flag and error result - return result
|
||||
GlobalFree(pushstring(GetResultStr(proc)));
|
||||
GlobalFree(system_pushstring(GetResultStr(proc)));
|
||||
// If proc is permanent?
|
||||
if ((proc->Options & POPT_PERMANENT) == 0)
|
||||
GlobalFree((HANDLE) proc); // No, free it
|
||||
}
|
||||
else // Ok result, return proc
|
||||
pushint((int) proc);
|
||||
system_pushint((int) proc);
|
||||
}
|
||||
} PLUGINFUNCTIONEND
|
||||
|
||||
|
@ -209,7 +209,7 @@ PLUGINFUNCTION(Call)
|
|||
{
|
||||
// Always return flag set - return separate return and result
|
||||
ParamsOut(proc);
|
||||
GlobalFree(pushstring(GetResultStr(proc)));
|
||||
GlobalFree(system_pushstring(GetResultStr(proc)));
|
||||
} else
|
||||
{
|
||||
if (proc->ProcResult != PR_OK)
|
||||
|
@ -242,7 +242,7 @@ PLUGINFUNCTION(Call)
|
|||
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->Options & POPT_ERROR) != 0) system_pushint(LastError);
|
||||
}
|
||||
|
||||
// If proc is permanent?
|
||||
|
@ -257,13 +257,13 @@ PLUGINFUNCTIONSHORT(Int64Op)
|
|||
char buf[128];
|
||||
|
||||
// Get strings
|
||||
o1 = popstring(); op = popstring();
|
||||
i1 = myatoi(o1); // convert first arg to int64
|
||||
o1 = system_popstring(); op = system_popstring();
|
||||
i1 = myatoi64(o1); // convert first arg to int64
|
||||
if ((*op != '~') && (*op != '!'))
|
||||
{
|
||||
// get second arg, convert it, free it
|
||||
o2 = popstring();
|
||||
i2 = myatoi(o2);
|
||||
o2 = system_popstring();
|
||||
i2 = myatoi64(o2);
|
||||
GlobalFree(o2);
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ PLUGINFUNCTIONSHORT(Int64Op)
|
|||
|
||||
// Output and freedom
|
||||
myitoa64(i1, buf);
|
||||
pushstring(buf);
|
||||
system_pushstring(buf);
|
||||
GlobalFree(o1); GlobalFree(op);
|
||||
} 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)++);
|
||||
*b = 0;
|
||||
(*p)--; // We should point at last digit
|
||||
return myatoi(buffer);
|
||||
return myatoi64(buffer);
|
||||
}
|
||||
|
||||
SystemProc *PrepareProc(BOOL NeedForCall)
|
||||
|
@ -321,7 +321,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
// Retrieve proc specs
|
||||
cb = (cbuf = AllocString()); // Current String buffer
|
||||
sbuf = AllocString(); // Safe String buffer
|
||||
ib = ibuf = popstring(); // Input string
|
||||
ib = ibuf = system_popstring(); // Input string
|
||||
|
||||
// Parse the string
|
||||
while (SectionType != -1)
|
||||
|
@ -387,7 +387,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
|
||||
if (proc != NULL) GlobalFree(proc);
|
||||
// Get already defined proc
|
||||
proc = (SystemProc *) INT_TO_POINTER(myatoi(cbuf));
|
||||
proc = (SystemProc *) INT_TO_POINTER(myatoi64(cbuf));
|
||||
if (!proc) break;
|
||||
|
||||
// Find the last clone at proc queue
|
||||
|
@ -668,7 +668,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
// Use direct system proc address
|
||||
int addr;
|
||||
|
||||
proc->Dll = (HANDLE) INT_TO_POINTER(myatoi(proc->DllName));
|
||||
proc->Dll = (HANDLE) INT_TO_POINTER(myatoi64(proc->DllName));
|
||||
|
||||
if (proc->Dll == 0)
|
||||
{
|
||||
|
@ -689,7 +689,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
addr = *((int *)addr);
|
||||
// now addr contains the pointer to first item at VTABLE
|
||||
// add the index of proc
|
||||
addr = addr + (int)(myatoi(proc->ProcName)*4);
|
||||
addr = addr + (int)(myatoi64(proc->ProcName)*4);
|
||||
proc->Proc = *((HANDLE*)addr);
|
||||
}
|
||||
break;
|
||||
|
@ -697,7 +697,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
if (*proc->DllName == 0)
|
||||
{
|
||||
// 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;
|
||||
} else
|
||||
{
|
||||
|
@ -720,7 +720,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -752,9 +752,9 @@ void ParamsIn(SystemProc *proc)
|
|||
// Step 1: retrive value
|
||||
if ((par->Input == IOT_NONE) || (par->Input == IOT_INLINE))
|
||||
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))
|
||||
realbuf = getuservariable(par->Input - 1);
|
||||
realbuf = system_getuservariable(par->Input - 1);
|
||||
else
|
||||
{
|
||||
// Inline input, will be freed as realbuf
|
||||
|
@ -776,10 +776,10 @@ void ParamsIn(SystemProc *proc)
|
|||
par->Value = 0;
|
||||
break;
|
||||
case PAT_INT:
|
||||
*((int*) place) = (int) myatoi(realbuf);
|
||||
*((int*) place) = (int) myatoi64(realbuf);
|
||||
break;
|
||||
case PAT_LONG:
|
||||
*((__int64*) place) = myatoi(realbuf);
|
||||
*((__int64*) place) = myatoi64(realbuf);
|
||||
break;
|
||||
case PAT_STRING:
|
||||
/* if (par->Input == IOT_NONE)
|
||||
|
@ -802,7 +802,7 @@ void ParamsIn(SystemProc *proc)
|
|||
case PAT_CALLBACK:
|
||||
// Generate new or use old callback
|
||||
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;
|
||||
}
|
||||
GlobalFree(realbuf);
|
||||
|
@ -863,7 +863,7 @@ void ParamsOut(SystemProc *proc)
|
|||
break;
|
||||
case PAT_STRING:
|
||||
{
|
||||
int num = lstrlen(*((char**) place));
|
||||
unsigned num = lstrlen(*((char**) place));
|
||||
if (num >= g_stringsize) num = g_stringsize-1;
|
||||
lstrcpyn(realbuf,*((char**) place), num+1);
|
||||
realbuf[num] = 0;
|
||||
|
@ -891,8 +891,8 @@ void ParamsOut(SystemProc *proc)
|
|||
|
||||
// Step 2: place it
|
||||
if (proc->Params[i].Output == IOT_NONE);
|
||||
else if (proc->Params[i].Output == IOT_STACK) pushstring(realbuf);
|
||||
else if (proc->Params[i].Output > 0) setuservariable(proc->Params[i].Output - 1, realbuf);
|
||||
else if (proc->Params[i].Output == IOT_STACK) system_pushstring(realbuf);
|
||||
else if (proc->Params[i].Output > 0) system_setuservariable(proc->Params[i].Output - 1, realbuf);
|
||||
|
||||
GlobalFree(realbuf);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue