Commit 422b146b authored by Damien Octeau's avatar Damien Octeau Committed by GitHub

Merge pull request #1 from cedricbonhomme/master

Refactoring in order to isolate PRIMO to its own namespace.
parents b4b3ae56 d154ee86
# Created by https://www.gitignore.io/api/python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
*.c
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
#exclude linking/*.pyx #exclude primo/linking/*.pyx
include *.txt include *.txt
include primo.py include bin/primo
include make_plots_and_stats.py include bin/make_plots_and_stats
include performance_experiments.py include bin/performance_experiments
include setup.py include setup.py
include linking/*.c include primo/linking/*.c
include linking/*.pxd include primo/linking/*.pxd
include linking/*.pxi include primo/linking/*.pxi
include linking/*.py include primo/linking/*.py
The PRIMO tool for static Intent resolution and probabilistic value inference.
# Installation
```shell
$ sudo python setup.py build
$ sudo python setup.py install
```
The script can be run directly from the top-level directory afterwards.
For further instructions, please see http://siis.cse.psu.edu/primo
# Usage
## As an application
```shell
$ primo --protodir ic3-output/ --dumpintentlinks links.blp
$ mkdir stats
$ make_plots_and_stats --input links.blp --out stats/
2016-05-10 09:20:34,538 [root] [INFO ] Loading file links.blp.
2016-05-10 09:20:34,541 [root] [INFO ] Loaded 35375 Intent links.
2016-05-10 09:20:34,541 [root] [INFO ] Plotting probability distribution CDF.
2016-05-10 09:20:35,669 [root] [INFO ] Finished plotting probability distribution CDF.
2016-05-10 09:20:35,669 [root] [INFO ] Plotting probability distribution histogram.
2016-05-10 09:20:36,632 [root] [INFO ] Finished plotting probability distribution histogram.
2016-05-10 09:20:36,632 [root] [INFO ] Plotting probability distribution by inter/intra app Intent.
2016-05-10 09:20:41,133 [root] [INFO ] Finished plotting histograms.
2016-05-10 09:20:41,133 [root] [INFO ] Computing Intent connectivities.
2016-05-10 09:20:41,158 [root] [INFO ] Finished computing Intent connectivities from Intent links.
2016-05-10 09:20:41,159 [root] [INFO ] Computing connectivity CDFs.
2016-05-10 09:20:41,731 [root] [INFO ] Plotting link CDF.
2016-05-10 09:20:42,272 [root] [INFO ] Finished plotting link CDF.
```
## As a module
```python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from primo.linking.fetch_data import FetchData
if __name__ == "__main__":
# Point of entry in execution mode
file_path = sys.argv[1:]
apps, components, intents, intent_filters = FetchData(file_path, "", True)
print("")
for app in apps:
print(app.name)
print("""\tSends external intent: {}
Has publicly accessible component: {}""". \
format(app.SendsExternalIntent(),
app.HasOpenComponent()))
```
To build:
python setup.py build
The script can be run directly from the top-level directory afterwards.
It can also be installed with python setup.py install
For further instructions, please see http://siis.cse.psu.edu/primo/
...@@ -25,7 +25,7 @@ import sys ...@@ -25,7 +25,7 @@ import sys
import gflags import gflags
from linking.plots_and_stats import MakePlotsAndStats from primo.linking.plots_and_stats import MakePlotsAndStats
FLAGS = gflags.FLAGS FLAGS = gflags.FLAGS
......
...@@ -29,7 +29,7 @@ import time ...@@ -29,7 +29,7 @@ import time
import gflags import gflags
from linking.find_links import FindLinksAndLogExceptions from primo.linking.find_links import FindLinksAndLogExceptions
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
......
...@@ -36,7 +36,7 @@ import time ...@@ -36,7 +36,7 @@ import time
import gflags import gflags
from linking import find_links from primo.linking import find_links
FLAGS = gflags.FLAGS FLAGS = gflags.FLAGS
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Application class and factory.""" """Application class and factory."""
from linking.components cimport Component from primo.linking.components cimport Component
from linking.components cimport MakeComponent from primo.linking.components cimport MakeComponent
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
from linking.attribute_matching cimport AttributeMap from primo.linking.attribute_matching cimport AttributeMap
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
cdef set SAMPLES = set() cdef set SAMPLES = set()
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.applications cimport Application from primo.linking.applications cimport Application
cdef int GetSkippedFilterCount() cdef int GetSkippedFilterCount()
cdef Component MakeComponent(object component_pb, Application application, cdef Component MakeComponent(object component_pb, Application application,
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
# limitations under the License. # limitations under the License.
"""A class and factory for Android application components.""" """A class and factory for Android application components."""
from linking.applications cimport Application from primo.linking.applications cimport Application
from linking.target_data cimport AddComponent from primo.linking.target_data cimport AddComponent
from linking.intent_filters cimport IntentFilter from primo.linking.intent_filters cimport IntentFilter
from linking.intent_filters cimport MakeIntentFilter from primo.linking.intent_filters cimport MakeIntentFilter
from linking.intents cimport MakeComponentIntent from primo.linking.intents cimport MakeComponentIntent
cdef int _id = 0 cdef int _id = 0
......
...@@ -20,8 +20,8 @@ from google.protobuf import text_format ...@@ -20,8 +20,8 @@ from google.protobuf import text_format
import logging import logging
import os import os
from linking import applications from primo.linking import applications
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
# limitations under the License. # limitations under the License.
cimport numpy as np cimport numpy as np
from linking.components cimport Component from primo.linking.components cimport Component
from linking.intents cimport Intent from primo.linking.intents cimport Intent
ctypedef np.int8_t DTYPE_t ctypedef np.int8_t DTYPE_t
......
...@@ -24,15 +24,15 @@ import logging ...@@ -24,15 +24,15 @@ import logging
import numpy as np import numpy as np
import time import time
from linking.applications cimport Application from primo.linking.applications cimport Application
from linking.components cimport Component from primo.linking.components cimport Component
from linking.target_data cimport GetAppsMatching from primo.linking.target_data cimport GetAppsMatching
from linking.target_data cimport GetComponentsOfApp from primo.linking.target_data cimport GetComponentsOfApp
from linking.target_data cimport GetComponentsWithKind from primo.linking.target_data cimport GetComponentsWithKind
from linking.target_data cimport GetComponentsWithName from primo.linking.target_data cimport GetComponentsWithName
from linking.target_data cimport GetExportedComponentCount from primo.linking.target_data cimport GetExportedComponentCount
from linking.target_data cimport GetExportedComponents from primo.linking.target_data cimport GetExportedComponents
from linking.intents cimport Intent from primo.linking.intents cimport Intent
DTYPE = np.int8 DTYPE = np.int8
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
# limitations under the License. # limitations under the License.
cimport numpy as np cimport numpy as np
from linking.intent_filters cimport IntentFilter from primo.linking.intent_filters cimport IntentFilter
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
from linking.intents cimport Intent from primo.linking.intents cimport Intent
ctypedef np.int8_t DTYPE_t ctypedef np.int8_t DTYPE_t
......
...@@ -21,36 +21,36 @@ DEF DEBUG = False ...@@ -21,36 +21,36 @@ DEF DEBUG = False
cimport cython cimport cython
cimport numpy as np cimport numpy as np
from linking.target_data import BASE_TYPE from primo.linking.target_data import BASE_TYPE
from linking.util import Powerset from primo.linking.util import Powerset
import logging import logging
import numpy as np import numpy as np
import time import time
from linking.intent_data cimport GetAttributeMaps from primo.linking.intent_data cimport GetAttributeMaps
from linking.intent_data cimport GetPreciseIntents from primo.linking.intent_data cimport GetPreciseIntents
from linking.target_data cimport GetExportedFilters from primo.linking.target_data cimport GetExportedFilters
from linking.target_data cimport GetFiltersOfApp from primo.linking.target_data cimport GetFiltersOfApp
from linking.target_data cimport GetFiltersWithUsedPermission from primo.linking.target_data cimport GetFiltersWithUsedPermission
from linking.target_data cimport GetFiltersWithAction from primo.linking.target_data cimport GetFiltersWithAction
from linking.target_data cimport GetFiltersWithAnyAction from primo.linking.target_data cimport GetFiltersWithAnyAction
from linking.target_data cimport GetFiltersWithBaseTypes from primo.linking.target_data cimport GetFiltersWithBaseTypes
from linking.target_data cimport GetFiltersWithCategories from primo.linking.target_data cimport GetFiltersWithCategories
from linking.target_data cimport GetFiltersWithHost from primo.linking.target_data cimport GetFiltersWithHost
from linking.target_data cimport GetFiltersWithKind from primo.linking.target_data cimport GetFiltersWithKind
from linking.target_data cimport GetFiltersWithPath from primo.linking.target_data cimport GetFiltersWithPath
from linking.target_data cimport GetFiltersWithPort from primo.linking.target_data cimport GetFiltersWithPort
from linking.target_data cimport GetFiltersWithScheme from primo.linking.target_data cimport GetFiltersWithScheme
from linking.target_data cimport GetFiltersWithType from primo.linking.target_data cimport GetFiltersWithType
from linking.target_data cimport GetFiltersWithTypes from primo.linking.target_data cimport GetFiltersWithTypes
from linking.target_data cimport GetFiltersWithoutType from primo.linking.target_data cimport GetFiltersWithoutType
from linking.target_data cimport GetNoDataFilters from primo.linking.target_data cimport GetNoDataFilters
from linking.intent_filters cimport IntentFilter from primo.linking.intent_filters cimport IntentFilter
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
from linking.intents cimport Intent from primo.linking.intents cimport Intent
from linking.attribute_matching cimport NonEmptyIntersection from primo.linking.attribute_matching cimport NonEmptyIntersection
include 'linking/constants.pxi' include 'primo/linking/constants.pxi'
DTYPE = np.int8 DTYPE = np.int8
......
...@@ -24,18 +24,18 @@ import traceback ...@@ -24,18 +24,18 @@ import traceback
import gflags import gflags
from linking.find_explicit_links cimport ExplicitLinkFinder from primo.linking.find_explicit_links cimport ExplicitLinkFinder
from linking.find_implicit_links cimport ImplicitLinkFinder from primo.linking.find_implicit_links cimport ImplicitLinkFinder
from linking.target_data cimport PrepareForQueries from primo.linking.target_data cimport PrepareForQueries
from linking.intent_data cimport GetImpreciseComponentIntents from primo.linking.intent_data cimport GetImpreciseComponentIntents
from linking.intent_data cimport GetPreciseComponentIntents from primo.linking.intent_data cimport GetPreciseComponentIntents
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
from linking.intents cimport Intent from primo.linking.intents cimport Intent
from linking.validation cimport PerformValidation from primo.linking.validation cimport PerformValidation
from linking import fetch_data from primo.linking import fetch_data
from linking import intents as intents_mod from primo.linking import intents as intents_mod
from linking import write_results from primo.linking import write_results
gflags.DEFINE_boolean('computeattributes', True, 'Compute attributes.') gflags.DEFINE_boolean('computeattributes', True, 'Compute attributes.')
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
cdef void AddPreciseIntent(ComponentIntent intent) cdef void AddPreciseIntent(ComponentIntent intent)
cdef void AddImpreciseIntent(ComponentIntent intent) cdef void AddImpreciseIntent(ComponentIntent intent)
......
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
# limitations under the License. # limitations under the License.
"""Global Intent maps and constants.""" """Global Intent maps and constants."""
from linking.intents cimport ComponentIntent from primo.linking.intents cimport ComponentIntent
from linking.intents cimport Intent from primo.linking.intents cimport Intent
import logging import logging
from linking.target_data import BASE_TYPE from primo.linking.target_data import BASE_TYPE
from linking.target_data import CLASS from primo.linking.target_data import CLASS
from linking.target_data import PACKAGE from primo.linking.target_data import PACKAGE
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
include 'linking/constants.pxi' include 'primo/linking/constants.pxi'
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.components cimport Component from primo.linking.components cimport Component
cdef IntentFilter MakeIntentFilter(object intent_filter_pb, cdef IntentFilter MakeIntentFilter(object intent_filter_pb,
Component component) Component component)
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
# limitations under the License. # limitations under the License.
"""Class and factory for Intent Filters.""" """Class and factory for Intent Filters."""
from linking.components cimport Component from primo.linking.components cimport Component
from linking.target_data cimport AddIntentFilterAttributes from primo.linking.target_data cimport AddIntentFilterAttributes
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
_ACTION_MAIN = u'android.intent.action.MAIN' _ACTION_MAIN = u'android.intent.action.MAIN'
...@@ -170,7 +170,7 @@ cdef class IntentFilter(object): ...@@ -170,7 +170,7 @@ cdef class IntentFilter(object):
""" """
return (self.actions and len(self.actions) >= 1 return (self.actions and len(self.actions) >= 1
and IntentFilter._ACTION_MAIN in self.actions) _ACTION_MAIN in self.actions)
def print_end_point(self): def print_end_point(self):
print "package",self.component.application_id print "package",self.component.application_id
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.intents cimport Intent from primo.linking.intents cimport Intent
cdef void UpdateImpreciseDistribution(Intent intent) cdef void UpdateImpreciseDistribution(Intent intent)
cdef void MakeRandomImprecision(Intent intent) cdef void MakeRandomImprecision(Intent intent)
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
"""Module for recording field imprecision distribution and for introducing """Module for recording field imprecision distribution and for introducing
imprecise fields according to a given distribution.""" imprecise fields according to a given distribution."""
from linking.intents cimport Intent from primo.linking.intents cimport Intent
from collections import Counter from collections import Counter
import random import random
include 'linking/constants.pxi' include 'primo/linking/constants.pxi'
# Explicit Intent imprecision counters. # Explicit Intent imprecision counters.
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.applications cimport Application from primo.linking.applications cimport Application
from linking.components cimport Component from primo.linking.components cimport Component
cdef class Intent(object): cdef class Intent(object):
cdef readonly unicode permission cdef readonly unicode permission
......
...@@ -16,21 +16,21 @@ ...@@ -16,21 +16,21 @@
# limitations under the License. # limitations under the License.
"""Class and factory for Intent.""" """Class and factory for Intent."""
from linking.applications cimport Application from primo.linking.applications cimport Application
from linking.components cimport Component from primo.linking.components cimport Component
from linking.intent_data cimport AddImpreciseIntent from primo.linking.intent_data cimport AddImpreciseIntent
from linking.intent_data cimport AddPreciseIntent from primo.linking.intent_data cimport AddPreciseIntent
from linking.target_data cimport GetTargetCountForValue from primo.linking.target_data cimport GetTargetCountForValue
from collections import Counter from collections import Counter
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
from linking.target_data import CLASS from primo.linking.target_data import CLASS
from linking.target_data import KIND from primo.linking.target_data import KIND
from linking.target_data import PACKAGE from primo.linking.target_data import PACKAGE
from linking.target_data import USED_PERMISSIONS from primo.linking.target_data import USED_PERMISSIONS
include 'linking/constants.pxi' include 'primo/linking/constants.pxi'
cdef dict _INTENT_COUNTERS = {ic3_data_pb2.ACTION: Counter(), cdef dict _INTENT_COUNTERS = {ic3_data_pb2.ACTION: Counter(),
......
...@@ -34,7 +34,7 @@ from matplotlib import rcParams ...@@ -34,7 +34,7 @@ from matplotlib import rcParams
import bloscpack as bp import bloscpack as bp
import numpy as np import numpy as np
from linking.write_results cimport Row from primo.linking.write_results cimport Row
FONT_SIZE = 22 FONT_SIZE = 22
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from linking.applications cimport Application from primo.linking.applications cimport Application
from linking.components cimport Component from primo.linking.components cimport Component
from linking.intent_filters cimport IntentFilter from primo.linking.intent_filters cimport IntentFilter
cdef void PrepareForQueries(set applications) cdef void PrepareForQueries(set applications)
cdef int GetExportedComponentCount(int kind, set search_space=?) cdef int GetExportedComponentCount(int kind, set search_space=?)
......
...@@ -23,10 +23,10 @@ DEF DYNAMIC_RECEIVER = 3 ...@@ -23,10 +23,10 @@ DEF DYNAMIC_RECEIVER = 3
from collections import Counter from collections import Counter
import logging import logging
from linking.attribute_matching cimport AttributeMap from primo.linking.attribute_matching cimport AttributeMap
from linking.util import Powerset from primo.linking.util import Powerset
from linking import ic3_data_pb2 from primo.linking import ic3_data_pb2
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
......
...@@ -20,20 +20,20 @@ Goodman-Kruskal's gamma.""" ...@@ -20,20 +20,20 @@ Goodman-Kruskal's gamma."""