Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();


            AdbServer         server = new AdbServer();
            StartServerResult result = server.StartServer(@"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe", restartServerIfNewer: false);

            txtStatus.Text = "Adb Status : " + result.ToString();
            txtIP.Text     = Properties.Settings.Default.LastIp;
            GetListOfDevices();

            var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));

            monitor.DeviceConnected    += this.OnDeviceConnected;
            monitor.DeviceDisconnected += Monitor_DeviceDisconnected;
            monitor.Start();
        }
Beispiel #2
0
        public AdbManager()
        {
            assembly  = GetType().Assembly;
            isWindows = System.Runtime.InteropServices.RuntimeInformation
                        .IsOSPlatform(OSPlatform.Windows);
            adbOutPath = Path.Combine(Directory.GetParent(assembly.Location).FullName,
                                      (isWindows ? "adb.exe" : "adb"));
            UnloadADB();
            LoadADB();
            AdbServer         server       = new AdbServer();
            StartServerResult serverResult = server.StartServer(adbOutPath, true);

            adbVersion      = AdbClient.Instance.GetAdbVersion();
            adbRefreshTimer = new Timer(state =>
            {
                try
                {
                    listOfDevices = AdbClient.Instance.GetDevices();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }, null, 0, 2000);
            deviceMonitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
            deviceMonitor.DeviceConnected += (sender, args) =>
            {
                addAdbLogToQueue(args.Device);
            };
            deviceMonitor.DeviceDisconnected += (sender, args) =>
            {
                removeAdbLogFromQuene(args.Device);
            };
            deviceMonitor.DeviceChanged += (sender, args) =>
            {
            };
            deviceMonitor.Start();
        }
Beispiel #3
0
        void PushDataBase()
        {
            AdbServer server = new AdbServer();

            StartServerResult result = server.StartServer(
                Environment.GetEnvironmentVariable("ANDROID_HOME") +
                @"\platform-tools\adb.exe",
                restartServerIfNewer: false);

            var device = AdbClient.Instance.GetDevices().First();

            using (SyncService service = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device))
                using (Stream stream = File.OpenRead(@"C:\Users\juanmanuel\desktop\ArgeoDB.db"))
                {
                    service.Push(
                        stream,
                        "/storage/self/primary/ArgeoDB.db",
                        444,
                        DateTime.Now,
                        null,
                        CancellationToken.None);
                }
        }
Beispiel #4
0
        void PullDataBase()
        {
            AdbServer server = new AdbServer();

            StartServerResult result = server.StartServer(
                Environment.GetEnvironmentVariable("ANDROID_HOME") +
                @"\platform-tools\adb.exe",
                restartServerIfNewer: false);

            var device = AdbClient.Instance.GetDevices().First();

            using (SyncService service = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device))
                using (Stream stream = File.OpenWrite(
                           System.IO.Path.GetTempPath() +
                           @"\ArgeoDB.db"))
                {
                    service.Pull(
                        "/storage/self/primary/ArgeoDB.db",
                        stream,
                        null,
                        CancellationToken.None);
                }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Connecting to the ADB server. Please wait..");

            AdbServer       server        = new AdbServer();
            AdbServerStatus currentStatus = server.GetStatus();

            StartServerResult startStatus = server.StartServer(ConfigurationManager.AppSettings["AdbPath"], restartServerIfNewer: false);

            switch (startStatus)
            {
            case StartServerResult.AlreadyRunning:
                Console.WriteLine("ADB daemon already running.");
                break;

            case StartServerResult.RestartedOutdatedDaemon:
                Console.WriteLine("Restarted outdated ADB daemon.");
                break;

            case StartServerResult.Started:
                Console.WriteLine("ADB daemon has been started.");
                break;
            }

            AdbClient client = new AdbClient();

            Console.WriteLine("Currently connected devices:");

            List <DeviceData> devices = client.GetDevices();

            for (int c = 0; c < devices.Count; c++)
            {
                Console.WriteLine($"\t{c}: {devices[c].Name}");
            }

            Console.Write("Device to attach: ");
            int deviceNumber = int.Parse(Console.ReadLine());

            Console.WriteLine("Running processes: ");

            List <ProcInfo> procs = GetProcs(client, devices[deviceNumber]);

            foreach (ProcInfo proc in procs)
            {
                Console.WriteLine($"\t{proc.Name}");
            }

            Console.Write("Process to monitor (name): ");
            string procName = Console.ReadLine();

            Console.Write("Keyword to search for: ");
            string keyWord = Console.ReadLine();

            if (string.IsNullOrEmpty(keyWord))
            {
                keyWord = null;
            }

            ProcInfo procToMonitor = procs.Where(n => n.Name == procName).FirstOrDefault();

            if (procToMonitor != null)
            {
                Console.WriteLine($"Watching {procToMonitor.Name} with PID {procToMonitor.Pid}...");
                DateTime lastLoggedAt = new DateTime();
                for (; ;)
                {
                    procs = GetProcs(client, devices[deviceNumber]);
                    if (procs.Any(n => n.Pid == procToMonitor.Pid && n.Name == n.Name))
                    {
                        ConsoleOutputReceiver logcatInspect = new ConsoleOutputReceiver();
                        client.ExecuteRemoteCommand("logcat -d", devices[deviceNumber], logcatInspect);
                        string[] allLogs = logcatInspect.ToString().Split("\n");
                        foreach (string log in allLogs)
                        {
                            string dateTimeString = Regex.Match(log, @"\d{2}-\d{2} \d{1,2}:\d{1,2}:\d{1,2}.\d{1,3}").Value;
                            if (!string.IsNullOrEmpty(dateTimeString))
                            {
                                DateTime loggedAt = DateTime.ParseExact(dateTimeString, "MM-dd HH:mm:ss.fff", null);
                                if (loggedAt > lastLoggedAt)
                                {
                                    if (keyWord != null && log.Contains(keyWord))
                                    {
                                        Console.WriteLine($"Keyword {keyWord} found: {log}");
                                    }
                                    lastLoggedAt = loggedAt;
                                }
                            }
                        }
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Console.WriteLine("Broke! Dumping logs!");
                        break;
                    }
                }
            }

            ConsoleOutputReceiver consoleOutput = new ConsoleOutputReceiver();

            client.ExecuteRemoteCommand("logcat -d", devices[deviceNumber], consoleOutput);

            File.WriteAllText($"logcat_dump_{procToMonitor.Name}_{procToMonitor.Pid}.txt", consoleOutput.ToString());

            return;
        }
Beispiel #6
0
        private void DoWork(object state)
        {
            try
            {
                AdbServer server = new AdbServer();
                if (!AdbServer.Instance.GetStatus().IsRunning)
                {
                    serverResult = server.StartServer(Path.Combine(_folderSettings.Value.ADB_Folder, "platform-tools"), restartServerIfNewer: false);
                }

                var ADBDevices = AdbClient.Instance.GetDevices();

                if (ADBDevices.Any())
                {
                    if (ADBDevices.Count == 1)
                    {
                        if (ADBDevices.First().Model == "Quest")
                        {
                            questDeviceInfo = new QuestDeviceInfo
                            {
                                Model   = ADBDevices.First().Model,
                                Serial  = ADBDevices.First().Serial,
                                Name    = ADBDevices.First().Name,
                                Product = ADBDevices.First().Product,
                                State   = ADBDevices.First().State.ToString()
                            };

                            QuestStatusEvent?.Invoke(this, new QuestStatusEventArgs(true, $"{ADBDevices.First().Model} is Connected"));
                        }
                        else
                        {
                            QuestStatusEvent?.Invoke(this, new QuestStatusEventArgs(false, "Quest is Disconnected"));
                        }
                    }
                    else
                    {
                        int  foreachloop = 0;
                        bool QuestFound  = false;
                        foreach (var ADBDevice in ADBDevices)
                        {
                            if (ADBDevice.Model == "Quest")
                            {
                                questDeviceInfo = new QuestDeviceInfo
                                {
                                    Model   = ADBDevice.Model,
                                    Serial  = ADBDevice.Serial,
                                    Name    = ADBDevice.Name,
                                    Product = ADBDevice.Product,
                                    State   = ADBDevice.State.ToString()
                                };

                                QuestStatusEvent?.Invoke(this, new QuestStatusEventArgs(true, $"{ADBDevice.Model} is Connected"));
                                break;
                            }

                            if (foreachloop == ADBDevices.Count())
                            {
                                QuestStatusEvent?.Invoke(this, new QuestStatusEventArgs(false, "Quest is Disconnected"));
                            }

                            foreachloop += 1;
                        }
                    }
                }
                else
                {
                    QuestStatusEvent?.Invoke(this, new QuestStatusEventArgs(false, "Quest is Disconnected"));
                }
            }
            catch (Exception e)
            {
            }
        }