You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/readme.md
+27-23
Original file line number
Diff line number
Diff line change
@@ -2,44 +2,48 @@
2
2
3
3
This is the manual of LibObjectFile with the following API covered:
4
4
5
-
-[ELF Object File Format](#elf-object-file-format) via the `ElfObjectFile` API
5
+
-[ELF Object File Format](#elf-object-file-format) via the `ElfFile` API
6
6
-[Archive ar File Format](#archive-ar-file-format) via the `ArArchiveFile` API
7
+
-[PE File Format](#pe-object-file-format) via the `PEFile` API
7
8
8
9
## ELF Object File Format
9
10
10
11
### Overview
11
12
12
-
The main entry-point for reading/writing ELF Object file is the [`ElfObjectFile`](https://github.com/xoofx/LibObjectFile/blob/master/src/LibObjectFile/Elf/ElfObjectFile.cs) class.
13
+
The main entry-point for reading/writing ELF Object file is the [`ElfFile`](https://github.com/xoofx/LibObjectFile/blob/master/src/LibObjectFile/Elf/ElfFile.cs) class.
13
14
14
15
This class is the equivalent of the ELF Header and contains also sections and segments (program headers)
15
16
16
17

17
18
18
19
### ELF Reading
19
20
20
-
The ELF API allows to read from a `System.IO.Stream` via the method `ElfObjectFile.Read`:
21
+
The ELF API allows to read from a `System.IO.Stream` via the method `ElfFile.Read`:
21
22
22
23
```C#
23
-
ElfObjectFileelf=ElfObjectFile.Read(inputStream);
24
+
ElfFileelf=ElfFile.Read(inputStream);
24
25
```
25
26
26
27
### ELF Writing
27
28
28
29
You can create an ELF object in memory and save it to the disk:
29
30
30
31
```c#
31
-
varelf=newElfObjectFile();
32
+
varelf=newElfFile();
32
33
33
34
varcodeStream=newMemoryStream();
34
35
codeStream.Write(Encoding.UTF8.GetBytes("This is a text"));
You can print an object to a similar textual format than `readelf` by using the extension method `ElfObjectFile.Print(TextWriter)`:
56
+
You can print an object to a similar textual format than `readelf` by using the extension method `ElfFile.Print(TextWriter)`:
53
57
54
58
```c#
55
59
// Using the previous code to create an ELF with a code section
@@ -108,13 +112,13 @@ The `Print` is trying to follow `readelf` from as compiled on `Ubuntu 18.04`. It
108
112
109
113
#### Section Header String Table
110
114
111
-
When sections are added to an `ElfObjectFile.Sections`, it is required to store their names in a Section Header String Table (`.shstrtab`)
115
+
When sections are added to an `ElfFile.Sections`, it is required to store their names in a Section Header String Table (`.shstrtab`)
112
116
113
117
In that case, you need to add explicitly an `ElfSectionHeaderStringTable` to the sections:
114
118
115
119
```C#
116
120
// Always required if sections are added
117
-
elf.AddSection(newElfSectionHeaderStringTable());
121
+
elf.Add(newElfSectionHeaderStringTable());
118
122
```
119
123
120
124
This section can be put at any places in the sections, but is usually put at the end.
@@ -125,43 +129,43 @@ There is a type of section called `ElfShadowSection` which are only valid at run
125
129
126
130
A shadow section is used by an `ElfSegment` for which a region of data might not be associated with an existing section. In that case, you still want to associate data with the segment.
127
131
128
-
This is specially required when working with executable that don't have any sections but have only segments/program headers. In that case, `ElfObjectFile.Read` will create `ElfCustomShadowSection` for each part of the file that are being referenced by an `ElfSegment`.
132
+
This is specially required when working with executable that don't have any sections but have only segments/program headers. In that case, `ElfFile.Read` will create `ElfCustomShadowSection` for each part of the file that are being referenced by an `ElfSegment`.
129
133
130
134
#### Null section and Program Header Table
131
135
132
-
The null section `ElfNullSection` must be put as the first section of an `ElfObjectFile`. It is the default when creating an `ElfObjectFile`.
136
+
The null section `ElfNullSection` must be put as the first section of an `ElfFile`. It is the default when creating an `ElfFile`.
133
137
134
138
The Program Header Table is implemented as the `ElfProgramHeaderTable` shadow section and is added right after the `NullSection`. This is required because a segment of type `PHDR` will reference it while it is not an actual section in the original ELF file.
135
139
136
140
#### ELF Layout
137
141
138
-
An `ElfObjectFile` represents an ELF Object File in memory that can be freely modified. Unlike its serialized version on the disk, the offsets and size of the sections and segments references can be changed dynamically.
142
+
An `ElfFile` represents an ELF Object File in memory that can be freely modified. Unlike its serialized version on the disk, the offsets and size of the sections and segments references can be changed dynamically.
139
143
140
-
You can force the computation of the layout of an ELF object file before saving it to the disk by using the method `ElfObjectFile.UpdateLayout`:
144
+
You can force the computation of the layout of an ELF object file before saving it to the disk by using the method `ElfFile.UpdateLayout`:
141
145
142
146
```C#
143
-
ElfObjectFileelf=...;
147
+
ElfFileelf=...;
144
148
145
149
// Update layout (ObjectFile.Layout, all offsets of Sections and Segments)
146
150
elf.UpdateLayout();
147
151
148
152
foreach(varsectioninelf.Sections)
149
153
{
150
-
// Section.Offset is now calculated as it was on the disk
0 commit comments