Permalink
Browse files

Add a setup.py install file

  • Loading branch information...
deactivated committed Aug 16, 2018
1 parent 5471abd commit 5591451010444bb2276213f7e1da59afcf5e2c8c
Showing with 138 additions and 99 deletions.
  1. +1 −0 MANIFEST.in
  2. +113 −0 idarling/server.py
  3. +3 −99 idarling_server.py
  4. +21 −0 setup.py
@@ -0,0 +1 @@
recursive-include idarling/resources *.png
@@ -0,0 +1,113 @@
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
import signal
import sys
import traceback

from PyQt5.QtCore import QCoreApplication, QTimer

from idarling.shared.server import Server


class DedicatedServer(Server):
"""
The dedicated server implementation.
"""

def __init__(self, ssl, parent=None):
logger = self.start_logging()
Server.__init__(self, logger, ssl, parent)

def local_file(self, filename):
filesDir = os.path.join(os.path.dirname(__file__), 'files')
filesDir = os.path.abspath(filesDir)
if not os.path.exists(filesDir):
os.makedirs(filesDir)
return os.path.join(filesDir, filename)

def start_logging(self):
logger = logging.getLogger('IDArling.Server')

# Get path to the log file
logDir = os.path.join(os.path.dirname(__file__), 'logs')
logDir = os.path.abspath(logDir)
if not os.path.exists(logDir):
os.makedirs(logDir)
logPath = os.path.join(logDir, 'idarling.%s.log' % os.getpid())

# Configure the logger
logger.setLevel(logging.DEBUG)
logFormat = '[%(asctime)s][%(levelname)s] %(message)s'
formatter = logging.Formatter(fmt=logFormat, datefmt='%H:%M:%S')

# Log to the console
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)

# Log to the log file
fileHandler = logging.FileHandler(logPath)
fileHandler.setFormatter(formatter)
logger.addHandler(fileHandler)

return logger


def start(args):
"""
The entry point of a Python program.
"""
app = QCoreApplication(sys.argv)
sys.excepthook = traceback.print_exception

server = DedicatedServer(args.ssl)
server.start(args.host, args.port)

# Allow the use of Ctrl-C to stop the server
def sigint_handler(signum, frame):
server.stop()
app.exit(0)
signal.signal(signal.SIGINT, sigint_handler)

def safe_timer(timeout, func, *args, **kwargs):
def timer_event():
try:
func(*args, **kwargs)
finally:
QTimer.singleShot(timeout, timer_event)
QTimer.singleShot(timeout, timer_event)
safe_timer(50, lambda: None)
return app.exec_()


def main():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--help', action='help',
help='show this help message and exit')

parser.add_argument('-h', '--host', type=str, default='127.0.0.1',
help='the hostname to start listening on')
parser.add_argument('-p', '--port', type=int, default=31013,
help='the port to start listening on')

security = parser.add_mutually_exclusive_group(required=True)
security.add_argument('--ssl', type=str, nargs=2,
metavar=('fullchain.pem', 'privkey.pem'),
help='the certificate and private key files')
security.add_argument('--no-ssl', action='store_true',
help='disable SSL (not recommended)')

start(parser.parse_args())
@@ -10,104 +10,8 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
import signal
import sys
import traceback
from idarling import server

from PyQt5.QtCore import QCoreApplication, QTimer

from idarling.shared.server import Server


class DedicatedServer(Server):
"""
The dedicated server implementation.
"""

def __init__(self, ssl, parent=None):
logger = self.start_logging()
Server.__init__(self, logger, ssl, parent)

def local_file(self, filename):
filesDir = os.path.join(os.path.dirname(__file__), 'files')
filesDir = os.path.abspath(filesDir)
if not os.path.exists(filesDir):
os.makedirs(filesDir)
return os.path.join(filesDir, filename)

def start_logging(self):
logger = logging.getLogger('IDArling.Server')

# Get path to the log file
logDir = os.path.join(os.path.dirname(__file__), 'logs')
logDir = os.path.abspath(logDir)
if not os.path.exists(logDir):
os.makedirs(logDir)
logPath = os.path.join(logDir, 'idarling.%s.log' % os.getpid())

# Configure the logger
logger.setLevel(logging.DEBUG)
logFormat = '[%(asctime)s][%(levelname)s] %(message)s'
formatter = logging.Formatter(fmt=logFormat, datefmt='%H:%M:%S')

# Log to the console
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)

# Log to the log file
fileHandler = logging.FileHandler(logPath)
fileHandler.setFormatter(formatter)
logger.addHandler(fileHandler)

return logger


def main(args):
"""
The entry point of a Python program.
"""
app = QCoreApplication(sys.argv)
sys.excepthook = traceback.print_exception

server = DedicatedServer(args.ssl)
server.start(args.host, args.port)

# Allow the use of Ctrl-C to stop the server
def sigint_handler(signum, frame):
server.stop()
app.exit(0)
signal.signal(signal.SIGINT, sigint_handler)

def safe_timer(timeout, func, *args, **kwargs):
def timer_event():
try:
func(*args, **kwargs)
finally:
QTimer.singleShot(timeout, timer_event)
QTimer.singleShot(timeout, timer_event)
safe_timer(50, lambda: None)
return app.exec_()


if __name__ == '__main__':
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--help', action='help',
help='show this help message and exit')

parser.add_argument('-h', '--host', type=str, default='127.0.0.1',
help='the hostname to start listening on')
parser.add_argument('-p', '--port', type=int, default=31013,
help='the port to start listening on')

security = parser.add_mutually_exclusive_group(required=True)
security.add_argument('--ssl', type=str, nargs=2,
metavar=('fullchain.pem', 'privkey.pem'),
help='the certificate and private key files')
security.add_argument('--no-ssl', action='store_true',
help='disable SSL (not recommended)')

main(parser.parse_args())
if __name__ == "__main__":
server.main()
@@ -0,0 +1,21 @@
#!/usr/bin/env python
from setuptools import find_packages, setup


setup(name='idarling',
version='0.1',
description='Collaborative Reverse Engineering plugin for IDA Pro',
url='https://github.com/IDArlingTeam/IDArling',
packages=find_packages(),
install_requires=[
"PyQt5; python_version >= '3.0'"
],
include_package_data=True,
entry_points={
"idapython_plugins": [
"idarling=idarling.plugin:Plugin"
],
"console_scripts": [
"idarling_server=idarling.server:main"
]
})

0 comments on commit 5591451

Please sign in to comment.