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

@@ -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