Exemplo n.º 1
0
 async def transferData(self, remote, writer, data):
     header = b'\x06\x03\x04'
     loop = asyncio.get_event_loop()
     try:
         await loop.sock_sendall(remote, data)
         #Log.info("Data has sent to remote: " + str(data))
     except Exception as e:
         Log.error("An error occured when send data to remote: " + str(e))
         return
     while True:
         try:
             recv = await loop.sock_recv(remote, 4096)
         except:
             break
         if not recv:
             break
         else:
             recv_len = len(recv)
             if (recv_len > 0):
                 #Log.info("Data received: "+str(recv))
                 b_sendLen = recv_len.to_bytes(2, byteorder='little')
                 writer.write(header + b_sendLen + recv)
                 try:
                     await writer.drain()
                 except:
                     return
                 #Log.debug("Data has sent to local")
             else:
                 break
Exemplo n.º 2
0
 def stop(self, loop):
     if self.server is not None:
         if self.ioloop is not None:
             self.ioloop.close()
         self.server.close()
         loop.run_until_complete(self.server.wait_closed())
         Log.warn("Socks proxy server has been stopped.")
     else:
         Log.warn("Socks proxy server is not found.")
Exemplo n.º 3
0
    def start(self, loop):
        self.coro = asyncio.start_server(self.accept_client,
                                         self.host,
                                         self.port,
                                         loop=loop)
        self.server = loop.run_until_complete(self.coro)
        Log.info("Sock proxy server started at " + self.host + ":" +
                 str(self.port))
        self.ioloop = asyncio.new_event_loop()

        def start_loop(loop):
            asyncio.set_event_loop(loop)
            loop.run_forever()

        iothread = Thread(target=start_loop, args=(self.ioloop, ))
        iothread.start()

        self.server = loop.run_forever()
Exemplo n.º 4
0
def load():
    if (os.path.exists(sys.path[0]+'/config.json')):
        f = open(sys.path[0]+'/config.json',encoding="utf-8")
        config = json.load(f)
        mode = ""
        if configModeCheck(config['mode'])>0:
            mode = config['mode']
        else:
            Log.error('Proxy mode is not set up')
            sys.exit(0)
        host = ""
        if config['host'] is None or len(config['host'])<=0:
            host = "0.0.0.0"
            Log.warn("Host is not set up, use default value: 0.0.0.0")
        else:
            host = config['host']
        port = 1234
        if config['port'] is None or config['port'] <= 0:
            Log.warn("Port is not set up, use default value: 1234")
        else:
            port = config['port']
        password = ""
        if config['password'] is None or len(config['password'])<=0:
            Log.warn("Password is not set up")
        else:
            password = config['password']
        securekey = "brbypass23333"
        if config['securekey'] is None or len(config['securekey'])<=0:
            Log.warn("Securekey is not set up, use default value: brbypass23333")
        else:
            securekey = config['securekey']
        return Config(host,port,password,mode,securekey)
    else:
        Log.error("Config file is not found")
        sys.exit(0)
Exemplo n.º 5
0
import os
import sys
import asyncio
from Controller import Log, Config
from Util import SocksProxy

#version
version = "0.1 Reborn"

#main execute
if __name__ == "__main__":
    Log.info("Starting brbypass [" + version + "]...")
    Log.debug("Config: " + Config.config.host + ":" + str(Config.config.port) +
              " @ \"" + Config.config.password + "\" % " + Config.config.mode)

    #mode change
    if Config.config.mode == "socks":
        loop = asyncio.get_event_loop()
        if (loop is None):
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)

        proxyServer = SocksProxy.SocksProxyServer(Config.config.host,
                                                  Config.config.port)
        try:
            proxyServer.start(loop)
        except KeyboardInterrupt:
            proxyServer.stop(loop)
            os._exit(0)
Exemplo n.º 6
0
    async def handle_client(self, reader, writer):
        timeout = 15
        client_peername = writer.get_extra_info('peername')
        Log.info("New Connection from: " + str(client_peername))
        remote = None
        loop = asyncio.get_event_loop()
        while True:
            try:
                headBuffer = await asyncio.wait_for(reader.read(2),
                                                    timeout=timeout)
            except:
                break
            if (headBuffer is None):
                continue
            else:
                if headBuffer == b'\x07\x02':
                    cmd = await asyncio.wait_for(reader.read(1),
                                                 timeout=timeout)
                    Log.debug('cmd==' + str(cmd))
                    if (cmd == b'\x01'):
                        if (len(Config.config.password) > 0):
                            _len = await asyncio.wait_for(reader.read(1),
                                                          timeout=timeout)
                            length = int.from_bytes(_len, byteorder='little')
                            _password = await asyncio.wait_for(
                                reader.read(length), timeout=timeout)
                            password = _password.decode('utf-8')
                            if (password == Config.config.password):
                                #  Response Message
                                #   0   1   2    3
                                #  x06 x03 CMD STATUS
                                writer.write(b'\x06\x03\x02\x00')
                                await writer.drain()
                            else:
                                writer.write(b'\x06\x03\x02\x01')
                                await writer.drain()
                        else:
                            writer.write(b'\x06\x03\x02\x00')
                            await writer.drain()
                            Log.debug("Auth resposne has sent to local.")
                    elif (cmd == b'\x02'):
                        address = None
                        port = None
                        b_type = await asyncio.wait_for(reader.read(1),
                                                        timeout=timeout)
                        if (b_type == b'\x01'):
                            # process header
                            address = ""
                            for i in range(4):
                                address = address + str(
                                    int.from_bytes(await asyncio.wait_for(
                                        reader.read(1), timeout=timeout),
                                                   byteorder='little'))
                                if (i != 3):
                                    address = address + '.'
                            b_port = await asyncio.wait_for(reader.read(2),
                                                            timeout=timeout)
                            port = int.from_bytes(b_port, byteorder='little')
                        elif (b_type == b'\x03'):
                            # process header
                            b_dLength = await asyncio.wait_for(reader.read(2),
                                                               timeout=timeout)
                            domainLength = int.from_bytes(b_dLength,
                                                          byteorder='little')
                            b_port = await asyncio.wait_for(reader.read(2),
                                                            timeout=timeout)
                            port = int.from_bytes(b_port, byteorder='little')
                            address = await asyncio.wait_for(
                                reader.read(domainLength), timeout=timeout)
                        elif (b_type == b'\x04'):
                            # process header
                            address = ""
                            for i in range(4):
                                address = address + \
                                    binascii.b2a_hex(await asyncio.wait_for(reader.read(4), timeout=timeout))
                                if i != 3:
                                    address = address + ":"
                            b_port = await asyncio.wait_for(reader.read(2),
                                                            timeout=timeout)
                            port = int.from_bytes(b_port, byteorder='little')

                        addrs = await loop.getaddrinfo(host=address, port=port)
                        if len(addrs) == 0:
                            Log.error('Get addrinfo failed.')
                            return
                        af, socktype, proto, canonname, sa = addrs[0]
                        remote = socket.socket(af, socktype, proto)
                        remote.setblocking(0)
                        remote.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY,
                                          1)
                        try:
                            await loop.sock_connect(remote, sa)
                        except Exception as e:
                            Log.error("Can't connect to remote: " + str(e))
                            return
                    elif (cmd == b'\x03'):
                        # Get contentLength
                        b_length = await asyncio.wait_for(reader.read(2),
                                                          timeout=timeout)
                        contentLength = int.from_bytes(b_length,
                                                       byteorder='little')
                        b_content = await asyncio.wait_for(
                            reader.read(contentLength), timeout=timeout)
                        asyncio.run_coroutine_threadsafe(self.transferData(
                            remote=remote, writer=writer, data=b_content),
                                                         loop=self.ioloop)
Exemplo n.º 7
0
        for oplayer in self.__oplayerList:
            oplayer.wheelEvent(QEvent)
        delta = QEvent.angleDelta()
        angle = delta.y()
        slice = -angle // 120
        self.__displayModel.instanceChange(slice)

    @Log.LogClassFuncInfos
    def addOplayer(self, oplayer):
        self.__oplayerList.append(oplayer)
        self.setOriImgSizeToOplayer()


if __name__ == '__main__':

    Log.removeLog()

    class MainWindow(QMainWindow):
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            self.setWindowTitle("QDicomLabel Test")
            self.showMaximized()
            # self.resize(500,500)
            # self.setGeometry(400,100,500,200)

            self.setAttribute(Qt.WA_Hover, True)
            self.setMouseTracking(True)
            self.imagelabel = DicomBasicDicomImageViewer()

            self.setCentralWidget(self.imagelabel)