Exemplo n.º 1
0
def WalkDesktop():
    def GetFirstChild(control):
        return control.GetFirstChildControl()

    def GetNextSibling(control):
        return control.GetNextSiblingControl()

    desktop = automation.GetRootControl()
    for control, depth in automation.WalkTree(desktop, getFirstChildFunc=GetFirstChild, getNextSiblingFunc=GetNextSibling, includeTop=True, maxDepth= 1):
        print(' ' * depth * 4 + str(control))
def ExpandTreeItem(treeItem):
    for item, depth, remainCount in automation.WalkTree(
            treeItem,
            getChildrenFunc=GetTreeItemChildren,
            includeTop=True,
            maxDepth=MaxExpandDepth):
        if isinstance(
                item, automation.TreeItemControl
        ):  #or item.ControlType == automation.ControlType.TreeItemControl
            if PrintTree:
                automation.Logger.WriteLine(' ' * (depth * 4) + item.Name)
            if depth < MaxExpandDepth:  # and automation.ExpandCollapseState.Collapsed == item.CurrentExpandCollapseState():
                item.Expand(0)
            item.ScrollIntoView()
def GetPersonDetail():
    detailWindow = automation.WindowControl(searchDepth=1,
                                            ClassName='TXGuiFoundation',
                                            SubName='的资料')
    detailPane = detailWindow.PaneControl(Name='资料')
    details = ''
    for control, depth, remainCount in automation.WalkTree(
            detailPane, lambda c: c.GetChildren()):
        if control.ControlType == automation.ControlType.TextControl:
            details += control.Name
        elif control.ControlType == automation.ControlType.EditControl:
            details += control.CurrentValue() + '\n'
    details += '\n' * 2
    detailWindow.Click(0.95, 0.02)
    return details
Exemplo n.º 4
0
def WalkDir():
    def GetDirChildren(dir):
        if os.path.isdir(dir):
            subdirs = []
            files = []
            for it in os.listdir(dir):
                absPath = os.path.join(dir, it)
                if os.path.isdir(absPath):
                    subdirs.append(absPath)
                else:
                    files.append(absPath)
            return subdirs + files

    for it, depth, remainCount in automation.WalkTree(r'c:\Program Files\Internet Explorer', getChildrenFunc=GetDirChildren, includeTop=True):
        print(' ' * depth * 4 + it)
def main(directory, maxDepth = 0xFFFFFFFF):
    remain = {}
    text = []
    absdir = os.path.abspath(directory)
    for it, depth, remainCount in automation.WalkTree(absdir, getChildrenFunc=GetDirChildren, includeTop=True, maxDepth=maxDepth):
        remain[depth] = remainCount
        isDir = os.path.isdir(it)
        prefix = ''.join(['│   ' if remain[i+1] else '    ' for i in range(depth - 1)])
        if depth > 0:
            if remain[depth] > 0:
                prefix += '├─→ ' if isDir else '├── '   #'□─→ '
            else:
                prefix += '└─→ ' if isDir else '└── '   #'□─→ '
        file = it[it.rfind('\\')+1:]
        text.append(prefix)
        text.append(file)
        text.append('\r\n')
        automation.Logger.Write(prefix)
        automation.Logger.WriteLine(file, automation.ConsoleColor.Cyan if os.path.isdir(it) else -1)
    automation.SetClipboardText(''.join(text))
Exemplo n.º 6
0
def Analyze(sampleRate=90000,
            beginNo=0,
            maxPackets=0xFFFFFFFF,
            calculateLost=False):
    wireSharkWindow = automation.WindowControl(searchDepth=1,
                                               ClassName='Qt5QWindowIcon')
    if wireSharkWindow.Exists(0, 0):
        wireSharkWindow.SetActive()
    else:
        automation.Logger.WriteLine('can not find wireshark',
                                    automation.ConsoleColor.Yellow)
        return
    tree = wireSharkWindow.TreeControl(searchDepth=4, SubName='Packet list')
    left, top, right, bottom = tree.BoundingRectangle
    tree.Click(10, 30)
    automation.SendKeys('{Home}{Ctrl}{Alt}4')
    time.sleep(0.5)
    tree.Click(10, 30)
    headers = []
    headerFunctionDict = {
        'No': int,
        'Time': float,
        'Source': str,
        'Destination': str,
        'Protocol': str,
        'Length': int,
        'Info': str,
    }
    index = 0
    packets = []
    for item, depth in automation.WalkTree(
            tree,
            getFirstChildFunc=lambda c: c.GetFirstChildControl(),
            getNextSiblingFunc=lambda c: c.GetNextSiblingControl()):
        if isinstance(item, automation.HeaderControl):
            headers.append(item.Name.rstrip('.'))
        elif isinstance(item, automation.TreeItemControl):
            if index == 0:
                if len(packets) >= maxPackets:
                    break
                packet = PacketInfo()
            name = item.Name
            packet.__dict__[headers[index]] = headerFunctionDict[
                headers[index]](name)
            if headers[index] == 'Info':
                startIndex = name.find('Seq=')
                if startIndex > 0:
                    endIndex = name.find(' ', startIndex)
                    packet.Seq = int(name[startIndex + 4:endIndex].rstrip(','))
                startIndex = name.find('Time=')
                if startIndex > 0:
                    endIndex = name.find(' ', startIndex)
                    packet.TimeStamp = int(name[startIndex +
                                                5:endIndex].rstrip(','))
                    if packet.No >= beginNo:
                        packets.append(packet)
                        automation.Logger.WriteLine(
                            'No: {0[No]:<10}, Time: {0[Time]:<10}, Protocol: {0[Protocol]:<6}, Length: {0[Length]:<6}, Info: {0[Info]:<10},'
                            .format(packet.__dict__))
            index = (index + 1) % len(headers)
            if item.BoundingRectangle[3] >= bottom:
                automation.SendKeys('{PageDown}')
                time.sleep(0.1)

    automation.Logger.WriteLine('\n----------\nAnalyze Result:')
    seq = packets[0].Seq - 1
    lostSeqs = []
    framePackets = []
    lastTimeStamp = -1
    for p in packets:
        seq += 1
        if seq != p.Seq:
            lostSeqs.extend(range(seq, p.Seq))
            seq = p.Seq
        if lastTimeStamp < 0:
            framePackets.append(p)
        else:
            if lastTimeStamp == p.TimeStamp:
                framePackets[-1] = p
            else:
                framePackets.append(p)
        lastTimeStamp = p.TimeStamp

    lastTimeStamp = -1
    lastTime = -1
    totalDiff = 0
    frameCount = 0
    for p in framePackets:
        if lastTimeStamp < 0:
            automation.Logger.WriteLine(
                'No: {0[No]:<8}, Time: {0[Time]:<10}, Protocol: {0[Protocol]}, Length: {0[Length]:<6}, TimeStamp: {0[TimeStamp]:<15}'
                .format(p.__dict__))
        else:
            diffTimeStamp = p.TimeStamp - lastTimeStamp
            frameCount += 1
            totalDiff += diffTimeStamp
            sumTime = p.Time - framePackets[0].Time
            sumTimeFromTimeStamp = (p.TimeStamp -
                                    framePackets[0].TimeStamp) / sampleRate
            automation.Logger.WriteLine(
                'No: {0[No]:<8}, Time: {0[Time]:<10}, Protocol: {0[Protocol]}, Length: {0[Length]:<6}, TimeStamp: {0[TimeStamp]:<15}, 帧时间戳差值: {1:<6}, 帧实际时间差值: {2:<10.6f}, 实际接收时间: {3:<10.6f}, 时间戳时间: {4:<10.6f}, 提前时间:{5:<10.6f}'
                .format(p.__dict__, diffTimeStamp, p.Time - lastTime, sumTime,
                        sumTimeFromTimeStamp, sumTimeFromTimeStamp - sumTime))
        lastTime = p.Time
        lastTimeStamp = p.TimeStamp
    if frameCount:
        averageDiff = totalDiff // frameCount
        frameCount += 1
        seqCount = packets[-1].Seq - packets[0].Seq + 1
        totalTimeFromTimeStamp = (framePackets[-1].TimeStamp -
                                  framePackets[0].TimeStamp) / sampleRate
        realTime = framePackets[-1].Time - framePackets[0].Time
        if calculateLost:
            automation.Logger.WriteLine(
                '\n包总数: {0}, 帧数: {1}, 实际帧率:{2:.2f}, 平均时间戳: {3}, 总时间: {4:.6f}, 时间戳总时间: {5:.6f}, 丢包数: {6}({7:.2f}%), 丢包序号: {8}'
                .format(len(packets), frameCount, frameCount / realTime,
                        averageDiff, realTime, totalTimeFromTimeStamp,
                        len(lostSeqs),
                        len(lostSeqs) / seqCount, lostSeqs))
        else:
            automation.Logger.WriteLine(
                '\n包总数: {0}, 帧数: {1}, 实际帧率:{2:.2f}, 平均时间戳: {3}, 总时间: {4:.6f}, 时间戳总时间: {5:.6f}'
                .format(len(packets), frameCount, frameCount / realTime,
                        averageDiff, realTime, totalTimeFromTimeStamp))