CCSDS_study project

This commit is contained in:
2026-05-05 21:54:35 +08:00
commit 9be41f9270
585 changed files with 91275 additions and 0 deletions

View File

View File

@@ -0,0 +1,19 @@
from debian:latest
run yes y | apt-get update && yes y | apt-get upgrade
run yes y | apt-get install python python-dev
run yes y | apt-get install python-pip python-setuptools
run yes y | apt-get install python-babel python-sphinx
run yes y | apt-get install python-numpy python-pcapy
run yes y | apt-get install gcc make
run yes y | apt-get install git
run yes y | apt-get install ipython
workdir root
run git clone https://dev.netzob.org/git/netzob -b next
workdir netzob
run python setup.py build
run python setup.py develop
run python setup.py install
workdir /root
run mkdir -p /root/.ipython/profile_default/startup/
run echo "from netzob.all import *" > /root/.ipython/profile_default/startup/00_netzob.py
cmd /usr/bin/ipython

View File

@@ -0,0 +1,12 @@
# README
This is the official repository for the netzob project. You can learn more about it [here](https://github.com/netzob/netzob)
## Simple Examples
Here are simple example showing how to run netzob from a container:
- Simply load netzob: `docker run --rm -it netzob/netzob`
- Load netzob with your current directory mounted at /data: `docker run --rm -it -v $(pwd):/data netzob/netzob`
- Have a command line to be able to navigate into the system, look at the code, modify it: `docker run --rm -it netzob/netzob bash`

View File

@@ -0,0 +1,78 @@
[epydoc]
# Information about the project.
name: Netzob
url: http://www.netzob.org/
# Definition of the main package of Netzob
modules: netzob
# Generate HTML documentation in the doc/api directory
output: html
target: doc/api/
# An integer indicating how verbose epydoc should be. The default
# value is 0; negative values will supress warnings and errors;
# positive values will give more verbose output.
verbosity: 1
# A boolean value indicating that Epydoc should show a tracaback
# in case of unexpected error. By default don't show tracebacks
debug: 0
# If True, don't try to use colors or cursor control when doing
# textual output. The default False assumes a rich text prompt
simple-term: 1
### Generation options
# The default markup language for docstrings, for modules that do
# not define __docformat__. Defaults to epytext.
docformat: epytext
# Whether or not parsing should be used to examine objects.
parse: yes
# Whether or not introspection should be used to examine objects.
introspect: yes
# Don't examine in any way the modules whose dotted name match this
# regular expression pattern.
#exclude
# Don't perform introspection on the modules whose dotted name match this
# regular expression pattern.
#exclude-introspect
# Don't perform parsing on the modules whose dotted name match this
# regular expression pattern.
#exclude-parse
# The format for showing inheritance objects.
# It should be one of: 'grouped', 'listed', 'included'.
inheritance: listed
# Whether or not to inclue private variables. (Even if included,
# private variables will be hidden by default.)
private: yes
# Whether or not to list each module's imports.
imports: yes
# Whether or not to include syntax highlighted source code in
# the output (HTML only).
sourcecode: yes
# Whether or not to includea a page with Epydoc log, containing
# effective option at the time of generation and the reported logs.
include-log: no
frames: no
# Include all automatically generated graphs. These graphs are
# generated using Graphviz dot.
graph: all
dotpath: /usr/bin/dot

View File

@@ -0,0 +1,21 @@
#!/bin/sh
# Nettoyage des espaces en fin de ligne :
sed -i -e "s, *\$,,g" **/*.py
# Nettoyage des espaces devant deux points :
sed -i -e 's, :$,:,g' **/*.py
# Whitespaces after parenthesis (
sed -i -e 's,( ,(,g' **/*.py
sed -i -e 's,\[ ,\[,g' **/*.py
# Whitespaces before parenthesis )
sed -i -e 's, ),),g' **/*.py
sed -i -e 's, \],\],g' **/*.py
# Blank lines at the end of file
sed -i -e ":a" -e '/^\n*$/{$d;N;ba}'
# Deux espaces avant un inline comment
sed -i -re 's,([^ ]) #,\1 #,' **/*.py

View File

@@ -0,0 +1,17 @@
# python-coverage.conf
# Configuration file for the coverage analysis of Netzob
[run]
# Ensure branch coverage
branch = True
# Don't cover python standard lib
cover_pylib = False
source = src/netzob
[report]
ignore_errors = True
[html]
directory = coverage_html

View File

@@ -0,0 +1,273 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#+---------------------------------------------------------------------------+
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
#| |
#| Netzob : Inferring communication protocols |
#+---------------------------------------------------------------------------+
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
#| 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 3 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, see <http://www.gnu.org/licenses/>. |
#+---------------------------------------------------------------------------+
#| @url : http://www.netzob.org |
#| @contact : contact@netzob.org |
#| @sponsors : Amossys, http://www.amossys.fr |
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
#+---------------------------------------------------------------------------+
import os
import re
import sys
import subprocess
from git import *
ignore_files = [
"__init__.py",
"src/netzob/ExternalLibs/xdot.py",
"test/src/common/xmlrunner.py",
".*\.txt", ".*\.rst",
".*\.png", ".*\.ico",
".*\.xsd", ".*\.xml",
"resources/*",
".*\.pyc",
"MANIFEST\.in",
".*\.po", ".*\.pot",
"doc/netzob\.1",
"\.git/*",
".*/PKG-INFO",
".*/.*\.so",
]
def getFiles():
currentPath = os.getcwd()
# First we initialize the repository object
repository = Repo(currentPath)
listFile = []
repositoryIndex = repository.index
for d in repositoryIndex.diff('HEAD'):
# Added path
if d.deleted_file:
path = d.a_blob.path
if not path in listFile:
listFile.append(path)
elif not d.new_file:
path = d.a_blob.path
if not path in listFile:
listFile.append(path)
return listFile
def checkPEP8(file):
localResult = []
try:
p = subprocess.Popen(['pep8', '--repeat', '--ignore=E501', file], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
localResult.append(line)
return localResult
except Exception as e:
if str(e).find("[Errno 2] No such file or directory") != -1 :
print("[E] PEP8 is not installed.")
else:
print("[E] PEP8 does not work, it is probably not installed.\nThe error is : {0}".format(str(e)))
sys.exit(1)
def checkClassDeclation(file):
localResult = []
with open(file, 'rb') as f:
lineNumber = 0
for line in f:
m = re.search('class\s+[^\(]*:', line)
if m:
localResult.append("Old class definition found on {0}".format(m.group()))
return localResult
def searchForPattern(file, pattern, errorName):
localResult = []
fileObject = open(file)
lineNumber = 0
for line in fileObject:
lineNumber += 1
if re.search(pattern, line) and not re.search('Thisisnotaconflict', line):
localResult.append(str(errorName) + " found at line " + str(lineNumber))
fileObject.close()
return localResult
# Verifies only LF ('\n') ended files are committed (no CRLF '\r\n').
def checkForCRLF(file):
localResult = []
with open(file, 'rb') as f:
lineNumber = 0
for line in f:
lineNumber += 1
if line.endswith(b"\r\n"):
localResult.append("A CRLF ending patterns found at line " + str(lineNumber))
return localResult
def checkHeader(file):
header = """#+---------------------------------------------------------------------------+
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
#| |
#| Netzob : Inferring communication protocols |
#+---------------------------------------------------------------------------+
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
#| 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 3 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, see <http://www.gnu.org/licenses/>. |
#+---------------------------------------------------------------------------+
#| @url : http://www.netzob.org |
#| @contact : contact@netzob.org |
#| @sponsors : Amossys, http://www.amossys.fr |
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
#+---------------------------------------------------------------------------+"""
header2 = header.replace("#", "//") # For C files
header3 = header.replace("#", "") # For other
headerGlade = header3.replace("---------------------------------------------------------------------------", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") # For other
with open(file, 'rb') as f:
data = f.read()
if not header in data and not header2 in data and not header3 in data:
if file.startswith(os.path.join("src", "netzob_plugins")): # Plugin
headersPlugin = header.split("2011 Georges Bossert and Frédéric Guihéry |")
if headersPlugin[0] in data and headersPlugin[1] in data:
return []
return ["The header has not been found in file"]
return []
def checkFile(file):
results = dict()
if file.endswith("__init__.py"):
return results
if file.endswith(".pyc"):
return results
# Verify no '<<<' and or conflicts info are commited
results['Conflicts'] = searchForPattern(file, '<<<<<<', 'hints of untreated conflicts') # Thisisnotaconflict
for ignore in ignore_files:
if re.match(ignore, file):
return results
# Verify no CRLF is used in source
results['CRLF'] = checkForCRLF(file)
# Verify the header is valid
results['Header'] = checkHeader(file)
# Check against PEP8 rules for python files
if os.path.splitext(file)[-1] == ".py":
results['PEP8'] = checkPEP8(file)
results['Old Class'] = checkClassDeclation(file)
return results
def verifyResults(results):
result = 0
for f in list(results.keys()):
resultFile = results[f]
if len(resultFile) > 0:
ruleNames = list(resultFile.keys())
localResult = 0
errorForCurrentFile = []
for ruleName in ruleNames:
ruleErrors = resultFile[ruleName]
if ruleErrors is not None and len(ruleErrors) > 0:
for ruleError in ruleErrors:
errorForCurrentFile.append("[E]\t %s : %s" % (ruleName, ruleError))
result = 1
localResult = 1
if len(errorForCurrentFile) > 0:
print("[I] File %s:" % (f))
for err in errorForCurrentFile:
print(err)
return result
def analyze(providedFiles):
if providedFiles is None:
# Retrieve all the files to analyze
print("[I] Retrieve all the files to analyze from the staged area.")
tmp_files = getFiles()
files = []
# Filters directories which could appears in files due to submodules creation
# TODO : should be invastigated in details why this could happen
for f in tmp_files:
if os.path.isfile(f):
files.append(f)
else:
print("[I] Retrieve all the file to analyze from the command line arguments.")
filesToAnalyze = getFilesFromListOfPath(providedFiles)
files = []
for fileToAnalyze in filesToAnalyze:
if os.path.isfile(fileToAnalyze):
try:
test = open(fileToAnalyze)
test.close()
files.append(fileToAnalyze)
except:
print("[E] File %s exists but is not readable." % fileToAnalyze)
globalResults = dict()
for fileToAnalyze in files:
globalResults[fileToAnalyze] = checkFile(fileToAnalyze)
# Compute the final result (0=sucess, 1=cannot commit)
result = verifyResults(globalResults)
if result == 0:
print("[I] No error found, commit allowed.")
else:
print("[E] Errors founds, commit not allowed.")
sys.exit(result)
def getFilesFromListOfPath(paths):
result = []
for p in paths:
if os.path.isfile(p):
result.append(p)
elif os.path.isdir(p):
subfiles = os.listdir(p)
toAnalyze = []
for s in subfiles:
toAnalyze.append(os.path.join(p, s))
subfilesResult = getFilesFromListOfPath(toAnalyze)
result.extend(subfilesResult)
return result
if __name__ == '__main__':
filesToAnalyze = None
if (len(sys.argv) > 1):
filesToAnalyze = sys.argv[1:]
# Execute the analysis
analyze(filesToAnalyze)

View File

@@ -0,0 +1,310 @@
# lint Python modules using external checkers.
#
# This is the main checker controling the other ones and the reports
# generation. It is itself both a raw checker and an astng checker in order
# to:
# * handle message activation / deactivation at the module level
# * handle some basic but necessary stats'data (number of classes, methods...)
#
[MASTER]
# Specify a configuration file.
#rcfile=
# Profiled execution.
profile=no
# Add <file or directory> to the black list. It should be a base name, not a
# path. You may set this option multiple times.
ignore=.svn
# Pickle collected data for later comparisons.
persistent=yes
# Set the cache size for astng objects.
cache-size=500
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
[MESSAGES CONTROL]
# Disable following rules:
# C0301: line too long
# E0611: Gobject use introspection wich is incomptaible with pylint
# E1101: Used when a variable is accessed for a nonexistent member
# (not compatible with _getObjects())
# C0111: Missing docstring
# C0103: Invalid name "%s" (should match %s)
disable=R,C0301,E0611,E1101,C0111,C0103
# Enable only checker(s) with the given id(s). This option conflict with the
# disable-checker option
#enable-checker=
# Enable all checker(s) except those with the given id(s). This option conflict
# with the disable-checker option
#disable-checker=C0301
# Enable all messages in the listed categories.
#enable-msg-cat=
# Disable all messages in the listed categories.
#disable-msg-cat=C,R,W
# Enable the message(s) with the given id(s).
#enable-msg=W0311,W0511,W0611,W0613
#W0142,E0213,W0703,W0613,W0622,W0201,W0612,W0511,W0212
# Disable the message(s) with the given id(s).
#disable-msg=
[REPORTS]
# set the output format. Available formats are text, parseable, colorized and
# html
output-format=parseable
# Include message's id in output
include-ids=no
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no
# Tells wether to display a full report or only the messages
reports=yes
# Python expression which should return a note less than 10 (10 is the highest
# note).You have access to the variables errors warning, statement which
# respectivly contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (R0004).
#evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
# Add a comment according to your evaluation note. This is used by the global
# evaluation report (R0004).
comment=no
# Enable the report(s) with the given id(s).
#enable-report=
# Disable the report(s) with the given id(s).
#disable-report=
# checks for
# * unused variables / imports
# * undefined variables
# * redefinition of variable from builtins or from an outer scope
# * use of variable before assigment
#
[VARIABLES]
# Tells wether we should check for unused import in __init__ files.
init-import=no
# A regular expression matching names used for dummy variables (i.e. not used).
dummy-variables-rgx=_|dummy
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
# try to find bugs in the code using type inference
#
[TYPECHECK]
# Tells wether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes
# When zope mode is activated, consider the acquired-members option to ignore
# access to some undefined attributes.
zope=no
# List of members which are usually get through zope's acquisition mecanism and
# so shouldn't trigger E0201 when accessed (need zope=yes to be considered).
acquired-members=REQUEST,acl_users,aq_parent
# checks for :
# * doc strings
# * modules / classes / functions / methods / arguments / variables name
# * number of arguments, local variables, branchs, returns and statements in
# functions, methods
# * required module attributes
# * dangerous default values as arguments
# * redefinition of function / method / class
# * uses of the global statement
#
[BASIC]
# Required attributes for module, separated by a comma
required-attributes=
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=__.*__
# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z1-9_]*)|(__.*__))$
# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$
# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-zA-Z0-9_]{2,30}$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-zA-Z0-9_]{2,30}$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-zA-Z0-9_]{2,30}$
# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-zA-Z0-9_]{1,30}$
# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
# List of builtins function names that should not be used, separated by a comma
bad-functions=apply,input
# checks for sign of poor/misdesign:
# * number of methods, attributes, local variables...
# * size, complexity of functions, methods
#
[DESIGN]
# Maximum number of arguments for function / method
max-args=12
# Maximum number of locals for function / method body
max-locals=30
# Maximum number of return / yield for function / method body
max-returns=12
# Maximum number of branch for function / method body
max-branchs=30
# Maximum number of statements in function / method body
max-statements=60
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of attributes for a class (see R0902).
max-attributes=20
# Minimum number of public methods for a class (see R0903).
min-public-methods=0
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
# checks for
# * external modules dependencies
# * relative / wildcard imports
# * cyclic imports
# * uses of deprecated modules
#
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report R0402 must not be disabled)
import-graph=
# Create a graph of external dependencies in the given file (report R0402 must
# not be disabled)
ext-import-graph=
# Create a graph of internal dependencies in the given file (report R0402 must
# not be disabled)
int-import-graph=
# checks for :
# * methods without self as first argument
# * overridden methods signature
# * access only to existant members via self
# * attributes not defined in the __init__ method
# * supported interfaces implementation
# * unreachable code
#
[CLASSES]
# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
# checks for similarities and duplicated code. This computation may be
# memory / CPU intensive, so you should disable it if you experiments some
# problems.
#
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=10
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
# checks for:
# * warning notes in the code like FIXME, XXX
# * PEP 263: source code with non ascii character but no encoding declaration
#
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# checks for :
# * unauthorized constructions
# * strict indentation
# * line length
# * use of <> instead of !=
#
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=90
# Maximum number of lines in a module
max-module-lines=1000
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=' '

View File

@@ -0,0 +1,10 @@
# This configuration file *MUST* be copied on Neyzob's root path (next to setup.py)
# before its usage.
[tox]
envlist = py26,py27,py30,py30,py31,py32
[testenv]
commands =
python setup.py install
python setup.py test

View File

View File

@@ -0,0 +1,146 @@
# -*- coding: utf-8 -*-
# vim: sw=4 ts=4 fenc=utf-8
# =============================================================================
# $Id$
# =============================================================================
# $URL$
# $LastChangedDate$
# $Rev$
# $LastChangedBy$
# =============================================================================
# Copyright (C) 2006 Ufsoft.org - Pedro Algarvio <ufs@ufsoft.org>
#
# Please view LICENSE for additional licensing information.
#
# Copyright (C) 2007 Unfinished Software, UfSoft.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# =============================================================================
from xml.parsers import expat
__all__ = ['extract_glade']
class ParseError(Exception):
pass
class GladeParser(object):
def __init__(self, source):
self.source = source
parser = expat.ParserCreate()
parser.buffer_text = True
parser.returns_unicode = True
parser.ordered_attributes = True
parser.StartElementHandler = self._handle_start
parser.EndElementHandler = self._handle_end
parser.CharacterDataHandler = self._handle_data
if not hasattr(parser, 'CurrentLineNumber'):
self._getpos = self._getpos_unknown
self.expat = parser
self._queue = []
self._comments = []
self._translate = False
self._data = []
def parse(self):
try:
bufsize = 4 * 1024 # 4K
done = False
while not done and len(self._queue) == 0:
data = self.source.read(bufsize)
if data == '': # end of data
if hasattr(self, 'expat'):
self.expat.Parse('', True)
del self.expat # get rid of circular references
done = True
else:
if isinstance(data, str):
data = data.encode('utf-8')
self.expat.Parse(data, False)
for event in self._queue:
yield event
self._queue = []
if done:
break
except expat.ExpatError as e:
raise ParseError(str(e))
def _handle_start(self, tag, attrib):
if 'translatable' in attrib:
if attrib[attrib.index('translatable')+1] == 'yes':
self._translate = True
if 'comments' in attrib:
self._comments.append(attrib[attrib.index('comments')+1])
def _handle_end(self, tag):
if self._translate is True:
if self._data:
self._enqueue(tag, self._data, self._comments)
self._translate = False
self._data = []
self._comments = []
def _handle_data(self, text):
if self._translate:
if not text.startswith('gtk-'):
self._data.append(text)
else:
self._translate = False
self._data = []
self._comments = []
def _enqueue(self, kind, data=None, comments=None, pos=None):
if pos is None:
pos = self._getpos()
if kind in ('property', 'property', 'col', 'col', 'item', 'item'):
if '\n' in data:
lines = data.splitlines()
lineno = pos[0] - len(lines) + 1
offset = -1
else:
lineno = pos[0]
offset = pos[1] - len(data)
pos = (lineno, offset)
self._queue.append((data, comments, pos[0]))
def _getpos(self):
return (self.expat.CurrentLineNumber,
self.expat.CurrentColumnNumber)
def _getpos_unknown(self):
return (-1, -1)
def extract_glade(fileobj, keywords, comment_tags, options):
parser = GladeParser(fileobj)
for message, comments, lineno in parser.parse():
yield (lineno, None, message, comment_tags and comments or [])

View File

@@ -0,0 +1,169 @@
# -*- coding: utf-8 -*-
#+---------------------------------------------------------------------------+
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
#| |
#| Netzob : Inferring communication protocols |
#+---------------------------------------------------------------------------+
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
#| 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 3 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, see <http://www.gnu.org/licenses/>. |
#+---------------------------------------------------------------------------+
#| @url : http://www.netzob.org |
#| @contact : contact@netzob.org |
#| @sponsors : Amossys, http://www.amossys.fr |
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
#+---------------------------------------------------------------------------+
#+---------------------------------------------------------------------------+
#| Inspiration was taken from Andi Albrecht solution
#+---------------------------------------------------------------------------+
#+----------------------------------------------------------------------------
#| Global Imports
#+----------------------------------------------------------------------------
from distutils.command.build import build
from distutils.core import Command
from distutils.errors import DistutilsOptionError
import optparse
import datetime
#+---------------------------------------------------------------------------+
#| manpage_command:
#| generates the man page for Netzob
#+---------------------------------------------------------------------------+
class manpage_command(Command):
description = "Generates Netzob's man page"
user_options = [
('output=', 'O', 'output file'),
('parser=', None, 'module path to optparser (e.g. mymod:func'),
]
def initialize_options(self):
self.output = None
self.parser = None
def configureCommandLine(self):
"""Retrieve and instantiate Netzob's CommandLine manager
in order to get its usage"""
# First we find the commandLine class (its name is provided through setup.cfg)
mod_name, class_name = self.parser.split(':')
fromlist = mod_name.split('.')
try:
mod = __import__(mod_name, fromlist=fromlist)
cmdLineClass = getattr(mod, class_name)
# Instantiate the retrieved class
cmdLine = cmdLineClass()
self._parser = cmdLine.getConfiguredParser()
except ImportError as err:
raise
def finalize_options(self):
if self.output is None:
raise DistutilsOptionError('\'output\' option is required')
if self.parser is None:
raise DistutilsOptionError('\'parser\' option is required')
self.configureCommandLine()
self._parser.formatter = ManPageFormatter()
self._parser.formatter.set_parser(self._parser)
self.announce('Writing man page %s' % self.output)
self._today = datetime.date.today()
def _markup(self, txt):
return txt.replace('-', '\\-')
def _write_header(self):
appname = self.distribution.get_name()
ret = []
ret.append('.TH %s 1 %s\n' % (self._markup(appname),
self._today.strftime('%Y\\-%m\\-%d')))
description = self.distribution.get_description()
if description:
name = self._markup('%s - %s' % (self._markup(appname),
description.splitlines()[0]))
else:
name = self._markup(appname)
ret.append('.SH NAME\n%s\n' % name)
synopsis = self._parser.get_usage()
if synopsis:
synopsis = synopsis.replace('%s ' % appname, '')
ret.append('.SH SYNOPSIS\n.B %s\n%s\n' % (self._markup(appname),
synopsis))
long_desc = self.distribution.get_long_description()
if long_desc:
ret.append('.SH DESCRIPTION\n%s\n' % self._markup(long_desc))
return ''.join(ret)
def _write_options(self):
ret = ['.SH OPTIONS\n']
ret.append(self._parser.format_option_help())
return ''.join(ret)
def _write_footer(self):
ret = []
appname = self.distribution.get_name()
author = '%s <%s>' % (self.distribution.get_author(),
self.distribution.get_author_email())
ret.append(('.SH AUTHORS\n.B %s\nwas written by %s.\n'
% (self._markup(appname), self._markup(author))))
homepage = self.distribution.get_url()
ret.append(('.SH DISTRIBUTION\nThe latest version of %s may '
'be downloaded from\n'
'.UR %s\n.UE\n'
% (self._markup(appname), self._markup(homepage),)))
return ''.join(ret)
def run(self):
manpage = []
manpage.append(self._write_header())
manpage.append(self._write_options())
manpage.append(self._write_footer())
stream = open(self.output, 'w')
stream.write(''.join(manpage))
stream.close()
class ManPageFormatter(optparse.HelpFormatter):
def __init__(self,
indent_increment=2,
max_help_position=24,
width=None,
short_first=1):
optparse.HelpFormatter.__init__(self, indent_increment,
max_help_position, width, short_first)
def _markup(self, txt):
return txt.replace('-', '\\-')
def format_usage(self, usage):
return self._markup(usage)
def format_heading(self, heading):
if self.level == 0:
return ''
return '.TP\n%s\n' % self._markup(heading.upper())
def format_option(self, option):
result = []
opts = self.option_strings[option]
result.append('.TP\n.B %s\n' % self._markup(opts))
if option.help:
help_text = '%s\n' % self._markup(self.expand_default(option))
result.append(help_text)
return ''.join(result)
build.sub_commands.append(('build_manpage', None))

View File

@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
#+---------------------------------------------------------------------------+
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
#| |
#| Netzob : Inferring communication protocols |
#+---------------------------------------------------------------------------+
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
#| 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 3 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, see <http://www.gnu.org/licenses/>. |
#+---------------------------------------------------------------------------+
#| @url : http://www.netzob.org |
#| @contact : contact@netzob.org |
#| @sponsors : Amossys, http://www.amossys.fr |
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
#+---------------------------------------------------------------------------+
#+----------------------------------------------------------------------------
#| Global Imports
#+----------------------------------------------------------------------------
from distutils.core import Command
import os
import sys
import unittest
class test_command(Command):
description = "Test Netzob"
user_options = [('reportfile=', None, 'name of the generated XML report file (not required)') ]
def initialize_options(self):
self.reportfile = None
self._dir = os.getcwd()
def finalize_options(self):
pass
def run(self):
'''
Finds all the tests modules in test/, and runs them.
'''
sys.path.insert(0, 'src/')
#insert in the path the directory where _libNeedleman.pyd is
if os.name == 'nt':
sys.path.insert(0, 'lib/libNeedleman/')
try:
# Verify that libNeedleman is in the path
from netzob import _libNeedleman
except:
# Else, assume the path is gotten from the 'python setup.py build' command
arch = os.uname()[-1]
python_version = sys.version[:3]
build_lib_path = "build/lib.linux-" + arch + "-" + python_version
sys.path.append(build_lib_path)
sys.path.insert(0, 'test/src/')
from common.xmlrunner import XMLTestRunner
from test_netzob import suite_global
#import netzob.NetzobGui as NetzobGui
# We retrieve the current test suite
currentTestSuite = suite_global.getSuite()
testResults = None
if self.reportfile is None or len(self.reportfile) == 0:
runner = unittest.TextTestRunner(verbosity = 1)
testResults = runner.run(currentTestSuite)
else:
# We execute the test suite
with open(self.reportfile, 'w') as fd:
fd.write('<?xml version="1.0" encoding="utf-8"?>\n')
reporter = XMLTestRunner(fd)
testResults = reporter.run(currentTestSuite)
self.cleanFile(self.reportfile)
if testResults is None:
sys.exit(False)
else:
sys.exit(bool(testResults.failures))
def cleanFile(self, filePath):
"""Clean the file to handle non-UTF8 bytes.
"""
with open(filePath, 'r') as aFile:
data = aFile.read()
cleanData = ""
for c in data:
if (0x1f < ord(c) < 0x80) or (ord(c) == 0x9) or (ord(c) == 0xa) or (ord(c) == 0xd):
cleanData += c
else:
cleanData += repr(c)
with open(filePath, 'w') as aFile:
aFile.write(cleanData)

View File

@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*-
#+---------------------------------------------------------------------------+
#| 01001110 01100101 01110100 01111010 01101111 01100010 |
#| |
#| Netzob : Inferring communication protocols |
#+---------------------------------------------------------------------------+
#| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
#| 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 3 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, see <http://www.gnu.org/licenses/>. |
#+---------------------------------------------------------------------------+
#| @url : http://www.netzob.org |
#| @contact : contact@netzob.org |
#| @sponsors : Amossys, http://www.amossys.fr |
#| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
#+---------------------------------------------------------------------------+
#+----------------------------------------------------------------------------
#| Global Imports
#+----------------------------------------------------------------------------
from glob import glob
import os
from fnmatch import fnmatch
def opj(*args):
path = os.path.join(*args)
return os.path.normpath(path)
def find_data_files(dstdir, srcdir, *wildcards, **kw):
"""Build a mapping of merge path and local files to put in
data_files argument of setup() call"""
# get a list of all files under the srcdir matching wildcards,
# returned in a format to be used for install_data
def walk_helper(arg, dirname, files):
if '.git' in dirname:
return
names = []
(lst,) = arg
for wc in wildcards:
wc_name = opj(dirname, wc)
for f in files:
filename = opj(dirname, f)
if fnmatch(filename, wc_name) and not os.path.isdir(filename):
names.append(filename)
lst.append((dirname.replace(srcdir, dstdir), names))
file_list = []
if kw.get('recursive', True):
os.walk(srcdir, walk_helper, (file_list,))
else:
walk_helper((file_list,), srcdir,
[os.path.basename(f) for f in glob(opj(srcdir, '*'))])
return file_list
def getPluginPaths():
"""getPluginPaths:
Computes and returns the path of all available plugins in the current repository.
@return a dictionary mapping the plugin name and with its root path"""
result = dict() #{pluginName:pluginPath}
pluginsSourcePath = opj(os.getcwd(), "src", "netzob_plugins")
# Available Plugin categories
plugin_categories = [] #["Clustering", "Capturers", "Importers", "Exporters", "RelationsIdentifier"]
# Find plugins in
for plugin_category in plugin_categories:
plugin_dir = opj(pluginsSourcePath, plugin_category)
plugin_list = os.listdir(plugin_dir)
for plugin_name in plugin_list:
if plugin_name != "__init__.py" and plugin_name != "__init__.pyc":
result[plugin_name] = opj(plugin_dir, plugin_name)
return result