Esempio n. 1
0
    def main(self, argv):

        #global mainWindow

        app = CQApplication(argv)

        #app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))

        self.mainWindow = EditorWindow()

        self.mainWindow.setArgv(argv)  # passing command line to the code

        self.mainWindow.show()

        self.mainWindow.processCommandLine()

        self.mainWindow.raise_(
        )  # to make sure on OSX window is in the foreground

        if sys.platform.startswith('win'):

            import win32process

            self.mainWindow.setProcessId(win32process.GetCurrentProcessId())

        app.exec_()
Esempio n. 2
0
def printMem(indent=""):
    if isUnix():
        import commands
        #
        procId = os.getpid()
        res = commands.getoutput('cat /proc/%s/status' % procId).split('\n')
        status = dict()
        for i in res:
            if i != '':
                res2 = i.split(":\t")
                status[res2[0]] = res2[1]
        print indent + "VmSize: %s  VmRSS: %s  VmData: %s " % (
            status['VmSize'], status['VmRSS'], status['VmData'])
    else:
        try:
            import win32process
            import win32con
            import win32api
            procId = win32process.GetCurrentProcessId()
            han = win32api.OpenProcess(
                win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ,
                0, procId)
            procmeminfo = win32process.GetProcessMemoryInfo(han)
            workMem = (procmeminfo["WorkingSetSize"] / 1024.)
            peakWork = (procmeminfo["PeakWorkingSetSize"] / 1024.)
            pageFile = (procmeminfo["PagefileUsage"] / 1024.)
            peakPageFile = (procmeminfo["PeakPagefileUsage"] / 1024.)
            print indent + "WorkMem: %sK  PeakMem: %sK  PageFile: %sK  PeakPageFile: %sK" % (
                workMem, peakWork, pageFile, peakPageFile)
        except:
            print "install pywin32 to be able to compute process memory"
Esempio n. 3
0
def _current_process_owns_console():
    #import os, win32api
    #return not win32api.GetConsoleTitle().startswith(os.environ["COMSPEC"])
    import win32console, win32process
    conswnd = win32console.GetConsoleWindow()
    wndpid = win32process.GetWindowThreadProcessId(conswnd)[1]
    curpid = win32process.GetCurrentProcessId()
    return curpid == wndpid
Esempio n. 4
0
def hidewindow():
    def callback(*args, **kwargs):
        hwnd, pid = args
        wpid = win32process.GetWindowThreadProcessId(hwnd)[1]
        if pid == wpid:
            win32gui.ShowWindow(hwnd, win32con.SW_HIDE)

    pid =  win32process.GetCurrentProcessId()
    win32gui.EnumWindows(callback, pid)
Esempio n. 5
0
    def dump_nt_objects(self):

        #
        # Windows stations and Desktops - TODO make is more OO: objects for windowstations and desktops.
        #
        win32con.WINSTA_ALL_ACCESS = 0x0000037f

        print
        print "[-] Sessions"
        print
        for session in win32ts.WTSEnumerateSessions(
                win32ts.WTS_CURRENT_SERVER_HANDLE, 1, 0):
            print "SessionId: %s" % session['SessionId']
            print "\tWinStationName: %s" % session['WinStationName']
            print "\tState: %s" % session['State']
            print

        session = win32ts.ProcessIdToSessionId(
            win32process.GetCurrentProcessId())
        print
        print "[-] Winstations in session %s" % session
        print
        for w in win32service.EnumWindowStations():
            print "winstation: %s" % w
        print

        for w in win32service.EnumWindowStations():
            print
            print "[-] Session %s, Winstation '%s'" % (session, w)
            print

            # Get SD
            try:
                h = 0
                h = win32service.OpenWindowStation(w, False,
                                                   win32con.READ_CONTROL)
                s = win32security.GetKernelObjectSecurity(
                    h, win32security.OWNER_SECURITY_INFORMATION
                    | win32security.GROUP_SECURITY_INFORMATION
                    | win32security.DACL_SECURITY_INFORMATION)
                s = sd('winstation', s)
                print s.as_text()
            except pywintypes.error, details:
                print "[E] Can't get READ_CONTROL winstation handle: %s" % details

            # Get Desktops
            try:
                h = 0
                h = win32service.OpenWindowStation(
                    w, False, win32con.WINSTA_ENUMDESKTOPS)
                print "[-] Session %s, Winstation '%s' has these desktops:" % (
                    session, w)
                for d in h.EnumDesktops():
                    print "\t%s" % d
                print
            except pywintypes.error, details:
                print "[E] Can't get WINSTA_ENUMDESKTOPS winstation handle: %s" % details
Esempio n. 6
0
    def test_console_reader(self):

        pid = win32process.GetCurrentProcessId()
        tid = win32api.GetCurrentThreadId()
        args = ['sleep', '1']

        with self.assertRaises(SystemExit):
            wexpect.ConsoleReader(wexpect.join_args(args),
                                  tid=tid,
                                  pid=pid,
                                  cp=1250,
                                  logdir='wexpect')

        os.system('cls')
Esempio n. 7
0
 def _check_for_no_windows(self):
     #print "Application._check_for_no_windows" ###
     apid = wp.GetCurrentProcessId()
     #print "... apid =", apid ###
     htop = gui.GetDesktopWindow()
     hwin = gui.GetWindow(htop, wc.GW_CHILD)
     while hwin:
         wpid = wp.GetWindowThreadProcessId(hwin)[1]
         if wpid == apid:
             #print "... hwin", hwin ###
             if gui.GetWindowLong(hwin, wc.GWL_STYLE) & wc.WS_VISIBLE:
                 #print "...... is visible" ###
                 return
         hwin = gui.GetWindow(hwin, wc.GW_HWNDNEXT)
     #print "... none visible" ###
     self.no_visible_windows()
    def main(self, argv):

        app = CQApplication(argv)

        QApplication.setWindowIcon(QIcon(':/icons/twedit-icon.png'))

        qt_version = str(QT_VERSION_STR).split('.')

        if platform.mac_ver()[0] != '' and int(qt_version[1]) >= 2:  # style sheets may not work properly for qt < 4.2

            app.setStyleSheet("QDockWidget::close-button, QDockWidget::float-button { padding: 0px;icon-size: 24px;}")

        pixmap = QPixmap("icons/lizard-at-a-computer-small.png")

        print("pixmap=", pixmap)

        splash = QSplashScreen(pixmap)

        splash.showMessage("Please wait.\nLoading Twedit++5 ...", Qt.AlignLeft, Qt.black)

        splash.show()

        app.processEvents()

        # app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))

        self.mainWindow = EditorWindow(False)

        self.mainWindow.setArgv(argv)  # passing command line to the code

        self.mainWindow.show()

        splash.finish(self.mainWindow)

        # self.mainWindow.processCommandLine()

        self.mainWindow.openFileList(self.fileList)

        self.mainWindow.raise_()  # to make sure on OSX window is in the foreground

        if sys.platform.startswith('win'):
            import win32process
            self.mainWindow.setProcessId(win32process.GetCurrentProcessId())
            # showTweditWindowInForeground()

        app.exec_()
#!/usr/bin/env python
Esempio n. 10
0
    import win32pdhutil
    import wmi
    if 0:  #prints the free disk space, total size and % free of disk drives.
        try:
            c = wmi.WMI()
            for disk in c.Win32_LogicalDisk(DriveType=3):
                print(
                    disk.Caption, "%.1fGb free %.1fGb avail -- %0.2f%% free" %
                    ((long(disk.FreeSpace)) * 1.0e-9,
                     (long(disk.Size)) * 1.0e-9,
                     (100.0 * long(disk.FreeSpace) / long(disk.Size))))
        except:
            pass

    import win32process
    current_id = win32process.GetCurrentProcessId()

    def wmi_mem():
        c = wmi.WMI(find_classes=False)
        for process in c.Win32_Process(['WorkingSetSize'], Handle=current_id):
            return process.WorkingSetSize

    last_mem = win32pdhutil.FindPerformanceAttributesByName(
        "python", counter="Virtual Bytes")
    last_wmi = wmi_mem()

    def mem(t='', p=1):
        global last_mem
        last_mem = win32pdhutil.FindPerformanceAttributesByName(
            "python", counter="Virtual Bytes")
        if p:
from os import environ
Esempio n. 12
0
    def dump_nt_objects(self):

        #
        # Windows stations and Desktops - TODO make is more OO: objects for windowstations and desktops.
        #
        win32con.WINSTA_ALL_ACCESS = 0x0000037f

        print()
        print("[-] Sessions")
        print()
        for session in win32ts.WTSEnumerateSessions(
                win32ts.WTS_CURRENT_SERVER_HANDLE, 1, 0):
            print("SessionId: %s" % session['SessionId'])
            print("\tWinStationName: %s" % session['WinStationName'])
            print("\tState: %s" % session['State'])
            print()
        session = win32ts.ProcessIdToSessionId(
            win32process.GetCurrentProcessId())
        print()
        print("[-] Winstations in session %s" % session)
        print()
        for w in win32service.EnumWindowStations():
            print("winstation: %s" % w)
        print()

        for w in win32service.EnumWindowStations():
            print()
            print("[-] Session %s, Winstation '%s'" % (session, w))
            print()

            # Get SD
            try:
                h = 0
                h = win32service.OpenWindowStation(w, False,
                                                   win32con.READ_CONTROL)
                s = win32security.GetKernelObjectSecurity(
                    h, win32security.OWNER_SECURITY_INFORMATION
                    | win32security.GROUP_SECURITY_INFORMATION
                    | win32security.DACL_SECURITY_INFORMATION)
                s = SD('winstation', s)
                print(s.as_text())
            except pywintypes.error as details:
                print("[E] Can't get READ_CONTROL winstation handle: %s" %
                      details)

            # Get Desktops
            h = 0
            try:

                h = win32service.OpenWindowStation(
                    w, False, win32con.WINSTA_ENUMDESKTOPS)
                print("[-] Session %s, Winstation '%s' has these desktops:" %
                      (session, w))
                for d in h.EnumDesktops():
                    print("\t%s" % d)
                print()
            except pywintypes.error as details:
                print(
                    "[E] Can't get WINSTA_ENUMDESKTOPS winstation handle: %s" %
                    details)
            if h:
                h.SetProcessWindowStation()
                for d in h.EnumDesktops():
                    print("[-] Session %s, Winstation '%s', Desktop '%s'" %
                          (session, w, d))
                    try:
                        hd = win32service.OpenDesktop(d, 0, False,
                                                      win32con.READ_CONTROL)
                        s = win32security.GetKernelObjectSecurity(
                            hd, win32security.OWNER_SECURITY_INFORMATION
                            | win32security.GROUP_SECURITY_INFORMATION
                            | win32security.DACL_SECURITY_INFORMATION)
                        s = SD('desktop', s)
                        print(s.as_text())
                    except pywintypes.error as details:
                        print("[E] Can't get READ_CONTROL desktop handle: %s" %
                              details)
            print()
        #
        # Objects
        #
        print()
        print("[-] Objects")
        print()
        root = NTObj("\\")
        for child in root.get_all_child_objects():
            print(child.as_text())
            if (child.get_type() == "Semaphore" or child.get_type() == "Event"
                    or child.get_type() == "Mutant" or child.get_type()
                    == "Timer" or child.get_type() == "Section"
                    or child.get_type() == "Device" or child.get_type()
                    == "SymbolicLink" or child.get_type() == "Key"
                    or child.get_type() == "Directory") and child.get_sd():
                print(child.get_sd().as_text())
            else:
                print("Skipping unknown object type: %s" % child.get_type())
                print()