private void RewriteCall(Statement stm, CallInstruction call) { var e = expander.Expand(call.Callee); var pt = e.Accept(asc) as Pointer; if (pt == null) { return; } var ft = pt.Pointee as FunctionType; if (ft == null) { return; } var returnId = ft.ReturnValue.DataType is VoidType ? null : ft.ReturnValue; var sigCallee = new ProcedureSignature(returnId, ft.Parameters); var ab = new ApplicationBuilder( program.Architecture, proc.Frame, call.CallSite, call.Callee, sigCallee, true); stm.Instruction = ab.CreateInstruction(); ssaIdTransformer.Transform(stm, call); }
RequestContinuation(IClient <Request, Response> client, Request clientRequest, ProcedureSignature invokedProcedure, IContinuation currentContinuation) { Client = client; request = clientRequest; procedure = invokedProcedure; continuation = currentContinuation; }
public void Dec_LoadCallSignatures() { var arch = new IntelArchitecture(ProcessorMode.Real); Program program = new Program { Architecture = arch }; decompiler.Project = new Project { Programs = { program } }; List <SerializedCall_v1> al = new List <SerializedCall_v1>(); SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("ds") }, new Argument_v1 { Kind = new Register_v1("bx"), } }; al.Add(new SerializedCall_v1(Address.SegPtr(0x0C32, 0x3200), sig)); var sigs = decompiler.LoadCallSignatures(program, al); ProcedureSignature ps = sigs[Address.SegPtr(0x0C32, 0x3200)]; Assert.IsNotNull(ps, "Expected a call signature for address"); }
public EquivalenceClassBuilder(TypeFactory factory, TypeStore store) { this.factory = factory; this.store = store; this.signature = null; this.segTypevars = new Dictionary <ushort, TypeVariable>(); }
public override ProcedureSignature Deserialize(SerializedSignature ss, Core.Frame frame) { if (ss == null) { return(null); } var argser = new ArgumentSerializer(this, Architecture, frame, ss.Convention); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); } var args = new List <Identifier>(); this.gr = 0; if (ss.Arguments != null) { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; Identifier arg = DeserializeArgument(argser, sArg); args.Add(arg); } } var sig = new ProcedureSignature(ret, args.ToArray()); return(sig); }
public Response HandleRequest(ProcedureSignature procedure, object[] arguments) { if ((CallContext.GameScene & procedure.GameScene) == 0) { throw new RPCException(procedure, "Procedure not available in game scene '" + CallContext.GameScene + "'"); } object returnValue; try { returnValue = procedure.Handler.Invoke(arguments); } catch (TargetInvocationException e) { if (e.InnerException is YieldException) { throw e.InnerException; } throw new RPCException(procedure, e.InnerException); } var response = new Response(); if (procedure.HasReturnType) { CheckReturnValue(procedure, returnValue); response.ReturnValue = returnValue; } return(response); }
private UserCallData LoadUserCall(SerializedCall_v1 call, Program program) { Address addr; if (!program.Platform.TryParseAddress(call.InstructionAddress, out addr)) { return(null); } var procSer = program.CreateProcedureSerializer(); ProcedureSignature sig = null; if (call.Signature != null) { sig = procSer.Deserialize( call.Signature, program.Architecture.CreateFrame()); } return(new UserCallData { Address = addr, Comment = call.Comment, NoReturn = call.NoReturn, Signature = sig, }); }
public DataType VisitProcedureConstant(ProcedureConstant pc) { ProcedureSignature sig = pc.Procedure.Signature; DataType [] argTypes = null; if (sig != null && sig.Parameters != null) { argTypes = new DataType[sig.Parameters.Length]; for (int i = 0; i < argTypes.Length; ++i) { argTypes[i] = sig.Parameters[i].TypeVariable; } } else { var ppp = pc.Procedure as PseudoProcedure; if (ppp != null) { argTypes = new DataType[ppp.Arity]; for (int i = 0; i < argTypes.Length; ++i) { argTypes[i] = factory.CreateUnknown(); } } } return(sig != null && sig.ReturnValue != null ? sig.ReturnValue.DataType : null); }
public void Dec_LoadCallSignatures() { var arch = new X86ArchitectureReal(); Program program = new Program { Architecture = arch, Platform = new MsdosPlatform(sc, arch) }; decompiler.Project = new Project { Programs = { program }, }; SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("ds") }, new Argument_v1 { Kind = new Register_v1("bx"), } }; var al = new List <SerializedCall_v1> { new SerializedCall_v1(Address.SegPtr(0x0C32, 0x3200), sig) }; var sigs = decompiler.LoadCallSignatures(program, al); ProcedureSignature ps = sigs[Address.SegPtr(0x0C32, 0x3200)]; Assert.IsNotNull(ps, "Expected a call signature for address"); }
public override void OnAfterCall(Identifier sp, ProcedureSignature sig, ExpressionVisitor <Expression> eval) { if (sig == null) { return; } var spReg = (RegisterStorage)sp.Storage; var spVal = GetValue(spReg); var stackOffset = SetValue( spReg, new BinaryExpression( Operator.IAdd, spVal.DataType, sp, Constant.Create( PrimitiveType.CreateWord(spReg.DataType.Size), sig.StackDelta)).Accept(eval)); if (stackOffset.IsValid) { if (stackOffset.ToInt32() > 0) { ErrorListener("Possible stack underflow detected."); } } ShrinkFpuStack(-sig.FpuStackDelta); }
/// <summary> /// Register a new procedure. /// </summary> /// <param name="proc"> the procedure. </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void register(org.neo4j.kernel.api.proc.CallableProcedure proc, boolean overrideCurrentImplementation) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException public virtual void Register(CallableProcedure proc, bool overrideCurrentImplementation) { ProcedureSignature signature = proc.Signature(); QualifiedName name = signature.Name(); string descriptiveName = signature.ToString(); ValidateSignature(descriptiveName, signature.InputSignature(), "input"); ValidateSignature(descriptiveName, signature.OutputSignature(), "output"); if (!signature.Void && signature.OutputSignature().Count == 0) { throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureRegistrationFailed, "Procedures with zero output fields must be declared as VOID"); } CallableProcedure oldImplementation = _procedures.get(name); if (oldImplementation == null) { _procedures.put(name, proc, signature.CaseInsensitive()); } else { if (overrideCurrentImplementation) { _procedures.put(name, proc, signature.CaseInsensitive()); } else { throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name); } } }
public void FrBindStackParameters() { Frame f = new Frame(PrimitiveType.Word16); f.ReturnAddressSize = 4; // far call. int stack = 2; Identifier loc02 = f.EnsureStackLocal(-stack, PrimitiveType.Word16, "wLoc02"); stack += loc02.DataType.Size; Identifier loc04 = f.EnsureStackLocal(-stack, PrimitiveType.Word16, "wLoc04"); ProcedureSignature sig = new ProcedureSignature( null, new Identifier[] { new Identifier("arg0", PrimitiveType.Word16, new StackArgumentStorage(4, PrimitiveType.Word16)), new Identifier("arg1", PrimitiveType.Word16, new StackArgumentStorage(6, PrimitiveType.Word16)) }); var cs = new CallSite(f.ReturnAddressSize + 2 * 4, 0); var fn = new ProcedureConstant(PrimitiveType.Pointer32, new PseudoProcedure("foo", sig)); ApplicationBuilder ab = new ApplicationBuilder(arch, f, cs, fn, sig, true); Instruction instr = ab.CreateInstruction(); using (FileUnitTester fut = new FileUnitTester("Core/FrBindStackParameters.txt")) { f.Write(fut.TextWriter); fut.TextWriter.WriteLine(instr.ToString()); fut.AssertFilesEqual(); } }
public void FrBindMixedParameters() { Frame f = new Frame(PrimitiveType.Word16); Identifier ax = f.EnsureRegister(Registers.ax); Identifier cx = f.EnsureRegister(Registers.cx); int stack = PrimitiveType.Word16.Size; Identifier arg1 = f.EnsureStackLocal(-stack, PrimitiveType.Word16); ProcedureSignature sig = new ProcedureSignature( ax, cx, new Identifier("arg0", PrimitiveType.Word16, new StackArgumentStorage(0, PrimitiveType.Word16))); var cs = new CallSite(stack, 0); ProcedureConstant fn = new ProcedureConstant(PrimitiveType.Pointer32, new PseudoProcedure("bar", sig)); ApplicationBuilder ab = new ApplicationBuilder(arch, f, cs, fn, sig, true); Instruction instr = ab.CreateInstruction(); using (FileUnitTester fut = new FileUnitTester("Core/FrBindMixedParameters.txt")) { f.Write(fut.TextWriter); fut.TextWriter.WriteLine(instr.ToString()); fut.AssertFilesEqual(); } }
void DirectDeclarator(ProcedureSignature sig) { SpaceForPointerOperator(sig.ReturnValue.DataType); fmt.Write(declaredName); ParameterTypeList(null); AbstractDeclarator(sig.ReturnValue.DataType); }
private void BindActualTypesToFormalTypes(Application appl) { ProcedureConstant pc = appl.Procedure as ProcedureConstant; if (pc == null) { throw new NotImplementedException("Indirect call."); } if (pc.Procedure.Signature == null) { return; } ProcedureSignature sig = pc.Procedure.Signature; if (appl.Arguments.Length != sig.Parameters.Length) { throw new InvalidOperationException( string.Format("Call to {0} had {1} arguments instead of the expected {2}.", pc.Procedure.Name, appl.Arguments.Length, sig.Parameters.Length)); } for (int i = 0; i < appl.Arguments.Length; ++i) { handler.EqualTrait(appl.Arguments[i], sig.Parameters[i]); sig.Parameters[i].Accept(this); } if (sig.ReturnValue != null) { handler.EqualTrait(appl, sig.ReturnValue); } }
public ProcedureSignature Deserialize(SerializedSignature ss, Frame frame) { ArgumentSerializer argser = new ArgumentSerializer(this, arch, frame); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.Deserialize(ss.ReturnValue); } ArrayList args = new ArrayList(); if (ss.Arguments != null) { foreach (SerializedArgument arg in ss.Arguments) { args.Add(argser.Deserialize(arg)); } } ProcedureSignature sig = new ProcedureSignature( ret, (Identifier [])args.ToArray(typeof(Identifier))); ApplyConvention(ss, sig); return(sig); }
private bool TryGetNoDecompiledProcedure(Address addr, out ExternalProcedure ep) { Procedure_v1 sProc; if (!program.User.Procedures.TryGetValue(addr, out sProc) || sProc.Decompile) { ep = null; return(false); } ProcedureSignature sig = null; if (!string.IsNullOrEmpty(sProc.CSignature)) { var usb = new UserSignatureBuilder(program); var procDecl = usb.ParseFunctionDeclaration(sProc.CSignature); if (procDecl != null) { var ser = program.CreateProcedureSerializer(); sig = ser.Deserialize( procDecl.Signature, program.Architecture.CreateFrame()); } } else { Warn(addr, "The user-defined procedure at address {0} did not have a signature.", addr); } ep = new ExternalProcedure(sProc.Name, sig); return(true); }
/// <summary> /// Decode a serialized value /// </summary> object Decode(ProcedureSignature procedure, int i, Type type, ByteString value) { if (TypeUtils.IsAClassType(type)) { return(ObjectStore.Instance.GetInstance((ulong)ProtocolBuffers.ReadValue(value, typeof(ulong)))); } else if (TypeUtils.IsACollectionType(type)) { return(DecodeCollection(procedure, i, type, value)); } else if (ProtocolBuffers.IsAMessageType(type)) { return(ProtocolBuffers.ParseFrom(type, value)); } else if (TypeUtils.IsAnEnumType(type)) { // TODO: Assumes it's underlying type is int var enumValue = ProtocolBuffers.ReadValue(value, typeof(int)); if (!Enum.IsDefined(type, enumValue)) { throw new RPCException(procedure, "Failed to convert value " + enumValue + " to enumeration type " + type); } return(Enum.ToObject(type, enumValue)); } else { return(ProtocolBuffers.ReadValue(value, type)); } }
public override void VisitApplication(Application appl) { var oldSig = signature; signature = null; appl.Procedure.Accept(this); ProcedureSignature sig = signature; if (sig != null) { if (sig.Parameters.Length != appl.Arguments.Length) { throw new InvalidOperationException("Parameter count must match."); } } for (int i = 0; i < appl.Arguments.Length; ++i) { appl.Arguments[i].Accept(this); if (sig != null) { EnsureTypeVariable(sig.Parameters[i]); store.MergeClasses(appl.Arguments[i].TypeVariable, sig.Parameters[i].TypeVariable); } } EnsureTypeVariable(appl); signature = oldSig; }
public ProcedureSignature GetCallSignatureAtAddress(Address addrCallInstruction) { ProcedureSignature sig = null; callSigs.TryGetValue(addrCallInstruction, out sig); return(sig); }
RequestContinuation(IClient client, Request request, ProcedureSignature procedure, IContinuation continuation) { Client = client; this.request = request; this.procedure = procedure; this.continuation = continuation; }
public FunctionType(ProcedureSignature sig) : base() { this.ReturnType = sig.ReturnValue != null ? sig.ReturnValue.DataType : VoidType.Instance; this.ArgumentTypes = sig.Parameters.Select(a => a.DataType).ToArray(); this.ArgumentNames = sig.Parameters.Select(a => a.Name).ToArray(); }
public void Setup() { this.mr = new MockRepository(); this.arch = new MipsLe32Architecture(); this.typeLoader = mr.Stub <ISerializedTypeVisitor <DataType> >(); this.ssig = null; this.sig = null; }
public void EqbProcedureSignature() { var sig = new ProcedureSignature(null, new Identifier("dwArg00", PrimitiveType.Word32, new StackArgumentStorage(0, PrimitiveType.Word32))); eqb.EnsureSignatureTypeVariables(sig); Assert.IsNotNull(sig.Parameters[0].TypeVariable); }
public void Impres_ProcedureByName_NoModule() { var proj = new Project { MetadataFiles = { new MetadataFile { ModuleName = "foo" } }, Programs = { program } }; var barSig = new ProcedureSignature( new Identifier( "res", PrimitiveType.Word16, new RegisterStorage("ax", 0, 0, PrimitiveType.Word16) ), new Identifier( "a", PrimitiveType.Word16, new RegisterStorage("cx", 0, 0, PrimitiveType.Word16) ), new Identifier( "b", PrimitiveType.Word16, new RegisterStorage("dx", 0, 0, PrimitiveType.Word16) ) ); program.EnvironmentMetadata.Modules.Add("foo", new ModuleDescriptor("foo") { ServicesByName = { { "bar", new SystemService { Name = "bar", Signature = barSig } } } }); var impres = new ImportResolver(proj, program, new FakeDecompilerEventListener()); var ep = impres.ResolveProcedure("foo", "bar", platform); Assert.AreEqual("bar", ep.Name); var sigExp = @"Register word16 ()(Register word16 a, Register word16 b) // stackDelta: 0; fpuStackDelta: 0; fpuMaxParam: -1 "; Assert.AreEqual(sigExp, ep.Signature.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotSetProcedureAllowedIfSettingNotSet() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotSetProcedureAllowedIfSettingNotSet() { ConfiguredSetup(DefaultConfiguration()); Procedures procedures = Neo.LocalGraph.DependencyResolver.resolveDependency(typeof(Procedures)); ProcedureSignature numNodes = procedures.Procedure(new QualifiedName(new string[] { "test" }, "numNodes")).signature(); assertThat(Arrays.asList(numNodes.Allowed()), empty()); }
public ProcedureCallContinuation(ProcedureCall procedureCall) { call = procedureCall; try { procedure = Services.Instance.GetProcedureSignature(call); } catch (System.Exception e) { exception = e; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSetAllowedToConfigSetting() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSetAllowedToConfigSetting() { ConfiguredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty")); Procedures procedures = Neo.LocalGraph.DependencyResolver.resolveDependency(typeof(Procedures)); ProcedureSignature numNodes = procedures.Procedure(new QualifiedName(new string[] { "test" }, "numNodes")).signature(); assertThat(Arrays.asList(numNodes.Allowed()), containsInAnyOrder("nonEmpty")); }
/// <summary> /// Add the traits of the procedure's signature. /// </summary> private void AddProcedureTraits(Procedure proc) { ProcedureSignature sig = proc.Signature; if (sig.ReturnValue != null) { handler.DataTypeTrait(sig.ReturnValue, sig.ReturnValue.DataType); } }
public void ExdApplication() { var arg = Id("arg", PrimitiveType.Word32); var sig = new ProcedureSignature(null, Id("r", PrimitiveType.Real32)); var ep = new ExternalProcedure("test", sig); RunTest( Test(m.Fn(ep, m.Load(PrimitiveType.Word32, m.Word32(0x0300400))), VoidType.Instance)); }
public void ApplyConvention(SerializedSignature ssig, ProcedureSignature sig) { string d = ssig.Convention; if (d == null || d.Length == 0) d = defaultConvention; if (d != null && d == "stdapi") sig.StackDelta = stackOffset; sig.FpuStackDelta = fpuStackOffset; }
public SerializedSignature Serialize(ProcedureSignature sig) { SerializedSignature ssig = new SerializedSignature(); if (!sig.ParametersValid) return ssig; ArgumentSerializer argSer = new ArgumentSerializer(this, Architecture, null, null); ssig.ReturnValue = argSer.Serialize(sig.ReturnValue); ssig.Arguments = new Argument_v1[sig.Parameters.Length]; for (int i = 0; i < sig.Parameters.Length; ++i) { Identifier formal = sig.Parameters[i]; ssig.Arguments[i] = argSer.Serialize(formal); } ssig.StackDelta = sig.StackDelta; ssig.FpuStackDelta = sig.FpuStackDelta; return ssig; }
public ProcedureSignature Deserialize(SerializedSignature ss, Frame frame) { ArgumentSerializer argser = new ArgumentSerializer(this, arch, frame); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.Deserialize(ss.ReturnValue); } ArrayList args = new ArrayList(); if (ss.Arguments != null) { foreach (SerializedArgument arg in ss.Arguments) { args.Add(argser.Deserialize(arg)); } } ProcedureSignature sig = new ProcedureSignature( ret, (Identifier [])args.ToArray(typeof(Identifier))); ApplyConvention(ss, sig); return sig; }
void DirectDeclarator(ProcedureSignature sig) { SpaceForPointerOperator(sig.ReturnValue.DataType); fmt.Write(declaredName); ParameterTypeList(null); AbstractDeclarator(sig.ReturnValue.DataType); }