public static bool IsValid(OPCode op) { switch (op) { case OPCode.Multiple: case OPCode.Add: case OPCode.Substract: case OPCode.Divide: case OPCode.Modulo: case OPCode.JoinString: case OPCode.JoinPadString: case OPCode.LessThan: case OPCode.LessThanEquals: case OPCode.NotEqual: case OPCode.Equals: case OPCode.GreaterThan: case OPCode.GreaterEquals: case OPCode.And: case OPCode.Or: case OPCode.ContainsString: case OPCode.StartsWith: case OPCode.OntoSprite: case OPCode.IntoSprite: return(true); default: return(false); } }
protected void ReplaceNextOperation(FlashReader inCode, FlashWriter outCode, ASMethod method, OPCode oldOP, object[] oldValues, OPCode newOP, object[] newValues) { while (inCode.IsDataAvailable) { OPCode op = inCode.ReadOP(); object[] values = inCode.ReadValues(op); if (op != oldOP) { outCode.WriteOP(op, values); continue; } if (oldValues != null && (oldValues.Length == values.Length)) { bool valuesMatch = true; for (int i = 0; i < oldValues.Length; i++) { if (oldValues[i] != null && !oldValues[i].Equals(values[i])) { valuesMatch = false; break; } } if (!valuesMatch) { outCode.WriteOP(op, values); continue; } } outCode.WriteOP(newOP, newValues); WriteLog($"Replaced operation '{oldOP}[{string.Join(", ", oldValues)}]' with '{newOP}[{string.Join(", ", newValues)}]' in method '{method}'."); break; } }
public static bool IsValid(OPCode op) { switch (op) { case OPCode.Kill: case OPCode.DecLocal: case OPCode.DecLocal_i: case OPCode.IncLocal: case OPCode.IncLocal_i: case OPCode.GetLocal: case OPCode.GetLocal_0: case OPCode.GetLocal_1: case OPCode.GetLocal_2: case OPCode.GetLocal_3: case OPCode.SetLocal: case OPCode.SetLocal_0: case OPCode.SetLocal_1: case OPCode.SetLocal_2: case OPCode.SetLocal_3: return(true); default: return(false); } }
/// <summary> /// Designed for modelling a DNS packet request. /// </summary> /// <param name="queryResponse"></param> /// <param name="opCode"></param> /// <param name="recursionDesired"></param> /// <param name="answerAuthenticated"></param> protected Parameters(OPCode opCode, bool recursionDesired, bool answerAuthenticated) : this(opCode: opCode, authoritativeAnswer: AA.NonAuthoritive, truncation: false, recursionDesired: recursionDesired, recursionAvailable: false, answerAuthenticated: answerAuthenticated, nonAuthenticatedData: false, response: ResponseCode.Ok) { QueryResponse = QR.Query; }
private void PhotonNetwork_OnEventCall(byte eventCode, object content, int senderId) { OPCode EventReceived = (OPCode)eventCode; Debug.Log("OpCode Received = " + EventReceived.ToString()); switch (EventReceived) { case OPCode.GameStart: if (!PhotonNetwork.isMasterClient) { StartMultiplayerGame(); } break; case OPCode.OpponentFinalScore: GameManager.Instance.IsOpponentGameOver = true; GameManager.Instance.MultiplayerOpponentScore = (int)content; if (GameManager.Instance.IsMyGameOver) { Debug.Log("From PhotonNetwork_OnEventCall OpponentFinalScore"); GameManager.Instance.CheckAndEvaluateMultiplayer(); } break; case OPCode.ScoreUpdate: GameManager.Instance.MultiplayerOpponentScoreUpdate((int)content); break; case OPCode.IndexSend: if (!PhotonNetwork.isMasterClient) { GameManager.Instance.SetMultiplayerIndex((int)content); PhotonNetwork.RaiseEvent((byte)OPCode.OpponentReceivedIndex, null, false, null); } break; case OPCode.OpponentReceivedIndex: if (PhotonNetwork.isMasterClient) { PhotonNetwork.RaiseEvent((byte)OPCode.GameStart, null, false, null); StartMultiplayerGame(); } break; case OPCode.RematchRequest: UIManager.Instance.ShowPopUp("Opponent has challenged for a rematch. Accept? ", null, TypeOfPopUpButtons.YesNo, TypeOfPopUp.Buttoned, 0, RematchAccepted, RematchRejected); break; case OPCode.RematchAccepted: if (PhotonNetwork.isMasterClient) { StartANewMultiplayerGame(); } break; case OPCode.RematchRejected: UIManager.Instance.ShowPopUp("Opponent has declined your challenge.", null, TypeOfPopUpButtons.Ok, TypeOfPopUp.Buttoned, 0, null, null, "Sorry!"); break; } }
public IEnumerable <ASInstruction> GetOPGroup(OPCode op) { if (_opGroups.ContainsKey(op)) { return(_opGroups[op]); } return(Enumerable.Empty <ASInstruction>()); }
public static string Get(OPCode code) { switch (code) { default: return("Unknown Error"); } }
public IEnumerable <TypedCH> GetCHs(OPCode opcode) { D.Assert(opcode.GetType() == opcode_type); foreach (var fi in CH_FIs) { yield return((TypedCH)fi.GetValue(opcode)); } }
public Packet(PacketType type, OPCode opcode, string username, string receiver, byte[] message) { Type = type; OPCode = opcode; Username = username; Receiver = receiver; Message = message; }
protected MemoryInstruction(OPCode op, ref WASMReader input, bool hasMemArgs) : this(op, hasMemArgs) { if (_hasMemArgs = hasMemArgs) { Align = input.ReadIntULEB128(); Offset = input.ReadIntULEB128(); } }
public int IndexOf(OPCode op) { if (_opGroups.ContainsKey(op)) { List <ASInstruction> instructions = _opGroups[op]; return(_indices[instructions[0]]); } return(-1); }
/// <summary> /// Sipper3DecodeRec Constructor. Will decode 'd' parameter.<see cref="Sipper3DecodeRec"/> class. /// </summary> /// <param name="d">An unsigned short that represents a Sipper3File record.</param> public Sipper3DecodeRec(ushort d) { bool[] bits = DecodeUshortIntoBits(d); image = bits[15]; eol = bits[14]; raw = bits[13]; grayScale = bits[12]; if (image && (!raw)) { // Fill in blanks spaces operation = OPCode.FillInBlankPixels; numBlankPixels = (ushort)((d & (ushort)0x07ff) * 4); } else if (image && raw && (!grayScale)) { int x = 11; int y = 0; operation = OPCode.RawPixels; pixels = new byte[12]; for (x = 11; x >= 0; x--, y++) { pixels[y] = (byte)(bits[x] ? 255 : 0); } } else if (image && raw && grayScale) { byte[] grayScalValues = { 0, 36, 73, 109, 146, 182, 219, 255 }; operation = OPCode.RawPixels; pixels = new byte[4]; pixels[0] = grayScalValues[ThreeBitsToByte(bits[11], bits[10], bits[9])]; pixels[1] = grayScalValues[ThreeBitsToByte(bits[8], bits[7], bits[6])]; pixels[2] = grayScalValues[ThreeBitsToByte(bits[5], bits[4], bits[3])]; pixels[3] = grayScalValues[ThreeBitsToByte(bits[2], bits[1], bits[0])]; } else if ((!image) && (!eol)) { operation = OPCode.SensorData; sensorNum = SixBitsToByte(bits[13], bits[12], bits[11], bits[10], bits[9], bits[8]); sensorData = (char)(d & 0x00ff); eol = false; } else if ((!image) && eol) { operation = OPCode.SensorRelatedData; sensorNum = SixBitsToByte(bits[13], bits[12], bits[11], bits[10], bits[9], bits[8]); sensorData = (char)(d & 0x00ff); text = eol; eol = false; } }
public static JsonObject conv(OPCode opc) { var J_opc = new JsonObject(); J_opc["kind"] = "opcode"; J_opc["id"] = ID(opc); J_opc["name"] = opc.GetType().Name; return(J_opc); }
// TODO: Use source generator to add new items at compile time. public static bool IsPropertyContainer(OPCode op) { switch (op) { case OPCode.CallPropVoid: case OPCode.CallProperty: case OPCode.ConstructProp: return(true); default: return(false); } }
protected void ReplaceNextOperation(ASMethod method, OPCode oldOP, object[] oldValues, OPCode newOP, object[] newValues) { using (var outCode = new FlashWriter()) using (var inCode = new FlashReader(method.Body.Bytecode)) { ReplaceNextOperation(inCode, outCode, method, oldOP, oldValues, newOP, newValues); CopyBytecode(inCode, outCode); method.Body.Bytecode = outCode.ToArray(); } }
public static JsonObject conv(OPCode op, CH_Edge ch_edge) { var J_edge = new JsonObject(); J_edge["kind"] = "OP>CH_edge"; J_edge["id_from"] = ID(op); J_edge["id_to"] = ID(ch_edge.CH); J_edge["fieldname"] = ch_edge.fieldname; return(J_edge); }
public static bool IsValid(OPCode op) { switch (op) { case OPCode.Inverse: case OPCode.Not: return(true); default: return(false); } }
public static int LastIndexOf(this ASCode code, int startIndex, OPCode op) { for (var i = startIndex; i >= 0; i--) { if (code[i].OP == op) { return(i); } } return(-1); }
public static int LastIndexOf(this ASCode code, OPCode op) { for (var i = code.Count - 1; i >= 0; i--) { if (code[i].OP == op) { return(i); } } return(-1); }
public IEnumerable <CH_Edge> GetCH_edges(OPCode opcode) { D.Assert(opcode.GetType() == opcode_type); foreach (var fi in CH_FIs) { yield return new CH_Edge { CH = (TypedCH)fi.GetValue(opcode), fieldname = fi.Name } } ; } }
public static int IndexOf(this ASCode code, int startIndex, OPCode op) { for (var i = startIndex; i < code.Count; i++) { if (code[i].OP == op) { return(i); } } return(-1); }
protected bool ContainsOperation(ASMethod method, OPCode operation, params object[] expectedValues) { using (var inCode = new FlashReader(method.Body.Bytecode)) { while (inCode.IsDataAvailable) { return(inCode.ReadValuesUntil( operation, expectedValues) != null); } } return(false); }
public static bool IsValid(OPCode op) { switch (op) { case OPCode.IfFalse: case OPCode.Jump: case OPCode.EndRepeat: return(true); default: return(false); } }
public Sipper2DecodeRec(ushort d) { bool[] bits = DecodeUshortIntoBits(d); if (bits[15]) { cameraNum = 1; } else { cameraNum = 0; } eol = bits[14]; raw = bits[13]; flow = bits[12]; if (raw) { operation = OPCode.RawPixels; pixels = new byte[4]; pixels[0] = grayScalValues[ThreeBitsToByte(bits[11], bits[10], bits[9])]; pixels[1] = grayScalValues[ThreeBitsToByte(bits[8], bits[7], bits[6])]; pixels[2] = grayScalValues[ThreeBitsToByte(bits[5], bits[4], bits[3])]; pixels[3] = grayScalValues[ThreeBitsToByte(bits[2], bits[1], bits[0])]; } else { // Fill in blanks spaces operation = OPCode.FillInBlankPixels; numBlankPixels = (ushort) ( ((bits[11] ? 2048 : 0) + (bits[10] ? 1024 : 0) + (bits[9] ? 512 : 0) + (bits[8] ? 256 : 0) + (bits[7] ? 128 : 0) + (bits[6] ? 64 : 0) + (bits[5] ? 32 : 0) + (bits[4] ? 16 : 0) + (bits[3] ? 8 : 0) + (bits[2] ? 4 : 0) + (bits[1] ? 2 : 0) + (bits[0] ? 1 : 0) ) * 4 ); } }
public static bool IsGetLocal(OPCode op) { switch (op) { case OPCode.GetLocal: case OPCode.GetLocal_0: case OPCode.GetLocal_1: case OPCode.GetLocal_2: case OPCode.GetLocal_3: return(true); default: return(false); } }
/// <summary> /// Designed for modelling a DNS packet response. /// </summary> /// <param name="queryResponse"></param> /// <param name="opCode"></param> /// <param name="authoritativeAnswer"></param> /// <param name="truncation"></param> /// <param name="recursionDesired"></param> /// <param name="recursionAvailable"></param> /// <param name="nonAuthenticatedData"></param> /// <param name="response"></param> /// <param name="answerAuthenticated"></param> protected Parameters(OPCode opCode, AA authoritativeAnswer, bool truncation, bool recursionDesired, bool recursionAvailable, bool answerAuthenticated, bool nonAuthenticatedData, ResponseCode response) { QueryResponse = QR.Response; OpCode = opCode; AuthoritativeAnswer = authoritativeAnswer; Truncation = truncation; RecursionDesired = recursionDesired; RecursionAvailable = recursionAvailable; Reserved = 00; //Zero'd bits as not used...yet. AnswerAuthenticated = answerAuthenticated; NonAuthenticatedData = nonAuthenticatedData; Response = response; }
protected void RemoveHostSuffix(ABCFile abc, ASMethod connectMethod) { using (var inCode = new FlashReader(connectMethod.Body.Bytecode)) using (var outCode = new FlashWriter(inCode.Length)) { int ifNeCount = 0; while (inCode.Position != inCode.Length) { OPCode op = inCode.ReadOP(); outCode.WriteOP(op); if (op == OPCode.IfNe && ++ifNeCount == 2) { var iFNeJumpCount = (int)inCode.ReadS24(); outCode.WriteS24(iFNeJumpCount + 6); continue; } else if (op != OPCode.PushInt) { continue; } int pushIntIndex = inCode.Read7BitEncodedInt(); int integerValue = abc.Constants.Integers[pushIntIndex]; switch (integerValue) { case 65244: case 65185: case 65191: case 65189: case 65188: case 65174: case 65238: case 65184: case 65171: case 65172: { pushIntIndex = abc.Constants.AddInteger(65290); break; } } outCode.Write7BitEncodedInt(pushIntIndex); } connectMethod.Body.Bytecode = outCode.ToArray(); } RemoveDeadFalseConditions(connectMethod.Body); }
static void Main(string[] args) { Console.WriteLine("use turing to calc 1+2"); //prepare tape var codes = new OPCode[] { new OPCode() { op = OP.NOP }, new OPCode() { op = OP.PUSH, v = 1 }, new OPCode() { op = OP.PUSH, v = 2 }, new OPCode() { op = OP.ADD }, new OPCode() { op = OP.RET }, }; var vm = new SimNeoTuringMachine(); vm.SetCodes(codes); //scroll the tape while (!vm.stop) { vm.StepOne(); } //watch calcstack var retvalue = vm.calcstack.Peek(); Console.WriteLine("return value = " + retvalue); Console.ReadLine(); }
protected ASMethod FindVerifyMethod(ASInstance instance, ABCFile abc, out int rsaStart) { List <MethodGetterSetterTrait> methodTraits = instance.FindTraits <MethodGetterSetterTrait>(TraitType.Method); rsaStart = -1; foreach (MethodGetterSetterTrait mgsTrait in methodTraits) { ASMethod method = mgsTrait.Method; if (method.ReturnType.ObjName != "void") { continue; } if (method.Parameters.Count != 1) { continue; } using (var code = new FlashReader(method.Body.Bytecode)) { while (code.Position != code.Length) { OPCode op = code.ReadOP(); if (op != OPCode.GetLex) { continue; } int typeIndex = code.Read7BitEncodedInt(); ASMultiname type = abc.Constants.Multinames[typeIndex]; if (type?.ObjName == "RSAKey") { rsaStart = code.Position; return(method); } } } } return(null); }
public static bool IsValid(OPCode op) { switch (op) { case OPCode.PushByte: case OPCode.PushDouble: case OPCode.PushFalse: case OPCode.PushInt: case OPCode.PushNan: case OPCode.PushNull: case OPCode.PushShort: case OPCode.PushString: case OPCode.PushTrue: case OPCode.PushUInt: return(true); default: return(false); } }
public void WriteOP(OPCode op, params object[] values) { Write((byte)op); if (values.Length == 0) return; switch (op) { case OPCode.AsType: case OPCode.Call: case OPCode.Coerce: case OPCode.Construct: case OPCode.ConstructSuper: case OPCode.DebugFile: case OPCode.DebugLine: case OPCode.DecLocal: case OPCode.DecLocal_i: case OPCode.DeleteProperty: case OPCode.Dxns: case OPCode.FindProperty: case OPCode.FindPropStrict: case OPCode.GetDescendants: case OPCode.GetGlobalSlot: case OPCode.GetLex: case OPCode.GetLocal: case OPCode.GetProperty: case OPCode.GetScopeObject: case OPCode.GetSlot: case OPCode.GetSuper: case OPCode.IncLocal: case OPCode.IncLocal_i: case OPCode.InitProperty: case OPCode.IsType: case OPCode.Kill: case OPCode.NewArray: case OPCode.NewCatch: case OPCode.NewClass: case OPCode.NewFunction: case OPCode.NewObject: case OPCode.PushDouble: case OPCode.PushInt: case OPCode.PushNamespace: case OPCode.PushShort: case OPCode.PushString: case OPCode.PushUInt: case OPCode.SetLocal: case OPCode.SetGlobalSlot: case OPCode.SetProperty: case OPCode.SetSlot: case OPCode.SetSuper: Write7BitEncodedInt((int)values[0]); break; case OPCode.CallMethod: case OPCode.CallProperty: case OPCode.CallPropLex: case OPCode.CallPropVoid: case OPCode.CallStatic: case OPCode.CallSuper: case OPCode.CallSuperVoid: case OPCode.ConstructProp: Write7BitEncodedInt((int)values[0]); Write7BitEncodedInt((int)values[1]); break; case OPCode.Debug: Write((byte)values[0]); Write7BitEncodedInt((int)values[1]); Write((byte)values[2]); Write7BitEncodedInt((int)values[3]); break; case OPCode.HasNext2: Write((uint)values[0]); Write((uint)values[1]); break; case OPCode.IfEq: case OPCode.IfFalse: case OPCode.IfGe: case OPCode.IfGt: case OPCode.IfLe: case OPCode.IfLt: case OPCode.IfNGe: case OPCode.IfNGt: case OPCode.IfNLe: case OPCode.IfNLt: case OPCode.IfNe: case OPCode.IfStrictEq: case OPCode.IfStrictNE: case OPCode.IfTrue: case OPCode.Jump: WriteS24((int)values[0]); break; case OPCode.LoopUpSwitch: { WriteS24((int)values[0]); Write7BitEncodedInt((int)values[1]); for (int i = 2; i < values.Length; i++) { var value = (int)values[i]; WriteS24(value); } break; } case OPCode.PushByte: Write((byte)values[0]); break; } }
public object[] ReadValues(OPCode op) { var values = new List<object>(); switch (op) { case OPCode.AsType: case OPCode.Call: case OPCode.Coerce: case OPCode.Construct: case OPCode.ConstructSuper: case OPCode.DebugFile: case OPCode.DebugLine: case OPCode.DecLocal: case OPCode.DecLocal_i: case OPCode.DeleteProperty: case OPCode.Dxns: case OPCode.FindProperty: case OPCode.FindPropStrict: case OPCode.GetDescendants: case OPCode.GetGlobalSlot: case OPCode.GetLex: case OPCode.GetLocal: case OPCode.GetProperty: case OPCode.GetScopeObject: case OPCode.GetSlot: case OPCode.GetSuper: case OPCode.IncLocal: case OPCode.IncLocal_i: case OPCode.InitProperty: case OPCode.IsType: case OPCode.Kill: case OPCode.NewArray: case OPCode.NewCatch: case OPCode.NewClass: case OPCode.NewFunction: case OPCode.NewObject: case OPCode.PushDouble: case OPCode.PushInt: case OPCode.PushNamespace: case OPCode.PushShort: case OPCode.PushString: case OPCode.PushUInt: case OPCode.SetLocal: case OPCode.SetGlobalSlot: case OPCode.SetProperty: case OPCode.SetSlot: case OPCode.SetSuper: values.Add(Read7BitEncodedInt()); break; case OPCode.CallMethod: case OPCode.CallProperty: case OPCode.CallPropLex: case OPCode.CallPropVoid: case OPCode.CallStatic: case OPCode.CallSuper: case OPCode.CallSuperVoid: case OPCode.ConstructProp: values.Add(Read7BitEncodedInt()); values.Add(Read7BitEncodedInt()); break; case OPCode.Debug: values.Add(ReadByte()); values.Add(Read7BitEncodedInt()); values.Add(ReadByte()); values.Add(Read7BitEncodedInt()); break; case OPCode.HasNext2: values.Add(ReadUInt32()); values.Add(ReadUInt32()); break; case OPCode.IfEq: case OPCode.IfFalse: case OPCode.IfGe: case OPCode.IfGt: case OPCode.IfLe: case OPCode.IfLt: case OPCode.IfNGe: case OPCode.IfNGt: case OPCode.IfNLe: case OPCode.IfNLt: case OPCode.IfNe: case OPCode.IfStrictEq: case OPCode.IfStrictNE: case OPCode.IfTrue: case OPCode.Jump: values.Add(ReadS24()); break; case OPCode.LoopUpSwitch: { values.Add(ReadS24()); int caseCount = (Read7BitEncodedInt() + 1); values.Add(caseCount - 1); for (int i = 0; i < caseCount; i++) values.Add(ReadS24()); break; } case OPCode.PushByte: values.Add(ReadByte()); break; } return values.ToArray(); }
public virtual void WriteOP(OPCode op) { Write((byte)op); }