Esempio n. 1
0
 void RollbackFiles(PKGRunningPackageData RunningPKG, out string ErrorText)
 {
     ErrorText = "";
     try
     {
         RunningPKG.script.Rollback(RunningPKG);
     }
     catch (Exception ee)
     {
         Debug.WriteLine(ee.ToString());
         ErrorText = "Script Error:\r\n" + ee.ToString();
     }
 }
Esempio n. 2
0
        bool InitPackageZipFile(string Filename, List <byte[]> CerCertificates, bool ZipIsMetaOnly, out string ErrorText,
                                out PKGRunningPackageData RunningPKG, string OtherDLL)
        {
            ErrorText  = "";
            RunningPKG = null;
            UpdateText("Initializing");
            Debug.WriteLine("Testing " + Filename);


            using (FileStream ZipFile = File.Open(Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (ZipArchive ZipArch = new ZipArchive(ZipFile, ZipArchiveMode.Read, true, Encoding.UTF8))
                {
                    ZipArchiveEntry entry;
                    entry = ZipArch.GetEntry("Script.json");
                    if (entry == null)
                    {
                        ZipFile.Close();
                        ErrorText = "Missing Script.json";
                        return(false);
                    }

                    if (TestSignatureBySignFile("Script.json", ZipArch, CerCertificates) == false)
                    {
                        ZipFile.Close();
                        ErrorText = "Script.json Signature check failed";
                        return(false);
                    }

                    byte[] packagedata;

                    packagedata = GetZipData(entry);
                    PKGRootData Package;
                    string      ScriptSource = Encoding.UTF8.GetString(packagedata);
                    try
                    {
                        Package = JsonConvert.DeserializeObject <PKGRootData>(ScriptSource);
                        if (Package.HeaderID != "FoxPackageScriptV1")
                        {
                            ErrorText = "Script.json is not the format wanted (Header)!";
                            ZipFile.Close();
                            return(false);
                        }
                    }
                    catch (Exception ee)
                    {
                        Debug.WriteLine(ee.ToString());
                        ErrorText = "Script.json is not the format wanted (Format)!";
                        ZipFile.Close();
                        return(false);
                    }

                    if (CheckScript(Package, ZipArch, true, ZipIsMetaOnly, out ErrorText) == false)
                    {
                        return(false);
                    }

                    foreach (PKGFile file in Package.Files)
                    {
                        if (ZipIsMetaOnly == true)
                        {
                            if (file.KeepInMeta == false)
                            {
                                continue;
                            }
                        }
                        if (TestSignatureByInternalSigning(Package, file.SrcFile, ZipArch, CerCertificates) == false)
                        {
                            ZipFile.Close();
                            ErrorText = file.SrcFile + " Signature check failed";
                            return(false);
                        }

                        if (AbortProcess == true)
                        {
                            ZipFile.Close();
                            ErrorText = "Aborted";
                            return(false);
                        }
                    }

                    Assembly asm = PackageCompiler.CompileScript(Package.Script, out ErrorText, OtherDLL, out ScriptTempDLLFilename);
                    if (asm == null)
                    {
                        ErrorText = "Script contains errors: \r\n" + ErrorText;
                        ZipFile.Close();
                        return(false);
                    }

                    object o = asm.CreateInstance("FoxSDC_Package.PackageScriptTemplate", false);
                    if (o == null)
                    {
                        ErrorText = "Cannot find entrypoint for the script";
                        ZipFile.Close();
                        return(false);
                    }

                    PKGScript script = null;
                    try
                    {
                        script = (PKGScript)o;
                    }
                    catch (Exception ee)
                    {
                        Debug.WriteLine(ee.ToString());
                        ErrorText = "Cannot bind function";
                        ZipFile.Close();
                        return(false);
                    }

                    RunningPKG                 = new PKGRunningPackageData();
                    RunningPKG.Files           = Package.Files;
                    RunningPKG.PackageID       = Package.PackageID;
                    RunningPKG.RebootRequired  = false;
                    RunningPKG.Title           = Package.Title;
                    RunningPKG.CerCertificates = CerCertificates;
                    RunningPKG.script          = script;
                    RunningPKG.asm             = asm;
                    RunningPKG.scriptsource    = Package.Script;
                    RunningPKG.Description     = Package.Description;
                    RunningPKG.RecieptData     = null;
                    RunningPKG.Filename        = Filename;
                    RunningPKG.NoReciept       = Package.NoReceipt;
                    RunningPKG.VersionID       = Package.VersionID;
                }
            }
            return(true);
        }