Changes
Page history
extend info related to compiling ASN.1 internal modules
authored
Feb 05, 2020
by
mich
Hide whitespace changes
Inline
Side-by-side
Compiling-asn1-specifications.md
View page @
5a8f7b13
...
@@ -134,14 +134,16 @@ A specific tool
...
@@ -134,14 +134,16 @@ A specific tool
[
tools/pycrate_asn1compile.py
](
https://github.com/p1sec/pycrate/blob/master/tools/pycrate_asn1compile.py
)
[
tools/pycrate_asn1compile.py
](
https://github.com/p1sec/pycrate/blob/master/tools/pycrate_asn1compile.py
)
is provided. Just requests its help to see how it works:
is provided. Just requests its help to see how it works:
$ ./tools/
pycrate_asn1compile.py
-
-h
elp
usage:
pycrate_asn1compile.py
[
-h
] [-s SPEC] [-i INPUT [INPUT ...]]
usage: pycrate_asn1compile.py [-h] [-i INPUT [INPUT ...]] [-o OUTPUT] [-j
]
[-o OUTPUT] [-j] [-fautotags] [-fextimpl
]
[-fautotags] [-fextimpl]
[-fverifwarn]
[-fverifwarn]
compile ASN.1 input file(s) for the pycrate ASN.1 runtime
compile ASN.1 input file(s) for the pycrate ASN.1 runtime
optional arguments:
optional arguments:
-h, --help show this help message and exit
-h, --help show this help message and exit
-s SPEC provide a specification shortname, instead of ASN.1
input file(s)
-i INPUT [INPUT ...] ASN.1 input file(s) or directory
-i INPUT [INPUT ...] ASN.1 input file(s) or directory
-o OUTPUT compiled output Python (and json) source file(s)
-o OUTPUT compiled output Python (and json) source file(s)
-j output a json file with information on ASN.1 objects
-j output a json file with information on ASN.1 objects
...
@@ -184,10 +186,35 @@ on the [ASN.1 runtime](./Using-the-pycrate-asn1-runtime):
...
@@ -184,10 +186,35 @@ on the [ASN.1 runtime](./Using-the-pycrate-asn1-runtime):
>>> import x2ap
>>> import x2ap
>>> # do whatever encodings / decodings you want with this generated module
>>> # do whatever encodings / decodings you want with this generated module
Another way to use the compiler is provided in order to recompile pycrate internal
ASN.1 modules. It corresponds to the
*-s*
option: using it trigger a recompilation
of the corresponding module within the pycrate_asn1dir sub-directory, producing both
python and json output file:
$ ./tools/pycrate_asn1compile.py -s RANAP
[proc] starting with ASN.1 specification: 3GPP_UTRAN_RANAP_25413
[proc] [RANAP-CommonDataTypes.asn] module RANAP-CommonDataTypes (oid: [0, 4, 0, 0, 20, 3, 0, 1, 3]): 8 ASN.1 assignments found
[proc] [RANAP-Constants.asn] module RANAP-Constants (oid: [0, 4, 0, 0, 20, 3, 0, 1, 4]): 370 ASN.1 assignments found
[proc] [RANAP-Containers.asn] module RANAP-Containers (oid: [0, 4, 0, 0, 20, 3, 0, 1, 5]): 15 ASN.1 assignments found
[proc] [RANAP-IEs.asn] module RANAP-IEs (oid: [0, 4, 0, 0, 20, 3, 0, 1, 2]): 507 ASN.1 assignments found
[proc] [RANAP-PDU-Contents.asn] module RANAP-PDU-Contents (oid: [0, 4, 0, 0, 20, 3, 0, 1, 1]): 401 ASN.1 assignments found
[proc] [RANAP-PDU-Descriptions.asn] module RANAP-PDU-Descriptions (oid: [0, 4, 0, 0, 20, 3, 0, 1, 0]): 60 ASN.1 assignments found
--- compilation cycle ---
--- verifications ---
[proc] ASN.1 modules processed: [u'RANAP-CommonDataTypes', u'RANAP-Constants', u'RANAP-Containers', u'RANAP-IEs', u'RANAP-PDU-Contents', u'RANAP-PDU-Descriptions']
[proc] ASN.1 objects compiled: 601 types, 336 sets, 418 values
[proc] done
/home/user/python/pycrate_asn1dir/RANAP.py file created
/home/user/python/pycrate_asn1dir/RANAP.json file created
In case you have installed pycrate system-wide, you will certainly need to run the
compiler as root, otherwise the produced files won't be allowed to be copied into
your system directory containing pycrate.
### the *pycrate_asn1c* modules
### the *pycrate_asn1c* modules
The ASN.1 compiler actually lies in the file
The ASN.1 compiler actually lies in the file
[
pycrate_asn1c/proc.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/proc.py
)
.
[
pycrate_asn1c/
asn
proc.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/
asn
proc.py
)
.
The function
*compile_text()*
takes a textual input containing ASN.1 module(s), or
The function
*compile_text()*
takes a textual input containing ASN.1 module(s), or
an iterable of textual inputs, and process them to build all the ASN.1 modules into a
an iterable of textual inputs, and process them to build all the ASN.1 modules into a
dictionnary in the global class called
*GLOBAL*
.
dictionnary in the global class called
*GLOBAL*
.
...
@@ -196,7 +223,7 @@ The compiler function can take specific keywords to force specific behaviours if
...
@@ -196,7 +223,7 @@ The compiler function can take specific keywords to force specific behaviours if
-
*autotags=True*
-
*autotags=True*
-
*extimpl=True*
-
*extimpl=True*
-
*verifwarn=True*
-
*verifwarn=True*
Those correspond
s
to the behaviours described in the help string returned by the
Those correspond to the behaviours described in the help string returned by the
*pycrate_asn1compile.py*
tool.
*pycrate_asn1compile.py*
tool.
Here is an example with the ASN.1 test file provided in the test directory:
Here is an example with the ASN.1 test file provided in the test directory:
...
@@ -256,21 +283,21 @@ file at the given destination:
...
@@ -256,21 +283,21 @@ file at the given destination:
### the *pycrate_asn1dir* directory
### the *pycrate_asn1dir* directory
Many ready-to-use ASN.1 modules are provided in the
Many ready-to-use ASN.1 modules are provided in the
[
pycrate_asn1dir/
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1dir/
)
[
pycrate_asn1dir/
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1dir/
)
directory. All ASN.1 definitions are placed in subdirectories, and corresponding
directory. All ASN.1 definitions are placed in sub
-
directories, and corresponding
Python and json source files are available directly there.
Python and json source files are available directly there.
The links between those subdirectories and Python and json files are set
The links between those sub
-
directories and Python and json files are set
in
[
pycrate_asn1c/specdir.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/specdir.py
)
.
in
[
pycrate_asn1c/specdir.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/specdir.py
)
.
It is possible to recompile a single ASN.1 specification, some of them, or
It is possible to recompile a single ASN.1 specification, some of them, or
all of them, with the
*generate_all()*
function in
all of them, with the
*generate_all()*
function in
[
pycrate_asn1c/proc.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/proc.py
)
.
[
pycrate_asn1c/proc.py
](
https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/proc.py
)
.
This function takes a dictionnary as argument, linking destination name to subdirectory name.
This function takes a dictionnary as argument, linking destination name to sub
-
directory name.
For instance,
`{'X2AP': '3GPP_EUTRAN_X2AP_36423', ...}`
.
For instance,
`{'X2AP': '3GPP_EUTRAN_X2AP_36423', ...}`
.
The default argument is the dictionnary
*ASN_SPECS*
from the
*specdir.py*
file.
The default argument is the dictionnary
*ASN_SPECS*
from the
*specdir.py*
file.
So, it is possible to add a subdirectory in this
*pycrate_asn1dir*
directory,
So, it is possible to add a sub
-
directory in this
*pycrate_asn1dir*
directory,
and a corresponding entry in the
*ASN_SPECS*
dictionnary. This will integrate the subdirectory
and a corresponding entry in the
*ASN_SPECS*
dictionnary. This will integrate the sub
-
directory
as part of the default ASN.1 modules in the pycrate library.
as part of the default ASN.1 modules in the pycrate library.
Finally, it is possible to launch a recompilation of all ASN.1 modules, as set in the
Finally, it is possible to launch a recompilation of all ASN.1 modules, as set in the
...
...
...
...