23{
25
26 switch (*c)
27 {
28 case '"':
29 do
30 {
32
33 if (*c == '\\')
34 {
36 if (*c == 'n')
37 {
39 continue;
40 }
41 if (*c == '\\')
42 {
44 continue;
45 }
46 else if (*c == 't')
47 {
49 continue;
50 }
51 else if (*c == 'x')
52 {
53 char ByteString[] = "000";
54 int len = (int)strlen(ByteString);
55 int i = 0;
56 for (; i < len; i++)
57 {
60 break;
61
63 ByteString[len - 1] = *c;
64 }
65
66 if (i == 0 || i == 3)
67 {
70 return Token;
71 }
72 else
73 {
75 char num = (char)strtol(ByteString, NULL, 16);
77 }
78 }
79 else if (*c == '"')
80 {
82 continue;
83 }
84 else
85 {
88 return Token;
89 }
90 }
91 else if (*c == '"')
92 {
93 break;
94 }
95 else
96 {
98 }
99 } while (1);
100
104 return Token;
105 case '~':
106 strcpy(Token->
Value,
"~");
109 return Token;
110
111 case '+':
113 if (*c == '+')
114 {
115 strcpy(Token->
Value,
"++");
118 return Token;
119 }
120 else if (*c == '=')
121 {
122 strcpy(Token->
Value,
"+=");
125 return Token;
126 }
127 else
128 {
129 strcpy(Token->
Value,
"+");
131 return Token;
132 }
133 case '-':
135 if (*c == '-')
136 {
137 strcpy(Token->
Value,
"--");
140 return Token;
141 }
142 else if (*c == '=')
143 {
144 strcpy(Token->
Value,
"-=");
147 return Token;
148 }
149 else
150 {
151 strcpy(Token->
Value,
"-");
153 return Token;
154 }
155 case '*':
157 if (*c == '=')
158 {
159 strcpy(Token->
Value,
"*=");
162 return Token;
163 }
164 else
165 {
166 strcpy(Token->
Value,
"*");
168 return Token;
169 }
170 case '>':
172 if (*c == '>')
173 {
174 strcpy(Token->
Value,
">>");
177 return Token;
178 }
179 else if (*c == '=')
180 {
181 strcpy(Token->
Value,
">=");
184 return Token;
185 }
186 else
187 {
188 strcpy(Token->
Value,
">");
190 return Token;
191 }
192 case '<':
194 if (*c == '<')
195 {
196 strcpy(Token->
Value,
"<<");
199 return Token;
200 }
201 else if (*c == '=')
202 {
203 strcpy(Token->
Value,
"<=");
206 return Token;
207 }
208 else
209 {
210 strcpy(Token->
Value,
"<");
212 return Token;
213 }
214 case '/':
216 if (*c == '=')
217 {
218 strcpy(Token->
Value,
"/=");
221
222 return Token;
223 }
224 else if (*c == '/')
225 {
226 do
227 {
229 } while (*c != '\n' && (int)*c != EOF);
230
233 return Token;
234 }
235 else if (*c == '*')
236 {
237 do
238 {
240 if (*c == '*')
241 {
243 if (*c == '/')
244 {
247 return Token;
248 }
249 }
250 if ((int)*c == EOF)
251 break;
252 } while (1);
253
256 return Token;
257 }
258 else
259 {
260 strcpy(Token->
Value,
"/");
262 return Token;
263 }
264
265 case '=':
267 if (*c == '=')
268 {
269 strcpy(Token->
Value,
"==");
272 return Token;
273 }
274 else
275 {
276 strcpy(Token->
Value,
"=");
278 return Token;
279 }
280 case '!':
282 if (*c == '=')
283 {
284 strcpy(Token->
Value,
"!=");
287 return Token;
288 }
289 else
290 {
291 strcpy(Token->
Value,
"!");
293 return Token;
294 }
295 case '%':
296 strcpy(Token->
Value,
"%");
299 return Token;
300
301 case ',':
302 strcpy(Token->
Value,
",");
305 return Token;
306
307 case ';':
308 strcpy(Token->
Value,
";");
311 return Token;
312
313 case ':':
314 strcpy(Token->
Value,
":");
317 return Token;
318
319 case '(':
320 strcpy(Token->
Value,
"(");
323 return Token;
324 case ')':
325 strcpy(Token->
Value,
")");
328 return Token;
329 case '{':
330 strcpy(Token->
Value,
"{");
333 return Token;
334 case '}':
335 strcpy(Token->
Value,
"}");
338 return Token;
339 case '|':
341 if (*c == '|')
342 {
343 strcpy(Token->
Value,
"||");
346 return Token;
347 }
348 else
349 {
350 strcpy(Token->
Value,
"|");
352 return Token;
353 }
354 case '&':
356 if (*c == '&')
357 {
358 strcpy(Token->
Value,
"&&");
361 return Token;
362 }
363 else
364 {
365 strcpy(Token->
Value,
"&");
367 return Token;
368 }
369
370 case '^':
371 strcpy(Token->
Value,
"^");
374 return Token;
375 case '@':
378 {
380 {
383 }
385 {
387 }
388 else
389 {
391 }
392 return Token;
393 }
394
395 case '$':
398 {
399
400
401
403 {
406 }
408 {
410 }
411 else
412 {
414 }
415
416 return Token;
417 }
418
419 case '.':
423 {
424 do
425 {
428 }
while (
IsLetter(*c) ||
IsHex(*c) || (*c ==
'_') || (*c ==
'!'));
429
433
434 if (HasBang)
435 {
437 }
438
440 {
442 char str[20] = {0};
445 }
446 else
447 {
448 if (HasBang)
449 {
451 return Token;
452 }
453 else
454 {
456 {
458 }
459 else
460 {
462 }
463 }
464 }
465 }
466 else
467 {
469 return Token;
470 }
471 return Token;
472
473 case ' ':
474 case '\t':
475 strcpy(Token->
Value,
"");
478 return Token;
479 case '\n':
480 strcpy(Token->
Value,
"\n");
483 return Token;
484
485 case '0':
487 if (*c == 'x')
488 {
490 while (
IsHex(*c) || *c ==
'`')
491 {
492 if (*c != '`')
495 }
497 return Token;
498 }
499 else if (*c == 'o')
500 {
502 while (
IsOctal(*c) || *c ==
'`')
503 {
504 if (*c != '`')
507 }
509 return Token;
510 }
511 else if (*c == 'n')
512 {
515 {
516 if (*c != '`')
519 }
521 return Token;
522 }
523 else if (*c == 'y')
524 {
527 {
528 if (*c != '`')
531 }
533 return Token;
534 }
535
537 {
538 do
539 {
540 if (*c != '`')
543 }
while (
IsHex(*c) || *c ==
'`');
545 return Token;
546 }
547 else
548 {
549 strcpy(Token->
Value,
"0");
551 return Token;
552 }
553
554 case 'L':
556 {
558 do
559 {
561
562 if (*c == '\\')
563 {
565 if (*c == 'n')
566 {
568 continue;
569 }
570 if (*c == '\\')
571 {
573 continue;
574 }
575 else if (*c == 't')
576 {
578 continue;
579 }
580 else if (*c == 'x')
581 {
582 char ByteString[] = "00000";
583 int len = (int)strlen(ByteString);
584 int i = 0;
585 for (; i < len; i++)
586 {
589 break;
590
592 ByteString[len - 1] = *c;
593 }
594
595 if (i == 0 || i == 5)
596 {
599 return Token;
600 }
601 else
602 {
604 wchar_t num = (wchar_t)strtol(ByteString, NULL, 16);
606 }
607 }
608 else if (*c == '"')
609 {
611 continue;
612 }
613 else
614 {
617 return Token;
618 }
619 }
620 else if (*c == '"')
621 {
622 break;
623 }
624 else
625 {
627 }
628 } while (1);
629
633 return Token;
634 }
635
636 default:
637 if (*c >= '0' && *c <= '9')
638 {
639 do
640 {
641 if (*c != '`')
644 }
while (
IsHex(*c) || *c ==
'`');
646 return Token;
647 }
648 else if ((*c >= 'a' && *c <= 'f') || (*c >= 'A' && *c <= 'F') || (*c == '_') || (*c == '!'))
649 {
650 uint8_t NotHex = 0;
651 do
652 {
653 if (*c != '`')
655
657 if (
IsHex(*c) || *c ==
'`')
658 {
659
660 }
661 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z'))
662 {
663 NotHex = 1;
664 break;
665 }
666 else
667 {
668 break;
669 }
670 } while (1);
671 if (NotHex)
672 {
673 do
674 {
675 if (*c != '`')
678 }
while (
IsLetter(*c) ||
IsHex(*c) || (*c ==
'_') || (*c ==
'!'));
680 {
682 }
684 {
686 }
687 else
688 {
692
693 if (HasBang)
694 {
696 }
697
699 {
701 char str[20] = {0};
704 }
705 else
706 {
707 if (HasBang)
708 {
710 return Token;
711 }
712 else
713 {
715 {
717 }
718 else
719 {
721 {
723 }
724 else
725 {
727 }
728 }
729 }
730 }
731 }
732 return Token;
733 }
734 else
735 {
737 {
739 }
741 {
743 }
745 {
749
750 if (HasBang)
751 {
753 }
754
756 {
758 char str[20] = {0};
761 }
762 else
763 {
764 if (HasBang)
765 {
767 return Token;
768 }
769 else
770 {
772 {
774 }
775 else
776 {
778 {
780 }
781 else
782 {
784 }
785 }
786 }
787 }
788 }
789 else
790 {
792 }
793 return Token;
794 }
795 }
796 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z') || (*c == '_') || (*c == '!'))
797 {
798 do
799 {
800 if (*c != '`')
803 }
while (
IsLetter(*c) ||
IsHex(*c) || (*c ==
'_') || (*c ==
'!'));
805 {
807 }
809 {
811 }
812 else
813 {
817
818 if (HasBang)
819 {
821 }
822
824 {
826 char str[20] = {0};
829 }
830 else
831 {
832 if (HasBang)
833 {
835 return Token;
836 }
837 else
838 {
840 {
842 }
843 else
844 {
846 {
848 }
849 else
850 {
852 }
853 }
854 }
855 }
856 }
857 return Token;
858 }
859
862 return Token;
863 }
864 return Token;
865}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
UINT64 Address
Definition HyperDbgScriptImports.h:67
PBOOLEAN WasFound
Definition HyperDbgScriptImports.h:45
#define INVALID
Definition ScriptEngineCommonDefinitions.h:96
char IsId(char *str)
eck if string is Id or not
Definition scanner.c:1006
char IsRegister(char *str)
Check if string is register or not.
Definition scanner.c:992
char IsKeyword(char *str)
Check whether a string is a keyword or not.
Definition scanner.c:963
char sgetc(char *str)
returns last character of string
Definition scanner.c:941
unsigned int InputIdx
number of read characters from input
Definition scanner.h:30
char IsUnderscore(char c)
Checks whether input char is underscore (_) or not.
Definition common.c:572
char IsLetter(char c)
Checks whether input char belongs to alphabet set or not.
Definition common.c:555
void AppendWchar(PTOKEN Token, wchar_t c)
Appends wchar_t to the token value.
Definition common.c:272
void RotateLeftStringOnce(char *str)
Rotate a character array to the left by one time.
Definition common.c:1524
void AppendByte(PTOKEN Token, char c)
Appends char to the token value.
Definition common.c:231
char IsOctal(char c)
Checks whether input char belongs to octal digit-set or not.
Definition common.c:606
void RemoveToken(PTOKEN *Token)
Removes allocated memory of a token.
Definition common.c:104
PTOKEN NewUnknownToken()
Allocates a new token.
Definition common.c:20
char IsBinary(char c)
Checks whether input char belongs to binary digit-set or not.
Definition common.c:589
PTOKEN NewToken(TOKEN_TYPE Type, char *Value)
Definition common.c:60
char IsDecimal(char c)
Checks whether input char belongs to decimal digit-set or not.
Definition common.c:540
char IsHex(char c)
Checks whether input char belongs to hexadecimal digit-set or not.
Definition common.c:525
int GetFunctionParameterIdentifier(PTOKEN Token)
Definition script-engine.c:3222
UINT64 ScriptEngineConvertNameToAddress(const char *FunctionOrVariableName, PBOOLEAN WasFound)
Converts name to address.
Definition script-engine.c:33
unsigned long long int RegisterToInt(char *str)
Converts register string to integer.
Definition script-engine.c:2888
int GetGlobalIdentifierVal(PTOKEN Token)
Returns the integer assigned to global variable.
Definition script-engine.c:3138
int GetLocalIdentifierVal(PTOKEN Token)
Returns the integer assigned to local variable.
Definition script-engine.c:3159
unsigned long long int PseudoRegToInt(char *str)
Converts pseudo register string to integer.
Definition script-engine.c:2989
read tokens from input stored in this structure
Definition common.h:72
unsigned int Len
Definition common.h:75
char * Value
Definition common.h:74
TOKEN_TYPE Type
Definition common.h:73