コード例 #1
0
        private void SetGenericsForItem(ScannedItem target)
        {
            target.CreateGenerics();

            foreach (var g in target.GenericParams)
            {
                target.AddGenerticParam(g);
            }

            switch (target)
            {
            case ScannedMethod m:

                foreach (var v in m.TargetMethod.Body.Variables)
                {
                    v.Type = m.ToGenericIfAvalible(v.Type);
                }

                m.TargetMethod.ReturnType = target.ToGenericIfAvalible(m.TargetMethod.ReturnType);
                break;


            case ScannedType t:
                /*
                 * foreach(var f in t.TargetType.Fields) {
                 *  f.FieldType = target.ToGenericIfAvalible(f.FieldType);
                 * }
                 */

                break;
            }
        }
コード例 #2
0
        public ScannedItem GetItem(MDToken token)
        {
            ScannedItem i = null;

            GenericsMapper.TryGetValue(token, out i);
            return(i);
        }
コード例 #3
0
 private void AddScannedItemGeneral(ScannedItem m)
 {
     m.Scan();
     if (!GenericsMapper.ContainsKey(m.GetToken()))
     {
         GenericsMapper.Add(m.GetToken(), m);
     }
 }
コード例 #4
0
        public override void ProcessOperand(ITypeService service, MethodDef method, IList <Instruction> body, ref int index, TypeRef operand)
        {
            ScannedItem current = service.GetScannedItem(method);

            if (current != null)
            {
                body[index].Operand = new TypeSpecUser(current.ToGenericIfAvalible(operand.ToTypeSig()));
            }
        }
コード例 #5
0
        public override void ProcessOperand(TypeService service, MethodDef method, IList <Instruction> body, ref int index, TypeDef operand)
        {
            ScannedItem t = service.GetItem(operand.MDToken);

            if (t == null)
            {
                return;
            }
            body[index].Operand = new TypeSpecUser(t.CreateGenericTypeSig(service.GetItem(method.DeclaringType.MDToken)));
        }
コード例 #6
0
        public override void ProcessOperand(TypeService service, MethodDef method, IList <Instruction> body, ref int index, MethodDef operand)
        {
            ScannedMethod tMethod       = service.GetItem(operand.MDToken) as ScannedMethod;
            ScannedItem   currentMethod = service.GetItem(method.MDToken) as ScannedMethod;

            if (tMethod != null)
            {
                var newspec = new MethodSpecUser(tMethod.TargetMethod, tMethod.CreateGenericMethodSig(currentMethod));

                body[index].Operand = newspec;
            }
        }
コード例 #7
0
        public static void ApplyCallProxy(ITypeService service, ScannedItem parentItem, IList <Instruction> body, ref int index, IMethodDefOrRef operand)
        {
            var proxyMethod = CallProxyFactory.Instance.GetFactory(operand.MethodSig.Params.Count + (operand.MethodSig.HasThis ? 1 : 0));

            if (proxyMethod == null)
            {
                return; //No factory for this parameter number (probaby disabled)
            }

            var sigs = new List <TypeSig>();

            sigs.Add(operand.DeclaringType.ToTypeSig());

            if (operand.MethodSig.HasThis)
            {
                sigs.Add(operand.DeclaringType.ToTypeSig());
            }

            foreach (var p in operand.MethodSig.Params)
            {
                if (p is GenericVar)
                {
                    sigs.Add((GenericVar)p);
                }
                else
                {
                    sigs.Add(p.ScopeType.ToTypeSig());
                }
            }

            if (operand.MethodSig.RetType == operand.Module.CorLibTypes.Void)
            {
                sigs.Add(operand.Module.CorLibTypes.Object);
            }
            body.Insert(index++, Instruction.CreateLdcI4(CallProxyFactory.Instance.GetIndexOfMethodInDeclaringType(operand)));

            if (parentItem != null)
            {
                sigs = sigs.Select(x => parentItem.ToGenericIfAvalible(x)).ToList();
            }

            body[index].Operand = new MethodSpecUser(proxyMethod, new GenericInstMethodSig(sigs));
            if (operand.MethodSig.RetType == operand.Module.CorLibTypes.Void)
            {
                body.Insert(++index, Instruction.Create(OpCodes.Pop));
            }
        }
コード例 #8
0
        public override void ProcessOperand(ITypeService service, MethodDef method, IList <Instruction> body, ref int index, TypeDef operand)
        {
            var currentMethod = service.GetScannedItem(method);
            var targetType    = service.GetScannedItem(operand);

            if (targetType != null)
            {
                var typeSigList = targetType.GenericCallTypes.Select(x => currentMethod?.ToGenericIfAvalible(x) ?? x).ToArray();
                new TypeSpecUser(new GenericInstSig(new ClassSig(operand), typeSigList));
            }

            return;

            //Broken
            ScannedItem current = service.GetScannedItem(method);

            if (current != null)
            {
                body[index].Operand = new TypeSpecUser(current.ToGenericIfAvalible(operand.ToTypeSig()));
            }
        }
コード例 #9
0
        public IEnumerable <ScannedItem> Scan(AmazonOrderItem[] amazonOrderItems, ChaseCreditLineItem[] creditLineItems)
        {
            List <ScannedItem> scannedItems = new List <ScannedItem>();

            IEnumerable <ChaseCreditLineItem> amazonCreditLineItems =
                from lineItem in creditLineItems
                where (lineItem.Description.IndexOf("Amazon", StringComparison.OrdinalIgnoreCase) > -1 ||
                       lineItem.Description.IndexOf("AMZN", StringComparison.OrdinalIgnoreCase) > -1) &&
                lineItem.Description.IndexOf("Kindle", StringComparison.OrdinalIgnoreCase) == -1 &&
                lineItem.Description.IndexOf("Audible", StringComparison.OrdinalIgnoreCase) == -1
                select lineItem;

            foreach (ChaseCreditLineItem amazonLineItem in amazonCreditLineItems)
            {
                // invert the amount as the credit report brings them in as negative
                decimal cost = -amazonLineItem.Amount;

                ScannedItem scannedItem = LocateScannedItemBasedOnCost(amazonOrderItems, amazonLineItem, cost);

                if (scannedItem == null)
                {
                    // Populate with some data, but most importantely indicate that the transaction(s) wasn't found
                    scannedItem = new ScannedItem()
                    {
                        ItemTotal   = cost,
                        PostingDate = amazonLineItem.PostingDate,
                        Title       = amazonLineItem.Description,
                        WasFound    = false
                    };
                }

                scannedItems.Add(scannedItem);
            }

            return(scannedItems);
        }
コード例 #10
0
        public static void ApplyObjectCreationProxy(ITypeService service, ScannedItem parentItem, IList <Instruction> body, ref int index, IMethodDefOrRef operand)
        {
            if (operand.MethodSig.Params.Count > 0)
            {
                return;
            }                                                   //Not supporeted yet

            var proxyMethod = ObjectCreationFactory.Instance.GetCreationMethod(operand.MethodSig.Params.Count);

            if (proxyMethod == null)
            {
                return; //No factory for this parameter number (probaby disabled)
            }

            var typeSig = operand.DeclaringType.ToTypeSig();

            if (parentItem != null)
            {
                typeSig = parentItem.ToGenericIfAvalible(typeSig);
            }

            body[index].OpCode  = OpCodes.Call;
            body[index].Operand = new MethodSpecUser(proxyMethod, new GenericInstMethodSig(typeSig));
        }
コード例 #11
0
        private static ScannedItem LocateScannedItemBasedOnCost(AmazonOrderItem[] amazonOrderItems, ChaseCreditLineItem amazonLineItem, decimal cost)
        {
            IEnumerable <AmazonOrderItem> orders =
                from orderItem in amazonOrderItems
                where orderItem.ItemTotal == cost && !orderItem.IsUsed && orderItem.OrderDate <= amazonLineItem.PostingDate
                orderby orderItem.OrderDate
                select orderItem;

            AmazonOrderItem order       = orders.FirstOrDefault();
            ScannedItem     scannedItem = null;

            if (order != null)
            {
                order.IsUsed = true;

                scannedItem = new ScannedItem()
                {
                    ItemTotal   = cost,
                    OrderDate   = order.OrderDate,
                    PostingDate = amazonLineItem.PostingDate,
                    Title       = order.Title,
                    WasFound    = true
                };
            }
            else
            {
                // Check for suscription savings - appears that these appear w/ + Gift Card in the description (HACK)
                IEnumerable <AmazonOrderItem> subscriptionOrders =
                    from orderItem in amazonOrderItems
                    where orderItem.PaymentInstrumentType.Contains("Gift") && !orderItem.IsUsed && orderItem.OrderDate <= amazonLineItem.PostingDate &&
                    ((Math.Round(orderItem.ItemSubtotal * (decimal)0.9595 + orderItem.ItemSubtotalTax, 2) == cost) || (Math.Round(orderItem.ItemSubtotal * (decimal)0.8595 + orderItem.ItemSubtotalTax, 2) == cost))
                    orderby orderItem.OrderDate
                    select orderItem;

                order = subscriptionOrders.FirstOrDefault();

                if (order != null)
                {
                    order.IsUsed = true;

                    scannedItem = new ScannedItem()
                    {
                        ItemTotal   = cost,
                        OrderDate   = order.OrderDate,
                        PostingDate = amazonLineItem.PostingDate,
                        Title       = order.Title,
                        WasFound    = true
                    };
                }
                else
                {
                    // Check for aggregate orders on the same day
                    List <IGrouping <DateTime, AmazonOrderItem> > orderGroups = new List <IGrouping <DateTime, AmazonOrderItem> >();

                    IEnumerable <IGrouping <DateTime, AmazonOrderItem> > ordersByDate = amazonOrderItems.GroupBy((o) => o.OrderDate);

                    foreach (IGrouping <DateTime, AmazonOrderItem> orderByDate in ordersByDate)
                    {
                        if (orderByDate.Count() > 1)
                        {
                            decimal total = orderByDate.Sum((o) => o.ItemTotal);

                            if (total == cost)
                            {
                                orderGroups.Add(orderByDate);
                            }
                        }
                    }

                    if (orderGroups.Any())
                    {
                        IOrderedEnumerable <IGrouping <DateTime, AmazonOrderItem> > orderGroupsOrderedByDate = orderGroups.OrderBy((groupedItem) => groupedItem.Key);
                        IGrouping <DateTime, AmazonOrderItem> orderGroup = orderGroupsOrderedByDate.First();

                        StringBuilder builder = new StringBuilder();

                        foreach (AmazonOrderItem items in orderGroup)
                        {
                            builder.Append(items.Title);
                            builder.Append(" ");
                            items.IsUsed = true;
                        }

                        scannedItem = new ScannedItem()
                        {
                            ItemTotal   = cost,
                            OrderDate   = orderGroup.Key,
                            PostingDate = amazonLineItem.PostingDate,
                            Title       = builder.ToString(),
                            WasFound    = true
                        };
                    }
                }
            }

            return(scannedItem);
        }