/// <summary> /// Check that the client is opened with the proper debugger port for the /// specified application name, and if not, reopen it. </summary> /// <param name="client"> </param> /// <param name="uiThread"> </param> /// <param name="appName"> /// @return </param> protected internal static Client checkDebuggerPortForAppName(Client client, string appName) { DebugPortManager.IDebugPortProvider provider = DebugPortManager.provider; if (provider != null) { Device device = client.deviceImpl; int newPort = provider.getPort(device, appName); if (newPort != DebugPortManager.DebugPortProvider.NO_STATIC_PORT && newPort != client.debuggerListenPort) { AndroidDebugBridge bridge = AndroidDebugBridge.bridge; if (bridge != null) { DeviceMonitor deviceMonitor = bridge.deviceMonitor; if (deviceMonitor != null) { deviceMonitor.addClientToDropAndReopen(client, newPort); client = null; } } } } return(client); }
private static Device GetDevice() { if (adb == null || !adb.IsConnected) { Log("ADB", "Initializing ADB.......", LOG_STYLE_NORMAL); adb = AndroidDebugBridge.CreateBridge(Directory.GetCurrentDirectory() + "\\ADB\\adb.exe", true); adb.Start(); } IList <Device> devices = adb.Devices; if (devices.Count < 1) { throw new Exception("Connect your device and retry!"); } FChooseDevice form = new FChooseDevice(); if (form.ShowDialog(devices) == DialogResult.OK) { return(FChooseDevice.Device); } else { throw new Exception("Choose device and retry!"); } }
private static AppBundleRunner CreateAppBundleRunner() { var androidSdk = new AndroidSdk(); var javaUtils = new JavaUtils(); var adb = new AndroidDebugBridge(androidSdk); var bundletool = new BundletoolHelper(javaUtils); return(new AppBundleRunner(adb, bundletool)); }
public override void Dispose() { if (!mDisposed) { ADB.Stop(); AndroidDebugBridge.Terminate(); mDisposed = true; } }
public Device[] GetADBDevices() { AndroidDebugBridge.Initialize(true); List <Device> Devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress); Device[] DevicesArray = Devices.ToArray(); return(DevicesArray); }
public void InitADB() { string adbLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DeviceMonitorHelper.ADB); AndroidDebugBridge.CreateBridge(adbLocation, false); AndroidDebugBridge.Instance.DeviceMonitor.UpdateDeviceListEvent += DeviceMonitor_UpdateDeviceListEvent; StopMonitorDevice = () => { AndroidDebugBridge.Instance.Stop(); }; }
static void Main(string[] arguments) { var args = new Arguments(arguments); AndroidDebugBridge bridge = AndroidDebugBridge.CreateBridge(Path.Combine(Environment.GetEnvironmentVariable("ANDROID_SDK"), "platform-tools\\adb.exe"), true); foreach (var item in Enum.GetNames(typeof(Actions))) { var actionName = item.Replace('_', '-').ToLower().Trim(); if (args.ContainsKey(actionName)) { Actions action = (Actions)Enum.Parse(typeof(Actions), item, true); switch (action) { case Actions.Devices: GetDevices( ); break; case Actions.Monitor: bridge.DeviceChanged += delegate(object sender, DeviceEventArgs e) { System.Console.WriteLine("Changed: {0}\t{1}", e.Device.SerialNumber, e.Device.State); }; bridge.DeviceConnected += delegate(object sender, DeviceEventArgs e) { System.Console.WriteLine("{0}\t{1}", e.Device.SerialNumber, e.Device.State); }; bridge.DeviceDisconnected += delegate(object sender, DeviceEventArgs e) { System.Console.WriteLine("{0}\t{1}", e.Device.SerialNumber, e.Device.State); }; System.Console.ReadLine( ); break; case Actions.Start_Server: StartServer( ); break; case Actions.Kill_Server: break; default: break; } try { AndroidDebugBridge.DisconnectBridge( ); bridge.Stop( ); } catch (IOException e) { System.Console.WriteLine(e.ToString( )); // ignore } return; } } PrintUsage( ); }
public static void Kill() { try { adb.Stop(); AdbHelper.Instance.KillAdb(AndroidDebugBridge.SocketAddress); } catch { adb = null; } }
public List <Device> GetDevices(string pathToAdb) { var madb = AndroidDebugBridge.CreateBridge(pathToAdb, true); madb.Start(); var devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress).ToList(); //madb.Stop(); return(devices); }
public bool Init(string adbLocation) { mADB = AndroidDebugBridge.CreateBridge(adbLocation, true); if (mADB.Start()) { RefreshDevices(); mADB.DeviceConnected += MBridge_DeviceConnected; mADB.DeviceDisconnected += MBridge_DeviceDisconnected; return(true); } return(false); }
// Stop the monitor running. This is idempotent public void Stop() { this.started = false; this.StopCommandQueueListener(); this.ReleaseDeviceNotificationHandles(); this.eventRaiser.DeviceArrived -= OnDeviceArrived; this.eventRaiser.DeviceRemoveComplete -= OnDeviceRemoveComplete; this.bridge?.StopTracking(); this.bridge = null; }
// Start the monitor running public void Start() { try { Log.ThresholdLevel = LogLevel.Debug; this.bridge = AndroidDebugBridge.Create(); this.bridge.DeviceConnected += (sender, e) => { this.IgnoreADBExceptionsDuring(() => EnsureUSBConnectedDevicesAreOnTCPIP("ADB device connected")); }; this.bridge.ServerStartedOrReconnected += (sender, e) => { this.IgnoreADBExceptionsDuring(() => { lock (this.deviceConnectionLock) { // Ensure any USB-connected devices are on TCPIP bool?anyDevices = EnsureUSBConnectedDevicesAreOnTCPIP("ADB server started"); // If the server isn't in fact connected to ANYONE (maybe the server stopped // while no USB device was connected; closing Android Studio stops the server) // then try to connect it to the last TCPIP device we used if (anyDevices.HasValue && !anyDevices.Value) { ReconnectToLastTCPIPDevice(); } } }); }; this.eventRaiser.DeviceArrived += OnDeviceArrived; this.eventRaiser.DeviceRemoveComplete += OnDeviceRemoveComplete; foreach (Guid guid in this.deviceInterfacesOfInterest) { GetUSBDeviceNotificationsFor(guid); } this.IgnoreADBExceptionsDuring(() => EnsureUSBConnectedDevicesAreOnTCPIP("BotBug start")); this.StartCommandQueueListener(); this.started = true; } catch (Exception) { Stop(); throw; } }
public ZaloCommunityService(Settings settings) { _settings = settings; try { _adb = AndroidDebugBridge.CreateBridge(Path.Combine(AndroidDebugBridgeOsLocation, "adb.exe"), true); _adb.Start(); } catch (Exception ex) { _log.Error(ex); } }
static void Main(string[] args) { AndroidDebugBridge mADB = AndroidDebugBridge.CreateBridge( "C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe", false); mADB.Start(); List <Device> devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress); IDevice device = devices[0]; System.Drawing.Bitmap image = (System.Drawing.Bitmap)device.Screenshot.ToImage(); image.Save("f:\\1.png", System.Drawing.Imaging.ImageFormat.Bmp); mADB.Stop(); }
public MainWindow() { InitializeComponent(); _mADB = AndroidDebugBridge.CreateBridge( "C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe", false); _mADB.Start(); List <Device> devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress); _device = devices[0]; _timer = new Timer(new TimerCallback(OnTimer)); _timer.Change(2000, 500); }
public ZaloAdbRequest(Settings settings) { ConsoleOutputReceiver = new ConsoleOutputReceiver(); AdbPath = settings.AndroidDebugBridgeOsWorkingLocation; try { Adb = AndroidDebugBridge.CreateBridge(Path.Combine(settings.AndroidDebugBridgeOsWorkingLocation, "adb.exe"), true); Adb.Start(); } catch (Exception ex) { _log.Error(ex); } }
public void CreateBridgeTest( ) { try { AndroidDebugBridge adb = CreateBridge(@"d:\android\android-sdk\platform-tools\adb.exe"); bool result = adb.Start( ); Assert.IsTrue(result, "Failed to start ADB"); adb.Devices.ForEach(d => { Console.WriteLine("{0}\t{1}", d.SerialNumber, d.State); }); adb.Stop( ); } catch (Exception ex) { Console.WriteLine(ex.ToString( )); throw; } }
public ToolsViewModel(Config config, ProgressViewModel progressView, OperationLocker locker, Window mainWindow, SpecialFolders specialFolders, Logger logger, PatchingManager patchingManager, AndroidDebugBridge debugBridge, QuestPatcherUIService uiService, InfoDumper dumper) { Config = config; ProgressView = progressView; Locker = locker; _mainWindow = mainWindow; _specialFolders = specialFolders; _logger = logger; _patchingManager = patchingManager; _debugBridge = debugBridge; _uiService = uiService; _dumper = dumper; _debugBridge.StoppedLogging += (_, _) => { _logger.Information("ADB log exited"); _isAdbLogging = false; this.RaisePropertyChanged(nameof(AdbButtonText)); }; }
static void Main(string[] arguments) { AndroidDebugBridge bridge = new AndroidDebugBridge(); try { bridge.DeviceConnected += (sender, e) => System.Console.WriteLine($"Device connected: {e.Device.SerialNumber}\t{e.Device.State}"); bridge.DeviceDisconnected += (sender, e) => System.Console.WriteLine($"Device disconnected: {e.Device.SerialNumber}\t{e.Device.State}"); bridge.ServerStartedOrReconnected += (sender, b) => System.Console.WriteLine($"ADB server started or reconnected"); bridge.ServerKilled += (sender, b) => System.Console.WriteLine($"ADB server killed"); bridge.StartTracking(); Device device = AdbHelper.Instance.GetDevices(AndroidDebugBridge.AdbServerSocketAddress)[0]; var props = device.Properties; // AdbHelper.Instance.Connect(AndroidDebugBridge.AdbServerSocketAddress, "192.168.0.22", 5555); } finally { bridge.StopTracking(); } }
/// <summary> ///启动adb进程 /// </summary> public static bool StartAdbProcess() { bool result = true; try { if (Util.IsProcessOpen("adb")) { result = true; } else { Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.FileName = adbFilePath; p.StartInfo.Arguments = "devices"; p.Start(); try { AndroidDebugBridge.Initialize(true); AndroidDebugBridge.CreateBridge(); AndroidDebugBridge.Instance.Start(); } catch (Exception) { CleanUpAdbProcess(); result = false; } } } catch (Exception e) { result = false; } return(result); }
public static void GetDevicesTest() { AndroidDebugBridge.Initialize(true); List <Device> devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress); foreach (var item in devices) { //Monitor. FileMonitor monitor = new FileMonitor(); //List of remote files to be downloaded. List <FileEntry> files = new List <FileEntry>(); //First remote file. FileEntry file = FileEntry.Find(item, "/data/data/com.netmarble.lin2ws/shared_prefs/NetmarbleNeo_LineageS.xml"); //Add remote file to list of remote files. files.Add(file); //Local filename string split character. string axe = ":"; //Local filename. string[] f = Regex.Split(item.SerialNumber, axe); //Local path + filename. string localFilename = "C:\\test\\" + f[f.Length - 1] + ".xml"; ShellOutputReceiver receiver = new ShellOutputReceiver(); if (!item.CanSU()) { MainWindow.main.UpdateLog = "Root Android."; } try { item.ExecuteShellCommand("input mouse tap 640 340", receiver); } catch (Exception e) { MainWindow.main.UpdateLog = e.ToString(); } //Pull file from remote emulator to local folder. item.SyncService.Pull(files, "C:\\test\\", monitor); //Rename file to adb port number. File.Delete(localFilename); File.Move("C:\\test\\NetmarbleNeo_LineageS.xml", localFilename); //sample code: //<string name="LOCAL_PUSH_TARGET">CharacterName</string> string text = Xml.FindInnerTextByTagAttribute(localFilename, "string", "name", "LOCAL_PUSH_TARGET"); MainWindow.main.UpdateLog = text; ////testing shell commands //ShellOutPRec receiver = new ShellOutPRec( ); //item.ExecuteShellCommand("ps", receiver); ////testing pull command //FileMonitor monitor = new FileMonitor(); //List<FileEntry> files = new List<FileEntry>(); //FileEntry file = FileEntry.Find(item, "/data/data/com.netmarble.lin2ws/shared_prefs/"); //files.Add(file); //item.SyncService.Pull(files, "shared_prefs", monitor); ////testing screencap //PixelFormat format = PixelFormat.Format32bppArgb; //Image image = item.Screenshot.ToImage(format); //MainWindow.main.UpdateLog = item.SerialNumber + ", " + item.State + item.IsEmulator + " - Emulator" + receiver; } }
public FileCopyConverter(AndroidDebugBridge debugBridge) { _debugBridge = debugBridge; }
private AndroidDebugBridge CreateBridge(String location) { AndroidDebugBridge adb = AndroidDebugBridge.CreateBridge(location, false); return(adb); }
/// <summary> /// Creates a new <seealso cref="DeviceMonitor"/> object and links it to the running /// <seealso cref="AndroidDebugBridge"/> object. </summary> /// <param name="server"> the running <seealso cref="AndroidDebugBridge"/>. </param> internal DeviceMonitor(AndroidDebugBridge server) { mServer = server; mDebuggerPorts.Add(DdmPreferences.debugPortBase); }
public DeviceConnector(string pathToExecutable) { androidDebugBridge = AndroidDebugBridge.CreateBridge(pathToExecutable, true); androidDebugBridge.Start(); }
public DeviceMonitorManager() { AndroidDebugBridge.AdbOsLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AndroidDebugBridge.ADB); _bridge = AndroidDebugBridge.Instance; }
public static String ExtractPassword(String phoneNumber) { byte[] usernameKey = Encoding.UTF8.GetBytes(phoneNumber); byte[] key = Hex.Decode(Encoding.UTF8.GetBytes("c2991ec29b1d0cc2b8c3b7556458c298c29203c28b45c2973e78c386c395")); MemoryStream PbkdfFileData = new MemoryStream(); PbkdfFileData.Write(key, 0, key.Length); PbkdfFileData.Write(usernameKey, 0, usernameKey.Length); PbkdfFileData.Flush(); PbkdfFileData.Close(); AndroidDebugBridge _AndroidDebugDevice = null; try { _AndroidDebugDevice = AndroidDebugBridge.CreateBridge("Tools\\adb.exe", false); _AndroidDebugDevice.Start(); //Get First Device Device _Device = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress).First(); if (_Device != null) { //Is Root Device if (_Device.CanSU()) { Object[] args = new Object[2]; args[0] = "/data/data/com.whatsapp/files/pw"; args[1] = "/sdcard"; _Device.ExecuteRootShellCommand("cp /data/data/com.whatsapp/files/pw /sdcard", new ConsoleOutputReceiver(), args); using (SyncService service = new SyncService(_Device)) { SyncResult syncResult = service.PullFile("/sdcard/pw", PasswordFile, new NullSyncProgressMonitor()); if (syncResult.Code == 0) { byte[] pw = File.ReadAllBytes(PasswordFile); byte[] pw_key = new byte[20]; Buffer.BlockCopy(pw, 49, pw_key, 0, 20); //File.WriteAllBytes("pw_key", pw_key); byte[] pw_salt = new byte[4]; Buffer.BlockCopy(pw, 29, pw_salt, 0, 4); //File.WriteAllBytes("pw_salt", pw_salt); byte[] pw_iv = new byte[16]; Buffer.BlockCopy(pw, 33, pw_iv, 0, 16); //File.WriteAllBytes("pw_iv", pw_iv); byte[] pbkdf2_pass_bin = PbkdfFileData.ToArray(); Pkcs5S2ParametersGenerator bcKeyDer = new Pkcs5S2ParametersGenerator(); bcKeyDer.Init(pbkdf2_pass_bin, pw_salt, 16); KeyParameter keyParameter = (KeyParameter)bcKeyDer.GenerateDerivedParameters("AES128", 128); byte[] pbkdf2_key_bin = keyParameter.GetKey(); Cipher cipher = Cipher.AES_128_OFB; CipherContext cipherContext = new CipherContext(cipher); byte[] passwordData = cipherContext.Decrypt(pw_key, pbkdf2_key_bin, pw_iv); String password = Convert.ToBase64String(passwordData); return(password); } } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } finally { if (_AndroidDebugDevice != null) { _AndroidDebugDevice.Stop(); } CleanUp(); } return(null); }
//HotKey Overload private void BtnProcessGrab_Click(object sender, HotkeyEventArgs e) { //Do NOT forget to also change overload method below if (btnProcessGrab.IsEnabled) { listProcessList.Items.Clear(); listProcessList.SelectionMode = SelectionMode.Multiple; Process[] EmulatorProcess; if (CbItemNox.IsSelected) { EmulatorProcess = Bot.GetOpenProcess("Nox"); if (EmulatorProcess == null)//value check { UpdateLog = "null process value ProcessGrabber_Click"; return; } if (EmulatorProcess != null)//enbale buttons for quest if we bind to the Nox player process { EnableButtons(); listProcessList.IsEnabled = true; listProcessList.Background = System.Windows.Media.Brushes.LightGreen; } foreach (Process pro in EmulatorProcess) { if (pro == null) { UpdateLog = "Null Process"; return; } ListBoxItem itm = new ListBoxItem() { Content = pro.MainWindowTitle.ToString() }; listProcessList.Items.Add(itm); EmulatorCount++; } Emulators = EmulatorProcess; } if (CbItemBS.IsSelected) { EmulatorProcess = Bot.GetOpenProcess("Bluestacks"); if (EmulatorProcess == null)//value check { UpdateLog = "Null process value ProcessGrabber_Click"; return; } if (EmulatorProcess != null)//enbale buttons for quest if we bind to the Nox player process { EnableButtons(); listProcessList.IsEnabled = true; listProcessList.Background = System.Windows.Media.Brushes.LightGreen; } foreach (Process pro in EmulatorProcess) { if (pro == null) { UpdateLog = "Null Process"; return; } if (pro.MainWindowTitle != "") { ListBoxItem itm = new ListBoxItem() { Content = pro.MainWindowTitle.ToString() }; listProcessList.Items.Add(itm); EmulatorCount++; } } Emulators = EmulatorProcess; } if (CbItemMEmu.IsSelected) { EmulatorProcess = Bot.GetOpenProcess("MEmu"); if (EmulatorProcess == null)//value check { UpdateLog = "Null process value ProcessGrabber_Click"; return; } if (EmulatorProcess != null)//enbale buttons for quest if we bind to the Nox player process { EnableButtons(); listProcessList.IsEnabled = true; listProcessList.Background = System.Windows.Media.Brushes.LightGreen; } foreach (Process pro in EmulatorProcess) { if (pro == null) { UpdateLog = "Null Process"; return; } if (pro.MainWindowTitle != "") { ListBoxItem itm = new ListBoxItem() { Content = pro.MainWindowTitle.ToString() }; listProcessList.Items.Add(itm); EmulatorCount++; } } Emulators = EmulatorProcess; } if (CbItemADB.IsSelected) { AndroidDebugBridge.Initialize(true); //ADB devices. List <Device> Devices = AdbHelper.Instance.GetDevices(AndroidDebugBridge.SocketAddress); L2RDevices = new L2RDevice[Devices.Count]; //Initializes the L2RDevice array. for (int i = 0; i < Devices.Count; i++) { L2RDevices[i] = new L2RDevice(Devices[i]); EmulatorCount++; } //Enbale buttons for quest if we find ADB devices. if (Devices != null) { EnableButtons(); listProcessList.IsEnabled = true; listProcessList.Background = System.Windows.Media.Brushes.LightGreen; } foreach (L2RDevice Device in L2RDevices) { if (Device.CharacterName == null) { UpdateLog = "Unable to find Character name"; } ListBoxItem itm = new ListBoxItem() { Content = Device.CharacterName }; listProcessList.Items.Add(itm); } } if (listProcessList.HasItems) { btnProcessGrab.IsEnabled = false; } UpdateLog = "Select any process that you would like the bot to ignore."; } }