File: Plugin.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 (178 lines) | stat: -rwxr-xr-x 3,676 bytes parent folder | download | duplicates (4)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Unicode support by Jim Park -- 08/23/2007

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

HWND g_hwndParent;

#define isvalidnsisvarindex(varnum) ( ((unsigned int)(varnum)) < (__INST_LAST) )

TCHAR *AllocString()
{
    return (TCHAR*) GlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
}

TCHAR *AllocStr(TCHAR *str)
{
    return lstrcpyn(AllocString(), str, g_stringsize);
}

TCHAR* system_popstring()
{
    stack_t *pSt;
    TCHAR *src, *dst, *retval;

    if (!g_stacktop || !*g_stacktop) return NULL;
    pSt = *g_stacktop, *g_stacktop = pSt->next, src = pSt->text, dst = (TCHAR*)pSt;

    // We don't have to call AllocString+lstrcpy+GlobalFree if we convert the stack item to a string
    for (retval = dst;;) if (!(*dst++ = *src++)) return retval;
}

TCHAR *system_pushstring(TCHAR *str)
{
        stack_t *th;
        if (!g_stacktop) return str;
        th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+(g_stringsize*sizeof(TCHAR)));
        lstrcpyn(th->text,str,g_stringsize);
        th->next=*g_stacktop;
        *g_stacktop=th;
        return str;
}

TCHAR *system_getuservariable(int varnum)
{
        if (!isvalidnsisvarindex(varnum)) return AllocString();
        return AllocStr(g_variables+varnum*g_stringsize);
}

TCHAR *system_setuservariable(int varnum, TCHAR *var)
{
        if (var && isvalidnsisvarindex(varnum)) {
                lstrcpy(g_variables + varnum*g_stringsize, var);
        }
        return var;
}

// Updated for int64 and simple bitwise operations
__int64 myatoi64(TCHAR *s)
{
  __int64 v=0;
  // Check for right input
  if (!s) return 0;
  if (*s == _T('0') && (s[1] == _T('x') || s[1] == _T('X')))
  {
    s++;
    for (;;)
    {
      int c=*(++s);
      if (c >= _T('0') && c <= _T('9')) c-=_T('0');
      else if (c >= _T('a') && c <= _T('f')) c-=_T('a')-10;
      else if (c >= _T('A') && c <= _T('F')) c-=_T('A')-10;
      else break;
      v<<=4;
      v+=c;
    }
  }
  else if (*s == _T('0') && s[1] <= _T('7') && s[1] >= _T('0'))
  {
    for (;;)
    {
      int c=*(++s);
      if (c >= _T('0') && c <= _T('7')) c-=_T('0');
      else break;
      v<<=3;
      v+=c;
    }
  }
  else
  {
    int sign=0;
    if (*s == _T('-')) sign++; else s--;
    for (;;)
    {
      int c=*(++s) - _T('0');
      if (c < 0 || c > 9) break;
      v*=10;
      v+=c;
    }
    if (sign) v = -v;
  }

  // Support for simple ORed expressions
  if (*s == _T('|')) 
  {
      v |= myatoi64(s+1);
  }

  return v;
}

void myitoa64(__int64 i, TCHAR *buffer)
{
    TCHAR buf[128], *b = buf;

    if (i < 0)
    {
        *(buffer++) = _T('-');
        i = -i;
    }
    if (i == 0) *(buffer++) = _T('0');
    else 
    {
        while (i > 0) 
        {
            *(b++) = _T('0') + ((TCHAR) (i%10));
            i /= 10;
        }
        while (b > buf) *(buffer++) = *(--b);
    }
    *buffer = 0;
}

INT_PTR system_popintptr()
{
    INT_PTR value;
    TCHAR *str;
    if ((str = system_popstring()) == NULL) return -1;
    value = StrToIntPtr(str);
    GlobalFree(str);
    return value;
}

void system_pushintptr(INT_PTR value)
{
    TCHAR buffer[50];
    wsprintf(buffer, sizeof(void*) > 4 ? _T("%Id") : _T("%d"), value);
    system_pushstring(buffer);
}

void *copymem(void *output, void *input, size_t cbSize)
{
  BYTE *out = (BYTE*) output;
  BYTE *in = (BYTE*) input;
  if ((input != NULL) && (output != NULL))
  {
    while (cbSize-- > 0) *(out++) = *(in++);
  }
  return output;
}

HANDLE GlobalCopy(HANDLE Old)
{
    size_t size = GlobalSize(Old);
    return copymem(GlobalAlloc(GPTR, size), Old, size);
}

UINT_PTR NSISCallback(enum NSPIM msg)
{
  return 0;
}

#ifdef _DEBUG
void main()
{
}
#endif