本文整理汇总了Python中hooker_common.OSCommand.OSCommand类的典型用法代码示例。如果您正苦于以下问题:Python OSCommand类的具体用法?Python OSCommand怎么用?Python OSCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OSCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stimulateWithMonkey
def stimulateWithMonkey(self, packageName):
"""Stimulates application with monkey"""
if self.state != AVDEmulator.STATE_STARTED:
raise Exception("Emulator is not started.")
if packageName is None or len(packageName)==0:
raise Exception("Cannot stimulate package that has no name.")
self._logger.info("Stimulating package {0} with monkey.".format(packageName))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"shell",
"monkey",
"-p",
packageName,
"-v",
"500",
"--throttle",
"6000",
"--ignore-timeouts"
]
OSCommand.executeAsyncCommand(cmd)
示例2: __pushRecoveryScript
def __pushRecoveryScript(self):
"""
Pushes recovery script to TWRP recovery directory.
This is done is 2 parts: first create the file on /sdcard/, then copy it to /cache/recovery/, using busybox.
"""
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"touch",
os.path.join(self._hookerDir, "openrecoveryscript")
]
OSCommand.executeCommand(cmd)
cmd = '{0} -s {1} shell echo "restore /sdcard/hooker/backup/" > {2}'.format(self.mainConfiguration.adbPath,
self.serialNumber,
os.path.join(self._hookerDir, "openrecoveryscript"))
OSCommand.executeCommand(cmd)
cmd = '{0} -s {1} shell su -c \'busybox cp {2} /cache/recovery/openrecoveryscript\''.format(self.mainConfiguration.adbPath,
self.serialNumber,
os.path.join(self._hookerDir, "openrecoveryscript") )
ret = OSCommand.executeCommand(cmd)
if len(ret)!=0:
raise Exception(ret)
示例3: __duplicateAVD
def __duplicateAVD(self):
"""Creates a new emulator based on a reference one."""
self._logger.debug("Duplicate AVD '{0}'.".format(self.mainConfiguration.referenceAVD))
# clean/delete if new emulator already exists
self.__deleteEmulatorFS()
refAVDName = os.path.split(self.mainConfiguration.referenceAVD)[1]
avdConfigFile = "{0}_{1}.ini".format(self.mainConfiguration.referenceAVD, self.emulatorId)
newConfigFile = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.ini".format(self.name))
referenceAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}_{1}.avd/".format(refAVDName, self.emulatorId))
newAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.avd/".format(self.name))
hwQemuConfigFile = os.path.join(newAVDDir, "hardware-qemu.ini")
defaultSnapshotConfigFile = os.path.join(newAVDDir, "snapshots.img.default-boot.ini")
# First we copy the template
self._logger.debug("Copy AVD reference config file '{0}' in '{1}'...".format(avdConfigFile, newConfigFile))
shutil.copyfile(avdConfigFile, newConfigFile)
# Copy the internal files of the reference avd
self._logger.debug("Duplicate the AVD internal content from '{0}' in '{1}'...".format(referenceAVDDir, newAVDDir))
# we use the internal linux 'cp' command for performance issues (shutil is too long)
# shutil.copytree(referenceAVDDir, newAVDDir)
cmd = "cp -R {0} {1}".format(referenceAVDDir, newAVDDir)
OSCommand.executeCommand(cmd)
# Than adapt the content of the copied files
self.__replaceContentInFile(newConfigFile, refAVDName, self.name)
self.__replaceContentInFile(hwQemuConfigFile, refAVDName, self.name)
self.__replaceContentInFile(defaultSnapshotConfigFile, refAVDName, self.name)
self.state = AndroidDevice.STATE_PREPARED
示例4: startActivity
def startActivity(self, activity):
"""Starts the specified activity on the emulator"""
if self.state != AVDEmulator.STATE_STARTED:
raise Exception("Cannot start an activity since the emulator is not started.")
if activity is None or len(activity)==0:
raise Exception("Cannot start an activity that has no name.")
if not self.__checkADBRecognizeEmu():
# self.__restartADBServer() # We cannot do that if we have multiple emulators...
raise Exception("ADB didn't find {0}".format(self.name))
self._logger.info("Starting activity {0} on emulator {1}".format(activity, self.name))
activityPackage = '.'.join(activity.split('.')[:-1])
activityName = ''.join(activity.split('.')[-1:])
# $ adb shell am start -n activityPackage/activity
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"shell",
"am",
"start",
"-n",
"{0}/.{1}".format(activityPackage, activityName)
]
OSCommand.executeAsyncCommand(cmd)
示例5: startActivityFromPackage
def startActivityFromPackage(self, packageName, activityName):
"""
Starts the specified activity from the specified package name on the emulator.
This method has to be called when package name is different from main activity.
"""
if self.state != AVDEmulator.STATE_STARTED:
raise Exception("Cannot start an activity since the emulator is not started.")
if activityName is None or len(activityName)==0:
raise Exception("Activity name is null.")
if packageName is None or len(packageName)==0:
raise Exception("Package name is null.")
if not self.__checkADBRecognizeEmu():
# self.__restartADBServer() # We cannot do that if we have multiple emulators...
raise Exception("ADB didn't find {0}".format(self.name))
self._logger.info("Starting activity {0}/{1} on emulator {2}".format(packageName, activityName, self.name))
# $ adb shell am start -n activityPackage/activity
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"shell",
"am",
"start",
"-n",
"{0}/{1}".format(packageName, activityName)
]
OSCommand.executeAsyncCommand(cmd)
示例6: __pushBackup
def __pushBackup(self):
""" Pushes backup folder to sdcard """
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"push",
os.path.join(self.__backupDir, "partitions"),
os.path.join(self._hookerDir, "backup")
]
OSCommand.executeCommand(cmd)
示例7: __duplicateAVD
def __duplicateAVD(self):
"""Creates a new emulator based on a reference one."""
self._logger.debug("Duplicate AVD '{0}'.".format(self.mainConfiguration.referenceAVD))
refAVDName = os.path.split(self.mainConfiguration.referenceAVD)[1]
if self.analysisType == "manual":
avdConfigFile = "{0}.ini".format(self.mainConfiguration.referenceAVD)
referenceAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.avd/".format(refAVDName))
else:
#avdConfigFile = "{0}_{1}.ini".format(self.mainConfiguration.referenceAVD, self.emulatorId)
#referenceAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}_{1}.avd/".format(refAVDName, self.emulatorId))
avdConfigFile = "{0}.ini".format(self.mainConfiguration.referenceAVD)
referenceAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.avd/".format(refAVDName))
if not os.path.exists(avdConfigFile):
raise Exception("AVD configuration file does not exist: {}".format(avdConfigFile))
if not os.path.isdir(referenceAVDDir):
raise Exception("AVD directory does not exist: {}".format(referenceAVDDir))
newConfigFile = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.ini".format(self.name))
newAVDDir = os.path.join(self.mainConfiguration.virtualDevicePath, "{0}.avd/".format(self.name))
# If dir exists, remove it
if os.path.exists(newAVDDir):
self._logger.debug("Old AVD detected, removing: {}".format(newAVDDir))
shutil.rmtree(newAVDDir)
if os.path.exists(newConfigFile):
self._logger.debug("Old AVD configuration detected, removing: {}".format(newConfigFile))
os.remove(newConfigFile)
hwQemuConfigFile = os.path.join(newAVDDir, "hardware-qemu.ini")
defaultSnapshotConfigFile = os.path.join(newAVDDir, "snapshots.img.default-boot.ini")
# First we copy the template
self._logger.debug("Copying AVD reference config file '{0}' in '{1}'...".format(avdConfigFile, newConfigFile))
shutil.copyfile(avdConfigFile, newConfigFile)
# Copy the internal files of the reference avd
self._logger.debug("Duplicating the AVD internal content from '{0}' in '{1}'...".format(referenceAVDDir, newAVDDir))
# we use the internal linux 'cp' command for performance issues (shutil is too long)
# shutil.copytree(referenceAVDDir, newAVDDir)
cmd = "cp -R {0} {1}".format(referenceAVDDir, newAVDDir)
OSCommand.executeCommand(cmd)
# Than adapt the content of the copied files
self.__replaceContentInFile(newConfigFile, refAVDName, self.name)
self.__replaceContentInFile(hwQemuConfigFile, refAVDName, self.name)
self.__replaceContentInFile(defaultSnapshotConfigFile, refAVDName, self.name)
self.state = AndroidDevice.STATE_PREPARED
示例8: __pullResults
def __pullResults(self):
"""Pull results of analysis"""
self._logger.info("Pulling results of analysis")
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"pull",
"/sdcard/hooker/events.logs",
"{0}{1}-events.logs".format(self.mainConfiguration.androidTemporaryPath,
datetime.datetime.now().strftime("%Y-%m-%d-%H:%M"))
]
OSCommand.executeAsyncCommand(cmd)
self._logger.info("Event logs has been pulled in {0}".format(self.mainConfiguration.androidTemporaryPath))
示例9: __removeDirectoryHookerFromAVD
def __removeDirectoryHookerFromAVD(self):
"""Removes directory on the emulator where hooker has copied files.
"""
self._logger.debug("Deleting {0} directory on emulator {1}".format(self._hookerDir, self.serialNumber))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"rm",
"-rf",
self._hookerDir
]
OSCommand.executeCommand(cmd)
示例10: _waitForDeviceToBeReady
def _waitForDeviceToBeReady(self):
"""Analyzes the device state and returns when it's ready."""
self._logger.debug("Waiting for device to be ready.")
cmd = [
self.__adbPath, "-s", "emulator-5554", "wait-for-device"
]
OSCommand.executeCommand(cmd)
self._logger.debug("Waiting for the device to be ready")
self._logger.debug(" - (dev.bootcomplete)")
ready = False
while not ready:
cmd = [
self.__adbPath, "-s", "emulator-5554", "shell", "getprop", "dev.bootcomplete"
]
result = OSCommand.executeCommand(cmd)
if result is not None and result.strip() == "1":
ready = True
else:
time.sleep(2)
self._logger.debug("- (sys_bootcomplete)")
ready = False
while not ready:
cmd = [
self.__adbPath, "-s", "emulator-5554", "shell", "getprop", "sys.boot_completed"
]
result = OSCommand.executeCommand(cmd)
if result is not None and result.strip() == "1":
ready = True
else:
time.sleep(1)
self._logger.debug(" - (init.svc.bootanim)")
ready = False
while not ready:
cmd = [
self.__adbPath, "-s", "emulator-5554", "shell", "getprop", "init.svc.bootanim"
]
result = OSCommand.executeCommand(cmd)
if result is not None and result.strip() == "stopped":
ready = True
else:
time.sleep(1)
time.sleep(5)
self._logger.info("Device seems to be ready!")
示例11: reboot
def reboot(self):
"""Reboot the device"""
self._logger.info("Rebooting device listening on port {0}".format(self.serialNumber))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"reboot"
]
OSCommand.executeAsyncCommand(cmd)
# Real device can take time to reboot
time.sleep(15)
# waits for device to be ready
self._waitForDeviceToBeReady()
self.state = AndroidDevice.STATE_STARTING
示例12: startInstaller
def startInstaller(self):
self._logger.info("Starting installer.")
if self.__checkAvdExist():
self._logger.info("Starting AVD... This can take some time, be patient and check your process if in doubt.")
self.__emulatorProcess = self.__startAvd()
time.sleep(2)
if self.__emulatorProcess.poll() is not None:
raise Exception(self.__emulatorProcess.communicate())
time.sleep(5)
self._waitForDeviceToBeReady()
self._logger.info("Ready to begin install")
localTime = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
cmd = [
self.__adbPath, "-s", "emulator-5554", "shell", "date", "-s", localTime
]
self._logger.debug(OSCommand.executeCommand(cmd))
# Install applications on device
self.__installApk()
# Print instructions to guide user to click on "Link Substrate Files" and "Restart System Soft"
self._logger.info("----------------------------------------------------------")
self._logger.info("You can now:")
self._logger.info("* Open SuperSU app, click on \"Continue\" to update SU binary, choose the \"Normal\" installation mode, wait a bit. Click on \"OK\" (NOT \"Reboot\"!) and exit the application.")
self._logger.info("* Open Substrate app, click \"Link Substrate Files\", allow Substrate, and reclick again on \"Link Substrate Files\".")
self._logger.info("* Install APK-instrumenter APK: {} install ../../APK-instrumenter/bin/ApkInstrumenterActivity-debug.apk".format(self.__adbPath))
self._logger.info("* Click on \"Restart System (Soft)\"".format(self.__adbPath))
self._logger.info("* Wait for the system to restart and disable the lockscreen security: `Menu > System Settings > Security > Screen lock > None`")
self._logger.info("* Close the emulator")
self._logger.info("----------------------------------------------------------")
示例13: startActivity
def startActivity(self, activity):
"""Starts the specified activity on the device"""
if self.state != AndroidDevice.STATE_STARTED:
raise Exception("Cannot start an activity since the device is not started.")
if activity is None or len(activity)==0:
raise Exception("Cannot start an activity that has no name.")
self._logger.info("Starting activity {0} on device {1}".format(activity, self.name))
activityPackage = '.'.join(activity.split('.')[:-1])
activityName = ''.join(activity.split('.')[-1:])
# $ adb shell am start -n activityPackage/activity
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"am",
"start",
"-n",
"{0}/.{1}".format(activityPackage, activityName)
]
res = OSCommand.executeCommand(cmd)
self._logger.debug("{}".format(res))
示例14: stimulateWithMonkey
def stimulateWithMonkey(self, packageName):
"""Stimulates application with monkey"""
if self.state != AndroidDevice.STATE_STARTED:
raise Exception("Device is not started.")
if packageName is None or len(packageName)==0:
raise Exception("Cannot stimulate package that has no name.")
self._logger.info("Stimulating package {0} with monkey.".format(packageName))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"monkey",
"-p",
packageName,
"-v",
"500",
"--throttle",
"6000",
"--ignore-timeouts"
]
p = OSCommand.executeAsyncCommand(cmd)
stdout, stderr = p.communicate()
self._logger.debug("{0}".format(stdout))
示例15: start
def start(self):
"""Starts the emulator"""
if self.state != AndroidDevice.STATE_PREPARED:
raise Exception("Cannot start the emulator. (expected state was {0}, current state is {1})".format(AndroidDevice.STATE_PREPARED, self.state))
# clean the temporary directory
self.__cleanTemporaryDirectory()
cmd = [
self.mainConfiguration.emulatorPath,
"@{0}".format(self.name),
"-no-snapshot-save",
"-netspeed",
"full",
"-netdelay",
"none",
"-port",
str(self.adbPort)
]
self.__emulatorProcess = OSCommand.executeAsyncCommand(cmd)
self.state = AndroidDevice.STATE_STARTING
# Waits for device to be ready
self._waitForDeviceToBeReady()
# Checks that APKInstrumenter is install
self.checkAPKInstrumenter()