Exemple #1
0
    def get_screenshot(self):
        """
        Gets the screenshot using `adb screncap` command
        :return:
        :rtype:
        """
        print("Make sure your phone display is switched on.")
        uid = uuid.uuid4().hex  # generate a random seed
        print("Generating Screenshot: {}".format(uid))

        # capture screenshot using `adb screencap`
        print("Please wait. A full definition screenshot is being captured")

        adb_screencap_process = adb.command(
            adb.path, 'shell screencap -p /sdcard/{uid}.png'.format(
                uid=uid
            ),
            device_id=self._device_id
        )
        adb_screencap_process_ecode = adb_screencap_process.wait(500)
        if adb_screencap_process_ecode != 0:
            print("Screenshot failed. Exiting")
            print(adb_screencap_process.stdout.read().decode('utf-8'))
            return
        # sleep for two seconds so that the image is processed
        time.sleep(2)

        # pull screenshot from android using `adb pull`
        adb_pull_process = adb.command(
            adb.path, 'pull /sdcard/{uid}.png {dest}'.format(
                uid=uid,
                dest=cfgpath
            ),
            device_id=self._device_id
        )
        adb_pull_process_ecode = adb_pull_process.wait(500)

        if adb_pull_process_ecode != 0:
            print("Screenshot pull failed. Exiting")
            print(adb_pull_process.stdout.read().decode('utf-8'))
            return

        # sleep for 1 second to get capture time
        time.sleep(1)

        # remove data from user sdcard
        adb.command(
            adb.path, "shell rm /sdcard/{uid}.png".format(uid=uid),
            device_id=self._device_id
        )
        print("[LOG] Screenshot captured. "
              "Saved to {cfgpath}".format(cfgpath=cfgpath))
        return os.path.join(cfgpath, '{uid}.png'.format(uid=uid))
Exemple #2
0
 def on_press0(key):
     try:
         if key.char in key_a.keys():
             print(key.char)
             print("running cmd")
             finalpos0 = key_a[key.char]
             c = adb.command(
                 adb.path,
                 'shell input tap {} {}'.format(*finalpos0),
                 device_id=mapper_device_id
             )
             print(c.stdout.read().decode('utf-8'))
             print("COMPLETED")
     except AttributeError as e:
         print("E: {}".format(e))
Exemple #3
0
    def on_key_press(self, key):
        try:
            if key.char in self.config.keys():
                print("[KEY] Hotkey command eecuting")
                position_to_tap = self.config.get(key.char)
                c = adb.command(
                    adb.path,
                    'shell input tap {} {}'.format(*position_to_tap),
                    device_id=self.get_device_id()
                )
                print(c.stdout.read().decode('utf-8'))
                print("[KEY][COMPLETE]")

        except AttributeError as e:
            print("E: {}".format(e))
Exemple #4
0
    def connect(self):
        try:
            ip = self.listView.currentItem().text()
        except AttributeError:
            # The IP Address in the ListView has precedence over the IP address
            # in the text box
            if not self.lineEdit.text().strip().isspace() or len(
                    self.lineEdit.text().strip()) != 0:
                if ':' in self.lineEdit.text():
                    self.nm_det.setText("Please provide the port in the "
                                        "'port' text box")
                    return
                if self.lineEdit.text().count('.') == 3:
                    ip = self.lineEdit.text().strip().lower()
                else:
                    self.nm_det.setText("Invalid IP address in text box")
                    return
            else:
                if self.os.system() == 'Windows':
                    self.nm_det.setText(
                        "Please enter an IP address in the text box")
                else:
                    self.nm_det.setText(
                        "Please enter an IP address in the text box. / "
                        "Click refresh")
                return

        sp = adb.command(adb.path, 'connect {}:5555'.format(ip))
        count = 0
        while True:
            count += 1
            readout = sp.stdout.readline().decode()
            if 'failed' in readout:
                self.nm_det.setText(
                    'Device failed to get connected (is it an Android dev?')
                return
            if 'connected' in readout:
                print(readout)
                break
            if count > 30:
                self.nm_det.setText('Device connect failed: Timeout')
            else:
                time.sleep(1)
        self.nm_det.setText("Connected to IP:{}:{}".format(
            ip, self.spinBox.value()))
Exemple #5
0
 def connect(self):
     try:
         ip = self.listView.currentItem().text()
     except AttributeError:
         return
     sp = adb.command(adb.path, 'connect {}:5555'.format(ip))
     count = 0
     while True:
         count += 1
         readout = sp.stdout.readline().decode()
         if 'failed' in readout:
             self.nm_det.setText(
                 'Device failed to get connected (is it an Android dev?')
             return
         if 'connected' in readout:
             print(readout)
             break
         if count > 30:
             self.nm_det.setText('Device connect failed: Timeout')
         else:
             time.sleep(1)
     self.nm_det.setText("Connected to IP:{}:{}".format(
         ip, self.spinBox.value()))
 def tcpip_launch(self):
     adb.command(adb.path, '-d tcpip 5555')
     self.nm_det.setText(
         "Now disconnect your device, and enter the IP address, and connect"
     )
     return
Exemple #7
0
 def tcpip_launch(self):
     adb.command(adb.path, 'tcpip')
Exemple #8
0
final_pos = [0.0, 0.0]

cfgmgr = InterfaceConfig()
config = cfgmgr.get_config()
adb.path = config['adb']

jsong = 'guiscrcpy.mapper.json'

print("+++++++++++++++++++++++++++++++++++++++")
print("guiscrcpy ~ mapper by srevinsaju")
print("=======================================")
print("Make sure that your device is turned on, and connected to your PC")
print('With USB debugging turned on.')
print("+++++++++++++++++++++++++++++++++++++++")
print("Waiting for device")
adb.command(adb.path, 'wait-for-any-device')
print("Device : OK!")

cfgpath = cfgmgr.cfgpath

parser = argparse.ArgumentParser()
parser.add_argument('-t',
                    '--delay',
                    default=10,
                    help="Set time to delay before screen is captured")
parser.add_argument('-r',
                    '--reset',
                    action="store_true",
                    help="Remove prefernces")
args = parser.parse_args()
Exemple #9
0
 def __init__(self):
     self.last_found_point = None
     self.image = None
     QtWidgets.QWidget.__init__(self)
     self.label = QtWidgets.QLabel(self)
     self.drawing = False
     self.widget = QtWidgets.QWidget(self)
     self.widget.setGeometry(QtCore.QRect(0, 0, 351, 34))
     self.widget.setObjectName("widget")
     self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
     self.horizontalLayout.setSizeConstraint(
         QtWidgets.QLayout.SetMaximumSize)
     self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
     self.horizontalLayout.setObjectName("horizontalLayout")
     self.lineEdit = QtWidgets.QLineEdit(self.widget)
     size_policy = QtWidgets.QSizePolicy(
         QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
     size_policy.setHorizontalStretch(0)
     size_policy.setVerticalStretch(0)
     size_policy.setHeightForWidth(
         self.lineEdit.sizePolicy().hasHeightForWidth())
     self.lineEdit.setSizePolicy(size_policy)
     self.lineEdit.setMinimumSize(QtCore.QSize(25, 25))
     self.lineEdit.setMaximumSize(QtCore.QSize(25, 16777215))
     self.lineEdit.setMaxLength(1)
     self.lineEdit.setObjectName("lineEdit")
     self.horizontalLayout.addWidget(self.lineEdit)
     self.pushButton = QtWidgets.QPushButton(self.widget)
     self.pushButton.setMaximumSize(QtCore.QSize(50, 16777215))
     self.pushButton.setObjectName("pushButton")
     self.horizontalLayout.addWidget(self.pushButton)
     self.label0 = QtWidgets.QLabel(self.widget)
     self.label0.setMinimumSize(QtCore.QSize(25, 25))
     self.label0.setStyleSheet(
         "color: rgb(0, 0, 0);\n"
         "border-radius: 10px;\n"
         "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, "
         "y2:1, stop:0 rgba(61, 255, 0, 255), stop:1 rgba(226, 255, 0, "
         "255));\n "
     )
     self.label0.setAlignment(QtCore.Qt.AlignCenter)
     self.label0.setObjectName("label")
     self.horizontalLayout.addWidget(self.label0)
     self.pushButton.pressed.connect(self.keyreg)
     # -- pullscreen shot
     a = adb.command(adb.path, 'shell screencap -p /sdcard/scr.png',
                     device_id=mapper_device_id)
     time.sleep(2)
     b = adb.command(adb.path, 'pull /sdcard/scr.png {}'.format(cfgpath),
                     device_id=mapper_device_id)
     time.sleep(1)
     print(b.stdout.read().decode('utf-8'))
     print(a.stdout.read().decode('utf-8'))
     adb.command(adb.path, "shell rm /sdcard/scr.png",
                 device_id=mapper_device_id)
     self.label.setSizePolicy(
         QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored
     )
     self.label.resize(800, 600)
     self.setContentsMargins(0, 0, 0, 0)
     self.label.setContentsMargins(0, 0, 0, 0)
     self.pixmap = QtGui.QPixmap(cfgpath + "scr.png")
     self.label.resize(
         int(0.5 * self.pixmap.width()),
         int(0.5 * self.pixmap.height())
     )
     self.resize(
         int(0.5 * self.pixmap.width()),
         int(0.5 * self.pixmap.height())
     )
     print("Lets Check")
     self.show()
     self.resize(self.label.size())
     self.label.setPixmap(self.pixmap)
     self.label.setMinimumSize(1, 1)
     self.label.setMaximumSize(
         int(0.5 * self.pixmap.width()), int(0.5 * self.pixmap.height())
     )
     self.setMaximumSize(
         int(0.5 * self.pixmap.width()),
         int(0.5 * self.pixmap.height())
     )
     self.label.installEventFilter(self)
     layout = QtWidgets.QVBoxLayout(self)
     layout.addWidget(self.label)
     # print("NICE LOOK")
     # print("image.width == ", self.label.width())
     # print("image.height == ", self.label.height())
     # print("POSITION self.label.pos()", self.label.pos())
     # print("pix.width()", self.pixmap.width(), self.pixmap.height())
     self.pushButton.setText("OK")
     self.label0.setWordWrap(True)
     self.label0.setText(
         "Click the point, and enter char in textbox and "
         "press OK to continue."
     )