public override EVariable Exec(EScope scope) { EVariable toUpdate = scope.Get(variable.ToString()); toUpdate.Assign(value.Solve(scope)); return(toUpdate); }
/// <summary>Called when the trainer needs to be detached from the game's process.</summary> private void DetachFromGame() { // Detach from the target process if (GameMemoryIO.IsAttached()) { // If the game's process is still running, all cheats must be disabled if (GameMemoryIO.TargetProcess.HasExited == false) { foreach (ECheat curCheat in Enum.GetValues(typeof(ECheat))) { SetCheatEnabled(curCheat, false); } } // Release injected memory, cleanup and detach GameMemoryInjector.ResetAllocatedMemoryData(); GameMemoryIO.DetachFromProcess(); } // Reset all of the values of the DependencyProperty objects which represent injected variables foreach (KeyValuePair <DependencyProperty, EVariable> curPair in sm_dependencyPropertyToInjectedVariable) { // Retrieve the initial value of the injected variable DependencyProperty varDepProp = curPair.Key; EVariable varID = curPair.Value; FieldInfo enumeratorInfo = typeof(EVariable).GetField(varID.ToString()); VariableDefinitionAttribute varDef = enumeratorInfo.GetCustomAttribute <VariableDefinitionAttribute>(); // Reset the variable back to its initial value this.SetValue(varDepProp, varDef.InitialValue); } }
public override EVariable Solve(EScope scope) { EVariable firstS = first.Solve(scope); EVariable secondS = second.Solve(scope); return(op.Solve(firstS, secondS)); }
public override EVariable Solve(EScope scope) { EFunction toRun = scope.GetFunction(callFunc.ToString()); EVariable output = toRun.Exec(scope, arguments); return(output); }
public static EVariable Calc(ESOSimpleType type, EVariable a, EVariable b) { ESOSimpleTypeObject selected = dict[type]; if (selected == null) { throw new ELangException("Invalid operation: " + type.ToString()); } return(selected.Calc(a, b)); }
public void Set(string name, EVariable variable) { try { variables.Add(name, variable); } catch { throw new ELangException("The variable " + name + " has already been declared"); } }
/// <summary>Checks all of the user's configurations on the trainer's UI, and updates the values of each necessary /// variable in the memory injected in the game's memory.</summary> private void UpdateBitmasksInGameMemory() { // Try to find all checkboxes which indicate which cheat is enabled for which team Queue <DependencyObject> objectsToProcess = new Queue <DependencyObject>(); objectsToProcess.Enqueue(m_hacksGroupBox); Dictionary <EVariable, UInt32> newBitmaskValues = new Dictionary <EVariable, uint>(); while (objectsToProcess.Count > 0) { // Look for checkboxes... DependencyObject curObject = objectsToProcess.Dequeue(); if (curObject is CheckBox) { // ...but only checkboxes whose Tag attributes indicate that they're associated with injection variables CheckBox curCheckBox = (CheckBox)curObject; if (curCheckBox.Tag is EVariable) { EVariable associatedVariable = (EVariable)curCheckBox.Tag; int associatedTeamNumber = Grid.GetColumn(curCheckBox) - 1; UInt32 associatedTeamMask = (UInt32)(1 << associatedTeamNumber); if (newBitmaskValues.ContainsKey(associatedVariable) == false) { newBitmaskValues[associatedVariable] = 0; } if (curCheckBox.IsChecked == true) { newBitmaskValues[associatedVariable] |= associatedTeamMask; } else { newBitmaskValues[associatedVariable] &= ~associatedTeamMask; } } } // Also look for checkboxes in children for (int c = VisualTreeHelper.GetChildrenCount(curObject) - 1; c >= 0; c--) { objectsToProcess.Enqueue(VisualTreeHelper.GetChild(curObject, c)); } } // Write all values foreach (KeyValuePair <EVariable, UInt32> curKeyPair in newBitmaskValues) { GameMemoryInjector.WriteVariableValue(curKeyPair.Key, curKeyPair.Value); } }
/// <summary> /// Called when one of the DependencyProperty objects from the #MainWindow has its value changed. /// This method automatically updates the value of the corresponding injected variable into the game's process' memory space. /// </summary> /// <param name="depObj">A reference to the DependencyObject which owns the changed DependencyProperty. This parameter is /// effectivelly a reference to the #MainWindow object.</param> /// <param name="args">Contains data related to the event which changed the DependencyProperty's value.</param> private static void InjectedVariableValueChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args) { // If the trainer is attached to the game, update the value of the variable into the game's memory space MainWindow mainWnd = (MainWindow)App.Current.MainWindow; if (mainWnd.GameMemoryIO.Attached) { // Retrieve the information we need to update the game's memory... EVariable varID = sm_dependencyPropertyToInjectedVariable[args.Property]; IntPtr varAddressInGame = mainWnd.GameMemoryInjector.GetInjectedVariableAddress(varID); // Update the game's memory mainWnd.GameMemoryIO.WriteToTarget(varAddressInGame, args.NewValue); } }
private EVariable Calc(EVariable a, EVariable b) { EVariable convA = a; EVariable convB = b; if (input.HasValue) { EType inputType = input.Value; convA = a.Convert(inputType); convB = b.Convert(inputType); } dynamic convC = calc(convA.Get(), convB.Get()); return(EVariable.New(output).Set(convC)); }
public override EVariable Solve(EVariable first, EVariable second) { switch (type) { case AssignType.Assign: second.Assign(first); return(second); case AssignType.Move: EVariable temp = second.Clone(); second.Assign(first); return(temp); default: throw new ELangException("Invalid Assigntype: " + type); } }
public override EVariable Exec(EScope scope) { EVariable newVar = new EVVoid(); foreach (EWord variable in variables) { newVar = EVariable.New(type); scope.Set(variable.ToString(), newVar); } if (assignOperations != null) { foreach (EAssignOperation assignOp in assignOperations) { assignOp.Exec(scope); } } return(newVar); }
public override EVariable Exec(EScope scope, ESolvable[] args) { // TODO: output type casting if (args.Length != arguments.Length) { throw new ELangException("Wrong amount of args for function " + name); } EScope lowerScope = scope.GetChild(); for (int i = 0; i < arguments.Length; i++) { string argname = arguments[i].GetVariable().ToString(); ETypeWord argtype = arguments[i].GetEType(); EVariable solved = EVariable.New(argtype).Assign(args[i].Solve(lowerScope)); lowerScope.Set(argname, solved); } return(Interpreter.Run(program, lowerScope)); }
private static LogEntryRegexMatchReplacer ForVariable(EVariable aVariable, LogEntry aLogEntry, Logger.LoggingErrorHandler aLoggingErrorHandler) { LogEntryRegexMatchReplacer mr = null; switch (aVariable) { case EVariable.Application: mr = new ApplicationReplacer(); break; case EVariable.Machine: mr = new MachineReplacer(); break; case EVariable.Category: mr = new CategoryReplacer(); break; case EVariable.Severity: mr = new SeverityReplacer(); break; case EVariable.Timestamp: mr = new TimestampReplacer(); break; case EVariable.Message: mr = new MessageReplacer(); break; } mr.Variable = aVariable; mr.LogEntry = aLogEntry; mr.LoggingErrorHandler = aLoggingErrorHandler; return mr; }
/// <summary> /// Return true if the given aFormatString matches the regex for the given variable /// </summary> /// <param name="aFormatString">The format string to check for a match</param> /// <param name="aVariable">The variable to check</param> /// <returns></returns> public static bool IsMatch(string aFormatString, EVariable aVariable) { var regex = new Regex(RegexPattern.Replace("[VariableName]", aVariable.ToString()), RegexOptions.IgnoreCase); return regex.IsMatch(aFormatString); }
public override EVariable Solve(EVariable first, EVariable second) { return(first.Convert(second.GetEType())); }
private long RunTest(int commandNum, OperationType op, int keyLen, int numericBitLen, byte scaleBits, bool isOptimized, bool isOp1Enc, bool isOp2Enc) { Config.SetGlobalParameters(keyLen, numericBitLen, scaleBits, isOptimized); Program program = new Program(); Numeric [] expectedResult = new Numeric [commandNum]; Expression[] ret = new Expression[commandNum]; Numeric[] operand1 = new Numeric[commandNum], operand2 = new Numeric[commandNum]; for (int i = 0; i < commandNum; ++i) { Expression variable = new EVariable(program, "a" + i); if (op == OperationType.Inverse) { //operand1[i] = new Numeric(1000, 0); operand1[i] = Utility.NextUnsignedNumeric(0, 14); operand2[i] = Utility.NextUnsignedNumeric(0, 14); } else if (op == OperationType.Multiplication) { //operand1[i] = new Numeric(30 << 21, 21); operand1[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen / 2); operand2[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen / 2); } else if (op == OperationType.Sin) { operand1[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen); operand2[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen); } else if (op == OperationType.Switch) { operand1[i] = i % 12; operand2[i] = 1; } else if (op == OperationType.NOT) { operand1[i] = Utility.NextUnsignedNumeric(0, 1); operand2[i] = 1; } else { //operand1[i] = new Numeric(30 << 21, 21); operand1[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen); operand2[i] = Utility.NextSignedNumeric(scaleBits, numericBitLen); //operand1[i] = new Numeric(-1350, fractionBitLength); } ENumericLiteral op1 = new ENumericLiteral(operand1[i]), op2 = new ENumericLiteral(operand2[i]); op1.needEnc = isOp1Enc; op2.needEnc = isOp2Enc; Expression expression = new EBinaryOperation(op1, op2, op); Statement statement = new SAssignment(variable, expression); program.AddStatement(statement); ret[i] = variable; switch (op) { case OperationType.Addition: expectedResult[i] = operand1[i] + operand2[i]; break; case OperationType.Substraction: expectedResult[i] = operand1[i] - operand2[i]; break; case OperationType.AND: expectedResult[i] = operand1[i] & operand2[i]; break; case OperationType.XOR: expectedResult[i] = operand1[i] ^ operand2[i]; break; case OperationType.Multiplication: expectedResult[i] = operand1[i] * operand2[i]; break; case OperationType.OR: expectedResult[i] = operand1[i] | operand2[i]; break; case OperationType.Sin: expectedResult[i] = new Numeric((BigInteger)(Math.Sin(operand1[i].GetVal()) * Math.Pow(2, Config.ScaleBits)), Config.ScaleBits); break; case OperationType.EqualZero: expectedResult[i] = (operand1[i].GetVal() == 0) ? new Numeric(1, 0) : new Numeric(0, 0); break; //case OperationType.FastEqualZero: // expectedResult[i] = ((operand1[i].ModPow(FastEqualZero.GetKeySize())).GetVal() == 0) ? new Numeric(1, 0) : new Numeric(0, 0); // break; case OperationType.LessZero: case OperationType.MultiLessZero: expectedResult[i] = (operand1[i].GetVal() >= 0) ? new Numeric(0, 0) : new Numeric(1, 0); break; case OperationType.None: expectedResult[i] = operand1[i]; break; case OperationType.HammingDistance: break; case OperationType.Inverse: expectedResult[i] = operand1[i]; break; case OperationType.IndexMSB: case OperationType.Switch: expectedResult[i] = operand1[i]; break; case OperationType.NOT: expectedResult[i] = operand1[i] ^ new Numeric(1, 0); break; default: throw new ArgumentException(); } } program.AddStatement(new SReturn(ret)); program.Translate(); var programEnc = program.EncProgram(); if (op == OperationType.HammingDistance) { for (int i = 0; i < commandNum; ++i) { expectedResult[i] = ((((ENumericLiteral)((ICAssignment)programEnc[0].icList[i]).operand1).GetValue()) ^ (((ENumericLiteral)((ICAssignment)programEnc[1].icList[i]).operand1).GetValue())).SumBits(Config.KeyBits); } } var totalTime = Party.RunAllParties(program, programEnc); int corrCount = 0; for (int i = 0; i < commandNum; ++i) { var computedRes = ((Numeric )program.vTable["a" + i]); var expRes = expectedResult[i]; if (op == OperationType.HammingDistance) { if (computedRes.GetVal() == expRes.GetVal() || computedRes.GetVal() + (int)Math.Pow(2, Math.Ceiling(Math.Log(Config.KeyBits + 1, 2))) == expRes.GetVal()) { corrCount++; } } else if (op == OperationType.Inverse) { if (Math.Abs(expRes.GetVal() - 1 / computedRes.GetVal()) < 10) { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + 1 / expRes.GetVal()); corrCount++; } else { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + 1 / expRes.GetVal()); Console.WriteLine("corr: " + 1 / expRes.GetVal() + ", computed: " + computedRes.GetVal()); } } else if (op == OperationType.NOT) { if (computedRes.GetUnsignedBigInteger() == expRes.GetUnsignedBigInteger()) { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + expectedResult[i]); corrCount++; } else { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + expectedResult[i]); Console.WriteLine("corr: " + expRes.GetVal() + ", computed: " + computedRes.GetVal()); } } else { if (Math.Abs(computedRes.GetVal() - expRes.GetVal()) < 0.1) { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + expectedResult[i]); corrCount++; } else { System.Diagnostics.Debug.WriteLine(i + ":"); System.Diagnostics.Debug.WriteLine("operand1: " + operand1[i]); System.Diagnostics.Debug.WriteLine("operand2: " + operand2[i]); System.Diagnostics.Debug.WriteLine("computed: " + program.vTable["a" + i]); System.Diagnostics.Debug.WriteLine("expected: " + expectedResult[i]); Console.WriteLine("corr: " + expRes.GetVal() + ", computed: " + computedRes.GetVal()); } } } Accuracy = (double)corrCount / commandNum; return(totalTime); }
public override EVariable Solve(EVariable first, EVariable second) { return(ESOSimpleTypeObject.Calc(type, first, second)); }
public ConcealOnKH(Party party, int line, Operation caller, NumericArray operands, EVariable variable, Program program) : base(party, line, caller, operands, null, OperationType.Conceal) { this.program = program; this.variable = variable; encType = operands[0].GetEncType(); }
Statement DeclarationStatement() { List <Statement> re = new List <Statement>(); if (vars.ContainsKey(currToken.sequence)) { Error("DeclarationStatement: variable has been declared"); } else { var currVar = new EVariable(program, currToken.sequence); vars.Add(currToken.sequence, currVar); NextToken(); if (Accept(Symbol.S_Assign)) { var exp = NumericExpression(); re.Add(new SAssignment(currVar, exp)); } else { re.Add(new SAssignment(currVar, new ENumericLiteral(0, 0))); } if (Accept(Symbol.S_LBracket)) { ENumericLiteral num; if (IsNumeric(out num)) { currVar.leftBoundary = num.GetValue(); } else { Error("DeclarationStatement: left boundary should be a number"); } //double resultDouble = 2; //if (!double.TryParse(currToken.sequence, out resultDouble)) //{ // Error("DeclarationStatement: left boundary should be a number"); //} //currVar.leftBoundary = new Numeric((BigInteger)(resultDouble * Math.Pow(2, Config.ScaleBits)), Config.ScaleBits); //NextToken(); Expect(Symbol.S_Comma); if (IsNumeric(out num)) { currVar.rightBoundary = num.GetValue(); } else { Error("DeclarationStatement: right boundary should be a number"); } // use STATDOM if (Accept(Symbol.S_Comma)) { double resultDouble; if (!double.TryParse(currToken.sequence, out resultDouble)) { Error("DeclarationStatement: probability should be a number"); } if (resultDouble < 0 || resultDouble > 1) { Error("DeclarationStatement: probability is out of range"); } currVar.prob = new Numeric((BigInteger)(resultDouble * Math.Pow(2, Config.ScaleBits)), Config.ScaleBits); NextToken(); } Expect(Symbol.S_RBracket); } } while (!Accept(Symbol.S_Semicolon)) { Expect(Symbol.S_Comma); if (vars.ContainsKey(currToken.sequence)) { Error("SDeclaration: variable has been declared"); } else { var currVar = new EVariable(program, currToken.sequence); vars.Add(currToken.sequence, currVar); NextToken(); if (Accept(Symbol.S_Assign)) { var exp = NumericExpression(); re.Add(new SAssignment(currVar, exp)); } else { re.Add(new SAssignment(currVar, new ENumericLiteral(0, 0))); } if (Accept(Symbol.S_LBracket)) { ENumericLiteral num; if (IsNumeric(out num)) { currVar.leftBoundary = num.GetValue(); } else { Error("DeclarationStatement: left boundary should be a number"); } Expect(Symbol.S_Comma); if (IsNumeric(out num)) { currVar.rightBoundary = num.GetValue(); } else { Error("DeclarationStatement: right boundary should be a number"); } // use STATDOM if (Accept(Symbol.S_Comma)) { double resultDouble; if (!double.TryParse(currToken.sequence, out resultDouble)) { Error("DeclarationStatement: probability should be a number"); } if (resultDouble < 0 || resultDouble > 1) { Error("DeclarationStatement: probability is out of range"); } currVar.prob = new Numeric((BigInteger)(resultDouble * Math.Pow(2, Config.ScaleBits)), Config.ScaleBits); NextToken(); } Expect(Symbol.S_RBracket); } } } if (re.Count == 0) { Error("DeclarationStatement: need to declare at least one variable"); return(null); } else if (re.Count == 1) { return(re[0]); } else { return(new SSequence(re.ToArray())); } }
public virtual EVariable Solve(EVariable first, EVariable second) { return(new EVVoid()); }
/// <summary> /// Registers a DependencyProperty which is associated to a given injected variable of the trainer. /// The default value and type for the property is retrieved from the associated injected variable. /// </summary> /// <param name="propertyName">The name of the DependencyProperty to be registered.</param> /// <param name="varID">The injected variable to be associated with the DependencyProperty.</param> /// <returns>Returns a DependencyProperty representing the injected variable.</returns> private static DependencyProperty RegisterInjectedVariableDependencyProperty(string propertyName, EVariable varID) { // Retrieve information about the variable MemberInfo enumeratorInfo = typeof(EVariable).GetField(varID.ToString()); VariableDefinitionAttribute varDef = enumeratorInfo.GetCustomAttribute <VariableDefinitionAttribute>(); Object defaultVarValue = varDef.InitialValue; Type varType = varDef.InitialValue.GetType(); // Register the DependencyProperty DependencyProperty newDepProperty = DependencyProperty.Register(propertyName, varType, typeof(MainWindow), new PropertyMetadata(defaultVarValue, InjectedVariableValueChanged)); sm_dependencyPropertyToInjectedVariable.Add(newDepProperty, varID); return(newDepProperty); }
public override EVariable Solve(EScope scope) { return(EVariable.New(type)); }