File: Buffers.c

package info (click to toggle)
nsis 3.06.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,468 kB
  • sloc: cpp: 37,707; ansic: 26,911; python: 1,344; asm: 712; xml: 409; pascal: 215; makefile: 207; javascript: 67
file content (119 lines) | stat: -rwxr-xr-x 2,686 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Unicode support by Jim Park -- 08/23/2007

#include "stdafx.h"
#include "Plugin.h"
#include "System.h"
#include "Buffers.h"

typedef struct tagTempStack TempStack;
struct tagTempStack
{
    TempStack *Next;
    TCHAR Data[0];
};
TempStack *tempstack = NULL;

static void AllocWorker(unsigned int mult)
{
    size_t size;
    if ((size = popintptr()) == 0)
    {
        system_pushint(0);
        return;
    }
    system_pushintptr((INT_PTR) GlobalAlloc(GPTR, size * mult));
}

PLUGINFUNCTIONSHORT(Alloc)
{
    AllocWorker(sizeof(unsigned char));
}
PLUGINFUNCTIONEND

PLUGINFUNCTIONSHORT(StrAlloc)
{
    AllocWorker(sizeof(TCHAR));
}
PLUGINFUNCTIONEND

PLUGINFUNCTIONSHORT(Copy)
{
    SIZE_T size = 0;
    HANDLE source, dest;
    TCHAR *str;
    // Get the string
    if ((str = system_popstring()) == NULL) return;

    // Check for size option
    if (str[0] == _T('/'))
    {
        size = (SIZE_T) StrToIntPtr(str+1);
        dest = (HANDLE) popintptr();
    }
    else dest = (HANDLE) StrToIntPtr(str);
    source = (HANDLE) popintptr();

    // Ok, check the size
    if (size == 0) size = (SIZE_T) GlobalSize(source);
    // and the destinantion
    if (!dest) 
    {
        dest = GlobalAlloc((GPTR), size);
        system_pushintptr((INT_PTR) dest);
    }

    // COPY!
    copymem(dest, source, size);

    GlobalFree(str);
}
PLUGINFUNCTIONEND

PLUGINFUNCTION(Store)
{
    TempStack *tmp;
    int size = ((INST_R9+1)*g_stringsize*sizeof(TCHAR));

    TCHAR *command, *cmd = command = system_popstring();
    while (*cmd != 0)
    {
        switch (*(cmd++))
        {
        case _T('s'):
        case _T('S'):
            // Store the whole variables range
            tmp = (TempStack*) GlobalAlloc(GPTR, sizeof(TempStack)+size);
            tmp->Next = tempstack;
            tempstack = tmp;

            // Fill with data
            copymem(tempstack->Data, g_variables, size);
            break;
        case _T('l'):
        case _T('L'):
            if (tempstack == NULL) break;

            // Fill with data
            copymem(g_variables, tempstack->Data, size);

            // Restore stack
            tmp = tempstack->Next;
            GlobalFree((HANDLE) tempstack);
            tempstack = tmp;
            break;
        case _T('P'):
            *cmd += 10;
        case _T('p'):
            GlobalFree((HANDLE) system_pushstring(system_getuservariable(*(cmd++)-_T('0'))));
            break;
        case _T('R'):
            *cmd += 10;
        case _T('r'):
            GlobalFree((HANDLE) system_setuservariable(*(cmd++)-_T('0'), system_popstring()));
            break;
        }
    }

    GlobalFree((HANDLE) command);
}
PLUGINFUNCTIONEND