Exemple #1
0
 /// <summary>
 /// Create a new VBA Project
 /// </summary>
 internal void Create()
 {
     if (Lcid > 0)
     {
         throw (new InvalidOperationException("Package already contains a VBAProject"));
     }
     ProjectID     = "{5DD90D76-4904-47A2-AF0D-D69B4673604E}";
     Name          = "VBAProject";
     SystemKind    = eSyskind.Win32;                   //Default
     Lcid          = 1033;                             //English - United States
     LcidInvoke    = 1033;                             //English - United States
     CodePage      = Encoding.GetEncoding(0).CodePage; //Switched from Default to make it work in Core
     MajorVersion  = 1361024421;
     MinorVersion  = 6;
     HelpContextID = 0;
     Modules.Add(new ExcelVBAModule(_wb.CodeNameChange)
     {
         Name = "ThisWorkbook", Code = "", Attributes = GetDocumentAttributes("ThisWorkbook", "0{00020819-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0
     });
     foreach (var sheet in _wb.Worksheets)
     {
         var name = GetModuleNameFromWorksheet(sheet);
         if (!Modules.Exists(name))
         {
             Modules.Add(new ExcelVBAModule(sheet.CodeNameChange)
             {
                 Name = name, Code = "", Attributes = GetDocumentAttributes(sheet.Name, "0{00020820-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0
             });
         }
     }
     _protection = new ExcelVbaProtection(this)
     {
         UserProtected = false, HostProtected = false, VbeProtected = false, VisibilityState = true
     };
 }
Exemple #2
0
        private void ReadProjectProperties()
        {
            _protection = new ExcelVbaProtection(this);
            string prevPackage = "";
            var    lines       = Regex.Split(ProjectStreamText, "\r\n");

            foreach (string line in lines)
            {
                if (line.StartsWith("["))
                {
                }
                else
                {
                    var split = line.Split('=');
                    if (split.Length > 1 && split[1].Length > 1 && split[1].StartsWith("\"")) //Remove any double qouates
                    {
                        split[1] = split[1].Substring(1, split[1].Length - 2);
                    }
                    switch (split[0])
                    {
                    case "ID":
                        ProjectID = split[1];
                        break;

                    case "Document":
                        string mn = split[1].Substring(0, split[1].IndexOf("/&H"));
                        Modules[mn].Type = eModuleType.Document;
                        break;

                    case "Package":
                        prevPackage = split[1];
                        break;

                    case "BaseClass":
                        Modules[split[1]].Type    = eModuleType.Designer;
                        Modules[split[1]].ClassID = prevPackage;
                        break;

                    case "Module":
                        Modules[split[1]].Type = eModuleType.Module;
                        break;

                    case "Class":
                        Modules[split[1]].Type = eModuleType.Class;
                        break;

                    case "HelpFile":
                    case "Name":
                    case "HelpContextID":
                    case "Description":
                    case "VersionCompatible32":
                        break;

                    //393222000"
                    case "CMG":
                        byte[] cmg = Decrypt(split[1]);
                        _protection.UserProtected = (cmg[0] & 1) != 0;
                        _protection.HostProtected = (cmg[0] & 2) != 0;
                        _protection.VbeProtected  = (cmg[0] & 4) != 0;
                        break;

                    case "DPB":
                        byte[] dpb = Decrypt(split[1]);
                        if (dpb.Length >= 28)
                        {
                            byte reserved = dpb[0];
                            var  flags    = new byte[3];
                            Array.Copy(dpb, 1, flags, 0, 3);
                            var keyNoNulls = new byte[4];
                            _protection.PasswordKey = new byte[4];
                            Array.Copy(dpb, 4, keyNoNulls, 0, 4);
                            var hashNoNulls = new byte[20];
                            _protection.PasswordHash = new byte[20];
                            Array.Copy(dpb, 8, hashNoNulls, 0, 20);
                            //Handle 0x00 bitwise 2.4.4.3
                            for (int i = 0; i < 24; i++)
                            {
                                int bit = 128 >> (int)((i % 8));
                                if (i < 4)
                                {
                                    if ((int)(flags[0] & bit) == 0)
                                    {
                                        _protection.PasswordKey[i] = 0;
                                    }
                                    else
                                    {
                                        _protection.PasswordKey[i] = keyNoNulls[i];
                                    }
                                }
                                else
                                {
                                    int flagIndex = (i - i % 8) / 8;
                                    if ((int)(flags[flagIndex] & bit) == 0)
                                    {
                                        _protection.PasswordHash[i - 4] = 0;
                                    }
                                    else
                                    {
                                        _protection.PasswordHash[i - 4] = hashNoNulls[i - 4];
                                    }
                                }
                            }
                        }
                        break;

                    case "GC":
                        _protection.VisibilityState = Decrypt(split[1])[0] == 0xFF;

                        break;
                    }
                }
            }
        }
 /// <summary>
 /// Create a new VBA Project
 /// </summary>
 internal void Create()
 {
     if(Lcid>0)
     {
         throw (new InvalidOperationException("Package already contains a VBAProject"));
     }
     ProjectID = "{5DD90D76-4904-47A2-AF0D-D69B4673604E}";
     Name = "VBAProject";
     SystemKind = eSyskind.Win32;            //Default
     Lcid = 1033;                            //English - United States
     LcidInvoke = 1033;                      //English - United States
     CodePage = Encoding.Default.CodePage;
     MajorVersion = 1361024421;
     MinorVersion = 6;
     HelpContextID = 0;
     Modules.Add(new ExcelVBAModule(_wb.CodeNameChange) { Name = "ThisWorkbook", Code = "", Attributes=GetDocumentAttributes("ThisWorkbook", "0{00020819-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0 });
     foreach (var sheet in _wb.Worksheets)
     {
         if (!Modules.Exists(sheet.Name))
         {
             Modules.Add(new ExcelVBAModule(sheet.CodeNameChange) { Name = sheet.Name, Code = "", Attributes = GetDocumentAttributes(sheet.Name, "0{00020820-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0 });
         }
     }
     _protection = new ExcelVbaProtection(this) { UserProtected = false, HostProtected = false, VbeProtected = false, VisibilityState = true };
 }
        private void ReadProjectProperties()
        {
            _protection = new ExcelVbaProtection(this);
            string prevPackage = "";
            var lines = Regex.Split(ProjectStreamText, "\r\n");
            foreach (string line in lines)
            {
                if (line.StartsWith("["))
                {

                }
                else
                {
                    var split = line.Split('=');
                    if (split.Length > 1 && split[1].Length > 1 && split[1].StartsWith("\"")) //Remove any double qouates
                    {
                        split[1] = split[1].Substring(1, split[1].Length - 2);
                    }
                    switch (split[0])
                    {
                        case "ID":
                            ProjectID = split[1];
                            break;
                        case "Document":
                            string mn = split[1].Substring(0, split[1].IndexOf("/&H"));
                            Modules[mn].Type = eModuleType.Document;
                            break;
                        case "Package":
                            prevPackage = split[1];
                            break;
                        case "BaseClass":
                            Modules[split[1]].Type = eModuleType.Designer;
                            Modules[split[1]].ClassID = prevPackage;
                            break;
                        case "Module":
                            Modules[split[1]].Type = eModuleType.Module;
                            break;
                        case "Class":
                            Modules[split[1]].Type = eModuleType.Class;
                            break;
                        case "HelpFile":
                        case "Name":
                        case "HelpContextID":
                        case "Description":
                        case "VersionCompatible32":
                            break;
                        //393222000"
                        case "CMG":
                            byte[] cmg = Decrypt(split[1]);
                            _protection.UserProtected = (cmg[0] & 1) != 0;
                            _protection.HostProtected = (cmg[0] & 2) != 0;
                            _protection.VbeProtected = (cmg[0] & 4) != 0;
                            break;
                        case "DPB":
                            byte[] dpb = Decrypt(split[1]);
                            if (dpb.Length >= 28)
                            {
                                byte reserved = dpb[0];
                                var flags = new byte[3];
                                Array.Copy(dpb, 1, flags, 0, 3);
                                var keyNoNulls = new byte[4];
                                _protection.PasswordKey = new byte[4];
                                Array.Copy(dpb, 4, keyNoNulls, 0, 4);
                                var hashNoNulls = new byte[20];
                                _protection.PasswordHash = new byte[20];
                                Array.Copy(dpb, 8, hashNoNulls, 0, 20);
                                //Handle 0x00 bitwise 2.4.4.3 
                                for (int i = 0; i < 24; i++)
                                {
                                    int bit = 128 >> (int)((i % 8));
                                    if (i < 4)
                                    {
                                        if ((int)(flags[0] & bit) == 0)
                                        {
                                            _protection.PasswordKey[i] = 0;
                                        }
                                        else
                                        {
                                            _protection.PasswordKey[i] = keyNoNulls[i];
                                        }
                                    }
                                    else
                                    {
                                        int flagIndex = (i - i % 8) / 8;
                                        if ((int)(flags[flagIndex] & bit) == 0)
                                        {
                                            _protection.PasswordHash[i - 4] = 0;
                                        }
                                        else
                                        {
                                            _protection.PasswordHash[i - 4] = hashNoNulls[i - 4];
                                        }
                                    }
                                }
                            }
                            break;
                        case "GC":
                            _protection.VisibilityState = Decrypt(split[1])[0] == 0xFF;

                            break;
                    }
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// Create a new VBA Project
 /// </summary>
 internal void Create()
 {
     if(Lcid>0)
     {
         throw (new InvalidOperationException("Package already contains a VBAProject"));
     }
     ProjectID = "{5DD90D76-4904-47A2-AF0D-D69B4673604E}";
     Name = "VBAProject";
     SystemKind = eSyskind.Win32;            //Default
     Lcid = 1033;                            //English - United States
     LcidInvoke = 1033;                      //English - United States
     CodePage = Encoding.Default.CodePage;
     MajorVersion = 1361024421;
     MinorVersion = 6;
     HelpContextID = 0;
     Modules.Add(new ExcelVBAModule(_wb.CodeNameChange) { Name = "ThisWorkbook", Code = "", Attributes=GetDocumentAttributes("ThisWorkbook", "0{00020819-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0 });
     foreach (var sheet in _wb.Worksheets)
     {
         if (!Modules.Exists(sheet.Name))
         {
             Modules.Add(new ExcelVBAModule(sheet.CodeNameChange) { Name = sheet.Name, Code = "", Attributes = GetDocumentAttributes(sheet.Name, "0{00020820-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0 });
         }
     }
     //References.Add(new ExcelVbaReference() { Name = "stdole", Libid = "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\SysWOW64\\stdole2.tlb#OLE Automation", ReferenceRecordID = 13 });
     //References.Add(new ExcelVbaReference() { Name = "Office", Libid = "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL#Microsoft Office 12.0 Object Library", ReferenceRecordID = 13 });
     _protection = new ExcelVbaProtection(this) { UserProtected = false, HostProtected = false, VbeProtected = false, VisibilityState = true };
     //References.Add(new ExcelVbaReferenceControl()
     //{
     //    Name = "MSForms",
     //    Libid = "*\\G{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0#C:\\Windows\\System32\\FM20.DLL#Microsoft Forms 2.0 Object Library",
     //    LibIdExternal = "*\\G{75A950D8-F976-4F2D-B7DA-E961BA02257E}#2.0#0#MSForms.exd#Microsoft Forms 2.0 Object Library",
     //    LibIdTwiddled = "*\\G{00000000-0000-0000-0000-000000000000}#0.0#0##",
     //    OriginalTypeLib=new Guid("0d452ee1-e08f-101a-852e-02608c4d0bb4"),
     //    Cookie=1,
     //    ReferenceRecordID=47
     //});
 }