Esempio n. 1
0
        /// <summary>
        /// Create symbols for the driver routines.
        /// </summary>
        private void AddDriverMethods(SortedList <Address, ImageSymbol> symbols, ByteMemoryArea memSeg)
        {
            void MakeSymbol(ByteMemoryArea mem, string prefix, string routineName, uint offset)
            {
                var name = $"{prefix}_{routineName}";
                var sym  = ImageSymbol.Procedure(this.arch, mem.BaseAddress + offset + 4, name);

                symbols.Add(sym.Address, sym);
            }

            var rdr          = memSeg.CreateBeReader(4 + 8);
            var offsetOpen   = rdr.ReadBeUInt16();
            var offsetPrime  = rdr.ReadBeUInt16();
            var offsetCtl    = rdr.ReadBeUInt16();
            var offsetStatus = rdr.ReadBeUInt16();
            var offsetClose  = rdr.ReadBeUInt16();
            var cbName       = rdr.ReadByte();
            var abName       = rdr.ReadBytes(cbName);
            var driverName   = Encoding.UTF8.GetString(abName);
            var driverPrefix = NamingPolicy.SanitizeIdentifierName(driverName);

            MakeSymbol(memSeg, driverPrefix, "Open", offsetOpen);
            MakeSymbol(memSeg, driverPrefix, "Prime", offsetPrime);
            MakeSymbol(memSeg, driverPrefix, "Ctl", offsetCtl);
            MakeSymbol(memSeg, driverPrefix, "Status", offsetStatus);
            MakeSymbol(memSeg, driverPrefix, "Close", offsetClose);
        }
Esempio n. 2
0
        private IConstructorDeclaration CreateConstructor(IClassDeclaration classDeclaration, IIdentifier fieldIdentifier, ITypeName typeName)
        {
            IConstructLanguage language = classDeclaration.Language;

            IParameter   parameter             = language.Parameter(typeName);
            NamingPolicy parameterNamingPolicy = parameter.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
            string       parameterName         = parameterNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);

            parameter.Identifier = language.Identifier(parameterName);
            Modifiers constructorModifiers = Modifiers.Public;
            Modifiers visibility           = classDeclaration.Modifiers.Modifiers.GetVisibility();

            if (visibility == Modifiers.None || visibility.IsInternal())
            {
                constructorModifiers = Modifiers.Internal;
            }

            IConstructorDeclaration constructor = language.Constructor(language.None <IDocComment>(),
                                                                       language.None <IAttributes>(),
                                                                       language.Modifiers(constructorModifiers),
                                                                       language.Parameters(parameter),
                                                                       language.None <IConstructorInitializer>(),
                                                                       language.Block(
                                                                           language.AssignmentStatement(
                                                                               language.MemberAccess(language.This(), fieldIdentifier),
                                                                               language.VariableAccess(parameter.Identifier))));

            return(constructor);
        }
Esempio n. 3
0
        public static DiGraph <RtlBlock> BuildIcfg(
            ScanResults sr,
            NamingPolicy namingPolicy,
            Dictionary <Address, block> blocks)
        {
            var icfg      = new DiGraph <RtlBlock>();
            var map       = new Dictionary <Address, RtlBlock>();
            var rtlBlocks =
                from b in blocks.Values
                join i in sr.FlatInstructions.Values on b.id equals i.block_id into instrs
                orderby b.id
                select new RtlBlock(b.id, namingPolicy.BlockName(b.id))
            {
                Instructions = instrs.Select(x => x.rtl).ToList()
            };

            foreach (var rtlBlock in rtlBlocks)
            {
                map[rtlBlock.Address] = rtlBlock;
                icfg.AddNode(rtlBlock);
            }
            foreach (var edge in sr.FlatEdges)
            {
                if (!map.TryGetValue(edge.first, out var from) ||
                    !map.TryGetValue(edge.second, out var to))
                {
                    continue;
                }
                icfg.AddEdge(from, to);
            }
            return(icfg);
        }
        private static IMethodDeclaration CreateVBInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers,
                                                            IList <IArgument> arguments, IList <IParameter> parameters, IConstructLanguage language)
        {
            IEventInvocation eventInvocation = language.New <IEventInvocation>();

            eventInvocation.DelegateInvocation =
                language.DelegateInvocation(
                    language.VariableAccess(eventDeclaration.Identifier),
                    language.Arguments(arguments));

            IMethodDeclaration method = language.Method(
                language.None <IDocComment>(),
                language.None <IAttributes>(),
                modifiers,
                language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                language.None <IMethodTypeParameters>(),
                language.Parameters(parameters),
                language.Block(
                    language.ExpressionStatement(eventInvocation)));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       methodName          = methodsNamingPolicy.ChangeNameAccordingToPolicy("Raise" + eventDeclaration.Identifier.Name + "Event",
                                                                                               eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return(method);
        }
        private static void GenerateSecondParameterAndArgument(IEventDeclaration eventDeclaration, IParameter parameter, IConstructLanguage language, FileModel fileModel, IList <IArgument> arguments, IList <IParameter> parameters)
        {
            NamingPolicy parametersNamingPolicy = language.PrimaryNamingPolicyFor <IParameter>(fileModel.UserSettings);
            IType        parameterType          = eventDeclaration.TypeName.Type.As <IDelegateType>().ReplaceParameterTypesIn(parameter.Type);

            IParameter newParameter = language.Parameter(
                parameter.IsRef,
                parameter.IsOut,
                parameter.IsParams,
                language.TypeName(eventDeclaration.StringTypeAtThisLocation()),
                parameter.DefaultValue);

            string parameterName = parametersNamingPolicy.ChangeNameAccordingToPolicy("propertyName", parameter.SolutionModel);

            newParameter.Identifier = language.Identifier(parameterName);

            IObjectCreation objectCreation = language.ObjectCreation(
                language.TypeName(parameterType), language.Arguments(
                    language.Argument(
                        language.VariableAccess(newParameter.Identifier))));

            arguments.Add(
                language.Argument(
                    objectCreation));

            parameters.Add(newParameter);
        }
Esempio n. 6
0
        private IFieldDeclaration CreateFieldToHoldWrappedClass(IConstructLanguage language, ITypeName typeName, IClassDeclaration classDeclaration)
        {
            IFieldDeclaration fieldDeclaration   = language.Field(language.Modifiers(Modifiers.Private | Modifiers.Readonly), typeName);
            NamingPolicy      fieldsNamingPolicy = fieldDeclaration.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
            string            fieldName          = fieldsNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);

            fieldDeclaration.Identifier = language.Identifier(fieldName);
            return(fieldDeclaration);
        }
Esempio n. 7
0
        public static ClrUserDefinedNamingRule GetUnitySerializedFieldRule()
        {
            var lowerCaseNamingPolicy = new NamingPolicy(new NamingRule {
                NamingStyleKind = NamingStyleKinds.aaBb
            });

            return(new ClrUserDefinedNamingRule(
                       new ClrNamedElementDescriptor(
                           AccessRightKinds.Any,
                           StaticnessKinds.Instance,
                           new ElementKindSet(UnityNamedElement.SERIALISED_FIELD),
                           "Unity serialized field"),
                       lowerCaseNamingPolicy
                       ));
        }
Esempio n. 8
0
 private string FilenameBasedOnSegment(Address addr, ImageSegment seg, string fileExtension)
 {
     if (!segmentFilenames.TryGetValue(seg, out var filename))
     {
         var sanitizedSegName = NamingPolicy.SanitizeIdentifierName(seg.Name);
         filename = $"{progname}_{sanitizedSegName}";
         segmentFilenames.Add(seg, filename);
     }
     // If the segment is large, we need to subdivide it.
     if (seg.Size > MaxChunkSize)
     {
         var offset = addr - seg.Address;
         var chunk  = offset / MaxChunkSize;
         filename = $"{filename}_{chunk:X4}";
     }
     return(Path.ChangeExtension(filename, fileExtension));
 }
Esempio n. 9
0
        public static string ReplaceRequestQuery <T>(ConverterCollection converters, NamingPolicy namingPolicy, string uri, string name, T value, bool urlEncode)
        {
            var typeCode = Type.GetTypeCode(typeof(T));

            if (typeCode == TypeCode.Object)
            {
                foreach (var item in GetObjectStringParameters(name, value, converters, namingPolicy))
                {
                    uri = ReplaceRequestQuery(uri, item.Key, item.Value, urlEncode);
                }
                return(uri);
            }
            else
            {
                return(ReplaceRequestQuery(uri, name, converters.ConvertValue <T, string>(value, true), urlEncode));
            }
        }
Esempio n. 10
0
        private IClassDeclaration CreateInitialViewModel(IClassDeclaration classDeclaration, IFieldDeclaration fieldDeclaration, IConstructorDeclaration viewModelConstructor)
        {
            IConstructLanguage language  = classDeclaration.Language;
            IClassDeclaration  viewModel = language.Class(
                language.Modifiers(Modifiers.Public),
                language.None <IClassTypeParameters>(),
                language.None <ITypeName>(),
                new List <ITypeName>(),
                new List <IDeclaration>()
            {
                fieldDeclaration, viewModelConstructor
            });

            NamingPolicy classesPolicy = viewModel.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
            string       viewModelName = classesPolicy.MakeTypeNameUniqueInNamespace(classDeclaration, classDeclaration.Identifier.Name + "ViewModel");

            viewModel.Identifier = language.Identifier(viewModelName);
            return(viewModel);
        }
        private static IMethodDeclaration CreateCSInvocator(IEventDeclaration eventDeclaration, IModifiers modifiers, IList <IArgument> arguments,
                                                            IList <IParameter> parameters, IConstructLanguage language)
        {
            IVariableDeclaration variable = language.Variable(
                eventDeclaration.TypeName,
                language.VariableAccess(eventDeclaration.Identifier));

            NamingPolicy variablesNamingPolicy = variable.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       variableName          = variablesNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.Name,
                                                                                                   eventDeclaration.SolutionModel);

            variable.Identifier = language.Identifier(variableName);

            IIfStatement ifStatement = language.IfStatement(
                language.BinaryExpression(
                    language.VariableAccess(variable.Identifier),
                    Operator.NotEqual,
                    language.New <INull>()),
                language.Block(
                    language.ExpressionStatement(
                        language.DelegateInvocation(
                            language.VariableAccess(variable.Identifier),
                            language.Arguments(arguments)))));

            IMethodDeclaration method = language.Method(
                language.None <IDocComment>(),
                language.None <IAttributes>(),
                modifiers,
                language.TypeName(eventDeclaration.VoidTypeAtThisLocation()),
                language.None <IMethodTypeParameters>(),
                language.Parameters(parameters),
                language.Block(
                    variable,
                    ifStatement));

            NamingPolicy methodsNamingPolicy = method.PrimaryNamingPolicy(eventDeclaration.FileModel.UserSettings);
            string       methodName          = methodsNamingPolicy.ChangeNameAccordingToPolicy("on" + eventDeclaration.Identifier.ToUpperFirstLetter().Name,
                                                                                               eventDeclaration.SolutionModel);

            method.Identifier = language.Identifier(methodName);

            return(method);
        }
Esempio n. 12
0
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IConstructEnumerable <IFieldDeclaration> fields = FindFields(fileModel, selection);

            if (fields.Exist())
            {
                IConstructLanguage language = fields.Language;

                foreach (IFieldDeclaration field in fields)
                {
                    IPropertyDeclaration property = language.Property(
                        language.None <IDocComment>(),
                        language.None <IAttributes>(),
                        language.Modifiers(Modifiers.Public),
                        language.TypeName(field.TypeName.Type),
                        language.None <IIdentifier>());

                    NamingPolicy propertyNamingPolicy = property.PrimaryNamingPolicy(fileModel.UserSettings);
                    string       propertyName         = propertyNamingPolicy.MakeMemberNameUniqueInScope(field, field.Identifier.Name);

                    property.Identifier = language.Identifier(propertyName);

                    IAccessor getter = language.FieldGetter(field.Identifier);
                    IAccessor setter = CreateSetter(language, propertyName, field);

                    property.Accessors = language.Enumerable(new List <IAccessor>()
                    {
                        getter, setter
                    });

                    field.EnclosingClass.Insert(property);
                }
            }
        }
Esempio n. 13
0
        void IChangeNamingRuleWindowProvider.ShowSettingsDialog(string ruleName, NamingPolicy policyToChange,
                                                                IDeclaredElement declaredElement,
                                                                IPsiSourceFile psiSourceFile, ITextControl textControl,
                                                                NamingManager namingManager,
                                                                IUIApplicationSimple uiApplicationSimple,
                                                                ISolution solution)
        {
            if (declaredElement is IField field && myUnityApi.IsSerialisedField(field))
            {
                var optionsDialogOwner = solution.TryGetComponent <IOptionsDialogViewOwner>();
                if (optionsDialogOwner != null)
                {
                    Logger.Catch(() => optionsDialogOwner.Show(page: UnityOptionsPage.Name));
                    return;
                }
            }

            base.ShowSettingsDialog(ruleName, policyToChange, declaredElement, psiSourceFile, textControl,
                                    namingManager, uiApplicationSimple, solution);
        }
Esempio n. 14
0
        public static IEnumerable <KeyValuePair <string, string> > GetObjectStringParameters <T>(string name, T value, ConverterCollection converters, NamingPolicy namingPolicy)
        {
            if (value == null)
            {
                yield break;
            }
            //Nullable<>
            if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                yield return(new KeyValuePair <string, string>(name, converters.ConvertValue <T, string>(value, true)));

                yield break;
            }

            if (typeof(IDictionary).IsAssignableFrom(typeof(T)))
            {
                IDictionary map = ((IDictionary)value);
                foreach (var item in map.Keys)
                {
                    if (map[item] == null)
                    {
                        continue;
                    }
                    yield return(new KeyValuePair <string, string>(item.ToString(), converters.ConvertValue <string>(item, true)));
                }
                yield break;
            }

            if (typeof(IEnumerable).IsAssignableFrom(typeof(T)))
            {
                foreach (var item in value as IEnumerable)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    yield return(new KeyValuePair <string, string>(name, converters.ConvertValue <string>(item, true)));
                }
                yield break;
            }

            //TODO: ReplaceRequestQuery
            //foreach (var property in value.GetType().GetProperties())
            //{
            //    object propertyValue = property.GetValue(value);
            //    if (propertyValue == null)
            //    {
            //        continue;
            //    }
            //    if (propertyValue is IEnumerable&&propertyValue)
            //    {

            //    }
            //}

            // get properties

            foreach (var property in typeof(T).GetProperties())
            {
                if (property.GetMethod == null)
                {
                    continue;
                }
                object propertyValue = property.GetValue(value);
                if (propertyValue == null)
                {
                    continue;
                }
                if (propertyValue is string)
                {
                    yield return(new KeyValuePair <string, string>(GetName(property, namingPolicy), propertyValue.ToString()));

                    continue;
                }
                if (propertyValue is IEnumerable)
                {
                    foreach (var item in propertyValue as IEnumerable)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        yield return(new KeyValuePair <string, string>(GetName(property, namingPolicy), converters.ConvertValue <string>(item, true)));
                    }
                    continue;
                }
                yield return(new KeyValuePair <string, string>(GetName(property, namingPolicy), converters.ConvertValue <string>(propertyValue, true)));
            }
        }
Esempio n. 15
0
 public static string GetName(PropertyInfo property, NamingPolicy namingPolicy)
 {
     return(namingPolicy.ConvertName(property.Name));
 }