Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
elfio mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Third Party Mirrors
elfio mirror
Commits
e6c59547
Commit
e6c59547
authored
4 years ago
by
Serge Lamikhov-Center
Browse files
Options
Downloads
Patches
Plain Diff
Make 'writer' examples to generate x86_64 files
parent
64e6b2d7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
examples/write_obj/write_obj.cpp
+3
-3
3 additions, 3 deletions
examples/write_obj/write_obj.cpp
examples/writer/writer.cpp
+4
-4
4 additions, 4 deletions
examples/writer/writer.cpp
with
9 additions
and
7 deletions
.gitignore
+
2
−
0
View file @
e6c59547
...
...
@@ -44,6 +44,8 @@ tests/elf_examples/write_exe_i386_32_section_added
tests/elf_examples/ppc-32bit-testcopy*.elf
tests/elf_examples/null_section_inside_segment*
tests/elf_examples/segment_containing_no_section*
examples/writer/hello_x86_64
examples/write_obj/hello
# various unwanted files (backups, objects, cmake artifacts)
*~
...
...
This diff is collapsed.
Click to expand it.
examples/write_obj/write_obj.cpp
+
3
−
3
View file @
e6c59547
...
...
@@ -7,7 +7,7 @@
* 2. Execute result file write_obj
* ./write_obj
* 3. Link output file hello.o:
*
gcc -m32 -s -nostartfiles -nostdlib hello.o -
o hello
*
ld -m elf x64 -o hell
o hello
.o
* 4. Run the result file:
* ./hello
*/
...
...
@@ -21,11 +21,11 @@ int main( void )
elfio
writer
;
// You can't proceed before this function call!
writer
.
create
(
ELFCLASS
32
,
ELFDATA2LSB
);
writer
.
create
(
ELFCLASS
64
,
ELFDATA2LSB
);
writer
.
set_os_abi
(
ELFOSABI_LINUX
);
writer
.
set_type
(
ET_REL
);
writer
.
set_machine
(
EM_
3
86
);
writer
.
set_machine
(
EM_
X
86
_64
);
// This is our code
char
text
[]
=
{
'\xB8'
,
'\x04'
,
'\x00'
,
'\x00'
,
'\x00'
,
// mov eax, 4
...
...
This diff is collapsed.
Click to expand it.
examples/writer/writer.cpp
+
4
−
4
View file @
e6c59547
...
...
@@ -7,11 +7,11 @@ int main( void )
elfio
writer
;
// You can't proceed without this function call!
writer
.
create
(
ELFCLASS
32
,
ELFDATA2LSB
);
writer
.
create
(
ELFCLASS
64
,
ELFDATA2LSB
);
writer
.
set_os_abi
(
ELFOSABI_LINUX
);
writer
.
set_type
(
ET_EXEC
);
writer
.
set_machine
(
EM_
3
86
);
writer
.
set_machine
(
EM_
X
86
_64
);
// Create code section
section
*
text_sec
=
writer
.
sections
.
add
(
".text"
);
...
...
@@ -41,7 +41,7 @@ int main( void )
// Add code section into program segment
text_seg
->
add_section_index
(
text_sec
->
get_index
(),
text_sec
->
get_addr_align
()
);
// Create data section
*
// Create data section
section
*
data_sec
=
writer
.
sections
.
add
(
".data"
);
data_sec
->
set_type
(
SHT_PROGBITS
);
data_sec
->
set_flags
(
SHF_ALLOC
|
SHF_WRITE
);
...
...
@@ -77,7 +77,7 @@ int main( void )
writer
.
set_entry
(
0x08048000
);
// Create ELF file
writer
.
save
(
"hello_
i3
86_
32"
);
writer
.
save
(
"hello_
x
86_
64"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment