本文整理汇总了Python中hooker_common.OSCommand.OSCommand.executeCommand方法的典型用法代码示例。如果您正苦于以下问题:Python OSCommand.executeCommand方法的具体用法?Python OSCommand.executeCommand怎么用?Python OSCommand.executeCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hooker_common.OSCommand.OSCommand
的用法示例。
在下文中一共展示了OSCommand.executeCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __pushRecoveryScript
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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)
示例2: __duplicateAVD
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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
示例3: __pushBackup
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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)
示例4: __duplicateAVD
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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
示例5: __removeDirectoryHookerFromAVD
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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)
示例6: _waitForDeviceToBeReady
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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!")
示例7: startActivity
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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))
示例8: startInstaller
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
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("----------------------------------------------------------")
示例9: __checkAvdExist
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def __checkAvdExist(self):
"""Checks if AVD exist"""
res = OSCommand.executeCommand("{} -list-avds".format(self.__emulatorPath))
if self.__avdName in res:
self._logger.info("Device {} found".format(self.__avdName))
return True
self._logger.error("Device {} not found.".format(self.__avdName))
return False
示例10: __restartADBServer
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def __restartADBServer(self):
"""
Restarts ADB server. This function is not used because we have to verify we don't have multiple devices.
"""
self._logger.info("Restarting ADB server...")
cmd = [
self.mainConfiguration.adbPath,
"kill-server"
]
OSCommand.executeCommand(cmd)
self._logger.info("ADB server has been killed.")
cmd = [
self.mainConfiguration.adbPath,
"start-server"
]
OSCommand.executeCommand(cmd)
self._logger.info("ADB server has been restarted.")
示例11: installAPK
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def installAPK(self, apkFilename):
"""Installs the specified APK on the emulator"""
if self.state != AVDEmulator.STATE_STARTED:
raise Exception("Cannot install the application since the emulator is not started.")
if apkFilename is None or len(apkFilename)==0:
raise Exception("Cannot install an application that has no name.")
self._logger.info("Installing APK {0} on emulator {1}".format(apkFilename, self.name))
# $ adb install file.apk
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"install",
apkFilename
]
OSCommand.executeCommand(cmd)
示例12: createTemplates
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def createTemplates(mainConfiguration, analysisConfiguration):
"""Duplicates the initial template, one for each emulator"""
refAVDName = os.path.split(mainConfiguration.referenceAVD)[1]
refAvdConfigFile = mainConfiguration.referenceAVD+".ini"
refAVDDir = os.path.join(mainConfiguration.virtualDevicePath, refAVDName+".avd/")
for emulatorNumber in range(analysisConfiguration.maxNumberOfEmulators):
newAvdConfigFile = mainConfiguration.referenceAVD+"_"+str(emulatorNumber)+".ini"
newAVDDir = os.path.join(mainConfiguration.virtualDevicePath, refAVDName+"_"+str(emulatorNumber)+".avd/")
# delete old versions
if os.path.exists(newAvdConfigFile):
os.remove(newAvdConfigFile)
if os.path.isdir(newAVDDir):
shutil.rmtree(newAVDDir)
shutil.copyfile(refAvdConfigFile, newAvdConfigFile)
cmd = "cp -R {0} {1}".format(refAVDDir, newAVDDir)
OSCommand.executeCommand(cmd)
示例13: writeContentOnSdCard
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def writeContentOnSdCard(self, filename, fileContent):
"""Create (or replace) the filename related to the hooker path
on the sdcard of the device with the specified fileContent."""
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"mkdir",
self._hookerDir
]
OSCommand.executeCommand(cmd)
filePath = os.path.join(self._hookerDir, filename)
self._logger.debug("Writing content on '{0}'".format(filePath))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.serialNumber,
"shell",
"touch",
filePath
]
OSCommand.executeCommand(cmd)
cmd = [
self.mainConfiguration.adbPath, "-s", self.serialNumber, "shell",
"echo", "\"{}\"".format(fileContent), ">", filePath
]
OSCommand.executeCommand(cmd)
示例14: writeContentOnSdCard
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def writeContentOnSdCard(self, filename, fileContent):
"""Create (or replace) the filename related to the hooker path
on the sdcard of the emulator with the specified fileContent."""
hookerDir = "/mnt/sdcard/hooker/"
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"shell",
"mkdir",
hookerDir
]
OSCommand.executeCommand(cmd)
filePath = os.path.join(hookerDir, filename)
self._logger.debug("Writing content on '{0}'".format(filePath))
cmd = [
self.mainConfiguration.adbPath,
"-s",
self.emulatorSerialNumber,
"shell",
"touch",
filePath
]
OSCommand.executeCommand(cmd)
cmd = '{0} -s {1} shell echo "{2}" > {3}'.format(
self.mainConfiguration.adbPath, self.emulatorSerialNumber,fileContent, filePath)
OSCommand.executeCommand(cmd)
示例15: createTemplates
# 需要导入模块: from hooker_common.OSCommand import OSCommand [as 别名]
# 或者: from hooker_common.OSCommand.OSCommand import executeCommand [as 别名]
def createTemplates(mainConfiguration, nb_templates):
"""Duplicates the initial template, one for each emulator.
This is necessary only during an automatic analysis.
"""
refAVDName = os.path.split(mainConfiguration.referenceAVD)[1]
refAvdConfigFile = "{0}.ini".format(mainConfiguration.referenceAVD)
refAVDDir = os.path.join(mainConfiguration.virtualDevicePath, "{0}.avd/".format(refAVDName))
for emulatorId in xrange(nb_templates):
newAvdConfigFile = "{0}_{1}.ini".format(mainConfiguration.referenceAVD, emulatorId)
newAVDDir = os.path.join(mainConfiguration.virtualDevicePath, "{0}_{1}.avd/".format(refAVDName, emulatorId))
# delete old versions
if os.path.exists(newAvdConfigFile):
os.remove(newAvdConfigFile)
if os.path.isdir(newAVDDir):
shutil.rmtree(newAVDDir)
shutil.copyfile(refAvdConfigFile, newAvdConfigFile)
cmd = "cp -R {0} {1}".format(refAVDDir, newAVDDir)
OSCommand.executeCommand(cmd)