コード例 #1
0
        /// <summary>
        /// Initializes a Strong Signed key type of Kit 360's
        /// </summary>
        /// <param name="xTypeIn"></param>
        public RSAParams(StrongSigned xTypeIn)
        {
            DJsIO xReader;

            switch (xTypeIn)
            {
            case StrongSigned.LIVE:
                xReader = new DJsIO(Properties.Resources.XK4, true);
                break;

            case StrongSigned.PIRS:
                xReader = new DJsIO(Properties.Resources.XK5, true);
                break;

            default:
                throw STFSExcepts.NotStrong;
            }
            xK.Exponent      = new byte[] { 0, 0, 0, 3 };
            xK.D             = Properties.Resources.XK3;
            xReader.Position = 0;
            xK.Modulus       = xReader.ReadBytes(0x100);
            xK.P             = xReader.ReadBytes(0x80);
            xK.Q             = xReader.ReadBytes(0x80);
            xK.DP            = xReader.ReadBytes(0x80);
            xK.DQ            = xReader.ReadBytes(0x80);
            xK.InverseQ      = xReader.ReadBytes(0x80);
            xReader.Dispose();
            xM = xTypeIn == StrongSigned.LIVE ? PackageMagic.LIVE : PackageMagic.PIRS;
            xV = true;
        }
コード例 #2
0
        public void TestPackages()
        {
            var engine   = Init();
            var snippets = engine.Snippets as Snippets;
            var pkgMagic = new PackageMagic(snippets.GlobalReferences);
            var channel  = new MockChannel();
            var response = pkgMagic.Execute("", channel);
            var result   = response.Output as string[];

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);

            // Try compiling TrotterEstimateEnergy, it should fail due to the lack
            // of chemistry package.
            response = engine.ExecuteMundane(SNIPPETS.TrotterEstimateEnergy, channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            response = pkgMagic.Execute("microsoft.quantum.chemistry", channel);
            result   = response.Output as string[];
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Length);

            // Now it should compile:
            AssertCompile(engine, SNIPPETS.TrotterEstimateEnergy, "TrotterEstimateEnergy");
        }
コード例 #3
0
        public void TestWorkspace()
        {
            var engine   = Init("Workspace.Chemistry");
            var snippets = engine.Snippets as Snippets;

            var wsMagic  = new WorkspaceMagic(snippets.Workspace);
            var pkgMagic = new PackageMagic(snippets.GlobalReferences);

            var channel = new MockChannel();
            var result  = new string[0];

            // Check the workspace, it should be in error state:
            var response = wsMagic.Execute("reload", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            response = wsMagic.Execute("", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            // Try compiling a snippet that depends on a workspace that depends on the chemistry package:
            response = engine.ExecuteMundane(SNIPPETS.DependsOnChemistryWorkspace, channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);

            // Add dependencies:
            response = pkgMagic.Execute("microsoft.quantum.chemistry", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            response = pkgMagic.Execute("microsoft.quantum.research", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            // Reload workspace:
            response = wsMagic.Execute("reload", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            response = wsMagic.Execute("", channel);
            result   = response.Output as string[];
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(3, result.Length);

            // Now compilation must work:
            AssertCompile(engine, SNIPPETS.DependsOnChemistryWorkspace, "DependsOnChemistryWorkspace");

            // Check an invalid command
            response = wsMagic.Execute("foo", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            // Check that everything still works:
            response = wsMagic.Execute("", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
        }
コード例 #4
0
        private async Task AssertTrace(string name, ExecutionPath expectedPath, int expectedDepth)
        {
            var engine = await Init("Workspace.ExecutionPathTracer");

            var snippets = engine.Snippets as Snippets;

            Assert.IsNotNull(snippets);
            Assert.IsNotNull(engine.SymbolsResolver);
            var configSource = new ConfigurationSource(skipLoading: true);

            var wsMagic    = new WorkspaceMagic(snippets !.Workspace, new UnitTestLogger <WorkspaceMagic>());
            var pkgMagic   = new PackageMagic(snippets.GlobalReferences, new UnitTestLogger <PackageMagic>());
            var traceMagic = new TraceMagic(engine.SymbolsResolver !, configSource, new UnitTestLogger <TraceMagic>());

            var channel = new MockChannel();

            // Add dependencies:
            var response = await pkgMagic.Execute("mock.standard", channel);

            PrintResult(response, channel);
            response.AssertIsOk();

            // Reload workspace:
            response = await wsMagic.Execute("reload", channel);

            PrintResult(response, channel);
            response.AssertIsOk();

            response = await traceMagic.Execute(name, channel);

            PrintResult(response, channel);
            response.AssertIsOk();

            var message = channel.iopubMessages.ElementAtOrDefault(0);

            Assert.IsNotNull(message);
            Assert.AreEqual("render_execution_path", message.Header.MessageType);

            var content = message.Content as ExecutionPathVisualizerContent;

            Assert.IsNotNull(content);

            Assert.AreEqual(expectedDepth, content?.RenderDepth);

            var path = content?.ExecutionPath.ToObject <ExecutionPath>();

            Assert.IsNotNull(path);
            Assert.AreEqual(expectedPath.ToJson(), path !.ToJson());
        }
コード例 #5
0
        public void TestInvalidPackages()
        {
            var engine   = Init();
            var snippets = engine.Snippets as Snippets;
            var pkgMagic = new PackageMagic(snippets.GlobalReferences);
            var channel  = new MockChannel();

            var response = pkgMagic.Execute("microsoft.quantum", channel);
            var result   = response.Output as string[];

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(1, channel.errors.Count);
            Assert.IsTrue(channel.errors[0].StartsWith("Unable to find package 'microsoft.quantum'"));
            Assert.IsNull(result);
        }
コード例 #6
0
        void XLoadCON(DJsIO xKV)
        {
            int xbase = 0;

            if (xKV.Length == 0x4000)
            {
                xbase = 0x10;
            }
            else if (xKV.Length != 0x3FF0)
            {
                throw CryptoExcepts.KVSize;
            }
            xM           = PackageMagic.CON;
            xKV.Position = 0x9B8 + xbase;
            xC           = xKV.ReadBytes(0x1A8);
            // D is a constant
            xK.D         = XPackage.Resources.XK0;
            xKV.Position = 0x28C + xbase;
            xK.Exponent  = xKV.ReadBytes(4);
            xKV.Position = 0x298 + xbase;
            xK.Modulus   = ScrambleMethods.StockScramble(xKV.ReadBytes(0x80), false);
            xK.P         = ScrambleMethods.StockScramble(xKV.ReadBytes(0x40), false);
            xK.Q         = ScrambleMethods.StockScramble(xKV.ReadBytes(0x40), false);
            xK.DP        = ScrambleMethods.StockScramble(xKV.ReadBytes(0x40), false);
            xK.DQ        = ScrambleMethods.StockScramble(xKV.ReadBytes(0x40), false);
            xK.InverseQ  = ScrambleMethods.StockScramble(xKV.ReadBytes(0x40), false);
            // Checks if the certificate is the same as the imported keys
            byte[] xPiece = xC.BytePiece(0x28, 0x80);
            if (BitConverter.ToString(ScrambleMethods.StockScramble(xPiece, false)) != BitConverter.ToString(xK.Modulus))
            {
                throw CryptoExcepts.CertConflict;
            }
            // Checks if keys work
            try
            {
                RSACryptoServiceProvider x = new RSACryptoServiceProvider();
                x.ImportParameters(xK);
            }
            catch (Exception x) { throw x; }
            xV = true;
        }
コード例 #7
0
        public async Task TestPackages()
        {
            var engine   = Init();
            var snippets = engine.Snippets as Snippets;

            var pkgMagic     = new PackageMagic(snippets.GlobalReferences);
            var references   = ((References)pkgMagic.References);
            var packageCount = references.AutoLoadPackages.Count + references.DeferredLoadPackages.Count;
            var channel      = new MockChannel();
            var response     = await pkgMagic.Execute("", channel);

            var result = response.Output as string[];

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.AreEqual(packageCount, result.Length);
            Assert.AreEqual("Microsoft.Quantum.Standard::0.0.0", result[0]);
            Assert.AreEqual("Microsoft.Quantum.Standard.Visualization::0.0.0", result[1]);

            // Try compiling TrotterEstimateEnergy, it should fail due to the lack
            // of chemistry package.
            response = await engine.ExecuteMundane(SNIPPETS.UseJordanWignerEncodingData, channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            response = await pkgMagic.Execute("mock.chemistry", channel);

            result = response.Output as string[];
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.IsNotNull(result);
            Assert.AreEqual(packageCount + 1, result.Length);

            // Now it should compile:
            await AssertCompile(engine, SNIPPETS.UseJordanWignerEncodingData, "UseJordanWignerEncodingData");
        }
コード例 #8
0
        public static void BuildXBox360Package(string packagePath, DLCPackageData info, IEnumerable<string> xboxFiles, PackageMagic? xboxPackageType)
        {
            LogRecord x = new LogRecord();
            RSAParams xboxRSA = xboxPackageType == PackageMagic.CON ? new RSAParams(new DJsIO(Resources.XBox360_KV, true)) : new RSAParams(StrongSigned.LIVE);
            CreateSTFS xboxSTFS = new CreateSTFS();
            xboxSTFS.HeaderData = info.GetSTFSHeader();
            foreach (string file in xboxFiles)
                xboxSTFS.AddFile(file, Path.GetFileName(file));

            STFSPackage xboxPackage = new STFSPackage(xboxSTFS, xboxRSA, packagePath, x);
            var generated = xboxPackage.RebuildPackage(xboxRSA);
            if (!generated)
                throw new InvalidOperationException("Error on create XBox360 package, details: \n\r" + x.Log);

            xboxPackage.FlushPackage(xboxRSA);
            xboxPackage.CloseIO();

            try
            {
                if (Directory.Exists(xboxWorkDir))
                    Directory.Delete(xboxWorkDir, true);
            }
            catch { /*Have no problem if don't delete*/ }
        }
コード例 #9
0
        public static void Generate(string packagePath, DLCPackageData info, GamePlatform platform, PackageMagic? xboxPackageType)
        {
            switch (platform)
            {
                case GamePlatform.XBox360:
                    if (!Directory.Exists(xboxWorkDir))
                        Directory.CreateDirectory(xboxWorkDir);
                    break;
                case GamePlatform.PS3:
                    if (!Directory.Exists(ps3WorkDir))
                        Directory.CreateDirectory(ps3WorkDir);
                    break;
                }

            using (var packPsarcStream = new MemoryStream())
            {
                GeneratePackagePsarc(packPsarcStream, info, platform);
                switch (platform) {
                    case GamePlatform.Pc:
                        using (var fl = File.Create(packagePath))
                            RijndaelEncryptor.Encrypt(packPsarcStream, fl, RijndaelEncryptor.DLCKey);
                        break;
                    case GamePlatform.XBox360:
                        BuildXBox360Package(packagePath, info, XBox360Files, xboxPackageType);
                        break;
                    case GamePlatform.PS3:
                        EncryptPS3EdatFiles(packagePath);
                        break;
                }
            }

            try {
                foreach (var sngTmpFile in SNGTmpFiles)
                {
                    if (File.Exists(sngTmpFile))
                        File.Delete(sngTmpFile);
                }
            } catch { /*Have no problem if don't delete*/ }

            XBox360Files.Clear();
            PS3Files.Clear();
            SNGTmpFiles.Clear();
        }
コード例 #10
0
 internal HeaderData(DJsIO xIOIn, PackageMagic MagicType)
 {
     read(xIOIn, null, MagicType);
 }
コード例 #11
0
 internal HeaderData(STFSPackage xPackage, PackageMagic MagicType)
 {
     read(xPackage.xIO, xPackage, MagicType);
 }
コード例 #12
0
 void read(DJsIO xIO, STFSPackage xPackage, PackageMagic MagicType)
 {
     xMagic = MagicType;
     xIO.Position = 0x22C;
     if (xPackage != null)
         xPackage.AddToLog("Reading Liscenses");
     xLisc = new List<STFSLicense>();
     for (int i = 0; i < 0x10; i++)
         xLisc.Add(new STFSLicense(xIO.ReadInt64(), xIO.ReadInt32(), xIO.ReadInt32(), i == 0));
     if (xPackage != null)
         xPackage.AddToLog("Reading Package locks");
     xIO.Position = 0x344;
     if (xPackage != null)
         xPackage.AddToLog("Reading Header Values");
     xThisType = (PackageType)xIO.ReadUInt32(); ;
     MetaDataVersion = xIO.ReadUInt32();
     xContentSize = xIO.ReadInt64();
     MediaID = xIO.ReadUInt32();
     Version_ = xIO.ReadUInt32();
     Version_Base = xIO.ReadUInt32();
     TitleID = xIO.ReadUInt32();
     Platform = xIO.ReadByte();
     ExecutableType = xIO.ReadByte();
     DiscNumber = xIO.ReadByte();
     DiscInSet = xIO.ReadByte();
     SaveGameID = xIO.ReadUInt32();
     SaveConsoleID = (long)xIO.ReadUInt40();
     ProfileID = xIO.ReadInt64();
     xIO.Position = 0x39D;
     DataFileCount = xIO.ReadUInt32();
     DataFileSize = xIO.ReadInt64();
     Reserved = xIO.ReadInt64();
     xSeriesID = xIO.ReadBytes(0x10);
     xSeasonID = xIO.ReadBytes(0x10);
     SeasonNumber = xIO.ReadUInt16();
     EpidsodeNumber = xIO.ReadUInt16();
     xIO.Position += 0x28;
     xDeviceID = xIO.ReadBytes(0x14);
     for (int i = 0; i < 9; i++)
         xTitles[i] = xIO.ReadString(StringForm.Unicode, 0x80).Replace("\0", "");
     for (int i = 0; i < 9; i++)
         xDescriptions[i] = xIO.ReadString(StringForm.Unicode, 0x80).Replace("\0", "");
     xPublisher = xIO.ReadString(StringForm.Unicode, 0x40).Replace("\0", "");
     xTitle = xIO.ReadString(StringForm.Unicode, 0x40).Replace("\0", "");
     IDTransferByte = xIO.ReadByte();
     // Package Image
     int xSize = xIO.ReadInt32();
     xIO.Position = 0x171A;
     if (xSize < 0x4000)
         xPackageImage = xIO.ReadBytes(xSize);
     else xPackageImage = xIO.ReadBytes(0x4000);
     // Content Image
     xIO.Position = 0x1716;
     xSize = xIO.ReadInt32();
     xIO.Position = 0x571A;
     if (xSize < 0x4000)
         xContentImage = xIO.ReadBytes(xSize);
     else xContentImage = xIO.ReadBytes(0x4000);
     xLoaded = true;
 }