public GlobalMethodRefToConstantAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) { var globalAddress = instruction.GetRipBasedInstructionMemoryAddress(); MethodData = LibCpp2IlMain.GetMethodDefinitionByGlobalAddress(globalAddress); var(type, genericParams) = Utils.TryLookupTypeDefByName(MethodData !.DeclaringType.FullName); if (type == null) { Console.WriteLine("Failed to lookup managed type for declaring type of " + MethodData.GlobalKey + ", which is " + MethodData.DeclaringType.FullName); return; } ResolvedMethod = type.Methods.FirstOrDefault(m => m.Name == MethodData.Name); if (ResolvedMethod == null) { return; } var destReg = instruction.Op0Kind == OpKind.Register ? Utils.GetRegisterNameNew(instruction.Op0Register) : null; var name = ResolvedMethod.Name; ConstantWritten = context.MakeConstant(typeof(MethodDefinition), ResolvedMethod, name, destReg); }
public static string Render(ConstantDefinition constant) { var sb = new StringBuilder(); sb.AppendLine($" // {constant.Location.Path.Path}:{constant.Location.Line}"); sb.AppendLine($" public const int {constant.Name} = unchecked((int){constant.Value});"); return(sb.ToString()); }
public InterfaceOffsetsReadAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) { var regName = Utils.GetRegisterNameNew(instruction.MemoryBase); var regConstant = context.GetConstantInReg(regName); _loadedFor = (Il2CppClassIdentifier)regConstant.Value; InterfaceOffsets = _loadedFor.backingType.InterfaceOffsets; _destReg = Utils.GetRegisterNameNew(instruction.Op0Register); _destinationConst = context.MakeConstant(typeof(Il2CppInterfaceOffset[]), InterfaceOffsets, reg: _destReg); }
public override Object Visit(ConstantDefinition node, Object obj) { if (!node.FullName.EndsWith("[]")) { this.map.AddNewVariable(node.Identifier, node.FullName, node.Location); } else { node.IdentifierExp.IndexOfSSA = -1; } node.Init.Accept(this, false); return(null); }
public override Object Visit(ConstantDefinition node, Object obj) { declarationSymbol(node); if (node.Location == ((AstNode)obj).Location || found) { found = true; return(this.table); } node.Init.Accept(this, obj); //node.Symbol = declarationSymbol(node); return(this.table); }
public string GetConstantDefinition(JObject constantName) { string constantNameStr = constantName.ToObject <Name>().name; Constant constant = Constants.Instance.GetConstantDefinition(constantNameStr); ConstantDefinition constantDefinition = new ConstantDefinition() { constantName = constant.ConstantName, constantValue = constant.ConstantValue, constantTypeStr = constant.ConstantTypeStr }; return(JsonConvert.SerializeObject(constantDefinition)); }
public GlobalStringRefToConstantAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) { var globalAddress = instruction.GetRipBasedInstructionMemoryAddress(); ResolvedString = LibCpp2IlMain.GetLiteralByAddress(globalAddress); if (ResolvedString == null) { return; } var destReg = instruction.Op0Kind == OpKind.Register ? Utils.GetRegisterNameNew(instruction.Op0Register) : null; ConstantWritten = context.MakeConstant(typeof(string), ResolvedString, null, destReg); }
public GlobalTypeRefToConstantAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) { var globalAddress = instruction.GetRipBasedInstructionMemoryAddress(); var typeData = LibCpp2IlMain.GetTypeGlobalByAddress(globalAddress); var(type, genericParams) = Utils.TryLookupTypeDefByName(typeData !.ToString()); ResolvedType = type; if (ResolvedType == null) { return; } _destReg = instruction.Op0Kind == OpKind.Register ? Utils.GetRegisterNameNew(instruction.Op0Register) : null; var name = ResolvedType.Name; ConstantWritten = context.MakeConstant(typeof(TypeDefinition), ResolvedType, name, _destReg); }
public LoadInterfaceMethodDataAction(MethodAnalysis context, Instruction instruction) : base(context, instruction) { if (context.GetConstantInReg("rcx") is {} castConstant && castConstant.Value is NewSafeCastResult castResult && context.GetConstantInReg("rdx") is {} interfaceConstant && interfaceConstant.Value is TypeDefinition interfaceType && context.GetConstantInReg("r8") is {} slotConstant && slotConstant.Value is int slot && context.Actions.FirstOrDefault(a => a is LocateSpecificInterfaceOffsetAction) is LocateSpecificInterfaceOffsetAction locator ) { _invokedOn = castResult.original; _interfaceType = interfaceType; _slotNumber = slot; resolvedMethod = SharedState.VirtualMethodsBySlot[(ushort)(locator._matchingInterfaceOffset.offset + _slotNumber)]; _resultConstant = context.MakeConstant(typeof(MethodDefinition), resolvedMethod, reg: "rax"); } }
public override Object Visit(ConstantDefinition node, Object obj) { int indent = Convert.ToInt32(obj); this.printIndentation(indent); if (node.IdentifierExp.IndexOfSSA != -1) { this.output.WriteLine("Constant Definition: {0}{1} [{2}:{3}]", node.Identifier, node.IdentifierExp.IndexOfSSA, node.Location.Line, node.Location.Column); } else { this.output.WriteLine("Constant Definition: {0} [{1}:{2}]", node.Identifier, node.Location.Line, node.Location.Column); } this.printIndentation(indent + 1); this.output.Write("Type: "); this.output.WriteLine(printType(node.TypeExpr)); return(node.Init.Accept(this, indent + 1)); }
public IEnumerable <ConstantDefinition> MakeConstantDefinition(Enumeration enumeration) { var result = new List <ConstantDefinition>(); foreach (var item in enumeration.Items) { var name = item.Name; if (_context.IsKnownUnitName(name)) { continue; } var constant = new ConstantDefinition { TypeName = TypeHelper.GetTypeName(enumeration.Type), Name = name, Value = ConvertValue(item.Value, enumeration.BuiltinType.Type).ToString(), Content = item.Comment?.BriefText }; _context.AddUnit(constant); result.Add(constant); } return(result); }
public override Object Visit(ConstantDefinition node, Object obj) { node.Init.Accept(this, obj); return(null); }
public abstract Object Visit(ConstantDefinition node, Object obj);
static void Main(string[] args) { string command = args[0]; if (command == "loopback") { var t = new TcpTransport(); t.StartServer(22332); RobotRaconteurNode.s.RegisterTransport(t); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService1.com__robotraconteur__testing__TestService1Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService2.com__robotraconteur__testing__TestService2Factory()); var s1 = new RobotRaconteurTestServiceSupport(); s1.RegisterServices(t); ServiceTestClient s = new ServiceTestClient(); s.RunFullTest("rr+tcp://localhost:22332/?service=RobotRaconteurTestService", "rr+tcp://localhost:22332/?service=RobotRaconteurTestService_auth") .GetAwaiter().GetResult(); RobotRaconteurNode.s.Shutdown(); } else if (command == "client") { var url = args[1]; var auth_url = args[2]; int count = 1; if (args.Length >= 4) { count = Int32.Parse(args[3]); } var t = new TcpTransport(); var t2 = new LocalTransport(); RobotRaconteurNode.s.RegisterTransport(t); RobotRaconteurNode.s.RegisterTransport(t2); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService1.com__robotraconteur__testing__TestService1Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService2.com__robotraconteur__testing__TestService2Factory()); for (int i = 0; i < count; i++) { ServiceTestClient s = new ServiceTestClient(); s.RunFullTest(url, auth_url).GetAwaiter().GetResult(); } RobotRaconteurNode.s.Shutdown(); Console.WriteLine("Test complete, no errors detected"); } else if (command == "server") { int port = int.Parse(args[1]); //NodeID id = new NodeID(args[2]); string name = args[2]; var t2 = new LocalTransport(); t2.StartServerAsNodeName(name); var t = new TcpTransport(); RobotRaconteurNode.s.RegisterTransport(t2); t.StartServer(port); RobotRaconteurNode.s.RegisterTransport(t); t.EnableNodeAnnounce(); try { t.LoadTlsNodeCertificate(); } catch (Exception) { Console.WriteLine("Warning: Could not load TLS certificate"); } RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService1.com__robotraconteur__testing__TestService1Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService2.com__robotraconteur__testing__TestService2Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService3.com__robotraconteur__testing__TestService3Factory()); var s = new RobotRaconteurTestServiceSupport(); s.RegisterServices(t); var s2 = new RobotRaconteurTestServiceSupport2(); s2.RegisterServices(t); Console.WriteLine("Press enter to quit..."); Console.ReadLine(); RobotRaconteurNode.s.Shutdown(); } else if (command == "findservicebytype") { string servicetype = args[1]; string[] schemes = args[2].Split(new char[] { ',' }); var t = new TcpTransport(); t.EnableNodeDiscoveryListening(); RobotRaconteurNode.s.RegisterTransport(t); System.Threading.Thread.Sleep(5000); var r = RobotRaconteurNode.s.FindServiceByType(servicetype, schemes).Result; foreach (var e in r) { Console.WriteLine("Name: " + e.Name); Console.WriteLine("RootObjectType: " + e.RootObjectType); Console.WriteLine("RootObjectImplements: " + e.ConnectionURL); Console.WriteLine("ConnectionURL: " + String.Join(", ", e.ConnectionURL)); Console.WriteLine("NodeID: " + e.NodeID.ToString()); Console.WriteLine("NodeName: " + e.NodeName); Console.WriteLine(); } RobotRaconteurNode.s.Shutdown(); } else if (command == "findnodebyid") { var nodeid = new NodeID(args[1]); string[] schemes = args[2].Split(new char[] { ',' }); var t = new TcpTransport(); t.EnableNodeDiscoveryListening(); RobotRaconteurNode.s.RegisterTransport(t); System.Threading.Thread.Sleep(6000); var r = RobotRaconteurNode.s.FindNodeByID(nodeid, schemes).Result; foreach (var e in r) { Console.WriteLine("NodeID: " + e.NodeID); Console.WriteLine("NodeName: " + e.NodeName); Console.WriteLine("ConnectionURL: " + String.Join(", ", e.ConnectionURL)); Console.WriteLine(); } RobotRaconteurNode.s.Shutdown(); } else if (command == "findnodebyname") { var name = args[1]; string[] schemes = args[2].Split(new char[] { ',' }); var t = new TcpTransport(); t.EnableNodeDiscoveryListening(); RobotRaconteurNode.s.RegisterTransport(t); System.Threading.Thread.Sleep(6000); var r = RobotRaconteurNode.s.FindNodeByName(name, schemes).Result; foreach (var e in r) { Console.WriteLine("NodeID: " + e.NodeID); Console.WriteLine("NodeName: " + e.NodeName); Console.WriteLine("ConnectionURL: " + String.Join(", ", e.ConnectionURL)); Console.WriteLine(); } RobotRaconteurNode.s.Shutdown(); } else if (command == "robdeftest") { var robdef_filenames = args.Skip(1).ToArray(); var defs = new Dictionary <string, ServiceDefinition>(); var defs2 = new Dictionary <string, ServiceDefinition>(); foreach (var fname in robdef_filenames) { string robdef_text = new StreamReader(fname).ReadToEnd(); var def = new ServiceDefinition(); def.FromString(robdef_text); defs.Add(def.Name, def); string robdef_text2 = def.ToString(); var def3 = new ServiceDefinition(); def3.FromString(robdef_text2); defs2.Add(def3.Name, def3); } ServiceDefinitionUtil.VerifyServiceDefinitions(defs); foreach (var n in defs.Keys) { if (!ServiceDefinitionUtil.CompareServiceDefinitions(defs[n], defs2[n])) { throw new Exception("Service definition parse does not match"); } } foreach (var def in defs.Values) { Console.WriteLine(def.ToString()); } foreach (var def in defs.Values) { foreach (var c in def.Constants.Values) { if (c.Name == "strconst") { var strconst = c.ValueToString(); Console.WriteLine("strconst " + strconst); var strconst2 = ConstantDefinition.EscapeString(strconst); var strconst3 = ConstantDefinition.UnescapeString(strconst2); if (strconst3 != strconst) { throw new Exception(""); } } if (c.Name == "int32const") { Console.WriteLine("int32const: " + c.ValueToScalar <int>()); } if (c.Name == "int32const_array") { var a = c.ValueToArray <int>(); Console.WriteLine("int32const_array: " + a.Length); } if (c.Name == "doubleconst_array") { var a = c.ValueToArray <double>(); Console.WriteLine("doubleconst_array: " + a.Length); } if (c.Name == "structconst") { var s = c.ValueToStructFields(); foreach (var f in s) { Console.Write(f.Name + ": " + f.ConstantRefName + " "); } Console.WriteLine(); } } } ServiceDefinition def1; if (defs.TryGetValue("com.robotraconteur.testing.TestService1", out def1)) { var entry = def1.Objects["testroot"]; var p1 = (PropertyDefinition)entry.Members["d1"]; if (p1.Direction != MemberDefinition_Direction.both) { throw new Exception(); } var p2 = (PipeDefinition)entry.Members["p1"]; if (p2.Direction != MemberDefinition_Direction.both) { throw new Exception(); } if (p2.IsUnreliable) { throw new Exception(); } var w1 = (WireDefinition)entry.Members["w1"]; if (w1.Direction != MemberDefinition_Direction.both) { throw new Exception(); } var m1 = (MemoryDefinition)entry.Members["m1"]; if (m1.Direction != MemberDefinition_Direction.both) { throw new Exception(); } } ServiceDefinition def2; if (defs.TryGetValue("com.robotraconteur.testing.TestService3", out def2)) { var entry = def2.Objects["testroot3"]; var p1 = (PropertyDefinition)entry.Members["readme"]; if (p1.Direction != MemberDefinition_Direction.readonly_) { throw new Exception(); } var p2 = (PropertyDefinition)entry.Members["writeme"]; if (p2.Direction != MemberDefinition_Direction.writeonly) { throw new Exception(); } var p3 = (PipeDefinition)entry.Members["unreliable1"]; if (p3.Direction != MemberDefinition_Direction.readonly_) { throw new Exception(); } if (!p3.IsUnreliable) { throw new Exception(); } var p4 = (PipeDefinition)entry.Members["unreliable2"]; if (p4.Direction != MemberDefinition_Direction.both) { throw new Exception(); } if (!p4.IsUnreliable) { throw new Exception(); } var w1 = (WireDefinition)entry.Members["peekwire"]; if (w1.Direction != MemberDefinition_Direction.readonly_) { throw new Exception(); } var w2 = (WireDefinition)entry.Members["pokewire"]; if (w2.Direction != MemberDefinition_Direction.writeonly) { throw new Exception(); } var m1 = (MemoryDefinition)entry.Members["readmem"]; if (m1.Direction != MemberDefinition_Direction.readonly_) { throw new Exception(); } Console.WriteLine("Found it"); } return; } else if (command == "loopback2") { var t = new TcpTransport(); t.StartServer(22332); RobotRaconteurNode.s.RegisterTransport(t); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService1.com__robotraconteur__testing__TestService1Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService2.com__robotraconteur__testing__TestService2Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService3.com__robotraconteur__testing__TestService3Factory()); var s1 = new RobotRaconteurTestServiceSupport2(); s1.RegisterServices(t); ServiceTestClient2 s = new ServiceTestClient2(); s.RunFullTest("rr+tcp://localhost:22332/?service=RobotRaconteurTestService2") .GetAwaiter().GetResult(); RobotRaconteurNode.s.Shutdown(); } else if (command == "client2") { var url = args[1]; int count = 1; if (args.Length >= 3) { count = Int32.Parse(args[2]); } var t = new TcpTransport(); RobotRaconteurNode.s.RegisterTransport(t); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService1.com__robotraconteur__testing__TestService1Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService2.com__robotraconteur__testing__TestService2Factory()); RobotRaconteurNode.s.RegisterServiceType(new com.robotraconteur.testing.TestService3.com__robotraconteur__testing__TestService3Factory()); for (int i = 0; i < count; i++) { ServiceTestClient2 s = new ServiceTestClient2(); s.RunFullTest(url).GetAwaiter().GetResult(); } RobotRaconteurNode.s.Shutdown(); Console.WriteLine("Test complete, no errors detected"); } else { throw new Exception("Unknown command"); } }
public override Object Visit(ConstantDefinition node, Object obj) { node.Init.Accept(this, obj); node.Symbol = declarationSymbol(node); return(null); }