示例#1
0
def fShell(szCmd, bRet=False):
	try:
		if bRet:
			return sp_co(szCmd, shell=True)[:-1]	# remove final \n
		else:
			return sp_call(szCmd, shell=True)
	except sp_CalledProcessError:
		return -1
示例#2
0
    def pbxproj_to_json(self):
        pbproj_to_json_cmd = ['plutil', '-convert', 'json', '-o', '-', self.xcode_pbxproj_path]
        try:
            json_unicode_str = sp_co(pbproj_to_json_cmd).decode(sys_get_fs_encoding())
            return json_loads(json_unicode_str)
        except CalledProcessError as cpe:
            raise XUniqueExit("""{}
Please check:
1. You have installed Xcode Command Line Tools and command 'plutil' could be found in $PATH;
2. The project file is not broken, such like merge conflicts, incomplete content due to xUnique failure. """.format(cpe.output))
示例#3
0
文件: Xatos.py 项目: truebit/Xatos
 def symbolicatecrash(self):
     '''use symbolicatecrash when dSYM file available'''
     try:
         sp_co(['which', 'xcodebuild'])
         self.__dev_dir = sp_co(['xcode-select', '-p']).decode(getfsencoding()).rstrip()
     except CalledProcessError as cpe:
         print_ng(cpe.output)
         print_ng('WARNING:: Xcode not installed, using "atos" instead of "symbolicatecrash"')
     else:
         self.__symbolicatecrash_path = self.get_symbolicatecrash_path()
         if not self.__env.get('DEVELOPER_DIR'):
             self.__env['DEVELOPER_DIR'] = self.__dev_dir
         if '.dsym' in self.dsym_or_app_path.lower():
             try:
                 output = sp_co([self.__symbolicatecrash_path, self.crashlog_path, self.dsym_or_app_path],
                                env=self.__env).decode(getfsencoding())
                 with open(self.crashlog_path, 'w',encoding=getfsencoding()) as f:
                     f.write(output)
             except CalledProcessError:
                 print_ng('WARNING:: symbolicatecrash failed, will use "atos" only')
示例#4
0
文件: Xatos.py 项目: truebit/Xatos
 def get_arm_uuid(self):
     uuid_arm_ptn = re_compile('([A-F0-9-]+) \((.+)\)')
     arm_uuid_dict = {}
     try:
         output = sp_co(['dwarfdump', '-u', self.dsym_or_app_path]).decode(getfsencoding())
     except CalledProcessError as cpe:
         raise SystemExit(cpe.output)
     for i in output.splitlines():
         match = uuid_arm_ptn.search(i)
         if match:
             uuid, arm = match.groups()
             lower_uuid = uuid.replace('-', '').lower()
             arm_uuid_dict[arm] = lower_uuid
     return arm_uuid_dict
示例#5
0
文件: Xatos.py 项目: truebit/Xatos
 def get_symbolicatecrash_path(self):
     if self.__dev_dir:
         xcode_version_list = sp_co(['xcodebuild', '-version']).decode(getfsencoding()).rstrip().split()
         xcode_verion = xcode_version_list[xcode_version_list.index('Xcode') + 1]
         if xcode_verion < '4.3':
             return '/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKit.framework/Versions/A/Resources/symbolicatecrash'
         elif xcode_verion < '5':
             return path.join(self.__dev_dir,
                              'Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKit.framework/Versions/A/Resources/symbolicatecrash')
         elif xcode_verion < '6':
             return path.join(self.__dev_dir,
                              'Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash')
         else:
             return path.join(path.dirname(self.__dev_dir),
                              'SharedFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash')
示例#6
0
文件: Xatos.py 项目: truebit/Xatos
 def desymbolicate(self):
     desym_result = {}
     with open(self.crashlog_path, encoding=getfsencoding()) as crash_fp:
         for line in crash_fp:
             line = line.decode(getfsencoding())
             if self.bin_line_head_ptn.search(line) and not self.bin_line_tail_ptn.search(line):
                 desym_result.setdefault(line)
     all_stack_addr = []
     all_symbol_addr = []
     lines = desym_result.keys()
     stack_decimal_ptn = False
     for line in lines:
         load_addr_result = self.load_addr_ptn.findall(line)
         if load_addr_result:
             stack_addr, load_addr = load_addr_result[0]
             all_stack_addr.append(stack_addr)
             assert load_addr == self.load_addr, 'ERROR:: Crashlog is invalid, load address is not the same'
         stack_addr_result = self.stack_decimal_ptn.findall(line)
         if stack_addr_result:
             """
             http://stackoverflow.com/a/13576028/562154
             symbol address = slide + stack address - load address
             The slide value is the value of vmaddr in LC_SEGMENT cmd (Mostly this is 0x1000). Run the following to get it:
             xcrun -sdk iphoneos otool -arch ARCHITECTURE -l "APP_BUNDLE/APP_EXECUTABLE"  | grep -A 10 "LC_SEGMENT" | grep -A 8 "__TEXT"|grep vmaddr
             Replace ARCHITECTURE with the actual architecture the crash report shows, e.g. armv7. Replace APP_BUNDLE/APP_EXECUTABLE with the path to the actual executable.
             The stack address is the hex value from the crash report.
             The load address is the first address showing in the Binary Images section at the very front of the line which contains your executable. (Usually the first entry).
             """
             stack_decimal_ptn = True
             stack_addr, decimal_sum = stack_addr_result[0]
             assert self.load_addr is not None, 'ERROR:: Cannot get load address'
             symbol_addr = hex(int(self.slide_addr, 16) + int(stack_addr, 16) - int(self.load_addr, 16))
             all_symbol_addr.append(symbol_addr)
     if stack_decimal_ptn:
         atos_cmd = ['xcrun', 'atos', '-o', self.dsym_or_app_path, '-arch', self.bin_arch]
         atos_cmd.extend(all_symbol_addr)
     else:
         atos_cmd = ['xcrun', 'atos', '-o', self.dsym_or_app_path, '-l', self.load_addr, '-arch', self.bin_arch]
         atos_cmd.extend(all_stack_addr)
     try:
         dsymed = [i for i in sp_co(atos_cmd).decode(getfsencoding()).splitlines() if i]
     except CalledProcessError as cpe:
         raise SystemExit('ERROR:: ' + cpe.output)
     if len(lines) != len(dsymed):
         raise SystemExit('ERROR:: Crashlog desymbolicate error!')
     for idx, line in enumerate(lines):
         desym_result[line] = '{}{}'.format(self.bin_line_head_ptn.search(line).group(), dsymed[idx])
     return desym_result
示例#7
0
文件: Xatos.py 项目: truebit/Xatos
 def get_slide_addr(self):
     otool_cmd = ['xcrun', 'otool', '-arch', self.bin_arch, '-l', self.dsym_or_app_path]
     output = sp_co(otool_cmd).decode(getfsencoding())
     lines = [i.strip() for i in output.splitlines() if i]
     cmd_segment = False
     segname_text = False
     for line in lines:
         if 'cmd LC_SEGMENT' in line:
             cmd_segment = True
         if cmd_segment and 'segname __' in line and 'segname __TEXT' not in line:
             cmd_segment = False
         if 'segname __TEXT' in line:
             segname_text = True
         if cmd_segment and segname_text:
             if 'vmaddr' in line:
                 return line.split()[1]
     raise SystemExit('ERROR:: cannot get binary image slide address')
示例#8
0
def main():
    return_message = "UNKNOWN ERROR, RETURN EMAIL NOT SET"

    email_file = open(emf, 'r')
    msgobj = email.message_from_file(email_file)
    email_file.close()
    if msgobj.is_multipart() is False:
        message = msgobj.get_payload()

    return_addy = msgobj.__getitem__("from")

    #We lower the received message to make matching easier
    nmsg = message.lower().strip()

    #FOR DEBUGGING!
    pq = open(path + os.sep + "mailmon_use.log", 'a')
    log_message = str(strftime(
        "%A %B %d, %Y - %r %Z")) + " :: " + return_addy + " :: " + nmsg
    pq.write(log_message)
    pq.write("\n")
    pq.close()

    if check_address(return_addy) is not True:
        return_message = "You are not authorized to use this service. Your previous and future messages will be logged."

    #############################
    #### COMMANDS START HERE ####
    #############################

    elif "hi" in nmsg or "hello" in nmsg or "hey" in nmsg:
        return_message = "Hello there! The current time here is: " + str(
            strftime("%A %B %d, %Y - %r %Z"))

    elif nmsg == "uptime":
        uptime = sp_co(
            '''uptime | egrep "([0-9][0-9]:?){3}.up.[0-9]{1,4}.days?" -o''',
            shell=True)
        return_message = "Current system uptime is: " + uptime.strip()

    elif nmsg == "whos-logged-in":
        try:
            last_raw = sp_co("last -w -F | grep logged", shell=True).strip()
        except:
            last_raw = ""
        last_list = re.split("\n", last_raw)
        return_message = "There are currently %s users logged in%s"
        num = 0
        for entry in last_list:
            entry = entry.strip()
            line_match = re.match("^(.*?)\s+(.*?)\s+(.*?)\s+.*$", entry)
            if line_match is not None:
                num += 1
                return_message += "\n%s from %s" % (line_match.group(1),
                                                    line_match.group(3))
        if num == 0:
            return_message = return_message % (str(num), "")
        else:
            return_message = return_message % (str(num), ":")

    #############################################
    #### ADD MORE COMMANDS BELOW USING ELIFS ####
    #############################################

    elif "help" in nmsg:
        cmdstr = "%s" % (cmdlist[3], )
        for cmd in cmdlist[4:]:
            cmdstr += ", " + cmd
        return_message = "List of commands: %s" % cmdstr

    else:
        return_message = "Unknown command, %s." % str(nmsg)

        #Try and match the failed command to a known command
        for cmd in cmdlist:
            if sMatcher(None, nmsg.lower(), cmd).ratio() > _MASTER_RATIO_:
                return_message += " Did you mean %s? " % cmd
                break

        return_message += " Reply with 'help' for a list of commands."
    send_email(return_message, return_addy)
示例#9
0
 def pbxproj_to_json(self):
     pbproj_to_json_cmd = ['plutil', '-convert', 'json', '-o', '-', self.xcode_pbxproj_path]
     json_str = sp_co(pbproj_to_json_cmd)
     return json.loads(json_str)
示例#10
0
 def pbxproj_to_json(self):
     pbproj_to_json_cmd = ['plutil', '-convert', 'json', '-o', '-', self.xcode_pbxproj_path]
     json_unicode_str = sp_co(pbproj_to_json_cmd).decode(sys_get_fs_encoding())
     return json_loads(json_unicode_str)
示例#11
0
def main():    
    return_message = "UNKNOWN ERROR, RETURN EMAIL NOT SET"
    
    #Load up the email into memory and remove the file on disk, that way we can process subsequent emails without overwriting anything.
    email_file = open(emf, 'r')
    msgobj = email.message_from_file(email_file)
    email_file.close()
    try:
        os.remove(emf)
    except:
        pass
    
    
    if msgobj.is_multipart() is False:
        message = msgobj.get_payload()
    else:
        #Multipart message, just get the text portion
        message = msgobj.get_payload()[0].get_payload()
        
    return_addy = msgobj.__getitem__("from")
    
    #We lower the received message to make matching easier
    nmsg = message.lower().strip()
    
    #FOR DEBUGGING!
    pq = open(path + os.sep + "mailmon_use.log", 'a')
    log_message = str(strftime("%A %B %d, %Y - %r %Z")) + " :: " + return_addy + " :: " + nmsg
    pq.write(log_message)
    pq.write("\n")
    pq.close()
    
    if check_address(return_addy) is not True:
        return_message = "You are not authorized to use this service. Your previous and future messages will be logged."
    
    #############################
    #### COMMANDS START HERE ####
    #############################
    
    
    elif "hi" in nmsg or "hello" in nmsg or "hey" in nmsg:
        return_message = "Hello there! The current time here is: " + str(strftime("%A %B %d, %Y - %r %Z"))
   
    elif nmsg == "uptime":
        uptime_total_seconds = float(sp_co("cat /proc/uptime | awk '{print $1}'", shell=True))
        days = int(uptime_total_seconds/(60*60*24)) #Not worrying about leap seconds or DST.
        hours = int(uptime_total_seconds%(60*60*24)/(60*60))
        minutes = int(uptime_total_seconds%(60*60*24)%(60*60)/60)
        seconds = int(uptime_total_seconds%(60*60*24)%(60*60)%60)
        timestring = ""
        if days > 0:
            timestring += "%s days " % days
        if hours > 0:
            timestring += "%s hours " % hours
        if minutes > 0:
            timestring += "%s minutes " % minutes
        if seconds > 0:
            timestring += "%s seconds" % seconds
        return_message = "Current system uptime is: " + timestring
    
    elif nmsg == "whos-logged-in":
        try:
            last_raw = sp_co("last -w -F | grep logged", shell=True).strip()
        except:
            last_raw = ""
        last_list = re.split("\n", last_raw)
        return_message = "There are currently %s users logged in%s"
        num = 0
        for entry in last_list:
            entry = entry.strip()
            line_match = re.match("^(.*?)\s+(.*?)\s+(.*?)\s+.*$", entry)
            if line_match is not None:
                num += 1
                return_message += "\n%s from %s" % (line_match.group(1), line_match.group(3))
        if num == 0:
            return_message = return_message % (str(num), "")
        else:
            return_message = return_message % (str(num), ":")
        
    #############################################
    #### ADD MORE COMMANDS BELOW USING ELIFS ####
    #############################################
   
    elif "help" in nmsg:
        cmdstr = cmdlist[0]
        for cmd in cmdlist[1:]:
            cmdstr += ", " + cmd
        return_message = "List of commands: %s" % cmdstr
    
    else:
        return_message = "Unknown command, %s." % str(nmsg)
        
        #Try and match the failed command to a known command
        for cmd in cmdlist:
            if sMatcher(None, nmsg.lower(), cmd).ratio() > _MASTER_RATIO_:
                return_message += " Did you mean %s? " % cmd
                break

        return_message += " Reply with 'help' for a list of commands."
    send_email(return_message, return_addy)