Exemplo n.º 1
0
        private static void OnHashesGenerated(BuildReport report, BuildHashes[] hashedBuilds)
        {
            Debug.Log("CodeHashGeneratorListener example listener saying hello.");

            var whitelistedHashes = string.Empty;

            // Upload hashes to the server or do anything you would like to.
            //
            // Note, you may have multiple builds each with own hashes in some cases after build,
            // e.g. when using "Split APKs by target architecture" option.
            foreach (var hashedBuild in hashedBuilds)
            {
                hashedBuild.PrintToConsole();

                whitelistedHashes += hashedBuild.SummaryHash + GenuineValidatorExample.Separator;

                var fileHashes       = hashedBuild.FileHashes;
                var fileHashesLength = fileHashes.Length;
                for (var i = 0; i < fileHashesLength; i++)
                {
                    var fileHash = fileHashes[i];
                    whitelistedHashes += fileHash.Hash;

                    if (i != fileHashesLength - 1)
                    {
                        whitelistedHashes += GenuineValidatorExample.Separator;
                    }
                }
            }

            // for example, you may put hashes next to the standalone build to compare them offline
            // just as a proof of concept, but please consider uploading your hashes to the server
            // and make comparison on the server-side instead when possible to add cheaters some more pain

            var outputFolder = Path.GetDirectoryName(report.summary.outputPath);

            if (string.IsNullOrEmpty(outputFolder) || !Directory.Exists(outputFolder))
            {
                Debug.LogError(ACTkConstants.LogPrefix + "Couldn't find build folder!");
                return;
            }

            var filePath = Path.Combine(outputFolder, GenuineValidatorExample.FileName);

            // encrypt to hide hashes from the eye
            var encryptedValue = ObscuredString.Encrypt(whitelistedHashes, GenuineValidatorExample.StringKey);

            // now just get raw bytes and write them to the file to compare hashes in runtime
            var bytes = GenuineValidatorExample.UnicodeCharsToBytes(encryptedValue);

            File.WriteAllBytes(filePath, bytes);
        }
        private static void OnHashesGenerate(BuildReport report, Dictionary <string, string> buildHashes)
        {
            Debug.Log("CodeHashGeneratorListener example listener saying hello.");

            // Upload hashes to the server or do anything you would like to.
            //
            // Note, you may have multiple builds each with own hash in some cases after build,
            // e.g. when using "Split APKs by target architecture" option.
            foreach (var buildHash in buildHashes)
            {
                Debug.Log("Build: " + buildHash.Key + "\n" +
                          "Hash: " + buildHash.Value);
            }

            // for example, you may put hash next to the standalone build to compare it offline
            // just as a proof of concept, please consider uploading your hash to the server
            // and make comparison on the server-side to add some more pain to the cheaters\

            var firstBuildHash = buildHashes.FirstOrDefault().Value;

            if (string.IsNullOrEmpty(firstBuildHash))
            {
                Debug.LogError(ACTkConstants.LogPrefix + "Couldn't find first build hash!");
                return;
            }

            var outputFolder = Path.GetDirectoryName(report.summary.outputPath);

            if (string.IsNullOrEmpty(outputFolder) || !Directory.Exists(outputFolder))
            {
                Debug.LogError(ACTkConstants.LogPrefix + "Couldn't find build folder!");
                return;
            }

            var filePath          = Path.Combine(outputFolder, GenuineValidatorExample.FileName);
            var hashOfTheHashHaha = GenuineValidatorExample.GetHash(firstBuildHash + GenuineValidatorExample.HashSalt);

            // let's put together build hash with its hash and encrypt it using constant key
            var encryptedValue = ObscuredString.Encrypt(firstBuildHash + GenuineValidatorExample.Separator + hashOfTheHashHaha, GenuineValidatorExample.StringKey);

            // now just get raw bytes and write them to the file to compare hash in runtime
            var bytes = GenuineValidatorExample.UnicodeCharsToBytes(encryptedValue);

            File.WriteAllBytes(filePath, bytes);
        }