extend info related to compiling ASN.1 internal modules authored by mich's avatar mich
......@@ -134,14 +134,16 @@ A specific tool
[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:
$ ./tools/pycrate_asn1compile.py --help
usage: pycrate_asn1compile.py [-h] [-i INPUT [INPUT ...]] [-o OUTPUT] [-j]
[-fautotags] [-fextimpl] [-fverifwarn]
usage: pycrate_asn1compile.py [-h] [-s SPEC] [-i INPUT [INPUT ...]]
[-o OUTPUT] [-j] [-fautotags] [-fextimpl]
[-fverifwarn]
compile ASN.1 input file(s) for the pycrate ASN.1 runtime
optional arguments:
-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
-o OUTPUT compiled output Python (and json) source file(s)
-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):
>>> import x2ap
>>> # 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 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/asnproc.py](https://github.com/p1sec/pycrate/blob/master/pycrate_asn1c/asnproc.py).
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
dictionnary in the global class called *GLOBAL*.
......@@ -196,7 +223,7 @@ The compiler function can take specific keywords to force specific behaviours if
- *autotags=True*
- *extimpl=True*
- *verifwarn=True*
Those corresponds 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.
Here is an example with the ASN.1 test file provided in the test directory:
......@@ -256,21 +283,21 @@ file at the given destination:
### the *pycrate_asn1dir* directory
Many ready-to-use ASN.1 modules are provided in the
[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.
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).
It is possible to recompile a single ASN.1 specification, some of them, or
all of them, with the *generate_all()* function in
[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', ...}`.
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,
and a corresponding entry in the *ASN_SPECS* dictionnary. This will integrate the subdirectory
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 sub-directory
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
......
......