/// <summary> /// Makes UnaryAssignment instruction type from NoOperation /// </summary> /// <param name="left_value">Left value (variable only)</param> /// <param name="right_value">Right value (variable only, can be the same as a left value)</param> /// <param name="operation">Unary operation</param> public static void UnaryAssignment(Instruction ins, Variable left_value, Variable right_value, Instruction.UnaryOperationType operation) { if (ins.statementType != Objects.Common.StatementType.NoOperation) { throw new ObfuscatorException("Only NoOperation instruction can be modified to other type!"); } if (left_value == null) { throw new ObfuscatorException("Wrong parameter passing: missing left value."); } if (right_value == null) { throw new ObfuscatorException("Wrong parameter passing: missing right value."); } string op = string.Empty; switch (operation) { case Instruction.UnaryOperationType.ArithmeticNegation: op = "-"; break; case Instruction.UnaryOperationType.LogicalNegation: op = "!"; break; default: throw new ObfuscatorException("Unsupported unary operation type."); } ins.RefVariables.Clear(); ins.RefVariables.Add(left_value); if (!left_value.Equals(right_value)) { ins.RefVariables.Add(right_value); } ins.statementType = Objects.Common.StatementType.UnaryAssignment; ins.TACtext = string.Join(" ", left_value.name, ":=", op, right_value.name); }
/// <summary> /// Parses a unary assignment instruction /// </summary> /// <param name="inst">Instruction to be parsed</param> /// <param name="left_value">Left value of the assignment (variable only)</param> /// <param name="right_value">Right value of the assignment (variable only)</param> /// <param name="operation">Unary operator</param> public static void UnaryAssignment(Instruction inst, out Variable left_value, out Variable right_value, out Instruction.UnaryOperationType operation) { Validate(inst, Objects.Common.StatementType.UnaryAssignment); System.Collections.Specialized.StringCollection refvarIDs = new System.Collections.Specialized.StringCollection(); Match matchResult = Regex.Match(inst.TACtext, "ID_[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}", RegexOptions.None); while (matchResult.Success) { refvarIDs.Add(matchResult.Value); matchResult = matchResult.NextMatch(); } left_value = inst.RefVariables.Find(x => x.ID == refvarIDs[0]); right_value = inst.RefVariables.Find(x => x.ID == refvarIDs[1]); switch (inst.TACtext.Split(' ')[2]) { case "-": operation = Instruction.UnaryOperationType.ArithmeticNegation; break; case "!": operation = Instruction.UnaryOperationType.LogicalNegation; break; default: throw new ParserException("Unsupported unary operation type."); } }