release 5 by brainsucker:
1. u flag - unload dll after procedure call. 2. some changes to asm to turn on Whole Program Optimization. 3. Dll shrinked for 1 kb. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2899 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
6488174f47
commit
9186fcc291
6 changed files with 127 additions and 23 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
#include "Buffers.h"
|
#include "Buffers.h"
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include <crtdbg.h>
|
||||||
|
|
||||||
// Parse Section Type
|
// Parse Section Type
|
||||||
#define PST_PROC 0
|
#define PST_PROC 0
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
#define PCD_PARAMS 2
|
#define PCD_PARAMS 2
|
||||||
#define PCD_DONE 3 // Just Continue
|
#define PCD_DONE 3 // Just Continue
|
||||||
|
|
||||||
int ParamSizeByType[7] = {0, // PAT_VOID (Size will be equal to 1)
|
const int ParamSizeByType[7] = {0, // PAT_VOID (Size will be equal to 1)
|
||||||
1, // PAT_INT
|
1, // PAT_INT
|
||||||
2, // PAT_LONG
|
2, // PAT_LONG
|
||||||
1, // PAT_STRING
|
1, // PAT_STRING
|
||||||
|
@ -26,15 +27,15 @@ int ParamSizeByType[7] = {0, // PAT_VOID (Size will be equal to 1)
|
||||||
0}; // PAT_CALLBACK (Size will be equal to 1)
|
0}; // PAT_CALLBACK (Size will be equal to 1)
|
||||||
|
|
||||||
int z1, z2; // I've made them static for easier use at callback procs
|
int z1, z2; // I've made them static for easier use at callback procs
|
||||||
int LastStackPlace = 0;
|
int LastStackPlace;
|
||||||
int LastStackReal = 0;
|
int LastStackReal;
|
||||||
DWORD LastError = 0;
|
DWORD LastError;
|
||||||
SystemProc *LastProc = NULL;
|
volatile SystemProc *LastProc;
|
||||||
int CallbackIndex = 0;
|
int CallbackIndex;
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
|
|
||||||
// Return to callback caller with stack restore
|
// Return to callback caller with stack restore
|
||||||
char retexpr[3] = {0xC2, 0x00, 0x00};
|
char retexpr[4];
|
||||||
HANDLE retaddr;
|
HANDLE retaddr;
|
||||||
|
|
||||||
char *GetResultStr(SystemProc *proc)
|
char *GetResultStr(SystemProc *proc)
|
||||||
|
@ -62,12 +63,18 @@ void WriteToLog(char *buffer)
|
||||||
DWORD written;
|
DWORD written;
|
||||||
char timebuffer[128];
|
char timebuffer[128];
|
||||||
|
|
||||||
|
GetTickCount();
|
||||||
|
|
||||||
if (logfile == NULL) return;
|
if (logfile == NULL) return;
|
||||||
|
|
||||||
SetFilePointer(logfile, 0, 0, FILE_END);
|
SetFilePointer(logfile, 0, 0, FILE_END);
|
||||||
|
|
||||||
wsprintf(timebuffer, "%04d %04d.%03d ", (++logop)%10000, (GetTickCount() / 1000) % 10000,
|
wsprintf(timebuffer, "%04d %04d.%03d ", (++logop)%10000, (GetTickCount() / 1000) % 10000,
|
||||||
GetTickCount() % 1000);
|
GetTickCount() % 1000);
|
||||||
|
|
||||||
|
_RPT0(_CRT_WARN, timebuffer);
|
||||||
|
_RPT0(_CRT_WARN, buffer);
|
||||||
|
|
||||||
WriteFile(logfile, timebuffer, lstrlen(timebuffer), &written, NULL);
|
WriteFile(logfile, timebuffer, lstrlen(timebuffer), &written, NULL);
|
||||||
WriteFile(logfile, buffer, lstrlen(buffer), &written, NULL);
|
WriteFile(logfile, buffer, lstrlen(buffer), &written, NULL);
|
||||||
// FlushFileBuffers(logfile);
|
// FlushFileBuffers(logfile);
|
||||||
|
@ -218,6 +225,12 @@ PLUGINFUNCTION(Call)
|
||||||
// Deallocate params if not callback
|
// Deallocate params if not callback
|
||||||
ParamsDeAllocate(proc);
|
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
|
// 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) pushint(LastError);
|
||||||
}
|
}
|
||||||
|
@ -572,6 +585,9 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
||||||
case 'e':
|
case 'e':
|
||||||
temp2 = POPT_ERROR;
|
temp2 = POPT_ERROR;
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
temp2 = POPT_UNLOAD;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Options
|
// New Options
|
||||||
|
@ -864,7 +880,7 @@ SystemProc __declspec(naked) *CallProc(SystemProc *proc)
|
||||||
SYSTEM_LOG_ADD("\t\tCall:\n");
|
SYSTEM_LOG_ADD("\t\tCall:\n");
|
||||||
SYSTEM_EVENT("\t\t\tBefore call ")
|
SYSTEM_EVENT("\t\t\tBefore call ")
|
||||||
|
|
||||||
if ((CallbackIndex > 0) && ((proc->Options & POPT_GENSTACK) == 0))
|
if (CallbackIndex && (!(proc->Options & POPT_GENSTACK)))
|
||||||
{
|
{
|
||||||
_asm
|
_asm
|
||||||
{
|
{
|
||||||
|
@ -909,7 +925,12 @@ SystemProc __declspec(naked) *CallProc(SystemProc *proc)
|
||||||
|
|
||||||
// Save proc
|
// Save proc
|
||||||
proc->Clone = LastProc;
|
proc->Clone = LastProc;
|
||||||
LastProc = proc;
|
_asm
|
||||||
|
{
|
||||||
|
mov eax, proc
|
||||||
|
mov LastProc, eax
|
||||||
|
}
|
||||||
|
//LastProc = proc;
|
||||||
|
|
||||||
SYSTEM_EVENT("\n\t\t\tNear call ")
|
SYSTEM_EVENT("\n\t\t\tNear call ")
|
||||||
SYSTEM_LOG_POST;
|
SYSTEM_LOG_POST;
|
||||||
|
@ -927,7 +948,7 @@ SystemProc __declspec(naked) *CallProc(SystemProc *proc)
|
||||||
SYSTEM_LOG_ADD(LastProc->ProcName);
|
SYSTEM_LOG_ADD(LastProc->ProcName);
|
||||||
SYSTEM_EVENT("\n\t\t\tShort-After call ")
|
SYSTEM_EVENT("\n\t\t\tShort-After call ")
|
||||||
|
|
||||||
if ((CallbackIndex > 0) && ((LastProc->Options & POPT_GENSTACK) == 0))
|
if ((CallbackIndex) && (!(LastProc->Options & POPT_GENSTACK)))
|
||||||
{
|
{
|
||||||
_asm
|
_asm
|
||||||
{
|
{
|
||||||
|
@ -939,7 +960,12 @@ SystemProc __declspec(naked) *CallProc(SystemProc *proc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore proc
|
// Restore proc
|
||||||
proc = LastProc;
|
_asm
|
||||||
|
{
|
||||||
|
mov eax, LastProc
|
||||||
|
mov proc, eax
|
||||||
|
}
|
||||||
|
// proc = LastProc;
|
||||||
LastProc = proc->Clone;
|
LastProc = proc->Clone;
|
||||||
|
|
||||||
// In case of cdecl convention we should clear stack
|
// In case of cdecl convention we should clear stack
|
||||||
|
@ -1103,11 +1129,22 @@ SystemProc __declspec(naked) *CallBack(SystemProc *proc)
|
||||||
push esi
|
push esi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MessageBox(NULL, "cool1", "Cool", MB_OK);
|
||||||
|
|
||||||
SYSTEM_LOG_ADD("\t\tReturn from callback:\n");
|
SYSTEM_LOG_ADD("\t\tReturn from callback:\n");
|
||||||
SYSTEM_EVENT("\t\t\tBefore call-back ");
|
SYSTEM_EVENT("\t\t\tBefore call-back ");
|
||||||
|
SYSTEM_LOG_POST;
|
||||||
|
|
||||||
z1 = proc->Params[0].Value;
|
//z1 = proc->Params[0].Value;
|
||||||
z2 = proc->Params[0]._value;
|
//z2 = proc->Params[0]._value;
|
||||||
|
//z1 = &(proc->Params[0].Value);
|
||||||
|
_asm
|
||||||
|
{
|
||||||
|
mov eax, proc
|
||||||
|
add eax, SYSTEM_ZERO_PARAM_VALUE_OFFSET
|
||||||
|
push [eax]
|
||||||
|
push [eax+4]
|
||||||
|
}
|
||||||
|
|
||||||
// Adjust return statement
|
// Adjust return statement
|
||||||
if ((proc->Options & POPT_CDECL) == 0) retexpr[1] = proc->ArgsSize;
|
if ((proc->Options & POPT_CDECL) == 0) retexpr[1] = proc->ArgsSize;
|
||||||
|
@ -1119,11 +1156,13 @@ SystemProc __declspec(naked) *CallBack(SystemProc *proc)
|
||||||
// Remove unneeded callback proc
|
// Remove unneeded callback proc
|
||||||
GlobalFree((HANDLE) proc);
|
GlobalFree((HANDLE) proc);
|
||||||
|
|
||||||
|
// MessageBox(NULL, "cool2", "Cool", MB_OK);
|
||||||
|
|
||||||
_asm
|
_asm
|
||||||
{
|
{
|
||||||
// Prepare return
|
// Prepare return
|
||||||
mov eax, z1
|
// mov eax, z1
|
||||||
mov edx, z2
|
//mov edx, z2
|
||||||
|
|
||||||
// Restore temporary stack and return
|
// Restore temporary stack and return
|
||||||
|
|
||||||
|
@ -1138,11 +1177,17 @@ SystemProc __declspec(naked) *CallBack(SystemProc *proc)
|
||||||
pop ebp
|
pop ebp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SYSTEM_LOG_DEBUG
|
||||||
SYSTEM_EVENT("\n\t\t\tSh-Before call-back");
|
SYSTEM_EVENT("\n\t\t\tSh-Before call-back");
|
||||||
SYSTEM_LOG_POST;
|
SYSTEM_LOG_POST;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Fake return from Callback
|
// Fake return from Callback
|
||||||
_asm {
|
_asm {
|
||||||
|
// callback proc result
|
||||||
|
pop edx
|
||||||
|
pop eax
|
||||||
|
|
||||||
// Restore registers
|
// Restore registers
|
||||||
pop esi
|
pop esi
|
||||||
pop edi
|
pop edi
|
||||||
|
@ -1267,6 +1312,18 @@ void CallStruct(SystemProc *proc)
|
||||||
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
||||||
{
|
{
|
||||||
g_hInstance=hInst;
|
g_hInstance=hInst;
|
||||||
|
|
||||||
|
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
||||||
|
{
|
||||||
|
// initialize some variables
|
||||||
|
LastStackPlace = 0;
|
||||||
|
LastStackReal = 0;
|
||||||
|
LastError = 0;
|
||||||
|
LastProc = NULL;
|
||||||
|
CallbackIndex = 0;
|
||||||
|
retexpr[0] = 0xC2;
|
||||||
|
retexpr[2] = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,18 @@
|
||||||
#define POPT_NEVERREDEF 0x8 // Never redefine
|
#define POPT_NEVERREDEF 0x8 // Never redefine
|
||||||
#define POPT_GENSTACK 0x10 // Use general stack (non temporary for callback)
|
#define POPT_GENSTACK 0x10 // Use general stack (non temporary for callback)
|
||||||
#define POPT_ERROR 0x20 // Call GetLastError after proc and push it to stack
|
#define POPT_ERROR 0x20 // Call GetLastError after proc and push it to stack
|
||||||
#define POPT_CLONE 0x40 // This is clone callback
|
#define POPT_UNLOAD 0x40 // unload dll after call
|
||||||
|
#define POPT_CLONE 0x80 // This is clone callback
|
||||||
|
|
||||||
// Our single proc parameter
|
// Our single proc parameter
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int Type;
|
int Type;
|
||||||
int Option; // -1 -> Pointer, 1-... -> Special+1
|
int Option; // -1 -> Pointer, 1-... -> Special+1
|
||||||
|
|
||||||
|
// if you'll change ProcParameter or SystemProc structure - update this value
|
||||||
|
#define SYSTEM_ZERO_PARAM_VALUE_OFFSET 0x820
|
||||||
|
|
||||||
int Value; // it can hold any 4 byte value
|
int Value; // it can hold any 4 byte value
|
||||||
int _value; // value buffer for structures > 4 bytes (I hope 8 bytes will be enough)
|
int _value; // value buffer for structures > 4 bytes (I hope 8 bytes will be enough)
|
||||||
int Size; // Value real size (should be either 1 or 2 (the number of pushes))
|
int Size; // Value real size (should be either 1 or 2 (the number of pushes))
|
||||||
|
@ -76,6 +81,7 @@ typedef struct tag_SystemProc
|
||||||
HANDLE Proc;
|
HANDLE Proc;
|
||||||
int Options;
|
int Options;
|
||||||
int ParamCount;
|
int ParamCount;
|
||||||
|
// if you'll change ProcParameter or SystemProc structure - update SYSTEM_ZERO_PARAM_VALUE_OFFSET value
|
||||||
ProcParameter Params[100]; // I hope nobody will use more than 100 params
|
ProcParameter Params[100]; // I hope nobody will use more than 100 params
|
||||||
|
|
||||||
// Callback specific
|
// Callback specific
|
||||||
|
@ -85,7 +91,7 @@ typedef struct tag_SystemProc
|
||||||
SystemProc *Clone;
|
SystemProc *Clone;
|
||||||
} SystemProc;
|
} SystemProc;
|
||||||
|
|
||||||
extern int ParamSizeByType[]; // Size of every parameter type (*4 bytes)
|
extern const int ParamSizeByType[]; // Size of every parameter type (*4 bytes)
|
||||||
|
|
||||||
extern HANDLE CreateCallback(SystemProc *cbproc);
|
extern HANDLE CreateCallback(SystemProc *cbproc);
|
||||||
extern SystemProc *PrepareProc(BOOL NeedForCall);
|
extern SystemProc *PrepareProc(BOOL NeedForCall);
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
IntermediateDirectory="Release"
|
IntermediateDirectory="Release"
|
||||||
ConfigurationType="2"
|
ConfigurationType="2"
|
||||||
CharacterSet="2"
|
CharacterSet="2"
|
||||||
WholeProgramOptimization="FALSE">
|
WholeProgramOptimization="TRUE">
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="1"
|
Optimization="1"
|
||||||
|
@ -97,9 +97,10 @@
|
||||||
OutputFile="d:\Program FIles\NSIS\Plugins\System.dll"
|
OutputFile="d:\Program FIles\NSIS\Plugins\System.dll"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
IgnoreAllDefaultLibraries="TRUE"
|
IgnoreAllDefaultLibraries="TRUE"
|
||||||
GenerateDebugInformation="FALSE"
|
GenerateDebugInformation="TRUE"
|
||||||
GenerateMapFile="TRUE"
|
GenerateMapFile="TRUE"
|
||||||
MapExports="TRUE"
|
MapExports="TRUE"
|
||||||
|
MapLines="TRUE"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
OptimizeReferences="2"
|
OptimizeReferences="2"
|
||||||
EnableCOMDATFolding="2"
|
EnableCOMDATFolding="2"
|
||||||
|
|
|
@ -115,10 +115,10 @@ enumex: ; End of drives or user cancel
|
||||||
|
|
||||||
; Logo
|
; Logo
|
||||||
File /oname=spltmp.bmp "${NSISDIR}\Contrib\Makensisw\logo.bmp"
|
File /oname=spltmp.bmp "${NSISDIR}\Contrib\Makensisw\logo.bmp"
|
||||||
; File /oname=spltmp.wav "${WINDIR}\media\Windows XP Startup.wav"
|
; File /oname=spltmp.wav "d:\Windows\Media\tada.wav"
|
||||||
|
|
||||||
; I. systemSplash variant
|
; I. systemSplash variant
|
||||||
!insertmacro smSystemSplash 500 "$TEMP\spltmp"
|
!insertmacro smSystemSplash 2000 "$TEMP\spltmp"
|
||||||
|
|
||||||
; II. Splash Plugin variant
|
; II. Splash Plugin variant
|
||||||
; splash::show 2000 $TEMP\spltmp
|
; splash::show 2000 $TEMP\spltmp
|
||||||
|
|
|
@ -166,6 +166,8 @@ redefined either by GET or CALL. This options is never inherited to childs.
|
||||||
s - use general Stack. Whenever the first callback defined the system
|
s - use general Stack. Whenever the first callback defined the system
|
||||||
starts using the temporary stacks for function calls.
|
starts using the temporary stacks for function calls.
|
||||||
e - call GetLastError() after procedure end and push result on stack,
|
e - call GetLastError() after procedure end and push result on stack,
|
||||||
|
u - unload DLL after call (using FreeLibrary, so you'll be able to
|
||||||
|
do something with it, delete for example).
|
||||||
|
|
||||||
----------------------------------
|
----------------------------------
|
||||||
Callback:
|
Callback:
|
||||||
|
|
38
Contrib/System/WhatsNew.txt
Normal file
38
Contrib/System/WhatsNew.txt
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
release 2.
|
||||||
|
1. Syntax, with inline input
|
||||||
|
2. Int64 full support (conversion/operations/comparison)
|
||||||
|
3. Structures support
|
||||||
|
4. Callbacks support, including multilevel callbacks
|
||||||
|
5. Some useful rountines (Alloc, Free, Copy)
|
||||||
|
6. CDecl and StdCall calling conventions
|
||||||
|
|
||||||
|
release 3, 22 march 2003.
|
||||||
|
1. Custom Message Boxes (with icons etc) -> bug in case of GetModuleHandle and
|
||||||
|
call to FreeLibrary (sysfunc.nsh)
|
||||||
|
2. GetFileSysTime -> No SystemTimeToTzSpecificLocalTime at win9x bug,
|
||||||
|
changed to use FileTimeToLocalFileTime (sysfunc.nsh)
|
||||||
|
3. Incorrect automatic structure size (&l) bug, value actually never filled
|
||||||
|
into the structure (strange -> winxp takes no care of the structure size
|
||||||
|
members, such as cbSize, and win98 does...) (system.c)
|
||||||
|
4. Changed Secondary Stack Allocation behavior - now we just leave 65kb of the
|
||||||
|
stack NSIS give to us to the NSIS itself, and use the other part as the stack
|
||||||
|
for our calls. (system.c)
|
||||||
|
5. Secondary Stack Optimization - in case of no more pending callback procs -
|
||||||
|
"free" the secondary stack pointer. (system.c)
|
||||||
|
6. PlaySound("", 0, 0) plays the default windows sound at win9x, so changed to
|
||||||
|
PlaySound(NULL, 0, 0) for effective sound stopping after splash (sysfunc.nsh).
|
||||||
|
|
||||||
|
release 4, 3 september 2003.
|
||||||
|
1. Division by zero fatal error at Int64Op killed.
|
||||||
|
2. bool type removed (use int instead).
|
||||||
|
3. GUID (g) and LPWSTR (w) types added.
|
||||||
|
4. Memory cleanup after using t (string), g (guid) and w (unicode string) added.
|
||||||
|
5. Automatic A-letter at proc name discovery.
|
||||||
|
6. COM optimized: new proc specification "x->y", where x is interface ptr, and
|
||||||
|
y is vtable member index. For such procs Interface pointer passed as first arg
|
||||||
|
automaticaly.
|
||||||
|
|
||||||
|
release 5, 11 september 2003.
|
||||||
|
1. u flag - unload dll after procedure call.
|
||||||
|
2. some changes to asm to turn on Whole Program Optimization.
|
||||||
|
3. Dll shrinked for 1 kb.
|
Loading…
Add table
Add a link
Reference in a new issue