ReactOS 0.4.16-dev-336-gb667d82
decode.c File Reference
#include "jscript.h"
#include "wine/debug.h"
Include dependency graph for decode.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (jscript)
 
static BOOL decode_dword (const WCHAR *p, DWORD *ret)
 
HRESULT decode_source (WCHAR *code)
 

Variables

static const unsigned char pick_encoding [64]
 
static const unsigned char dictionary [][3]
 
static const int digits []
 

Function Documentation

◆ decode_dword()

static BOOL decode_dword ( const WCHAR p,
DWORD ret 
)
static

Definition at line 89 of file decode.c.

90{
91 DWORD i;
92
93 for(i=0; i<6; i++) {
94 if(p[i] >= ARRAY_SIZE(digits) || digits[p[i]] == 0xff)
95 return FALSE;
96 }
97 if(p[6] != '=' || p[7] != '=')
98 return FALSE;
99
100 *ret = (digits[p[0]] << 2)
101 + (digits[p[1]] >> 4)
102 + ((digits[p[1]] & 0xf) << 12)
103 + ((digits[p[2]] >> 2) << 8)
104 + ((digits[p[2]] & 0x3) << 22)
105 + (digits[p[3]] << 16)
106 + ((digits[p[4]] << 2) << 24)
107 + ((digits[p[5]] >> 4) << 24);
108 return TRUE;
109}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const int digits[]
Definition: decode.c:71
int ret

Referenced by decode_source().

◆ decode_source()

HRESULT decode_source ( WCHAR code)

Definition at line 111 of file decode.c.

112{
113 const WCHAR *src = code;
114 WCHAR *dst = code;
115
116 static const WCHAR decode_beginW[] = {'#','@','~','^'};
117 static const WCHAR decode_endW[] = {'^','#','~','@'};
118
119 while(*src) {
120 if(!wcsncmp(src, decode_beginW, ARRAY_SIZE(decode_beginW))) {
121 DWORD len, i, j=0, csum, s=0;
122
123 src += ARRAY_SIZE(decode_beginW);
124
125 if(!decode_dword(src, &len))
126 return JS_E_INVALID_CHAR;
127
128 src += 8;
129
130 for(i=0; i<len; i++) {
131 if (src[i] == '@') {
132 switch(src[++i]) {
133 case '#':
134 s += dst[j++] = '\r';
135 break;
136 case '&':
137 s += dst[j++] = '\n';
138 break;
139 case '!':
140 s += dst[j++] = '<';
141 break;
142 case '*':
143 s += dst[j++] = '>';
144 break;
145 case '$':
146 s += dst[j++] = '@';
147 break;
148 default:
149 FIXME("unescape %c\n", src[i]);
150 return E_FAIL;
151 }
152 }else if (src[i] < 128) {
153 s += dst[j] = dictionary[src[i]][pick_encoding[j%64]];
154 j++;
155 }else {
156 FIXME("Unsupported char %c\n", src[i]);
157 return E_FAIL;
158 }
159 }
160
161 src += len;
162 dst += j;
163
164 if(!decode_dword(src, &csum) || s != csum)
165 return JS_E_INVALID_CHAR;
166 src += 8;
167
168 if(wcsncmp(src, decode_endW, ARRAY_SIZE(decode_endW)))
169 return JS_E_INVALID_CHAR;
170 src += ARRAY_SIZE(decode_endW);
171 }else {
172 *dst++ = *src++;
173 }
174 }
175
176 *dst = 0;
177
178 TRACE("decoded %s\n", debugstr_w(code));
179 return S_OK;
180}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_FAIL
Definition: ddrawi.h:102
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define S_OK
Definition: intsafe.h:52
static BOOL decode_dword(const WCHAR *p, DWORD *ret)
Definition: decode.c:89
static const unsigned char pick_encoding[64]
Definition: decode.c:31
#define JS_E_INVALID_CHAR
Definition: jscript.h:542
#define debugstr_w
Definition: kernel32.h:32
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define TRACE(s)
Definition: solgame.cpp:4
Definition: inflate.c:139
Definition: ffs.h:52
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by compile_script().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ dictionary

Definition at line 37 of file decode.c.

◆ digits

const int digits[]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff}

Definition at line 71 of file decode.c.

Referenced by __get_fdigit(), __get_fdigit_or_sep(), _gcvt_s(), _Initialize_get_float(), LocaleTest::_money_put_get2(), LocaleTest::_num_put_get(), _Stl_string_to_double(), af_latin_metrics_check_digits(), complete_digits(), CRYPT_AsnDecodeGeneralizedTime(), decode_dword(), do_process_key(), format_float(), MCI_GetDWord(), msvcrt_int_to_base32(), msvcrt_int_to_base32_w(), NumPutGetTest::num_put_float(), number(), numberf(), streamout(), strntoi(), ui2ipv4(), and WPRINTF_GetLen().

◆ pick_encoding

const unsigned char pick_encoding[64]
static
Initial value:
= {
1,2,0,1,2,0,2,0,0,2,0,2,1,0,2,0,
1,0,2,0,1,1,2,0,0,2,1,0,2,0,0,2,
1,1,0,2,0,2,0,1,0,1,1,2,0,1,0,2,
1,0,2,0,1,1,2,0,0,1,1,2,0,1,0,2}

Definition at line 31 of file decode.c.

Referenced by decode_source().