| 1 |
# ESSTRA Utility |
| 2 |
|
| 3 |
The ESSTRA Utility is a Python script for accessing metadata embedded in |
| 4 |
binary files by the ESSTRA Core. |
| 5 |
|
| 6 |
## Status of This Version |
| 7 |
|
| 8 |
The ESSTRA Utility is being developed on Ubuntu 22.04 with Python 3.10.12 |
| 9 |
installed on a x86\_64 PC. |
| 10 |
|
| 11 |
This version of the ESSTRA Utility includes features named `show`, `shrink`, |
| 12 |
`update` and `rm` as described below. |
| 13 |
|
| 14 |
Please note that the specifications and features of the ESSTRA Utility, the |
| 15 |
data formats and the content of the metadata, as well as the input/output |
| 16 |
specifications of each tool are tentative and may change in future versions. |
| 17 |
|
| 18 |
## Prerequisite |
| 19 |
|
| 20 |
Since the ESSTRA Utility depends on the [PyYAML](https://pyyaml.org/) |
| 21 |
module to handle YAML data, you may need to install it by typing: |
| 22 |
|
| 23 |
```sh |
| 24 |
$ pip install pyyaml |
| 25 |
or |
| 26 |
$ sudo apt install python3-yaml |
| 27 |
``` |
| 28 |
|
| 29 |
## How to Install |
| 30 |
|
| 31 |
To install `esstra` in `/usr/local/bin/`, type: |
| 32 |
|
| 33 |
```sh |
| 34 |
$ sudo make install |
| 35 |
``` |
| 36 |
|
| 37 |
Ensure that the environment variable `PATH` includes `/usr/local/bin/`. |
| 38 |
|
| 39 |
## How to Use |
| 40 |
|
| 41 |
The first argument of `esstra` is a *command*, and the second or subsequent |
| 42 |
arguments are the arguments for the *command*: |
| 43 |
|
| 44 |
```sh |
| 45 |
$ esstra <command> <arg> [<arg>...] |
| 46 |
``` |
| 47 |
|
| 48 |
Supported commands in this version are as follows: |
| 49 |
|
| 50 |
* `show`: outputs metadata in binary files |
| 51 |
* `shrink`: reduces the size of binary files by removing duplication in metadata |
| 52 |
* `update`: updates metadata in binary files by specifying additional information about the source files |
| 53 |
* `rm`: removes metadata from binary files |
| 54 |
|
| 55 |
## Command "show" |
| 56 |
|
| 57 |
A command line: |
| 58 |
|
| 59 |
```sh |
| 60 |
$ esstra show <binary> [<binary>...] |
| 61 |
``` |
| 62 |
|
| 63 |
outputs metadata embedded in the specified binary files in YAML format. |
| 64 |
For example, passing a binary file `hello` built from `hello.c` as in |
| 65 |
[Sample "hello"](../samples/hello/) to the command: |
| 66 |
|
| 67 |
```sh |
| 68 |
$ esstra show hello |
| 69 |
``` |
| 70 |
|
| 71 |
would give you an output as follows: |
| 72 |
|
| 73 |
```yaml |
| 74 |
# |
| 75 |
# BinaryFileName: hello |
| 76 |
# BinaryPath: /home/snagao/esstra/samples/hello/hello |
| 77 |
# |
| 78 |
Headers: |
| 79 |
ToolName: ESSTRA Core |
| 80 |
ToolVersion: 0.2.0 |
| 81 |
DataFormatVersion: 0.1.0 |
| 82 |
InputFileNames: |
| 83 |
- hello.c |
| 84 |
SourceFiles: |
| 85 |
- Directory: /home/snagao/esstra/samples/hello |
| 86 |
Files: |
| 87 |
- File: hello.c |
| 88 |
SHA1: 62592ce351eab2dfb75deb8c01101e07d6fe3c67 |
| 89 |
- Directory: /usr/include |
| 90 |
Files: |
| 91 |
- File: features-time64.h |
| 92 |
SHA1: 57c3c8093c3af70e5851f6d498600e2f6e24fdeb |
| 93 |
- File: features.h |
| 94 |
SHA1: d8725bb98129d6d70ddcbf010021c2841db783f7 |
| 95 |
- File: stdc-predef.h |
| 96 |
SHA1: 2fef05d80514ca0be77efec90bda051cf87d771f |
| 97 |
- File: stdio.h |
| 98 |
SHA1: c7181b48c4194cd122024971527aab4056baf600 |
| 99 |
: |
| 100 |
(snip) |
| 101 |
: |
| 102 |
``` |
| 103 |
|
| 104 |
Please note that the `show` command always displays [**shrunk**](#command-shrink) data even if |
| 105 |
the binary file's metadata itself is not shrunk. |
| 106 |
|
| 107 |
As the output of this command is in YAML format, you can parse it with any YAML |
| 108 |
processors. |
| 109 |
Below is an example of how to use the command |
| 110 |
[`yq`](https://mikefarah.gitbook.io/yq) with a pipe to convert the output to JSON: |
| 111 |
|
| 112 |
```sh |
| 113 |
$ esstra show hello | yq -oj |
| 114 |
{ |
| 115 |
"Headers": { |
| 116 |
"ToolName": "ESSTRA Core", |
| 117 |
"ToolVersion": "0.2.0", |
| 118 |
"DataFormatVersion": "0.1.0", |
| 119 |
"InputFileNames": [ |
| 120 |
"hello.c" |
| 121 |
] |
| 122 |
}, |
| 123 |
"SourceFiles": [ |
| 124 |
{ |
| 125 |
"Directory": "/home/snagao/esstra/samples/hello", |
| 126 |
"Files": [ |
| 127 |
{ |
| 128 |
"File": "hello.c", |
| 129 |
"SHA1": "62592ce351eab2dfb75deb8c01101e07d6fe3c67" |
| 130 |
} |
| 131 |
], |
| 132 |
"Directory": "/usr/include", |
| 133 |
"Files": [ |
| 134 |
{ |
| 135 |
"File": "features-time64.h", |
| 136 |
"SHA1": "57c3c8093c3af70e5851f6d498600e2f6e24fdeb" |
| 137 |
}, |
| 138 |
{ |
| 139 |
"File": "features.h", |
| 140 |
"SHA1": "d8725bb98129d6d70ddcbf010021c2841db783f7" |
| 141 |
}, |
| 142 |
{ |
| 143 |
"File": "stdc-predef.h", |
| 144 |
"SHA1": "2fef05d80514ca0be77efec90bda051cf87d771f" |
| 145 |
}, |
| 146 |
: |
| 147 |
(snip) |
| 148 |
: |
| 149 |
``` |
| 150 |
|
| 151 |
## Command "shrink" |
| 152 |
|
| 153 |
> [!NOTE] |
| 154 |
> We are planning to remove this command in future versions by using |
| 155 |
> technologies other than the GCC Plugin (possibly by using |
| 156 |
> [Linker Plugins](https://sourceware.org/binutils/docs/ld/Plugins.html)) |
| 157 |
> to automatically remove duplication in metadata without user intervention. |
| 158 |
|
| 159 |
The current version of the ESSTRA Core cannot avoid data duplication, which |
| 160 |
especially occurs when a binary file is built from two or more source files. |
| 161 |
|
| 162 |
The `shrink` command is meant to be used in such situations. It reduces the |
| 163 |
size of the binary files by removing duplication in the metadata: |
| 164 |
|
| 165 |
```sh |
| 166 |
$ esstra shrink <binary> [<binary> ...] |
| 167 |
``` |
| 168 |
|
| 169 |
For more details, refer to the case study document |
| 170 |
[Demo of ESSTRA Usage on OpenSSL Package](../doc/case-study/openssl.md). |
| 171 |
|
| 172 |
### Why duplication? |
| 173 |
|
| 174 |
Here is the answer to the question "Why does duplication occur?" |
| 175 |
In short, this arises from constraints of the mechanism of the GCC Plugin. |
| 176 |
|
| 177 |
First, the ESSTRA Core intervenes with GCC as a GCC plugin, gathers information about the source |
| 178 |
and header files involved in the current compilation process, and writes information from all |
| 179 |
those files into the object file as metadata. |
| 180 |
|
| 181 |
Then, when the linker finally combines the object files into a single binary file, the metadata |
| 182 |
in the individual object files is combined "as-is" in the binary file. |
| 183 |
|
| 184 |
However, GCC compiles each source file "independently," even if multiple source files are |
| 185 |
specified on the command line. This means that even if multiple source files are compiled to |
| 186 |
produce a single binary file, a GCC plugin during the compilation of one source file does not know |
| 187 |
the information during compilation of another source file. |
| 188 |
|
| 189 |
In software development, it is very common for a single binary file to be built from multiple |
| 190 |
source files, common header files are `#include`'d, and recursively common header files are |
| 191 |
`#include`'d. This ultimately results in duplication in metadata in binary files. |
| 192 |
|
| 193 |
To eliminate this duplication, the ESSTRA utility provides a `shrink` command. The command |
| 194 |
minimizes the size of binary files by removing duplication in the metadata and leaving only the |
| 195 |
necessary data. |
| 196 |
|
| 197 |
## Command "update" |
| 198 |
|
| 199 |
The `update` command in the current version attaches "license information" to |
| 200 |
each file's information in the binary files' metadata. |
| 201 |
|
| 202 |
We believe that other kinds of information could also be helpful, such as |
| 203 |
copyright information, CVE numbers and so on. |
| 204 |
Since ESSTRA is at an early stage in development, we have developed a feature |
| 205 |
that attaches license information as a sort of feasibility study. |
| 206 |
|
| 207 |
To attach license information, you need to prepare an |
| 208 |
[SPDX 2.3 tag-value](https://spdx.github.io/spdx-spec/v2.3/) file |
| 209 |
including `LicenseInfoInFile:` tags. |
| 210 |
Some license scanners like [FOSSology](https://fossology.github.io/) can |
| 211 |
generate such files. |
| 212 |
|
| 213 |
A typical usage is: |
| 214 |
|
| 215 |
```sh |
| 216 |
$ esstra update <binary> -i <spdx-tv-file> |
| 217 |
``` |
| 218 |
|
| 219 |
If you want to update two or binary files with two or more license information |
| 220 |
files at once, you can specify them all on the command line: |
| 221 |
|
| 222 |
```sh |
| 223 |
$ esstra update <binary> [<binary> ...] -i <spdx-tv-file> [<spdx-tv-file> ..] |
| 224 |
``` |
| 225 |
|
| 226 |
For more details on the `update` command, please refer to the document |
| 227 |
[Sample "hello2"](../samples/hello2/README.md). |
| 228 |
|
| 229 |
## Command "rm" |
| 230 |
|
| 231 |
The `rm` command completely removes metadata embedded in binary files by |
| 232 |
the ESSTRA Core during compilation: |
| 233 |
|
| 234 |
```sh |
| 235 |
$ esstra rm <binary> [<binary> ...] |
| 236 |
``` |
| 237 |
|
| 238 |
When a binary file with metadata removed is specified for the ESSTRA Utility, an |
| 239 |
error occurs as shown below: |
| 240 |
|
| 241 |
```sh |
| 242 |
$ esstra rm hello |
| 243 |
* processing 'hello'... |
| 244 |
* done. |
| 245 |
$ esstra show hello |
| 246 |
# |
| 247 |
# BinaryFileName: hello |
| 248 |
# |
| 249 |
Exception: RuntimeError("section not found: .'esstra") |
| 250 |
``` |
| 251 |
|
| 252 |
## How to uninstall |
| 253 |
|
| 254 |
To uninstall the ESSTRA Utility from your system, run the |
| 255 |
following command: |
| 256 |
|
| 257 |
```sh |
| 258 |
$ sudo make uninstall |
| 259 |
``` |
| 260 |
|
| 261 |
## License |
| 262 |
|
| 263 |
See the [LICENSE](../LICENSE) file. |