Beispiel #1
0
        public ICirClass addClass(string newClassSignature)
        {
            if (newClassSignature == null || dClasses_bySignature.ContainsKey(newClassSignature))
                return null;
            //return dClasses_bySignature[classSignature];

            var cirClass = new CirClass(newClassSignature);
            
            dClasses_bySignature.Add(newClassSignature, cirClass);
            return cirClass;
        }
        public ICirClass addClass(string newClassSignature)
        {
            if (newClassSignature == null || dClasses_bySignature.ContainsKey(newClassSignature))
            {
                return(null);
            }
            //return dClasses_bySignature[classSignature];

            var cirClass = new CirClass(newClassSignature);

            dClasses_bySignature.Add(newClassSignature, cirClass);
            return(cirClass);
        }
 /// <summary>
 /// this will return the current CirClass object for the signature provided or create a new CirClass
 /// object and return it 
 /// </summary>
 /// <param name="cirData"></param>
 /// <param name="classSignature"></param>
 /// <returns></returns>
 private static ICirClass getCirClass(ICirData cirData, string classSignature)
 {
     try
     {
         if (cirData.dClasses_bySignature.ContainsKey(classSignature))
             return cirData.dClasses_bySignature[classSignature];
         var newCirClass = new CirClass(classSignature);
         cirData.dClasses_bySignature.Add(classSignature, newCirClass);
         return newCirClass;
     }
     catch (Exception ex)
     {
         DI.log.ex(ex, "in CirFactory.getCirClass", true);
         return null;
     }
 }
 public static CirClass copy(CirClass cirClass)
 {
     var newCirClass = new CirClass
                           {
                               SymbolDef = cirClass.SymbolDef,
                               Signature = cirClass.Signature,
                               bClassHasMethodsWithControlFlowGraphs =
                                   cirClass.bClassHasMethodsWithControlFlowGraphs,
                               ///TODO
                               /// need to change this so that newCirClass gets a new copy of these dictionaries
                               dSuperClasses = cirClass.dSuperClasses,
                               dIsSuperClassedBy = cirClass.dIsSuperClassedBy,
                               dField_Class = cirClass.dField_Class,
                               dField_Member = cirClass.dField_Member,
                               lcmIsUsedByMethod_Argument = cirClass.lcmIsUsedByMethod_Argument,
                               lcmIsUsedByMethod_ReturnType = cirClass.lcmIsUsedByMethod_ReturnType,
                               lcmIsUsedByMethod_InternalVariable = cirClass.lcmIsUsedByMethod_InternalVariable
                           };
     return newCirClass;
 }
Beispiel #5
0
        public static ICirClass addClass(ICirData cirData, CommonIRDumpCommonIRClassMethods cmClass)
        {
            if (cirData.dClasses_bySignature.ContainsKey(cmClass.ClassType))
                return cirData.dClasses_bySignature[cmClass.ClassType];


            var ccNewCirClass = new CirClass { Signature = cmClass.ClassType, SymbolDef = cmClass.SymbolRef };
            cirData.dClasses_bySignature.Add(ccNewCirClass.Signature, ccNewCirClass);

            addSymbol(cirData, cmClass.SymbolRef, cmClass.ClassType);
            return ccNewCirClass;
        }
Beispiel #6
0
        public static ICirClass addClass(ICirData cirData, CommonIRDumpClassSymbols csClassSymbols)
        {
            ICirClass ccCirClass;
            if (cirData.dClasses_bySignature.ContainsKey(csClassSymbols.UniqueID))
                // check if I need to check for new data (i.e. data that is not already in dClasses.ContainsKey(csClassSymbols.UniqueID)
                ccCirClass = cirData.dClasses_bySignature[csClassSymbols.UniqueID];
            else
            {
                ccCirClass = new CirClass
                {
                    Signature = csClassSymbols.UniqueID,
                    SymbolDef = csClassSymbols.SymbolDef
                };
                cirData.dClasses_bySignature.Add(ccCirClass.Signature, ccCirClass);
                addSymbol(cirData, ccCirClass.SymbolDef, ccCirClass.Signature);
            }

            // add SuperClasses
            if (ccCirClass.dSuperClasses.Count ==0)
                mapSuperClasses(cirData, csClassSymbols, ccCirClass);

            //if (ccCirClass.Name != "")
            //    return ccCirClass;
            
            ccCirClass.IsAnonymous = csClassSymbols.Anonymous;
            ccCirClass.Name = csClassSymbols.Name;

            
            /*if (csClassSymbols.Superclasses != null)
                foreach (CommonIRDumpClassSymbolsSuperclass csSuperClass in csClassSymbols.Superclasses)
                    ccNewCirClass.dSuperClasses.Add(csSuperClass.SymbolRef, csSuperClass.ClassType);*/

            // add class fields
            if (csClassSymbols.ClassFields != null && ccCirClass.dField_Class.Count == 0)
                foreach (CommonIRDumpClassSymbolsClassField csClassField in csClassSymbols.ClassFields)
                {
                    var fsFieldClass = new FieldClass
                    {
                        GuaranteedInitBeforeUsed = csClassField.GuaranteedInitBeforeUsed,
                        Name = csClassField.Name,
                        PrintableType = csClassField.PrintableType,
                        SymbolRef = csClassField.SymbolRef,
                        Signature = csClassField.UniqueID
                    };

                    foreach (PropertyInfo pProperty in csClassField.GetType().GetProperties())
                    {
                        if (pProperty.Name != "GuaranteedInitBeforeUsed" && pProperty.Name != "Name" &&
                            pProperty.Name != "PrintableType" && pProperty.Name != "SymbolRef" &&
                            pProperty.Name != "UniqueID")
                        {
                            object oPropertyObject = DI.reflection.getProperty(pProperty.Name, csClassField, false);
                            if (oPropertyObject != null)
                            {
                                object oPropertyValue = DI.reflection.getProperty("Value", oPropertyObject, false);
                                if (oPropertyValue != null)
                                    fsFieldClass.dFieldData.Add(pProperty.Name, oPropertyValue.ToString());
                                else
                                    fsFieldClass.dFieldData.Add(pProperty.Name, oPropertyObject.ToString());
                            }
                        }
                    }
                    ccCirClass.dField_Class.Add(fsFieldClass.Signature, fsFieldClass);
                }
            // add member fields
            if (csClassSymbols.MemberFields != null && ccCirClass.dField_Member.Count == 0)
                foreach (CommonIRDumpClassSymbolsMemberField csMemberField in csClassSymbols.MemberFields)
                {
                    var fsFieldMember = new FieldMember
                    {
                        Name = csMemberField.Name,
                        PrintableType = csMemberField.PrintableType,
                        SymbolRef = csMemberField.SymbolRef
                    };
                    ccCirClass.dField_Member.Add(fsFieldMember.Name, fsFieldMember);
                    addSymbol(cirData, fsFieldMember.SymbolRef, fsFieldMember.PrintableType);
                }


            return ccCirClass;
        }
Beispiel #7
0
 public static ICirClass addClass(ICirData cirData, String sSymbolRef, String sSignature)
 {
     if (cirData.dClasses_bySignature.ContainsKey(sSignature))
     {
         DI.log.error("in addClass, class already exists: {0}: {1}", sSymbolRef, getSymbol(cirData, sSymbolRef));
         return cirData.dClasses_bySignature[sSignature];
     }
     var ccCirClass = new CirClass { SymbolDef = sSymbolRef, Signature = sSignature };
     cirData.dClasses_bySignature.Add(ccCirClass.Signature, ccCirClass);
     addSymbol(cirData,sSymbolRef, sSignature);
     return ccCirClass;
 }
Beispiel #8
0
        public static void populateDictionariesWithXrefs(CommonIRDump cidCirDump, ICirData cirData)
        {
            try
            {
                if (cidCirDump == null)
                    return;

                O2Timer tTimer = new O2Timer("Populate Dictionaries With Xrefs").start();

                // files
                addCompilationUnitFiles(cirData,cidCirDump.CommonIR.CompilationUnit);
                
                //addSymbolsFromCirDump_Functions(cirData,cidCirDump.CommonIR.FunctionSigType);

                // calculate the classes

                if (cidCirDump.CommonIR.ClassMethods != null)
                    foreach (CommonIRDumpCommonIRClassMethods cmClass in cidCirDump.CommonIR.ClassMethods)
                    {
                        ICirClass ccCirClass = addClass(cirData,cmClass);

                        // process static methods
                        if (null != cmClass.ClassStaticFunction)
                            foreach (
                                CommonIRDumpCommonIRClassMethodsClassStaticFunction csfStaticFunction in
                                    cmClass.ClassStaticFunction)
                            {
                                addFunction(cirData,csfStaticFunction, ccCirClass);
                            }

                        // process member methods (i.e. non static)
                        if (null != cmClass.ClassMemberFunction)
                            foreach (
                                CommonIRDumpCommonIRClassMethodsClassMemberFunction cmfMemberFunction in
                                    cmClass.ClassMemberFunction)
                            {
                                addFunction(cirData,cmfMemberFunction, ccCirClass);
                            }
                    }
                // calculate the NonClassFunction

                if (cidCirDump.CommonIR.NonClassFunction != null)
                {
                    var signatureForNoClassDef = "<no class def>";
                    var cirNoClass = new CirClass(signatureForNoClassDef);
                    cirData.dClasses_bySignature.Add(signatureForNoClassDef, cirNoClass);
                    foreach (
                        CommonIRDumpCommonIRNonClassFunction ncfNonClassFunction in cidCirDump.CommonIR.NonClassFunction
                        )
                    {
                        /*if (ncfNonClassFunction.UniqueID == "VB6_Builtin.StringConcat(...):void")
                        {
                        }
                        DI.log.debug("in populateDictionariesWithXrefs, adding NonClassdefFunction:{0}", ncfNonClassFunction.UniqueID);
                        */

                        addFunction(cirData, ncfNonClassFunction, cirNoClass);



                        // fcdCirData.addFunction(ncfNonClassFunction, null);
                    }
                }

                //   resolveIsCalledByXrefsProbs();

                // add this here since the Functions and classes signatures should be resolved by now
                addSymbolsFromCommonIr(cirData, cidCirDump.CommonIR);
                mapClassesMetadata(cirData, cidCirDump.SymbolData);
                mapFunctionsMetadata(cirData, cidCirDump.CommonIR.FunctionSigType);                

                resolveDbId(cirData);
                if (cirData.bVerbose)
                    tTimer.stop();
            }
            catch (Exception ex)
            {
                DI.log.error("in populateDictionariesWithXrefs: {0}", ex.Message);
            }
        }