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