コード例 #1
0
ファイル: PKImporter.cs プロジェクト: Michael-Z/DriveHud
        protected virtual bool TryDecryptBody(PokerKingPackage package, Process process, IEmulatorService emulatorService, bool withRepeat = true)
        {
            try
            {
                if (!userTokens.TryGetValue(package.UserId, out string token))
                {
                    withRepeat = false;

                    LogProvider.Log.Info(Logger, $"Token for user #{package.UserId} not found");

                    // read token from emulator
                    var loginResponses = emulatorService.ExecuteAdbCommand(process,
                                                                           Encoding.ASCII.GetString(arg1),
                                                                           Encoding.ASCII.GetString(arg2));

                    foreach (var loginResponseXml in loginResponses)
                    {
                        if (!PKLoginResponse.TryParse(loginResponseXml, out PKLoginResponse loginResponse))
                        {
                            LogProvider.Log.Warn(Logger, $"Failed to parse token for user #{package.UserId} from response.");
                            continue;
                        }

                        userTokens.AddOrUpdate(loginResponse.UserId, loginResponse.UserToken, (dictKey, oldValue) => loginResponse.UserToken);
                        LogProvider.Log.Info(Logger, $"Token for user #{loginResponse.UserId} has been updated.");

                        if (loginResponse.UserId == package.UserId)
                        {
                            token = loginResponse.UserToken;
                        }
                    }

                    if (string.IsNullOrEmpty(token))
                    {
                        LogProvider.Log.Warn(Logger, $"Failed to find token for user #{package.UserId}.");
                        return(false);
                    }
                }

                var key = Encoding.ASCII.GetBytes(token);

                package.Body = PKCipherHelper.Decode(key, package.Body);

                return(true);
            }
            catch (Exception e)
            {
                if (withRepeat)
                {
                    LogProvider.Log.Warn(Logger, $"Failed to read the body of user #{package.UserId} room #{package.RoomId}. Removing invalid token.");
                    userTokens.TryRemove(package.UserId, out string removeToken);

                    return(TryDecryptBody(package, process, emulatorService, false));
                }

                LogProvider.Log.Error(Logger, $"Couldn't read the body of {package.PackageType} user #{package.UserId} room #{package.RoomId}", e);
            }

            return(false);
        }
コード例 #2
0
ファイル: PKModelTests.cs プロジェクト: Michael-Z/DriveHud
        public void PKLoginResponseTryParseTest(string fileName, uint userId, string userToken)
        {
            var fileText = File.ReadAllText(fileName);

            var result = PKLoginResponse.TryParse(fileText, out PKLoginResponse loginResponse);

            Assert.IsTrue(result, "TryParse result must be true");
            Assert.IsNotNull(loginResponse);

            Assert.Multiple(() =>
            {
                Assert.That(loginResponse.UserId, Is.EqualTo(userId));
                Assert.That(loginResponse.UserToken, Is.EqualTo(userToken));
            });
        }
コード例 #3
0
        //[TestCase(20792)]
        public void TestAdbCommand(int processId)
        {
            var process = Process.GetProcessById(processId);

            Assert.IsNotNull(process, $"Process must be running.");

            var emulatorService = new EmulatorService();

            // load emulator data to service
            emulatorService.GetTableWindowHandle(process);

            var outputs = emulatorService.ExecuteAdbCommand(process,
                                                            "shell",
                                                            "\"cat /data/data/com.ylc.qp.Pokermate/shared_prefs/Cocos2dxPrefsFile.xml\"");

            Assert.Multiple(() =>
            {
                foreach (var output in outputs)
                {
                    var result = PKLoginResponse.TryParse(output, out PKLoginResponse loginResponse);
                    Assert.IsTrue(result);
                }
            });
        }