Skip to content

Commit

Permalink
Adding pySym.Project
Browse files Browse the repository at this point in the history
  • Loading branch information
bannsec committed Dec 4, 2017
1 parent e4d096e commit 6ea889f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fix_git.sh
@@ -0,0 +1,2 @@
# Sooo... If you want to git checkout different branches, you need to update the git repo to fetch ALL sources
git config --local --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
49 changes: 49 additions & 0 deletions pySym/Factory.py
@@ -0,0 +1,49 @@
import logging
logger = logging.getLogger("Factory")

import ast
import enforce

from .pyPath import Path
from .pyPathGroup import PathGroup

@enforce.runtime_validation
class Factory:

def __init__(self, project):
self._project = project

def path(self) -> Path:
"""pySym.pyPath.Path: Path object for this project."""

# Read in the file
with open(self._project.file_name, "r") as f:
source = f.read()

# Parse it
body = ast.parse(source).body

# Return the new path
return Path(body,source=source)

def path_group(self) -> PathGroup:
"""pySym.pyPathGroup.PathGroup: Basic PathGroup object for this project."""
return PathGroup(self.path)

##############
# Properties #
##############

@property
def _project(self):
"""pySym.Project.Project: Associated Project object."""
return self.__project

@_project.setter
def _project(self, project) -> None:
if type(project) is not Project:
raise Exception("Invalid type for project ({0}) should be type Project".format(type(project)))

self.__project = project

from .Project import Project
41 changes: 41 additions & 0 deletions pySym/Project.py
@@ -0,0 +1,41 @@
import logging
logger = logging.getLogger("Project")

import enforce
import os

#@enforce.runtime_validation
class Project:

def __init__(self, file):
self.file_name = file
self.factory = Factory(self)

##############
# Properties #
##############

@property
def factory(self):
return self.__factory

@factory.setter
def factory(self, factory) -> None:
self.__factory = factory

@property
def file_name(self) -> str:
"""str: Name of the file that's being symbolically executed."""
return self.__file_name

@file_name.setter
def file_name(self, file_name: str) -> None:
file_name = os.path.abspath(file_name)

# Make sure this is a real file.
if not os.path.isfile(file_name):
raise Exception("Not a valid file: {file_name:s}".format(file_name=file_name))

self.__file_name = file_name

from .Factory import Factory
2 changes: 2 additions & 0 deletions pySym/__init__.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from .Project import Project

"""
import ast
import argparse
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -24,7 +24,7 @@
# Install z3 or no?
#

install_requires=['prettytable']
install_requires=['prettytable','enforce']

if "PYSYM_NO_Z3" not in os.environ:
install_requires.append('z3-solver')
Expand Down

0 comments on commit 6ea889f

Please sign in to comment.