Example #1
0
        /// <summary>
        /// Default ctor
        /// </summary>
        private ManifestBuilder(string assemblyFile, IEnumerable <string> referenceFolders, string packageName, NameConverter nsConverter, bool debuggable, List <string> appWidgetProviderCodeFiles, string targetSdkVersion)
        {
#if DEBUG
            //Debugger.Launch();
#endif

            module           = new XModule();
            this.packageName = packageName;
            this.nsConverter = nsConverter;
            this.debuggable  = debuggable;
            this.appWidgetProviderCodeFiles = appWidgetProviderCodeFiles;
            this.targetSdkVersion           = targetSdkVersion;

            // Load assembly file
            if (!File.Exists(assemblyFile))
            {
                throw new ArgumentException(string.Format("Assembly {0} not found", assemblyFile));
            }

            var assemblyResolver = new AssemblyResolver(referenceFolders, null, module.OnAssemblyLoaded);
            var parameters       = new ReaderParameters {
                AssemblyResolver = assemblyResolver
            };
            assembly = assemblyResolver.Load(assemblyFile, parameters);
        }
Example #2
0
        public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction)
        {
            var        action     = testAction as SpecialExecutionTaskTestAction;
            var        module     = action.TCItem.GetModule();
            XModule    xMod       = module as XModule;
            var        xParams    = xMod.GetXParams();
            ModuleType moduleType = ModuleType.Method;
            //if (!Enum.TryParse(xParams.Single(x => x.Name.ToLower() == "type").Value, out moduleType))
            //{
            //    throw new InvalidOperationException("Invalid value in 'Type' Technical Parameter");
            //}

            ReflectionConfig config = new ReflectionConfig
            {
                ClassName   = xParams.Single(x => x.Name.ToLower() == "classname").Value,
                LibraryFile = xParams.Single(x => x.Name.ToLower() == "libraryfile").Value,
                MethodName  = xParams.Single(x => x.Name.ToLower() == "methodname").Value
            };

            var          classObject = ActivateObject(config);
            ActionResult result      = null;

            switch (moduleType)
            {
            case ModuleType.Class:
                result = ExecuteClass(action, classObject);
                break;

            case ModuleType.Method:
                result = ExecuteMethod(action, classObject, config);
                break;
            }
            return(result);
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public ILGenericParameter(XModule module, GenericParameter p) : 
     base(module)
 {
     this.p = p;
     constraints = new Lazy<XTypeReference[]>(()=>
         p.Constraints.Select(k=>AsTypeReference(module, k)).ToArray());
 }
Example #4
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AstBuilder(MethodDefinition methodDef, bool optimize, DecompilerContext context)
 {
     this.methodDef = methodDef;
     this.optimize = optimize;
     this.context = context;
     module = context.CurrentModule;
 }
Example #5
0
        private XModuleAttribute CreateModuleAttribute(XModule parent, ParameterViewModel parameter)
        {
            var moduleAttribute = parent.CreateModuleAttribute();

            BuildModuleAttribute(moduleAttribute, parameter.Name, parameter.ParameterType, 1, true);
            return(moduleAttribute);
        }
Example #6
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public ILGenericParameter(XModule module, GenericParameter p) :
     base(module)
 {
     this.p      = p;
     constraints = new Lazy <XTypeReference[]>(() =>
                                               p.Constraints.Select(k => AsTypeReference(module, k)).ToArray());
 }
        /// <summary>
        /// Handles response data in Xml/JSON Resource specialization
        /// </summary>
        /// <param name="wseTestStep">TestStep of WSE Artifacts</param>
        /// <param name="apiTestStep">TestStep of API Engine Artifacts</param>
        /// <param name="payloadParser">Parse xml and json payload from Wse XModules and TestSteps</param>
        /// <param name="payloadSetterFactory">Create module attributes and Set values for payload in for Api artifacts </param>
        public override void HandleSpecialization(XTestStep wseTestStep,
                                                  XTestStep apiTestStep,
                                                  IPayloadParser payloadParser,
                                                  IPayloadSetterFactory payloadSetterFactory)
        {
            XModule specializationModule =
                (XModule)wseTestStep.Search(TqlToGetWseTestStepSpecializationModule)?.FirstOrDefault();

            if (specializationModule != null)
            {
                try {
                    var wseTestStepValue =
                        (XTestStepValue)wseTestStep.Search(TqlToGetWseTestStepValue)?.FirstOrDefault();
                    if (wseTestStepValue != null && !StringExtensions.IsNullOrBlankInTosca(wseTestStepValue.Value))
                    {
                        TestCase testCase = (TestCase)wseTestStep.Search(TqlToSearchTestCase)?.FirstOrDefault();

                        if (testCase != null)
                        {
                            ResourceManagerHandler.AddResourceToResourceId(testCase.Name, wseTestStepValue.Value);
                        }
                    }
                }
                catch (Exception ex) {
                    FileLogger.Instance.Error("Unable to fetch WSE tesstep value ", ex);
                }
            }
            else
            {
                successor?.HandleSpecialization(wseTestStep, apiTestStep, payloadParser, payloadSetterFactory);
            }
        }
Example #8
0
 /// <summary>
 /// Gets a class reference for the given type reference.
 /// </summary>
 internal static ClassReference GetClassReference(this JvmClassLib.TypeReference type, XTypeUsageFlags usageFlags, DexTargetPackage targetPackage, XModule module)
 {
     var classRef = type.GetReference(usageFlags, targetPackage, module) as ClassReference;
     if (classRef == null)
         throw new ArgumentException(string.Format("type {0} is not a class reference", type.ClassName));
     return classRef;
 }
Example #9
0
        public XModuleAttribute SetupAttributes(XModule mainModule, HtmlElement iframe)
        {
            XModuleAttribute iframeAttribute = mainModule.CreateModuleAttribute();

            iframeAttribute.Name = iframe.TagName;
            iframeAttribute.DefaultActionMode = XTestStepActionMode.Select;
            iframeAttribute.Cardinality       = "0-1";
            iframeAttribute.BusinessType      = "HtmlFrame";


            AddBusinessParam(iframeAttribute.CreateConfigurationParam(), "Engine", "Html");
            AddBusinessParam(iframeAttribute.CreateConfigurationParam(), "BusinessAssociation", "Descendants");
            AddBusinessParam(iframeAttribute.CreateTechnicalIDParam(), "Id", iframe.Id);
            AddBusinessParam(iframeAttribute.CreateTechnicalIDParam(), "Tag", iframe.TagName);

            var htmlDocumentAttr = iframeAttribute.CreateModuleAttribute();

            htmlDocumentAttr.Name              = "HtmlDocument";
            htmlDocumentAttr.BusinessType      = "HtmlDocument";
            htmlDocumentAttr.Cardinality       = "0-1";
            htmlDocumentAttr.DefaultActionMode = XTestStepActionMode.Select;
            AddBusinessParam(htmlDocumentAttr.CreateConfigurationParam(), "BusinessAssociation", "Descendants");
            AddBusinessParam(htmlDocumentAttr.CreateConfigurationParam(), "Engine", "Html");

            return(htmlDocumentAttr);
        }
Example #10
0
        /// <summary>
        /// Default ctor
        /// </summary>
        internal XTypeSystem(XModule module)
        {
            Bool = new XPrimitiveType(module, XTypeReferenceKind.Bool, "Boolean");
            Byte = new XPrimitiveType(module, XTypeReferenceKind.Byte, "Byte");
            SByte = new XPrimitiveType(module, XTypeReferenceKind.SByte, "SByte");
            Char = new XPrimitiveType(module, XTypeReferenceKind.Char, "Char");
            Short = new XPrimitiveType(module, XTypeReferenceKind.Short, "Int16");
            UShort = new XPrimitiveType(module, XTypeReferenceKind.UShort, "UInt16");
            Int = new XPrimitiveType(module, XTypeReferenceKind.Int, "Int32");
            UInt = new XPrimitiveType(module, XTypeReferenceKind.UInt, "UInt32");
            Long = new XPrimitiveType(module, XTypeReferenceKind.Long, "Int64");
            ULong = new XPrimitiveType(module, XTypeReferenceKind.ULong, "UInt64");
            Float = new XPrimitiveType(module, XTypeReferenceKind.Float, "Single");
            Double = new XPrimitiveType(module, XTypeReferenceKind.Double, "Double");
            Void = new XPrimitiveType(module, XTypeReferenceKind.Void, "Void");
            IntPtr = new XPrimitiveType(module, XTypeReferenceKind.IntPtr, "IntPtr");
            UIntPtr = new XPrimitiveType(module, XTypeReferenceKind.UIntPtr, "UIntPtr");
            TypedReference = new XPrimitiveType(module, XTypeReferenceKind.TypedReference, "TypedReference");

            Exception = new XTypeReference.SimpleXTypeReference(module, "System", "Exception", null, false, null);
            Object = new XTypeReference.SimpleXTypeReference(module, "System", "Object", null, false, null);
            String = new XTypeReference.SimpleXTypeReference(module, "System", "String", null, false, null);
            Type = new XTypeReference.SimpleXTypeReference(module, "System", "Type", null, false, null);

            NoType = new XTypeReference.SimpleXTypeReference(module, "____no_type___", "___no_type`99999", null, false, null);
        }
        /// <summary>
        /// Parses WSE Module to get payload in string format
        /// </summary>
        /// <param name="wseModule">WSE Module</param>
        /// <param name="tql"> Not used</param>
        /// <returns>payload in string format</returns>
        public string Parse(XModule wseModule, string tql = "")
        {
            try {
                if (wseModule == null)
                {
                    return(string.Empty);
                }
                XModuleAttribute jsonObject = wseModule
                                              .Search("=>SUBPARTS:XModuleAttribute").Cast <XModuleAttribute>()
                                              .FirstOrDefault(x => x.BusinessType
                                                              == "JsonObject" || x.BusinessType == "JsonArray");

                if (jsonObject != null)
                {
                    JArray  arrayObject = new JArray();
                    JObject plainObject = CommonUtilities.ConstructJsonStructure(jsonObject, new JObject());
                    if (jsonObject.BusinessType == "JsonObject")
                    {
                        return(Convert.ToString(plainObject));
                    }

                    arrayObject.Add(plainObject.Values());
                    return(Convert.ToString(arrayObject));
                }
            }
            catch (Exception e) {
                FileLogger.Instance.Error(
                    $"Failed to create Json payload for request :{wseModule?.Name}",
                    e);
            }

            return(string.Empty);
        }
Example #12
0
        /// <summary>
        /// Default ctor
        /// </summary>
        internal XTypeSystem(XModule module)
        {
            Bool           = new XPrimitiveType(module, XTypeReferenceKind.Bool, "Boolean");
            Byte           = new XPrimitiveType(module, XTypeReferenceKind.Byte, "Byte");
            SByte          = new XPrimitiveType(module, XTypeReferenceKind.SByte, "SByte");
            Char           = new XPrimitiveType(module, XTypeReferenceKind.Char, "Char");
            Short          = new XPrimitiveType(module, XTypeReferenceKind.Short, "Int16");
            UShort         = new XPrimitiveType(module, XTypeReferenceKind.UShort, "UInt16");
            Int            = new XPrimitiveType(module, XTypeReferenceKind.Int, "Int32");
            UInt           = new XPrimitiveType(module, XTypeReferenceKind.UInt, "UInt32");
            Long           = new XPrimitiveType(module, XTypeReferenceKind.Long, "Int64");
            ULong          = new XPrimitiveType(module, XTypeReferenceKind.ULong, "UInt64");
            Float          = new XPrimitiveType(module, XTypeReferenceKind.Float, "Single");
            Double         = new XPrimitiveType(module, XTypeReferenceKind.Double, "Double");
            Void           = new XPrimitiveType(module, XTypeReferenceKind.Void, "Void");
            IntPtr         = new XPrimitiveType(module, XTypeReferenceKind.IntPtr, "IntPtr");
            UIntPtr        = new XPrimitiveType(module, XTypeReferenceKind.UIntPtr, "UIntPtr");
            TypedReference = new XPrimitiveType(module, XTypeReferenceKind.TypedReference, "TypedReference");

            Exception = new XTypeReference.SimpleXTypeReference(module, "System", "Exception", null, false, null);
            Object    = new XTypeReference.SimpleXTypeReference(module, "System", "Object", null, false, null);
            String    = new XTypeReference.SimpleXTypeReference(module, "System", "String", null, false, null);
            Type      = new XTypeReference.SimpleXTypeReference(module, "System", "Type", null, false, null);

            NoType = new XTypeReference.SimpleXTypeReference(module, "____no_type___", "___no_type`99999", null, false, null);
        }
        static void Main(string[] args)
        {
            using (TCAPI tcapi = TCAPI.CreateInstance())
            {
                TCWorkspace     workspace      = tcapi.OpenWorkspace(@"C:\Users\estan\Desktop\trainings\TOSCA Customizations\Tosca Workspace\Training Customizations\Training Customizations.tws", "Admin", "");
                TCProject       project        = workspace.GetProject();
                List <TCObject> result         = project.Search($"=>SUBPARTS:TCFolder[UniqueId==\"{unique_id_test_case_folder}\"]");
                TCFolder        testCaseFolder = (TCFolder)result.First();
                testCaseFolder.Checkout();

                TestCase testCase = testCaseFolder.CreateTestCase();
                testCase.Name = "Test Creating Test Case";

                XModule tboxSetBuffer = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_set_buffer}\"]").First();
                XModule tboxWait      = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_wait}\"]").First();


                XTestStep      setBufferTestStep  = testCase.CreateXTestStepFromXModule(tboxSetBuffer);
                XTestStepValue setBUfferStepvalue = setBufferTestStep.CreateXTestStepValue(tboxSetBuffer.Attributes.First());
                setBUfferStepvalue.Name       = "Test Buffer Creation";
                setBUfferStepvalue.Value      = "42";
                setBUfferStepvalue.ActionMode = XTestStepActionMode.Input;

                XTestStep      tboxSetWaitTimeStep      = testCase.CreateXTestStepFromXModule(tboxWait);
                XTestStepValue tboxWaitSettimeStepValue = tboxSetWaitTimeStep.TestStepValues.First();
                tboxWaitSettimeStepValue.Value = "500";
            }
        }
        /// <summary>
        /// Parses WSE XModule to get data.
        /// </summary>
        /// <param name="wseModule">WSE XModule</param>
        public void Parse(XModule wseModule)
        {
            try {
                var methodParser = new MethodParser();
                Method = methodParser.Parse(wseModule);

                var addressParser = new AddressParser();
                AddressParserResult addressParserResult = addressParser.Parse(wseModule);
                Endpoint    = addressParserResult.Endpoint;
                Resource    = addressParserResult.Resource;
                QueryParams = addressParserResult.QueryParams;

                var headerParser = new HeaderParser();
                Headers         = headerParser.Parse(wseModule, AddOnConstants.RequestHeadersTql);
                Headers         = CommonUtilities.ModifyContentTypeToEmpty(Headers);
                ResponseHeaders = headerParser.Parse(wseModule, AddOnConstants.ResponseHeadersTql);

                var payloadParser = new XmlPayloadParser();
                RequestPayload  = payloadParser.Parse(wseModule, AddOnConstants.RequestPayloadTql);
                ResponsePayload = payloadParser.Parse(wseModule, AddOnConstants.ResponsePayloadTql);

                var statusCodeParser = new StatusCodeParser();
                ResponseStatus = statusCodeParser.ParseResponseStatus(wseModule);

                HashCode = GetHashCode(wseModule);
            }
            catch (Exception e) {
                FileLogger.Instance.Error(e);
            }
        }
        /// <summary>
        /// Create a synthetic field and add it to the given declaring type.
        /// </summary>
        public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType)
        {
            var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType);

            declaringType.Add(type);
            return(type);
        }
Example #16
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AstBuilder(MethodDefinition methodDef, bool optimize, DecompilerContext context)
 {
     this.methodDef = methodDef;
     this.optimize  = optimize;
     this.context   = context;
     module         = context.CurrentModule;
 }
Example #17
0
        /// <summary>
        /// Get Endpoint, Resource and Query Params from WSE Module
        /// </summary>
        /// <param name="wseModule"></param>
        /// <returns>AddressParserResult object which contains Endpoint, Resource and Query Params</returns>
        public AddressParserResult Parse(XModule wseModule)
        {
            var addressParserResult = new AddressParserResult();

            try {
                TCObject addressValueTql =
                    wseModule.Search(AddOnConstants.AddressValueTql).FirstOrDefault();
                if (addressValueTql == null)
                {
                    return(addressParserResult);
                }

                XModuleAttribute addressValue = addressValueTql as XModuleAttribute;

                if (string.IsNullOrEmpty(addressValue?.DefaultValue))
                {
                    return(addressParserResult);
                }
                ParseAddressInternal(addressParserResult, addressValue.DefaultValue);
            }
            catch (Exception ex) {
                FileLogger.Instance.Error(ex);
            }

            return(addressParserResult);
        }
Example #18
0
        public void CompileIfRequired(ilspy::Mono.Cecil.AssemblyDefinition assembly, bool stopBeforeGeneratingCode = false)
        {
            if (_compiler != null && _previousAssembly == assembly
            && (_isFullyCompiled || stopBeforeGeneratingCode))
                return;

            CompilationErrors = null;
            _compiler = null;

#if DEBUG
            var framework = Frameworks.Instance.GetBySdkVersion(15);
#else
            var framework = Frameworks.Instance.GetNewestVersion();
#endif
            string frameworkFolder = framework.Folder;
            var refFolders = new List<string> { frameworkFolder };

            var module = new XModule();
            var classLoader = new AssemblyClassLoader(module.OnClassLoaded);
            var resolver = new AssemblyResolver(refFolders, classLoader, module.OnAssemblyLoaded);
            var parameter = new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = resolver,ReadSymbols = true};

            var assemblies = new[] { resolver.Load(assembly.MainModule.FullyQualifiedName, parameter) }.ToList();
            List<AssemblyDefinition> references = new List<AssemblyDefinition>();
            
            if(assembly.MainModule.Name != "dot42.dll")
                references = new[] { resolver.Load(AssemblyConstants.SdkAssemblyName, parameter) }.ToList();
            
            foreach (var a in assemblies)
                references.Remove(a);

            var c = new AssemblyCompiler(CompilationMode.All, assemblies, references, new Table("pkg.name"),
                                         new NameConverter("pkg.name", ""), true, 
                                         new AssemblyClassLoader(file => { }), definition => null,
                                         new DexMethodBodyCompilerCache(), new HashSet<string>(), 
                                         module, _generateSetNextInstructionCode);

            c.StopCompilationBeforeGeneratingCode = stopBeforeGeneratingCode;
            c.StopAtFirstError = false;
            
            try
            {
                c.Compile();
            }
            catch (AggregateException ex)
            {
                CompilationErrors = ex.Flatten().InnerExceptions.Select(e => e.Message.Replace(": ", "\n//      ").Replace("; ", "\n//      &  ")).ToList();
            }

            if (c.MapFile != null)
            {
                c.MapFile.Optimize();
                MapFile = new MapFileLookup(c.MapFile);
            }

            _compiler = c;
            _previousAssembly = assembly;
            _isFullyCompiled = !stopBeforeGeneratingCode;
        }
Example #19
0
        /// <summary>
        /// Gets a class reference for the given type reference.
        /// </summary>
        internal static TypeReference GetReference(this Mono.Cecil.TypeReference type, DexTargetPackage targetPackage, XModule module)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            var xType = XBuilder.AsTypeReference(module, type);
            return xType.GetReference(targetPackage);
        }
Example #20
0
        /// <summary>
        /// Gets a Dex method reference for the given type reference.
        /// </summary>
        internal static MethodReference GetReference(this Mono.Cecil.MethodReference method, DexTargetPackage targetPackage, XModule module)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            var xMethod = XBuilder.AsMethodReference(module, method);
            return xMethod.GetReference(targetPackage);
        }
Example #21
0
        /// <summary>
        /// Gets a Dex field reference for the given field reference.
        /// </summary>
        internal static FieldReference GetReference(this Mono.Cecil.FieldReference field, DexTargetPackage targetPackage, XModule module)
        {
            if (field == null)
                throw new ArgumentNullException("field");

            var xField = XBuilder.AsFieldReference(module, field);
            return xField.GetReference(targetPackage);
        }
Example #22
0
        public override double GetValue(double t)
        {
            // Read the target t value from the lookup graph:
            t = XModule.GetValue(t);

            // Read at that point:
            return(SourceModule.GetValue(t));
        }
Example #23
0
        public static XParam CreateConfigurationParam(this XModule module)
        {
            var xp = XParam.Create();

            xp.ParamType = XParam.ParamTypeE.Configuration;
            module.Properties.Add(xp);
            return(xp);
        }
Example #24
0
        // TestFrm t;

        public override void Initialize()
        {
            itemRMenuFrm          = new ItemRMenuFrm(XSupport, XModule);
            itemRMenuFrm.Visible  = true;
            itemRMenuFrm.TopLevel = false;

            XModule.InsertControl(itemRMenuFrm, "*PAGE(CustomPanel,VWeb)");
        }
Example #25
0
        public static XModuleAttribute CreateModuleAttribute(this XModule module)
        {
            var ma = XModuleAttribute.Create();

            ma.Module.Set(module);
            //module.Attributes.Add(ma);
            return(ma);
        }
Example #26
0
        /// <summary>
        /// Gets a class reference for the given type reference.
        /// </summary>
        internal static TypeReference GetReference(this JvmClassLib.TypeReference type, XTypeUsageFlags usageFlags, DexTargetPackage targetPackage, XModule module)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            var xType = XBuilder.AsTypeReference(module, type, usageFlags);
            return xType.GetReference(targetPackage);
        }
Example #27
0
        public static XParam CreateTechnicalIDParam(this XModule module)
        {
            var xp = XParam.Create();

            xp.ParamType = XParam.ParamTypeE.TechnicalID;
            module.Properties.Add(xp);
            return(xp);
        }
        /// <summary>
        /// Create a synthetic field and add it to the given declaring type.
        /// </summary>
        public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType, string fullScopeId)
        {
            var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType, fullScopeId);
            if(declaringType != null)
                declaringType.Add(type);

            module.Register(type);
            return type;
        }
Example #29
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type)
     : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name))
 {
     this.type = type;
     fields = new List<XFieldDefinition>(type.Fields.Count);
     methods = new List<XMethodDefinition>(type.Methods.Count);
     nested = new List<XTypeDefinition>();
     interfaces = new List<XTypeReference>();
 }
Example #30
0
        public override double GetWrapped(double x, double y, int wrap)
        {
            // Read coords:
            double lookX = (XModule == null)?0:XModule.GetWrapped(x, y, wrap);
            double lookY = (YModule == null)?0:YModule.GetWrapped(x, y, wrap);

            // Read:
            return(SourceModule.GetWrapped(lookX, lookY, wrap));
        }
Example #31
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read coords:
            double lookX = (XModule == null)?0:XModule.GetValue(x, y);
            double lookY = (YModule == null)?0:YModule.GetValue(x, y);

            // Read colour:
            return(SourceModule.GetColour(lookX, lookY));
        }
Example #32
0
        /// <summary>
        /// Returns the output of the two source modules added together.
        /// </summary>
        public override double GetValue(double x, double y)
        {
            // Read coords:
            double lookX = (XModule == null)?0:XModule.GetValue(x, y);
            double lookY = (YModule == null)?0:YModule.GetValue(x, y);

            // Read:
            return(SourceModule.GetValue(lookX, lookY));
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type)
     : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name))
 {
     this.type  = type;
     fields     = new List <XFieldDefinition>(type.Fields.Count);
     methods    = new List <XMethodDefinition>(type.Methods.Count);
     nested     = new List <XTypeDefinition>();
     interfaces = new List <XTypeReference>();
 }
Example #34
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public JavaTypeDefinition(XModule module, XTypeDefinition declaringType, ClassFile type)
     : base(module, declaringType, false, null)
 {
     this.type = type;
     fields = type.Fields.Select(x => new JavaFieldDefinition(this, x)).Cast<XFieldDefinition>().ToList().AsReadOnly();
     methods = type.Methods.Select(x => new JavaMethodDefinition(this, x)).Cast<XMethodDefinition>().ToList().AsReadOnly();
     nested = type.InnerClasses.Where(x => x.InnerClassFile.DeclaringClass == type).Select(x => new JavaTypeDefinition(module, this, x.InnerClassFile)).Cast<XTypeDefinition>().ToList().AsReadOnly();
     interfaces = new List<XTypeReference>();
 }
Example #35
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public JavaTypeDefinition(XModule module, XTypeDefinition declaringType, ClassFile type)
     : base(module, declaringType, false, null)
 {
     this.type  = type;
     fields     = type.Fields.Select(x => new JavaFieldDefinition(this, x)).Cast <XFieldDefinition>().ToList().AsReadOnly();
     methods    = type.Methods.Select(x => new JavaMethodDefinition(this, x)).Cast <XMethodDefinition>().ToList().AsReadOnly();
     nested     = type.InnerClasses.Where(x => x.InnerClassFile.DeclaringClass == type).Select(x => new JavaTypeDefinition(module, this, x.InnerClassFile)).Cast <XTypeDefinition>().ToList().AsReadOnly();
     interfaces = new List <XTypeReference>();
 }
Example #36
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AstBuilder(XModule module, MethodDefinition methodDef, XTypeDefinition declaringType, bool optimize)
 {
     this.module            = module;
     typeSystem             = module.TypeSystem;
     this.methodDef         = methodDef;
     this.declaringType     = declaringType;
     this.optimize          = optimize;
     codeAttr               = methodDef.Attributes.OfType <CodeAttribute>().FirstOrDefault();
     validExceptionHandlers = (codeAttr != null) ? codeAttr.ExceptionHandlers.Where(IsValid).ToList() : null;
 }
Example #37
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AstBuilder(XModule module, MethodDefinition methodDef, XTypeDefinition declaringType, bool optimize)
 {
     this.module = module;
     typeSystem = module.TypeSystem;
     this.methodDef = methodDef;
     this.declaringType = declaringType;
     this.optimize = optimize;
     codeAttr = methodDef.Attributes.OfType<CodeAttribute>().FirstOrDefault();
     validExceptionHandlers = (codeAttr != null) ? codeAttr.ExceptionHandlers.Where(IsValid).ToList() : null;
 }
Example #38
0
        /// <summary>
        /// Convert an Java type reference to an XTypeReference.
        /// </summary>
        public static XTypeReference AsTypeReference(XModule module, ClassFile classFile, XTypeUsageFlags usageFlags)
        {
            if (classFile == null)
            {
                return(null);
            }
            var objectType = new ObjectTypeReference(classFile.ClassName, null);

            return(AsTypeReference(module, objectType, usageFlags));
        }
Example #39
0
 /// <summary>
 /// .NET ctor
 /// </summary>
 public DecompilerContext(XMethodDefinition currentMethod)
 {
     if (currentMethod == null)
         throw new ArgumentNullException("currentMethod");
     name = currentMethod.Name;
     declaringTypeName = currentMethod.DeclaringType.Name;
     declaringType = currentMethod.DeclaringType;
     returnType = currentMethod.ReturnType;
     currentModule = currentMethod.Module;
 }
Example #40
0
        /// <summary>
        /// Identify whether WSE XtestStepvalues(Request) is using Web service request data in JSON Resource specialization
        /// Identify whether WSE XtestStepvalues(Request) is using Web service request data in XML Resource specialization
        /// </summary>
        /// <param name="testStep">Wse TestStep</param>
        /// <param name="embeddedModule">Specialization Module for Request</param>
        /// <returns>true if xmodule is using specialization</returns>
        public static bool IsRequestIsUsingEmbeddedModule(XTestStep testStep, out XModule embeddedModule)
        {
            var name = "Request";
            var specializationModulesToExclude = new List <string>()
            {
                "Web service request data in JSON Resource",
                "Web service request data in XML Resource"
            };

            return(IsUsingEmbeddedModule(testStep, name, specializationModulesToExclude, out embeddedModule));
        }
Example #41
0
        /// <summary>
        /// Create a synthetic field and add it to the given declaring type.
        /// </summary>
        public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType, string fullScopeId)
        {
            var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType, fullScopeId);

            if (declaringType != null)
            {
                declaringType.Add(type);
            }

            module.Register(type);
            return(type);
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 private XSyntheticTypeDefinition(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType)
     : base(module, declaringType, flags.HasFlag(XSyntheticTypeFlags.ValueType), null)
 {
     this.flags      = flags;
     this.@namespace = @namespace;
     this.name       = name;
     this.baseType   = baseType;
     fields          = new List <XFieldDefinition>();
     methods         = new List <XMethodDefinition>();
     nestedTypes     = new List <XTypeDefinition>();
     interfaces      = new List <XTypeReference>();
 }
        // private void NameChanged(object Sender, XEventArgs e)
        // {
        // }


        // protected void Page_Load(object sender, EventArgs e)
        // {
        // }


        // private void checkActive(object Sender, XEventArgs e)
        // {
        // }


        //public override void AfterPost()
        //{
        //    itemForm.syncOnSave();
        //}

        public override void Initialize()
        {
            ItemTable         = XModule.GetTable("MTRL");
            itemForm          = new ItemForm();
            itemForm.TopLevel = false;
            itemForm.MTRL     = ItemTable;
            itemForm.Visible  = true;

            XModule.InsertControl(itemForm, "+PAGE(PG8,Web)");

            CallCount++;
        }
Example #44
0
 /// <summary>
 /// Default ctor
 /// </summary>
 private XSyntheticTypeDefinition(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType)
     : base(module, declaringType, flags.HasFlag(XSyntheticTypeFlags.ValueType), null)
 {
     this.flags = flags;
     this.@namespace = @namespace;
     this.name = name;
     this.baseType = baseType;
     fields = new List<XFieldDefinition>();
     methods = new List<XMethodDefinition>();
     nestedTypes = new List<XTypeDefinition>();
     interfaces = new List<XTypeReference>();
 }
        private static int GetHashCode(XModule xModule)
        {
            var stringBuilder = new StringBuilder();
            var treeObjects   = xModule.Search("=>SUBPARTS:XModuleAttribute[Name==\"Request\"]=>SubAttributes");

            foreach (var t in treeObjects)
            {
                stringBuilder.Append(t.DisplayedName);
            }

            return(stringBuilder.ToString().GetHashCode());
        }
Example #46
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AssemblyCompiler(CompilationMode mode, List<AssemblyDefinition> assemblies, List<AssemblyDefinition> references, Table resources, NameConverter nameConverter, bool generateDebugInfo, AssemblyClassLoader assemblyClassLoader,
     HashSet<string> rootClassNames, XModule module)
 {
     this.mode = mode;
     this.assemblies = assemblies;
     this.references = references;
     this.resources = resources;
     this.generateDebugInfo = generateDebugInfo;
     this.assemblyClassLoader = assemblyClassLoader;
     this.rootClassNames = rootClassNames;
     this.module = module;
     targetPackage = new Target.Dex.DexTargetPackage(nameConverter, this);
 }
            /// <summary>
            /// Default ctor
            /// </summary>
            public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type)
                : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name))
            {
                this.type = type;
                fields = new List<XFieldDefinition>(type.Fields.Count);
                methods = new List<XMethodDefinition>(type.Methods.Count);
                nested = new List<XTypeDefinition>();
                interfaces = new List<XTypeReference>();

                // Add nested types
                foreach (var source in type.NestedTypes/*.Where(t=>t.IsReachable) should we only consider reachables?*/)
                {
                    var nestedType = new ILTypeDefinition(Module, this, source);
                    nested.Add(nestedType);
                    module.Register(nestedType);
                }

                 methodToIdx = type.Methods.Select((m, idx) => new { m, idx }).ToDictionary(k => k.m, k => k.idx);
            }
Example #48
0
        /// <summary>
        /// Default ctor
        /// </summary>
        private ManifestBuilder(string assemblyFile, IEnumerable<string> referenceFolders, string packageName, NameConverter nsConverter, bool debuggable, List<string> appWidgetProviderCodeFiles, string targetSdkVersion)
        {
#if DEBUG
            //Debugger.Launch();
#endif

            module = new XModule();
            this.packageName = packageName;
            this.nsConverter = nsConverter;
            this.debuggable = debuggable;
            this.appWidgetProviderCodeFiles = appWidgetProviderCodeFiles;
            this.targetSdkVersion = targetSdkVersion;

            // Load assembly file
            if (!File.Exists(assemblyFile))
                throw new ArgumentException(string.Format("Assembly {0} not found", assemblyFile));
            var parameters = new ReaderParameters { AssemblyResolver = new AssemblyResolver(referenceFolders, null, module.OnAssemblyLoaded) };
            assembly = AssemblyDefinition.ReadAssembly(assemblyFile, parameters);
            module.OnAssemblyLoaded(assembly);
        }
Example #49
0
 /// <summary>
 /// TODO: the list of parameters has gotten way to long.
 /// </summary>
 public AssemblyCompiler(CompilationMode mode, List<AssemblyDefinition> assemblies, 
                         List<AssemblyDefinition> references, Table resources, NameConverter nameConverter, 
                         bool generateDebugInfo, AssemblyClassLoader assemblyClassLoader, 
                         Func<AssemblyDefinition, string> assemblyToFilename, DexMethodBodyCompilerCache ccache,
                         HashSet<string> rootClassNames, XModule module, bool generateSetNextInstructionCode)
 {
     this.mode = mode;
     this.assemblies = assemblies;
     this.references = references;
     this.resources = resources;
     this.generateDebugInfo = generateDebugInfo;
     this.assemblyClassLoader = assemblyClassLoader;
     this.assemblyToFilename = assemblyToFilename;
     this.rootClassNames = rootClassNames;
     this.module = module;
     this.generateSetNextInstructionCode = generateDebugInfo && generateSetNextInstructionCode;
     targetPackage = new Target.Dex.DexTargetPackage(nameConverter, this);
     methodBodyCompilerCache = ccache;
     StopAtFirstError = true;
 }
 private void btnCreateCustomer_Click(object sender, EventArgs e)
 {
     Customer = Prg.CreateModule("CUSTOMER");
     CustTbl = Customer.GetTable("TRDR");
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public ILGenericParameter(XModule module, GenericParameter p) : 
     base(module)
 {
     this.p = p;
 }
Example #52
0
        /// <summary>
        /// Convert a nullable .GetValueOrDefault()
        /// </summary>
        private static void ConvertPrimitiveGetValueOrDefault(AstExpression node, XMethodReference ilMethod, XTypeReference type, AstExpression target, XModule data)
        {
            // Clear node
            var originalArgs = node.Arguments.ToList();
            var getValueRef = new XMethodReference.Simple("GetValue", false, ilMethod.ReturnType, ilMethod.DeclaringType, new[] { data.TypeSystem.Object, data.TypeSystem.Bool }, null);
            node.Operand = getValueRef;
            node.Arguments.Clear();
            node.InferredType = type;
            node.ExpectedType = type;

            AddLoadArgument(node, target, originalArgs[0]);
            node.Arguments.Add(new AstExpression(node.SourceLocation, AstCode.Ldc_I4, 1) { InferredType = data.TypeSystem.Bool });
        }
Example #53
0
        /// <summary>
        /// Create an argument for an annotation.
        /// 
        /// Java Annotations have some limitations compared to CLRs Attributes:
        ///    - While they can have default values, there is no way to 
        ///      specify an "unset" field or property.
        //     - 'null' is not allowed, neither as value nor as default (!)
        /// We have to emulate those two extra states to model
        /// the flexible constructor/property/field approach of
        /// CLR.
        /// We therefore save all values in arrays with the semantic:
        ///   - no elements   unset; this is the default value.
        ///   - one element:  the actual value
        ///   - two elements: null
        /// </summary>
        private static AnnotationArgument CreateAnnotationArgument(string name, TypeReference valueType, object value, DexTargetPackage targetPackage, XModule module)
        {
            if (valueType.IsSystemType())
            {
                // Convert .NET type reference to Dex type reference
                value = ((TypeReference) value).GetReference(targetPackage, module);
            }

            if (valueType.IsArray && value is CustomAttributeArgument[])
            {
                List<object> values = new List<object>();

                foreach (var argument in (CustomAttributeArgument[]) value)
                {
                    // dereference if argument is an object or params array.
                    var arg = argument.Value as CustomAttributeArgument? ?? argument;

                    object val;

                    if (arg.Type.IsSystemType())
                        val = ((TypeReference)arg.Value).GetReference(targetPackage, module);
                    else
                        val = arg.Value;

                    // Don't add an extra level of indirection for this 
                    // uncommon case until someone really needs it.
                    if (val == null)
                        throw new Exception("CustomAttributes: null values in array arguments are not supported.");

                    values.Add(val);
                }

                value = values.ToArray();
            }

            if (value != null)
            {
                // Note: there could be a special enum handling here, though it should work without.

                if (valueType.IsUInt64())
                    return new AnnotationArgument(name, new object[] { unchecked((long)(ulong)value) });
                if (valueType.IsUInt32())
                    return new AnnotationArgument(name, new object[] { unchecked((int)(uint)value) });
                if (!valueType.IsPrimitive || valueType.IsWide() || valueType.IsFloat())
                    return new AnnotationArgument(name, new[] { value });
                return new AnnotationArgument(name, new object[] { unchecked(Convert.ToInt32(value)) });
            }

            if(valueType.IsWide())
                return new AnnotationArgument(name, new object[] { 0L, 0L});
            if (valueType.IsPrimitive)
                return new AnnotationArgument(name, new object[] { 0, 0 });

            return new AnnotationArgument(name, new object[] { "", "" });
        }
Example #54
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public JavaParameter(XModule module, string name, TypeReference type)
     : base(name)
 {
     this.module = module;
     this.type = type;
 }
Example #55
0
 /// <summary>
 /// Create a synthetic field and add it to the given declaring type.
 /// </summary>
 public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType)
 {
     var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType);
     declaringType.Add(type);
     return type;
 }
Example #56
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected XTypeDefinition(XModule module, XTypeDefinition declaringType, bool isValueType, IEnumerable<string> genericParameterNames)
     : base(module, declaringType, isValueType, genericParameterNames)
 {
 }
        private void printSalDoc()
        {

           SalDoc = Prg.CreateModule("SALDOC");
           SalDoc.LocateData(101820);

           object[] myArray;
           myArray = new object[4];
           object SysRequest = Prg.GetStockObj("SysRequest", true);
           myArray[0] = SalDoc.Handle;

           myArray[1] = edFormCode.Text;
           myArray[2] = @"928";
           myArray[3] = "C:\\Users\\johng\\Desktop\\netPrint.txt";
           Prg.CallPublished(SysRequest, "PrintForm", myArray);
       }
        private static Prototype MakePrototype(Mono.Cecil.TypeReference propType, DexTargetPackage targetPackage, XModule module)
        {
            // use object arrays.
            var type = new DexLib.ArrayType(module.TypeSystem.Object.GetReference(targetPackage));
            return new Prototype(type);

            // always use arrays.
            //var arrayType = propType.MakeArrayType().GetReference(targetPackage, module);
            //return new Prototype(arrayType);
        }
Example #59
0
        /// <summary>
        /// Compile an assembly into a dex file.
        /// </summary>
        private static void CompileAssembly(CommandLineOptions options, NameConverter nsConverter)
        {
            // Load resource type usage info file
            var usedTypeNames = LoadResourceTypeUsageInformation(options);

            // Load assemblies
            var assemblies = new List<AssemblyDefinition>();
            var module = new XModule();
            var classLoader = new AssemblyClassLoader(module.OnClassLoaded);
            var resolver = new AssemblyResolver(options.ReferenceFolders, classLoader, module.OnAssemblyLoaded);
            var readerParameters = new ReaderParameters(ReadingMode.Immediate)
            {
                AssemblyResolver = resolver,
                SymbolReaderProvider = new SafeSymbolReaderProvider(),
                ReadSymbols = true
            };
            foreach (var asmPath in options.Assemblies)
            {
                var asm = resolver.Load(asmPath, readerParameters);
                module.OnAssemblyLoaded(asm);
                classLoader.LoadAssembly(asm);
                assemblies.Add(asm);
            }
            // Load references
            var references = new List<AssemblyDefinition>();
            foreach (var refPath in options.References)
            {
                var asm = resolver.Load(refPath, readerParameters);
                module.OnAssemblyLoaded(asm);
                classLoader.LoadAssembly(asm);
                references.Add(asm);
            }

            // Load resources
            Table table;
            using (var stream = new FileStream(options.InputResources, FileMode.Open, FileAccess.Read))
            {
                table = new Table(stream);
            }

            // Create compiler
            var compiler = new AssemblyCompiler(options.CompilationMode, assemblies, references, table, nsConverter, options.DebugInfo, classLoader, usedTypeNames, module);
            compiler.Compile();
            compiler.Save(options.OutputFolder, options.FreeAppsKeyPath);
        }
Example #60
0
        /// <summary>
        /// Program main code
        /// </summary>
        /// <returns>true on success, false on usage due to invalid options</returns>
        internal static bool MainCode(CommandLineOptions options)
        {
            if (options.ShowHelp)
            {
                return false;
            }

            // Detect target
            var target = Locations.SetTarget(options.Target);

            // Build APK/BAR?
            if (!string.IsNullOrEmpty(options.PackagePath))
            {
#if DEBUG
                //Debugger.Launch();
#endif

                // Build APK first
                var apkPath = options.PackagePath;
                if (target == Targets.BlackBerry)
                {
                    // Put APK in TEMP folder
                    apkPath = Path.GetTempFileName() + ".apk";
                }

                var apkBuilder = new ApkBuilder.ApkBuilder(apkPath);
                apkBuilder.MapFilePath = Path.ChangeExtension(options.PackagePath, ".d42map");
                apkBuilder.ManifestPath = options.ManifestFile;
                apkBuilder.DexFiles.AddRange(options.DexFiles);
                apkBuilder.MapFiles.AddRange(options.MapFiles);
                if (options.Assemblies.Any())
                {
                    apkBuilder.Assemblies.AddRange(options.Assemblies);
                }
                apkBuilder.ResourcesFolder = options.ResourcesFolder;
                apkBuilder.PfxFile = options.PfxFile;
                apkBuilder.PfxPassword = options.PfxPassword;
                apkBuilder.CertificateThumbprint = options.CertificateThumbprint;
                apkBuilder.FreeAppsKeyPath = options.FreeAppsKeyPath;
                apkBuilder.PackageName = options.PackageName;
                apkBuilder.NativeCodeLibraries.AddRange(options.NativeCodeLibs);
                apkBuilder.Build();

                if (target == Targets.BlackBerry)
                {
                    // Now build BAR
                    var barBuilder = new BarBuilder.BarBuilder(options.PackagePath);
                    barBuilder.ApkPath = apkPath;
                    barBuilder.DebugTokenPath = options.DebugToken;
                    barBuilder.Build();                    
                }
            }
            else if (!string.IsNullOrEmpty(options.JarFile)) // Import jar file?
            {
                var module = new XModule();
                var resolver = new AssemblyResolver(options.ReferenceFolders, new AssemblyClassLoader(module.OnClassLoaded), module.OnAssemblyLoaded);
                var jarImporter = new JarImporter(options.JarFile, options.LibName, options.ImportStubsOnly, false/*true*/, options.GeneratedCodeFolder, resolver, options.ExcludedPackages, options.UseAutoExcludedPackages);
                foreach (var path in options.References)
                {
                    jarImporter.ImportAssembly(path);
                }
                jarImporter.ImportAssembliesCompleted();
                jarImporter.Import();
            }
            else if (options.WcfProxyInputAssemblies.Any()) // Generate WCF Proxy
            {
                var resolver = new AssemblyResolver(options.ReferenceFolders, null, null);
                var readerParameters = new ReaderParameters(ReadingMode.Immediate) {
                    AssemblyResolver = resolver,
                    SymbolReaderProvider = new SafeSymbolReaderProvider(),
                    ReadSymbols = true
                };
                var assemblies = options.WcfProxyInputAssemblies.Select(x => AssemblyDefinition.ReadAssembly(x, readerParameters)).ToList();
                var proxyTool = new ProxyBuilderTool(assemblies, options.GeneratedProxySourcePath);
                proxyTool.Build();
            }
            else
            {
                // Create namespace converter
                var nsConverter = new NameConverter(options.PackageName, options.RootNamespace);

                // Create manifest file?
                if (options.CreateManifest)
                {
                    ManifestBuilder.CreateManifest(target, options.Assemblies.First(), options.ReferenceFolders, options.PackageName, nsConverter, 
                        options.DebugInfo, options.AppWidgetProviders, options.TargetSdkVersion, options.OutputFolder);
                }
                else
                {
                    // Code compilation?
                    if (options.Assemblies.Any())
                    {
#if DEBUG
                        //Debugger.Launch();
#endif

                        CompileAssembly(options, nsConverter);
                    }
                }

                // Xml compilation
                if (options.CompileResources)
                {
                    if (!CompileResources(options))
                        return false;
                }
            }
            return true;
        }