private static int ParseMemRegB(ref byte[] arg1, PluginScript func, int x, int off) { int y = 0; while (y < func.pbA.Length && func.pbA[y].bName != func.funcCalls[x].argNames[off]) { y++; } if (y == func.pbA.Length) { arg1 = BitConverter.GetBytes(misc.ParseVal(func.funcCalls[x].argNames[off], 1)); } else { arg1 = func.pbA[y].byteA; } return(y); }
private static int ParseMemRegU(ref ulong arg1, PluginScript func, int x, int off) { int y = 0; while (y < func.pulA.Length && func.pulA[y].ulName != func.funcCalls[x].argNames[off]) { y++; } if (y == func.pulA.Length) { arg1 = (ulong)misc.ParseVal(func.funcCalls[x].argNames[off], 1); } else { arg1 = func.pulA[y].ulongA; } return(y); }
private static void RunFunc(ref PluginScript func) { ulong arg1 = 0; byte[] arg2 = null; //int y = 0; for (int x = 0; x < func.funcCalls.Length; x++) { switch (func.funcCalls[x].fName) { case "SetVar": //Check if the the destination variable is defined string[] strArr = func.funcCalls[x].argNames[0].Split(' '); string destVar = strArr[0]; int found = 0; int z = 0; for (z = 0; z < func.pbA.Length; z++) { if (destVar == func.pbA[z].bName) { found = 1; break; } } if (found == 0) { for (z = 0; z < func.pulA.Length; z++) { if (destVar == func.pulA[z].ulName) { found = 2; break; } } } //Variable is defined if (found != 0) { /* PluginScript temp = new PluginScript(); temp.pbA = new PluginByteA[0]; temp.pulA = new PluginULongA[0]; ParseScriptType(ref temp, strArr, func.funcCalls[x].argNames[0]); RunFunc(ref temp); if (found == 1) func.pbA[z].byteA = temp.pbA[0].byteA; else func.pulA[z].ulongA = temp.pulA[0].ulongA; */ } break; case "SetMem": ParseMemRegU(ref arg1, func, x, 0); ParseMemRegB(ref arg2, func, x, 1); Form1.apiSetMem(arg1, arg2); break; case "GetMem": int b = ParseMemRegU(ref arg1, func, x, 0); ParseMemRegB(ref arg2, func, x, 1); Form1.apiGetMem(arg1, ref arg2); func.pbA[b].byteA = arg2; break; case "GetMemU": ulong gmuArg2 = 0; ParseMemRegU(ref arg1, func, x, 0); int e = ParseMemRegU(ref gmuArg2, func, x, 1); int size = 0; if (func.funcCalls[x].argNames[2].IndexOf("0x") >= 0) size = Convert.ToInt32(func.funcCalls[x].argNames[2], 16); else size = Convert.ToInt32(func.funcCalls[x].argNames[2], 10); Form1.apiGetMemU(arg1, ref gmuArg2, size); func.pulA[e].ulongA = gmuArg2; break; case "Add": case "Div": case "Mult": case "Sub": ulong mathArg2 = 0; int off = ParseMemRegU(ref mathArg2, func, x, 0); ParseMemRegU(ref arg1, func, x, 1); ParseMemRegU(ref mathArg2, func, x, 2); switch (func.funcCalls[x].fName) { case "Add": func.pulA[off].ulongA = arg1 + mathArg2; break; case "Div": func.pulA[off].ulongA = arg1 / mathArg2; break; case "Mult": func.pulA[off].ulongA = arg1 * mathArg2; break; case "Sub": func.pulA[off].ulongA = arg1 - mathArg2; break; } break; } } }
private static void ParseScriptType(ref PluginScript pstFunc, string[] strArr, string line) { int ind = 0; int x = 0; switch (strArr[0]) { case "byte[]": //Byte Array ind = pstFunc.pbA.Length; Array.Resize(ref pstFunc.pbA, pstFunc.pbA.Length + 1); pstFunc.pbA[ind].byteA = StringBAToBA(line); pstFunc.pbA[ind].bName = strArr[1]; break; case "ulong": //Ulong ind = pstFunc.pulA.Length; Array.Resize(ref pstFunc.pulA, pstFunc.pulA.Length + 1); if (strArr[3].IndexOf("0x") >= 0) pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 16); else pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 10); pstFunc.pulA[ind].ulName = strArr[1]; break; case "Add": //Adds arg2 with arg3 and stores the result in arg1 case "Div": //Divides arg2 by arg3 and stores the result in arg1 case "Mult": //Multiplies arg2 with arg3 and stores the result in arg1 case "Sub": //Subtracts arg3 from arg2 and stores the result in arg1 case "GetMemU": //Get memory and return the ulong of it case "GetMem": //Get memory case "SetMem": //Set memory ind = pstFunc.funcCalls.Length; Array.Resize(ref pstFunc.funcCalls, pstFunc.funcCalls.Length + 1); pstFunc.funcCalls[ind].fName = strArr[0]; pstFunc.funcCalls[ind].argNames = new string[strArr.Length - 1]; for (x = 0; x < (strArr.Length - 1); x++) pstFunc.funcCalls[ind].argNames[x] = strArr[x + 1].Replace(",", ""); break; default: //Sets a variable to something if (strArr.Length >= 4 && strArr[3].IndexOf("byte[") >= 0) { ind = pstFunc.pbA.Length; Array.Resize(ref pstFunc.pbA, pstFunc.pbA.Length + 1); pstFunc.pbA[ind].byteA = StringBAToBA(line); pstFunc.pbA[ind].bName = strArr[1]; } else if (strArr.Length >= 4 && strArr[3].IndexOf("ulong") >= 0) { ind = pstFunc.pulA.Length; Array.Resize(ref pstFunc.pulA, pstFunc.pulA.Length + 1); if (strArr[3].IndexOf("0x") >= 0) pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 16); else pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 10); pstFunc.pulA[ind].ulName = strArr[1]; } else if (strArr.Length >= 3 && pstFunc.funcCalls != null) { if (strArr[1] == "=") { ind = pstFunc.funcCalls.Length; Array.Resize(ref pstFunc.funcCalls, pstFunc.funcCalls.Length + 1); pstFunc.funcCalls[ind].fName = "SetVar"; pstFunc.funcCalls[ind].argNames = new string[1]; pstFunc.funcCalls[ind].argNames[0] = line.Trim(); } } //else if (pstFunc.funcCalls != null) // break; } }
private static int ParseMemRegU(ref ulong arg1, PluginScript func, int x, int off) { int y = 0; while (y < func.pulA.Length && func.pulA[y].ulName != func.funcCalls[x].argNames[off]) y++; if (y == func.pulA.Length) arg1 = (ulong)misc.ParseVal(func.funcCalls[x].argNames[off], 1); else arg1 = func.pulA[y].ulongA; return y; }
private static int ParseMemRegB(ref byte[] arg1, PluginScript func, int x, int off) { int y = 0; while (y < func.pbA.Length && func.pbA[y].bName != func.funcCalls[x].argNames[off]) y++; if (y == func.pbA.Length) arg1 = BitConverter.GetBytes(misc.ParseVal(func.funcCalls[x].argNames[off], 1)); else arg1 = func.pbA[y].byteA; return y; }
private static void RunFunc(ref PluginScript func) { ulong arg1 = 0; byte[] arg2 = null; //int y = 0; for (int x = 0; x < func.funcCalls.Length; x++) { switch (func.funcCalls[x].fName) { case "SetVar": //Check if the the destination variable is defined string[] strArr = func.funcCalls[x].argNames[0].Split(' '); string destVar = strArr[0]; int found = 0; int z = 0; for (z = 0; z < func.pbA.Length; z++) { if (destVar == func.pbA[z].bName) { found = 1; break; } } if (found == 0) { for (z = 0; z < func.pulA.Length; z++) { if (destVar == func.pulA[z].ulName) { found = 2; break; } } } //Variable is defined if (found != 0) { /* * PluginScript temp = new PluginScript(); * temp.pbA = new PluginByteA[0]; * temp.pulA = new PluginULongA[0]; * ParseScriptType(ref temp, strArr, func.funcCalls[x].argNames[0]); * RunFunc(ref temp); * if (found == 1) * func.pbA[z].byteA = temp.pbA[0].byteA; * else * func.pulA[z].ulongA = temp.pulA[0].ulongA; */ } break; case "SetMem": ParseMemRegU(ref arg1, func, x, 0); ParseMemRegB(ref arg2, func, x, 1); Form1.apiSetMem(arg1, arg2); break; case "GetMem": int b = ParseMemRegU(ref arg1, func, x, 0); ParseMemRegB(ref arg2, func, x, 1); Form1.apiGetMem(arg1, ref arg2); func.pbA[b].byteA = arg2; break; case "GetMemU": ulong gmuArg2 = 0; ParseMemRegU(ref arg1, func, x, 0); int e = ParseMemRegU(ref gmuArg2, func, x, 1); int size = 0; if (func.funcCalls[x].argNames[2].IndexOf("0x") >= 0) { size = Convert.ToInt32(func.funcCalls[x].argNames[2], 16); } else { size = Convert.ToInt32(func.funcCalls[x].argNames[2], 10); } Form1.apiGetMemU(arg1, ref gmuArg2, size); func.pulA[e].ulongA = gmuArg2; break; case "Add": case "Div": case "Mult": case "Sub": ulong mathArg2 = 0; int off = ParseMemRegU(ref mathArg2, func, x, 0); ParseMemRegU(ref arg1, func, x, 1); ParseMemRegU(ref mathArg2, func, x, 2); switch (func.funcCalls[x].fName) { case "Add": func.pulA[off].ulongA = arg1 + mathArg2; break; case "Div": func.pulA[off].ulongA = arg1 / mathArg2; break; case "Mult": func.pulA[off].ulongA = arg1 * mathArg2; break; case "Sub": func.pulA[off].ulongA = arg1 - mathArg2; break; } break; } } }
private static void ParseScriptType(ref PluginScript pstFunc, string[] strArr, string line) { int ind = 0; int x = 0; switch (strArr[0]) { case "byte[]": //Byte Array ind = pstFunc.pbA.Length; Array.Resize(ref pstFunc.pbA, pstFunc.pbA.Length + 1); pstFunc.pbA[ind].byteA = StringBAToBA(line); pstFunc.pbA[ind].bName = strArr[1]; break; case "ulong": //Ulong ind = pstFunc.pulA.Length; Array.Resize(ref pstFunc.pulA, pstFunc.pulA.Length + 1); if (strArr[3].IndexOf("0x") >= 0) { pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 16); } else { pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 10); } pstFunc.pulA[ind].ulName = strArr[1]; break; case "Add": //Adds arg2 with arg3 and stores the result in arg1 case "Div": //Divides arg2 by arg3 and stores the result in arg1 case "Mult": //Multiplies arg2 with arg3 and stores the result in arg1 case "Sub": //Subtracts arg3 from arg2 and stores the result in arg1 case "GetMemU": //Get memory and return the ulong of it case "GetMem": //Get memory case "SetMem": //Set memory ind = pstFunc.funcCalls.Length; Array.Resize(ref pstFunc.funcCalls, pstFunc.funcCalls.Length + 1); pstFunc.funcCalls[ind].fName = strArr[0]; pstFunc.funcCalls[ind].argNames = new string[strArr.Length - 1]; for (x = 0; x < (strArr.Length - 1); x++) { pstFunc.funcCalls[ind].argNames[x] = strArr[x + 1].Replace(",", ""); } break; default: //Sets a variable to something if (strArr.Length >= 4 && strArr[3].IndexOf("byte[") >= 0) { ind = pstFunc.pbA.Length; Array.Resize(ref pstFunc.pbA, pstFunc.pbA.Length + 1); pstFunc.pbA[ind].byteA = StringBAToBA(line); pstFunc.pbA[ind].bName = strArr[1]; } else if (strArr.Length >= 4 && strArr[3].IndexOf("ulong") >= 0) { ind = pstFunc.pulA.Length; Array.Resize(ref pstFunc.pulA, pstFunc.pulA.Length + 1); if (strArr[3].IndexOf("0x") >= 0) { pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 16); } else { pstFunc.pulA[ind].ulongA = (ulong)Convert.ToUInt64(strArr[3].Replace(";", ""), 10); } pstFunc.pulA[ind].ulName = strArr[1]; } else if (strArr.Length >= 3 && pstFunc.funcCalls != null) { if (strArr[1] == "=") { ind = pstFunc.funcCalls.Length; Array.Resize(ref pstFunc.funcCalls, pstFunc.funcCalls.Length + 1); pstFunc.funcCalls[ind].fName = "SetVar"; pstFunc.funcCalls[ind].argNames = new string[1]; pstFunc.funcCalls[ind].argNames[0] = line.Trim(); } } //else if (pstFunc.funcCalls != null) // break; } }