Skip to content

Commit

Permalink
Move reverse to haystack[reverse] package
Browse files Browse the repository at this point in the history
  • Loading branch information
trolldbois committed Jun 7, 2017
1 parent 2eccb6d commit aaf7cc5
Show file tree
Hide file tree
Showing 51 changed files with 57 additions and 10,731 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: python

python:
- "2.7"
# - "3.5"
- "3.5"

# we are using pre-dumped tests files
# and not testing the dumping capacity of haystack.
Expand Down
70 changes: 1 addition & 69 deletions haystack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,69 +1 @@
# -*- coding: utf-8 -*-

"""
:mod:`haystack` -- a package to search known C or ctypes allocators in memory.
==============================================================================
.. module:: haystack
:platform: Unix, Windows
:synopsys: Search, reverse C/ctypes allocators from memory.
.. moduleauthor:: Loic Jaquemet <loic.jaquemet+python [at] gmail.com>
Available subpackages
---------------------
gui
An attempt to make a Qt4 GUI.
reverse
Framework to reverse engineer memory allocators
"""

__author__ = "Loic Jaquemet loic.jaquemet+python@gmail.com"

__all__ = [
]

# verify the version
from pkg_resources import get_distribution, DistributionNotFound
import os.path

try:
_dist = get_distribution('haystack')
# Normalize case for Windows systems
dist_loc = os.path.normcase(_dist.location)
here = os.path.normcase(__file__)
if not here.startswith(os.path.join(dist_loc, 'haystack')):
# not installed, but there is another version that *is*
raise DistributionNotFound
except DistributionNotFound:
__version__ = 'Please install this project with setup.py'
else:
__version__ = _dist.version

# search API
from haystack.search import api
search_record = api.search_record
output_to_string = api.output_to_string
output_to_python = api.output_to_python

try:
import resource
# augment our file limit capacity to max
maxnofile = resource.getrlimit(resource.RLIMIT_NOFILE)
# print 'maxnofile', maxnofile
resource.setrlimit(
resource.RLIMIT_NOFILE,
(maxnofile[1],
maxnofile[1]))
# maxnofile_after = resource.getrlimit(resource.RLIMIT_NOFILE)
# print 'maxnofile_after', maxnofile_after
# travis-ci says
# maxnofile (64000, 64000)
# maxnofile_after (64000, 64000)
except ImportError as e:
pass


# bad bad idea...
MMAP_HACK_ACTIVE = True
# do not load huge mmap
MAX_MAPPING_SIZE_FOR_MMAP = 1024 * 1024 * 20
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
8 changes: 7 additions & 1 deletion haystack/dump_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
log = logging.getLogger('dump_loader')


# bad bad idea...
MMAP_HACK_ACTIVE = True
# do not load huge mmap
MAX_MAPPING_SIZE_FOR_MMAP = 1024 * 1024 * 20


class LazyLoadingException(Exception):

def __init__(self, filename):
Expand Down Expand Up @@ -178,7 +184,7 @@ def _load_memory_mappings(self):
mmap = AMemoryMapping(start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname)
mmap = LocalMemoryMapping.fromBytebuffer(mmap, mmap_content_file.read())
# use file mmap when file is too big
elif end - start > haystack.MAX_MAPPING_SIZE_FOR_MMAP:
elif end - start > MAX_MAPPING_SIZE_FOR_MMAP:
log.warning('Using a file backed memory mapping. no mmap in memory for this memorymap (%s).' % (pathname) +
' Search will fail. Buffer is needed.')
mmap = FileBackedMemoryMapping(mmap_content_file.name, start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname)
Expand Down
11 changes: 2 additions & 9 deletions haystack/mappings/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@
from haystack.mappings import base
from haystack.mappings.base import AMemoryMapping

__author__ = "Loic Jaquemet"
__copyright__ = "Copyright (C) 2012 Loic Jaquemet"
__email__ = "loic.jaquemet+python@gmail.com"
__license__ = "GPL"
__maintainer__ = "Loic Jaquemet"
__status__ = "Production"
__credits__ = ["Victor Skinner"]

log = logging.getLogger('file')

MMAP_HACK_ACTIVE = True

class LocalMemoryMapping(AMemoryMapping):

Expand Down Expand Up @@ -219,7 +212,7 @@ def _mmap(self):
if hasattr(self._memdump, 'fileno'): # normal file.
# XXX that is the most fucked up, non-portable fuck I ever
# wrote.
if haystack.MMAP_HACK_ACTIVE:
if MMAP_HACK_ACTIVE:
log.debug('Using MMAP_HACK: %s' % self)
# if self.pathname.startswith('/usr/lib'):
# raise Exception
Expand Down
28 changes: 18 additions & 10 deletions haystack/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011,2012,2013 Loic Jaquemet loic.jaquemet+python@gmail.com
#

import ctypes
import inspect
Expand All @@ -23,17 +20,28 @@
LoadException(Exception)
"""

__author__ = "Loic Jaquemet"
__copyright__ = "Copyright (C) 2013 Loic Jaquemet"
__email__ = "loic.jaquemet+python@gmail.com"
__license__ = "GPL"
__maintainer__ = "Loic Jaquemet"
__status__ = "Production"

log = logging.getLogger('model')


try:
import resource
# augment our file limit capacity to max
maxnofile = resource.getrlimit(resource.RLIMIT_NOFILE)
# print 'maxnofile', maxnofile
resource.setrlimit(
resource.RLIMIT_NOFILE,
(maxnofile[1],
maxnofile[1]))
# maxnofile_after = resource.getrlimit(resource.RLIMIT_NOFILE)
# print 'maxnofile_after', maxnofile_after
# travis-ci says
# maxnofile (64000, 64000)
# maxnofile_after (64000, 64000)
except ImportError as e:
pass


log = logging.getLogger('model')


class NotValid(Exception):
Expand Down
14 changes: 0 additions & 14 deletions haystack/reverse/__init__.py

This file was deleted.

169 changes: 0 additions & 169 deletions haystack/reverse/api.py

This file was deleted.

0 comments on commit aaf7cc5

Please sign in to comment.