Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

Commit 74713b8

Browse files
committed
- add replaceValueBetweenBrackets used in cases $x[$z[3]] nasted variables (array)
-add replaceValueBetweenBrackets to StrAnalyze. -add ResizeArray, GetArraySize, Write2File ,InputBox -StrAnalyze check in cases the input is null. - put return before DbgCmdExecDirect. - add Function returnSpaces to return n spaces as string . - add feature to str2Hex ( if the input is int it will converted to hex) - fix ForWard for missing spaces . - remove 0x from return str type GetArgValueByType .
1 parent 4f46f99 commit 74713b8

File tree

8 files changed

+518
-154
lines changed

8 files changed

+518
-154
lines changed

AdvancedScript/HelperFunctions.cpp

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ System::Void GetArg(String^ input, Generic::List<String^>^% arguments, bool brac
8585
}
8686
}
8787
else {
88+
if ( (temp != "") && (temp != " ") ){
8889
arguments->Add(temp->Trim());
8990
temp = "";
91+
}
9092
}
9193
}
9294
}
@@ -204,48 +206,51 @@ String^ charPTR2String(char* input) {
204206

205207
}
206208

207-
String^ str2Hex(String^ input) {
209+
/// it return hex from string if avalible
210+
/// in case the input value is int it will be converted to hex
211+
///
212+
String^ str2Hex(String^ input,VarType inputType_, bool addx0) {
208213
String^ intValue;
209-
if (input->StartsWith("0x")) {
214+
if (input->StartsWith("0x")) { /// it mean its hex value
210215
if (CheckHexIsValid(input->Substring(2, input->Length-2), intValue) > 0) {
211-
return input;
216+
if (addx0)
217+
return input;
218+
else
219+
return input->Substring(2, input->Length - 2);
212220
}
213221
}
214222
else
215223
{
216-
217-
if (CheckHexIsValid(input, intValue) > 0) {
218-
return "0x" + input;
219-
}
220-
/*if (Information::IsNumeric(input)) {
221-
return duint2Hex(Str2duint((input)));
222-
}*/
223-
/*int check_ = CheckHexIsValid(input, intValue);
224+
int check_ = CheckHexIsValid(input, intValue);
224225
switch (check_)
225-
{
226-
case 0: {
227-
break;
228-
}
229-
case 1: {
230-
return "0x" + input;
226+
{
227+
case 1: { /// the value is numaric so we don't know if it's hex or int so user define it
228+
if (inputType_ == VarType::int_) { /// the input value is int not hex value
229+
if (addx0)
230+
return "0x" + duint2Hex(Str2duint(input));
231+
else
232+
return duint2Hex(Str2duint(input));
233+
}
234+
else /// the input value is hex
235+
{
236+
if (addx0)
237+
return input;
238+
else
239+
return "0x" + input;
240+
}
241+
231242
}
232-
case 2: { /// it's hex value
233-
return "0x" + input;
243+
case 2: { /// the value is valid hex
244+
if (addx0)
245+
return input;
246+
else
247+
return "0x" + input;
234248
}
235249
default:
236-
break;
237-
}*/
238-
/*if (Information::IsNumeric(input)) {
239-
return duint2Hex(Str2duint((input)));
240-
}
241-
else
242-
{
243-
String^ intValue;
244-
int check_ = CheckHexIsValid(input, intValue);
245-
246-
}*/
250+
return "NULL /";
251+
}
247252
}
248-
return "NULL/ ";
253+
return "NULL/";
249254
}
250255

251256
duint Hex2duint(String^ input_) {
@@ -337,6 +342,18 @@ String^ reMoveSpaces(String^ input_) {
337342
return temp;
338343
}
339344

345+
int Str2int(String^ input) { /// we need it just in case we need an int just
346+
int result;
347+
if (int::TryParse(input, result)) {
348+
return result;
349+
}
350+
else {
351+
_plugin_logprintf("can't get int from argument");
352+
return -1;
353+
}
354+
355+
}
356+
340357
duint Str2duint(String^ input_) {
341358
#ifdef _WIN64
342359
duint result;

AdvancedScript/HelperFunctions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ String^ charPTR2String(char* input);
1414
String^ ClearSlash_etc(String^ input);
1515
String^ GetAPIName_LableWay(duint Addr_);
1616
duint Str2duint(String^ input_);
17+
int Str2int(String^ input);
1718
duint Hex2duint(String^ input_);
1819
String^ str2Asci(String^ input);
1920
String^ ReplaceAtIndex(String^ OriginalString, String^ oldValue, String^ newValue);
2021
String^ AddZero2Addr(String^ input);
2122

22-
String^ str2Hex(String^ input);
23+
2324
bool IsAllSpaces(String^ input_);
2425

2526
template<class T>
@@ -42,12 +43,15 @@ enum VarType
4243
int_,
4344
str,
4445
array_,
46+
hex,
4547
};
4648

4749
VarType GetVarType(String^ vartype);
4850
Generic::List<String^>^ GetClipBoard();
4951
void SetClipBoard(String^ input);
5052

53+
String^ str2Hex(String^ input, VarType inputType_,bool addx0);
54+
5155
System::Void GetArg(String^ input, Generic::List<String^>^% arguments, bool brackets=false);
5256

5357
///////////////////////////////////////////////////////////////////Helper Functions

AdvancedScript/Parser.cpp

Lines changed: 111 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,30 @@ String^ findVarValue(String^ input, VarType retAsVartype, String^% VarString) {
101101
return "NULL/ something go wrong in resolve index";
102102
}
103103
if (Information::IsNumeric(ArrayIndexValue)) { /// if it's resolved as int value then we used it
104+
if ((int)Str2duint(ArrayIndexValue) > ScriptFunList::VarList[indexofVar]->arrayLength -1) { // -1 because array begin from 0
105+
return "NULL/ value beggier than array index";
106+
}
104107
if (retAsVartype == VarType::str) {/// if we need ret var value as string it will back as str no need to change the value
105108
return ScriptFunList::VarList[indexofVar]->varvalue[(int)Str2duint(ArrayIndexValue)];
106109
}
107110
else //// but if the retAsVartype (ret value of the var) is int so we need to resolve it as int because array hold string
108111
{
109112
String^ intValue; /// we ret the int value from the array item
113+
if (ScriptFunList::VarList[indexofVar]->varvalue[(int)Str2duint(ArrayIndexValue)] == nullptr) {
114+
return "NULL/ no value for this cell in the array";
115+
}
110116
if (CheckHexIsValid(ScriptFunList::VarList[indexofVar]->varvalue[(int)Str2duint(ArrayIndexValue)], intValue) == 0) { /// /// check the value of the vra if it's not Numeric then if could be Hex
111117
return "NULL/ array value is not Numeric";/// that something wrong in the index of the array
112118
}
113119
else {
114-
return intValue;
120+
return intValue;
115121
}
116122
}
117123
}
118124
String^ intValue;
125+
if ((int)Str2duint(ArrayIndexValue) > ScriptFunList::VarList[indexofVar]->arrayLength - 1) { // -1 because array begin from 0
126+
return "NULL/ value beggier than array index";
127+
}
119128
if (CheckHexIsValid(ArrayIndexValue, intValue) == 0) { /// /// check if array index is not Numeric then if could be Hex
120129
return "NULL/ array index is not Numeric";/// that something wrong in the index of the array
121130
}
@@ -237,13 +246,13 @@ String^ ForWard(String^ input, int tokenindex, String^% VarString) { /// tokenin
237246
{
238247
temp = temp->Substring(tokenindex, temp->Length - tokenindex); // get value after token
239248
int i1 = 0;
240-
if (i1 + 1 < temp->Length) {
241-
while (temp->Substring(i1 + 1, 1) == " ") /// count how many spaces
242-
{
243-
VarString = " " + VarString;
244-
if (i1 + 1 > input->Length) { break; } // if we reach the begin of the string
245-
i1 += 1;
246-
}
249+
if (i1 + 1 < temp->Length) {
250+
while (temp->Substring(i1 + 1, 1) == " ") /// count how many spaces
251+
{
252+
VarString = " " + VarString;
253+
if (i1 + 1 > input->Length) { break; } // if we reach the begin of the string
254+
i1 += 1;
255+
}
247256
}
248257
temp = temp->Trim(); /// remove all spaces after token like >> 55 + 10
249258
int i = 0;
@@ -254,7 +263,7 @@ String^ ForWard(String^ input, int tokenindex, String^% VarString) { /// tokenin
254263
if (i + 1 > temp->Length) { break; } // if we reach the begin of the string
255264
}
256265
if (value_ == "") {
257-
value_ = temp;
266+
value_ = temp;
258267
}
259268

260269
VarString = value_ + VarString;
@@ -709,11 +718,12 @@ String^ GetArgValueByType(String^ argument, VarType type_) { /// return value b
709718
}
710719
else {
711720
/// as it's str we return the int value to hex value
712-
String^ oldv="";
713-
if (CheckHexIsValid(tempInput, oldv)) {
714-
if (!tempInput->StartsWith("0x")) {
721+
String^ oldv = "";
722+
if (CheckHexIsValid(tempInput, oldv)) {
723+
/*if (!tempInput->StartsWith("0x")) {
715724
tempInput = "0x" + tempInput->Trim();
716-
}
725+
}*/
726+
tempInput = tempInput->Trim();
717727
}
718728
argument = ReplaceAtIndex(argument, oldValue, tempInput);
719729
}
@@ -730,16 +740,90 @@ String^ GetArgValueByType(String^ argument, VarType type_) { /// return value b
730740
return argument;
731741
}
732742

743+
String^ returnSpaces(int SpaceNum) { /// used for replaceValueBetweenBrackets to fill the gaps with spaces
744+
String^ temp;
745+
for (int i = 0; i < SpaceNum; i++)
746+
{
747+
temp = temp + " ";
748+
}
749+
return temp;
750+
}
751+
752+
/// used in cases $x[$z[3]] nasted variables (array)
753+
String^ replaceValueBetweenBrackets(String^ input_) {
754+
String^ tempstr;
755+
if ((input_->Contains("[")) && (input_->Contains("]"))) {
756+
/// setx $c,$x[$z[3]]
757+
String^ Tinput = input_;
758+
int beginB = input_->LastIndexOf("[") + 1;
759+
tempstr = input_->Substring(beginB, input_->Length - beginB);
760+
int EndB = tempstr->IndexOf("]");
761+
tempstr = tempstr->Substring(0, EndB);
762+
763+
while (beginB > 0)
764+
{
765+
if (tempstr->Trim()->StartsWith("$")) {
766+
String^ newValue = StrAnalyze(tempstr, VarType::int_); /// we get int value after Analyze so we should make it hex
767+
if (newValue->Contains("NULL/")) {
768+
return "NULL/";
769+
}
770+
if ((Information::IsNumeric(newValue))) {
771+
input_ = ReplaceAtIndex(input_, tempstr, str2Hex(newValue,VarType::int_,false));
772+
Tinput = ReplaceAtIndex(Tinput, "[" + tempstr + "]", returnSpaces((Tinput, "[" + tempstr + "]")->Length));
773+
}
774+
}
775+
else
776+
{
777+
Tinput = ReplaceAtIndex(Tinput, "[" + tempstr + "]", returnSpaces((Tinput, "[" + tempstr + "]")->Length));
778+
}
779+
int beginB = Tinput->LastIndexOf("[") + 1;
780+
if (beginB <= 0)
781+
break;
782+
tempstr = Tinput->Substring(beginB, Tinput->Length - beginB);
783+
int EndB = tempstr->IndexOf("]");
784+
tempstr = input_->Substring(beginB, EndB);
785+
786+
}
787+
}
788+
//while ((input_->Contains("[")) && (input_->Contains("]")))
789+
//{
790+
// /// setx $c,$x[$z[3]]
791+
// int beginB = input_->LastIndexOf("[")+1; //
792+
// String^ tempstr = input_->Substring(beginB, input_->Length - beginB);
793+
// int EndB = tempstr->IndexOf("]");
794+
// tempstr = tempstr->Substring(0, EndB); //
795+
// String^ newValue = StrAnalyze(tempstr, VarType::int_);
796+
// if ((!Information::IsNumeric(newValue))) {
797+
// return "NULL/";
798+
// }
799+
// else
800+
// {
801+
// input_=ReplaceAtIndex(input_, tempstr, newValue);
802+
// }
803+
804+
//}
805+
806+
return input_;
807+
}
808+
733809
String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value should be int , other wise it would be str and we add str to gather
734810
array <String^>^ breaks = { "*" ,"/" ,"+" ,"-" ,"$" ," " , "{" , "}" , "\"" };
735811
array <String^>^ token_ = { "*" ,"/" ,"+" ,"-" };
736812
array <String^>^ vars_ = { "$" ," " , "{" , "\"" };
737813
Generic::List <String^>^ StrHolderList = gcnew Generic::List <String^>;
738-
String^ temp ="";
814+
String^ temp = "";
739815
int begin_ = 0;
740816
if (input == "") {
741817
return input;
742818
}
819+
/// in cases like this
820+
/// setx $c,$x[$z[3]] here we have nested
821+
String^ retvalue = replaceValueBetweenBrackets(input);
822+
if (!retvalue->Contains("NULL/"))
823+
input = retvalue;
824+
else
825+
return "NULL/";
826+
///
743827
if (Array::IndexOf(vars_, input->Substring(0, 1)) >= 0) {/// if (i=0) begin with vars defenations this we need to add it
744828

745829
if (input->Substring(0, 1) == " ") { /// in case calc str or array we need spaces
@@ -803,7 +887,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
803887
}
804888

805889
}
806-
890+
807891
for (int i = begin_; i < input->Length; i++)
808892
{
809893
if (Array::IndexOf(breaks, input->Substring(i, 1)) < 0) {
@@ -891,7 +975,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
891975
}
892976
}
893977
if (Array::IndexOf(token_, input->Substring(i, 1)) >= 0) {
894-
if ((temp != "")|| ((temp == nullptr)) ) {
978+
if ((temp != "") || ((temp == nullptr))) {
895979
StrHolderList->Add(temp);
896980
}
897981
StrHolderList->Add(input->Substring(i, 1));
@@ -904,7 +988,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
904988
temp = "";
905989
}
906990
}
907-
if (temp->Length ==1) { // case enter 1 special char
991+
if (temp->Length == 1) { // case enter 1 special char
908992
StrHolderList->Add(temp);
909993
temp = ""; /// rest temp
910994
}
@@ -935,16 +1019,16 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
9351019
case str:
9361020
{
9371021
for (int i = 0; i < StrHolderList->Count; i++)
938-
{
939-
if (Array::IndexOf(token_, StrHolderList[i]) < 0) {
940-
StrHolderList[i] = GetArgValueByType(StrHolderList[i], VarType::str);
941-
StrHolder = StrHolder + StrHolderList[i];
942-
}
943-
else
944-
{
945-
StrHolder = StrHolder + StrHolderList[i];
946-
}
947-
1022+
{
1023+
if (Array::IndexOf(token_, StrHolderList[i]) < 0) {
1024+
StrHolderList[i] = GetArgValueByType(StrHolderList[i], VarType::str);
1025+
StrHolder = StrHolder + StrHolderList[i];
1026+
}
1027+
else
1028+
{
1029+
StrHolder = StrHolder + StrHolderList[i];
1030+
}
1031+
9481032
}
9491033
break;
9501034
}

AdvancedScript/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ String^ resolveString(String^ input, int% commaCount);
1414
String^ argumentValue(String^ argument, String^% OldValue_);
1515
String^ GetArgValueByType(String^ argument, VarType type_);
1616
String^ StrAnalyze(String^ input, VarType type_);
17-
17+
String^ returnSpaces(int SpaceNum);
18+
String^ replaceValueBetweenBrackets(String^ input_);
1819
//script test
1920

2021
//Logx memdump(76FA0000, 50)

0 commit comments

Comments
 (0)