File: README.md

package info (click to toggle)
esstra 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,872 kB
  • sloc: ansic: 2,615; python: 510; cpp: 247; makefile: 113; sh: 3
file content (263 lines) | stat: -rw-r--r-- 7,692 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# ESSTRA Utility

The ESSTRA Utility is a Python script for accessing metadata embedded in
binary files by the ESSTRA Core.

## Status of This Version

The ESSTRA Utility is being developed on Ubuntu 22.04 with Python 3.10.12
installed on a x86\_64 PC.

This version of the ESSTRA Utility includes features named `show`, `shrink`,
`update` and `rm` as described below.

Please note that the specifications and features of the ESSTRA Utility, the
data formats and the content of the metadata, as well as the input/output
specifications of each tool are tentative and may change in future versions.

## Prerequisite

Since the ESSTRA Utility depends on the [PyYAML](https://pyyaml.org/)
module to handle YAML data, you may need to install it by typing:

```sh
$ pip install pyyaml
or
$ sudo apt install python3-yaml
```

## How to Install

To install `esstra` in `/usr/local/bin/`, type:

```sh
$ sudo make install
```

Ensure that the environment variable `PATH` includes `/usr/local/bin/`.

## How to Use

The first argument of `esstra` is a *command*, and the second or subsequent
arguments are the arguments for the *command*:

```sh
$ esstra <command> <arg> [<arg>...]
```

Supported commands in this version are as follows:

* `show`: outputs metadata in binary files
* `shrink`: reduces the size of binary files by removing duplication in metadata
* `update`: updates metadata in binary files by specifying additional information about the source files
* `rm`: removes metadata from binary files

## Command "show"

A command line:

```sh
$ esstra show <binary> [<binary>...]
```

outputs metadata embedded in the specified binary files in YAML format.
For example, passing a binary file `hello` built from `hello.c` as in
[Sample "hello"](../samples/hello/) to the command:

```sh
$ esstra show hello
```

would give you an output as follows:

```yaml
#
# BinaryFileName: hello
# BinaryPath: /home/snagao/esstra/samples/hello/hello
#
Headers:
  ToolName: ESSTRA Core
  ToolVersion: 0.2.0
  DataFormatVersion: 0.1.0
  InputFileNames:
  - hello.c
SourceFiles:
- Directory: /home/snagao/esstra/samples/hello
  Files:
  - File: hello.c
    SHA1: 62592ce351eab2dfb75deb8c01101e07d6fe3c67
- Directory: /usr/include
  Files:
  - File: features-time64.h
    SHA1: 57c3c8093c3af70e5851f6d498600e2f6e24fdeb
  - File: features.h
    SHA1: d8725bb98129d6d70ddcbf010021c2841db783f7
  - File: stdc-predef.h
    SHA1: 2fef05d80514ca0be77efec90bda051cf87d771f
  - File: stdio.h
    SHA1: c7181b48c4194cd122024971527aab4056baf600
          :
        (snip)
          :
```

Please note that the `show` command always displays [**shrunk**](#command-shrink) data even if
the binary file's metadata itself is not shrunk.

As the output of this command is in YAML format, you can parse it with any YAML
processors.
Below is an example of how to use the command
[`yq`](https://mikefarah.gitbook.io/yq) with a pipe to convert the output to JSON:

```sh
$ esstra show hello | yq -oj
{
  "Headers": {
    "ToolName": "ESSTRA Core",
    "ToolVersion": "0.2.0",
    "DataFormatVersion": "0.1.0",
    "InputFileNames": [
      "hello.c"
    ]
  },
  "SourceFiles": [
    {
      "Directory": "/home/snagao/esstra/samples/hello",
      "Files": [
        {
          "File": "hello.c",
          "SHA1": "62592ce351eab2dfb75deb8c01101e07d6fe3c67"
        }
      ],
      "Directory": "/usr/include",
      "Files": [
        {
          "File": "features-time64.h",
          "SHA1": "57c3c8093c3af70e5851f6d498600e2f6e24fdeb"
        },
        {
          "File": "features.h",
          "SHA1": "d8725bb98129d6d70ddcbf010021c2841db783f7"
        },
        {
          "File": "stdc-predef.h",
          "SHA1": "2fef05d80514ca0be77efec90bda051cf87d771f"
        },
            :
          (snip)
            :
```

## Command "shrink"

> [!NOTE]
> We are planning to remove this command in future versions by using
> technologies other than the GCC Plugin (possibly by using
> [Linker Plugins](https://sourceware.org/binutils/docs/ld/Plugins.html))
> to automatically remove duplication in metadata without user intervention.

The current version of the ESSTRA Core cannot avoid data duplication, which
especially occurs when a binary file is built from two or more source files.

The `shrink` command is meant to be used in such situations. It reduces the
size of the binary files by removing duplication in the metadata:

```sh
$ esstra shrink <binary> [<binary> ...]
```

For more details, refer to the case study document
[Demo of ESSTRA Usage on OpenSSL Package](../doc/case-study/openssl.md).

### Why duplication?

Here is the answer to the question "Why does duplication occur?"
In short, this arises from constraints of the mechanism of the GCC Plugin.

First, the ESSTRA Core intervenes with GCC as a GCC plugin, gathers information about the source
and header files involved in the current compilation process, and writes information from all
those files into the object file as metadata.

Then, when the linker finally combines the object files into a single binary file, the metadata
in the individual object files is combined "as-is" in the binary file.

However, GCC compiles each source file "independently," even if multiple source files are
specified on the command line. This means that even if multiple source files are compiled to
produce a single binary file, a GCC plugin during the compilation of one source file does not know
the information during compilation of another source file.

In software development, it is very common for a single binary file to be built from multiple
source files, common header files are `#include`'d, and recursively common header files are
`#include`'d. This ultimately results in duplication in metadata in binary files.

To eliminate this duplication, the ESSTRA utility provides a `shrink` command. The command
minimizes the size of binary files by removing duplication in the metadata and leaving only the
necessary data.

## Command "update"

The `update` command in the current version attaches "license information" to
each file's information in the binary files' metadata.

We believe that other kinds of information could also be helpful, such as
copyright information, CVE numbers and so on.
Since ESSTRA is at an early stage in development, we have developed a feature
that attaches license information as a sort of feasibility study.

To attach license information, you need to prepare an
[SPDX 2.3 tag-value](https://spdx.github.io/spdx-spec/v2.3/) file
including `LicenseInfoInFile:` tags.
Some license scanners like [FOSSology](https://fossology.github.io/) can
generate such files.

A typical usage is:

```sh
$ esstra update <binary> -i <spdx-tv-file>
```

If you want to update two or binary files with two or more license information
files at once, you can specify them all on the command line:

```sh
$ esstra update <binary> [<binary> ...] -i <spdx-tv-file> [<spdx-tv-file> ..]
```

For more details on the `update` command, please refer to the document
[Sample "hello2"](../samples/hello2/README.md).

## Command "rm"

The `rm` command completely removes metadata embedded in binary files by
the ESSTRA Core during compilation:

```sh
$ esstra rm <binary> [<binary> ...]
```

When a binary file with metadata removed is specified for the ESSTRA Utility, an
error occurs as shown below:

```sh
$ esstra rm hello
* processing 'hello'...
* done.
$ esstra show hello
#
# BinaryFileName: hello
#
Exception: RuntimeError("section not found: .'esstra")
```

## How to uninstall

To uninstall the ESSTRA Utility from your system, run the
following command:

```sh
$ sudo make uninstall
```

## License

See the [LICENSE](../LICENSE) file.