From 6ea889fff3e9a3453a5c2b53862385c9a3228e5d Mon Sep 17 00:00:00 2001 From: bannsec Date: Mon, 4 Dec 2017 04:33:44 +0000 Subject: [PATCH] Adding pySym.Project --- fix_git.sh | 2 ++ pySym/Factory.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ pySym/Project.py | 41 +++++++++++++++++++++++++++++++++++++++ pySym/__init__.py | 2 ++ setup.py | 2 +- 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 fix_git.sh create mode 100644 pySym/Factory.py create mode 100644 pySym/Project.py diff --git a/fix_git.sh b/fix_git.sh new file mode 100755 index 0000000..374cd61 --- /dev/null +++ b/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/* diff --git a/pySym/Factory.py b/pySym/Factory.py new file mode 100644 index 0000000..223a998 --- /dev/null +++ b/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 diff --git a/pySym/Project.py b/pySym/Project.py new file mode 100644 index 0000000..8cc13dc --- /dev/null +++ b/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 diff --git a/pySym/__init__.py b/pySym/__init__.py index 1937c76..c3222ad 100755 --- a/pySym/__init__.py +++ b/pySym/__init__.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from .Project import Project + """ import ast import argparse diff --git a/setup.py b/setup.py index fde9d96..e29562b 100644 --- a/setup.py +++ b/setup.py @@ -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')