Ejemplo n.º 1
0
        }// FindDependenciesForThisNode

        static private void AddAssemblyInfo(ArrayList al, AssemInfo ai)
        {
            // Look through this list and see if we have any other
            int nLen = al.Count;

            for (int i = 0; i < nLen; i++)
            {
                AssemInfo aiMatch = (AssemInfo)al[i];
                if (String.Compare(ai.Name, aiMatch.Name, false, CultureInfo.InvariantCulture) == 0)
                {
                    if (String.Compare(ai.Version, aiMatch.Version, false, CultureInfo.InvariantCulture) == 0)
                    {
                        if (String.Compare(ai.Locale, aiMatch.Locale, false, CultureInfo.InvariantCulture) == 0)
                        {
                            if (String.Compare(ai.PublicKeyToken, aiMatch.PublicKeyToken, false, CultureInfo.InvariantCulture) == 0)
                            {
                                // We found a match! Don't add this into our list
                                return;
                            }
                        }
                    }
                }
            }
            // We didn't find it... let's add it in.
            al.Add(ai);
        }// AddAssemblyInfo
Ejemplo n.º 2
0
        }// doAcceptPaste

        private void AddAssemInfo(AssemInfo asinfo)
        {
            BindingRedirInfo bri = new BindingRedirInfo();

            bri.Name           = asinfo.Name;
            bri.PublicKeyToken = asinfo.PublicKeyToken;
            AddConfiguredAssembly(bri);
        }// AddAssmInfo
Ejemplo n.º 3
0
        }// onAssemChange

        internal void onOKClick(Object o, EventArgs arg)
        {
            if (m_lv.SelectedIndices.Count > 0)
            {
                m_aSelectedAssem  = (AssemInfo)m_ol[m_lv.SelectedIndices[0]];
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }// onOKClick
Ejemplo n.º 4
0
        }// DependencyFinder

        static private void FindDependenciesForThisNode(CApplicationDepends cad)
        {
            // Let's dig into what assemblies this application depends upon
            cad.m_taskPadWaiting = new CGenericTaskPad(cad, "LOADINGDEPENDASSEM_HTML");
            cad.m_oResults       = cad.m_taskPadWaiting;
            cad.RefreshResultView();

            if (cad.m_sAppFile != null && cad.m_olAssems == null)
            {
                AssemblyDependencies ad = null;
                try
                {
                    // Grab the path off this sucker
                    String[] sArgs = cad.m_sAppFile.Split(new char[] { '\\' });
                    // Now join the directory together
                    String sDir = String.Join("\\", sArgs, 0, sArgs.Length > 1?sArgs.Length - 1:1);

                    // We want to give the assembly loader the path that this application
                    // lives in. That way it will be able to find any private assemblies
                    // that the app may depend on.
                    ad             = new AssemblyDependencies(cad.m_sAppFile, new LoadAssemblyInfo().AppPath(sDir));
                    cad.m_olAssems = new ArrayList();
                    ArrayList al = ad.Assems;
                    for (int i = 0; i < al.Count; i++)
                    {
                        AssemInfo    ai = new AssemInfo();
                        AssemblyName an = (AssemblyName)al[i];
                        ai.Name           = an.Name;
                        ai.Version        = an.Version.ToString();
                        ai.Locale         = an.CultureInfo.ToString();
                        ai.PublicKeyToken = ByteArrayToString(an.GetPublicKeyToken());

                        AddAssemblyInfo(cad.m_olAssems, ai);
                    }
                    ad.DoneLoading();
                    cad.m_fAllowListView = true;
                }
                catch (Exception)
                {
                    cad.m_taskPad  = new CGenericTaskPad(cad, "ERRORDEPENDASSEM_HTML");
                    cad.m_olAssems = null;
                }

                if (ad != null)
                {
                    ad.DoneLoading();
                }
            }
            else if (cad.m_sAppFile == null)
            {
                cad.m_olAssems = null;
                cad.m_taskPad  = new CGenericTaskPad(cad, "ERRORDEPENDASSEM_HTML");
            }
            cad.m_oResults = cad.m_taskPad;
            cad.RefreshResultView();
        }// FindDependenciesForThisNode
Ejemplo n.º 5
0
        }// Fusion

        internal static bool CompareAssemInfo(AssemInfo ai1, AssemInfo ai2)
        {
            if (!ai1.Name.Equals(ai2.Name))
            {
                return(false);
            }
            if (!ai1.Version.Equals(ai2.Version))
            {
                return(false);
            }
            if (!ai1.Locale.Equals(ai2.Locale))
            {
                return(false);
            }
            if (!ai1.PublicKey.Equals(ai2.PublicKey))
            {
                return(false);
            }
            if (!ai1.PublicKeyToken.Equals(ai2.PublicKeyToken))
            {
                return(false);
            }
            if (!ai1.Modified.Equals(ai2.Modified))
            {
                return(false);
            }
            if (!ai1.Codebase.Equals(ai2.Codebase))
            {
                return(false);
            }
            if (!ai1.ProcType.Equals(ai2.ProcType))
            {
                return(false);
            }
            if (!ai1.OSType.Equals(ai2.OSType))
            {
                return(false);
            }
            if (!ai1.OSVersion.Equals(ai2.OSVersion))
            {
                return(false);
            }
            if (ai1.nCacheType != ai2.nCacheType)
            {
                return(false);
            }
            if (!ai1.sCustom.Equals(ai2.sCustom))
            {
                return(false);
            }

            // If we got this far, then these two asseminfos are equal
            return(true);
        }// CompareAssemInfo
        }// TurnCodebaseToFilename

        internal override int onDoubleClick(Object o)
        {
            if (o != null)
            {
                AssemInfo ai  = (AssemInfo)o;
                CDO       cdo = new CDO(this);
                cdo.Data = o;

                OpenMyResultPropertyPage(ai.Name, cdo);
                return(HRESULT.S_OK);
            }
            return(HRESULT.S_FALSE);
        }// onDoubleClick
        }// onDoubleClick

        internal override int onDelete(Object o)
        {
            String sMessage;

            if (o is ArrayList)
            {
                sMessage = CResourceStore.GetString("CSharedAssemblies:VerifyDelete");
            }
            else
            {
                sMessage = String.Format(CResourceStore.GetString("CSharedAssemblies:VerifyDeleteSingle"), ((AssemInfo)o).Name);
            }


            int nRes = MessageBox(sMessage,
                                  CResourceStore.GetString("CSharedAssemblies:VerifyDeleteTitle"),
                                  MB.ICONQUESTION | MB.YESNO);

            if (nRes == MB.IDYES)
            {
                if (o is ArrayList)
                {
                    ArrayList al = (ArrayList)o;
                    for (int i = 0; i < al.Count; i++)
                    {
                        int nVictim = ((int)al[i]) - 1;
                        if (!Fusion.RemoveAssemblyFromGac((AssemInfo)m_olAssems[nVictim]))
                        {
                            MessageBox(String.Format(CResourceStore.GetString("CSharedAssemblies:ErrorRemoving"), ((AssemInfo)m_olAssems[nVictim]).Name),
                                       CResourceStore.GetString("CSharedAssemblies:ErrorRemovingTitle"),
                                       MB.ICONEXCLAMATION);
                        }
                    }
                }
                else
                {
                    AssemInfo ai = (AssemInfo)o;
                    if (!Fusion.RemoveAssemblyFromGac(ai))
                    {
                        MessageBox(String.Format(CResourceStore.GetString("CSharedAssemblies:ErrorRemoving"), ai.Name),
                                   CResourceStore.GetString("CSharedAssemblies:ErrorRemovingTitle"),
                                   MB.ICONEXCLAMATION);
                    }
                }

                m_olAssems = Fusion.ReadFusionCache();
                CNodeManager.Console.SelectScopeItem(HScopeItem);
            }

            return(HRESULT.S_OK);
        }// onDelete
        }// CSharedAssemblies

        internal override void ResultItemSelected(IConsole2 con, Object oResults)
        {
            IConsoleVerb icv;

            // Get the IConsoleVerb interface from MMC
            con.QueryConsoleVerb(out icv);

            icv.SetVerbState(MMC_VERB.DELETE, MMC_BUTTON_STATE.ENABLED, 1);

            if (oResults is AssemInfo)
            {
                AssemInfo ai = (AssemInfo)oResults;

                // We only want to user to be able to copy this item if it is a GAC Assembly

                if (ai.nCacheType == ASM_CACHE.GAC)
                {
                    icv.SetVerbState(MMC_VERB.COPY, MMC_BUTTON_STATE.ENABLED, 1);
                }
            }
            else if (oResults is ArrayList)
            {
                // Run through the array list. If everything is from the GAC, then
                // we'll enable the copy verb
                ArrayList al        = (ArrayList)oResults;
                bool      fFoundZap = false;
                int       nIndex    = 0;
                while (!fFoundZap && nIndex < al.Count)
                {
                    if (((AssemInfo)m_olAssems[(int)(al[nIndex]) - 1]).nCacheType != ASM_CACHE.GAC)
                    {
                        fFoundZap = true;
                    }
                    nIndex++;
                }
                if (!fFoundZap)
                {
                    icv.SetVerbState(MMC_VERB.COPY, MMC_BUTTON_STATE.ENABLED, 1);
                }
            }

            icv.SetVerbState(MMC_VERB.CUT, MMC_BUTTON_STATE.ENABLED, 0);
        }// ResultItemSelected
        }// Paste

        internal void AddAssembly(AssemInfo asinfo)
        {
            try
            {
                // Let's create a strong name....
                byte[] baPublicKey;

                if (asinfo.PublicKey == null || asinfo.PublicKey.Length == 0)
                {
                    // The codebase is of the form file:///c:\somefile\sdfsf
                    // We need to translate it to a simple path
                    Uri uCodebase = new Uri(asinfo.Codebase);

                    // We need to load the assembly to get this info
                    AssemblyLoader al = new AssemblyLoader();
                    AssemblyRef    ar = al.LoadAssemblyInOtherAppDomainFrom(uCodebase.AbsolutePath);

                    AssemblyName an = ar.GetName();
                    baPublicKey = an.GetPublicKey();
                    al.Finished();
                }
                else
                {
                    baPublicKey = StringToByteArray(asinfo.PublicKey);
                }

                StrongNamePublicKeyBlob       snpkb = new StrongNamePublicKeyBlob(baPublicKey);
                StrongNameMembershipCondition snmc  = new StrongNameMembershipCondition(snpkb, asinfo.Name, null);

                m_pl.AddFullTrustAssembly(snmc);
                SecurityPolicyChanged();
                RefreshData();
                RefreshResultView();
            }
            catch (Exception)
            {
                MessageBox(CResourceStore.GetString("CTrustedAssemblies:TrustAssemFail"),
                           CResourceStore.GetString("CTrustedAssemblies:TrustAssemFailTitle"),
                           MB.ICONEXCLAMATION);
            }
        }// AddAssembly
Ejemplo n.º 10
0
        internal CFusionNoVersionDialog() : base(false)
        {
            this.Text = CResourceStore.GetString("InheritedAssemblyDialogs:ChooseFromGac");
            m_ol      = Fusion.ReadFusionCacheJustGAC();

            // Filter out duplicate versions....
            for (int i = 0; i < m_ol.Count; i++)
            {
                AssemInfo ai = (AssemInfo)m_ol[i];
                // Run through and see if anybody else has this name and public key token
                for (int j = i + 1; j < m_ol.Count; j++)
                {
                    AssemInfo ai2 = (AssemInfo)m_ol[j];
                    if (ai2.Name.Equals(ai.Name) && ai2.PublicKeyToken.Equals(ai.PublicKeyToken))
                    {
                        m_ol.RemoveAt(j);
                        j--;
                    }
                }
            }
            PutInAssemblies();
        } // CFusionNoVersionDialog
Ejemplo n.º 11
0
        }// ApplyPropPages

        private CPropPage[] GetPropertyPages(AssemInfo ai)
        {
            // Let's see if we already have an entry for this assemby item
            int nLen = m_alResultPropPages.Count;

            for (int i = 0; i < nLen; i++)
            {
                if (Fusion.CompareAssemInfo(((PropPagePairs)m_alResultPropPages[i]).ai, ai))
                {
                    return(((PropPagePairs)m_alResultPropPages[i]).ppages);
                }
            }

            // If we're here, then we have a new property page to add
            PropPagePairs ppp = new PropPagePairs();

            ppp.ppages = new CPropPage[1] {
                new CAssemGenProps(ai)
            };
            ppp.ai = ai;
            m_alResultPropPages.Add(ppp);
            return(ppp.ppages);
        }// GetPropertyPages
Ejemplo n.º 12
0
        }// AddAssemblyToGac

        internal static bool RemoveAssemblyFromGac(AssemInfo aInfo)
        {
            IAssemblyCache ac = null;
            int            hr = CreateAssemblyCache(out ac, 0);
            uint           n;

            if (aInfo.sCustom.Length > 0)
            {
                // We need to take this string, byte-ify it, then string-ify it.
                // Why?
                // We need our string:
                // ZAP........
                // to be
                // 900041005000.......
                aInfo.sFusionName += ",Custom=" + ByteArrayToString(StringToByteArray(aInfo.sCustom));
            }

            int nRet = ac.UninstallAssembly(0, aInfo.sFusionName, (IntPtr)0, out n);

            if (nRet != HRESULT.S_OK)
            {
                // Ok, something kind of funky happened.... let's see if this item really did get removed from the cache
                ArrayList al = new ArrayList();
                ReadCache(al, aInfo.nCacheType);

                // See if our item is in here.....
                for (int i = 0; i < al.Count; i++)
                {
                    AssemInfo ai = (AssemInfo)al[i];
                    if (ai.Name.Equals(aInfo.Name) && ai.PublicKeyToken.Equals(aInfo.PublicKeyToken) && ai.Version.Equals(aInfo.Version))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }// RemoveAssemblyFromGac
Ejemplo n.º 13
0
 //-------------------------------------------------
 // CAssemGenProps - Constructor
 //
 // Sets up some member variables
 //-------------------------------------------------
 internal CAssemGenProps(AssemInfo ai)
 {
     m_ai     = ai;
     m_sTitle = CResourceStore.GetString("CAssemGenProps:PageTitle");
 }// CAssemGenProps
Ejemplo n.º 14
0
        }// ReadFusionCache

        private static void ReadCache(ArrayList alAssems, uint nFlag)
        {
            IAssemblyEnum       aEnum  = null;
            IApplicationContext AppCtx = null;
            IAssemblyName       aName  = null;

            int hr = CreateAssemblyEnum(out aEnum, null, null, nFlag, 0);

            while (hr == HRESULT.S_OK)
            {
                hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0);
                if (hr == HRESULT.S_OK)
                {
                    uint   iLen         = 0;
                    IntPtr pDisplayName = (IntPtr)0;
                    // Get the length of the string we need
                    aName.GetDisplayName((IntPtr)0, ref iLen, 0);
                    if (iLen > 0)
                    {
                        // Do some yucky memory allocating here
                        // We need to assume that a wide character is 2 bytes.
                        pDisplayName = Marshal.AllocHGlobal(((int)iLen + 1) * 2);
                        aName.GetDisplayName(pDisplayName, ref iLen, 0);
                        String sDisplayName = Marshal.PtrToStringUni(pDisplayName);
                        Marshal.FreeHGlobal(pDisplayName);


                        AssemInfo newguy = new AssemInfo();
                        newguy.sFusionName = sDisplayName;

                        // Our info is in a comma seperated list. Let's pull it out
                        String[] sFields = sDisplayName.Split(new char[] { ',' });

                        newguy.Name = sFields[0];
                        // The version string is represented as Version=######
                        // Let's take out the 'Version='
                        newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1);
                        // Same goes for the locale
                        newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1);
                        // And the internal key token
                        sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1);
                        if (sFields[3].Equals("null"))
                        {
                            sFields[3] = CResourceStore.GetString("None");
                        }

                        newguy.PublicKeyToken = sFields[3];

                        // Now get some more stuff we can't get from a 'GetDisplayName' call
                        newguy.PublicKey = GetFusionString(aName, ASM_NAME.PUBLIC_KEY);
                        newguy.Codebase  = GetFusionString(aName, ASM_NAME.CODEBASE_URL);

                        // newguy.Modified = GetFusionString(aName, ASM_NAME.CODEBASE_LASTMOD);
                        // Currently, there's a fusion bug which prevents us from getting this information
                        // We'll go out to the file system and get the data right now.
                        newguy.Modified = "";
                        try
                        {
                            if (newguy.Codebase != null && newguy.Codebase.Length > 0)
                            {
                                Uri    uCodebase     = new Uri(newguy.Codebase);
                                String sAbsolutePath = uCodebase.AbsolutePath;
                                if (File.Exists(sAbsolutePath))
                                {
                                    newguy.Modified = File.GetLastWriteTime(sAbsolutePath).ToString();
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        newguy.ProcType  = GetFusionString(aName, ASM_NAME.PROCESSOR_ID_ARRAY);
                        newguy.OSType    = GetFusionString(aName, ASM_NAME.OSINFO_ARRAY);
                        newguy.OSVersion = ""; // We'll need to munge the OSINFO_ARRAY a bit
                        // This will grab the ZAP signature
                        newguy.sCustom    = GetFusionString(aName, ASM_NAME.CUSTOM);
                        newguy.nCacheType = nFlag;
                        alAssems.Add(newguy);
                    }
                }
            }
        }// ReadFusionCache