Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
a8f6db91
Commit
a8f6db91
authored
Sep 20, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a helper to loop over ELF load sections
parent
a0dd71ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
src/cc/bcc_elf.c
src/cc/bcc_elf.c
+35
-0
src/cc/bcc_elf.h
src/cc/bcc_elf.h
+6
-1
No files found.
src/cc/bcc_elf.c
View file @
a8f6db91
...
...
@@ -470,6 +470,41 @@ int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback,
path
,
callback
,
(
struct
bcc_symbol_option
*
)
option
,
payload
,
0
);
}
int
bcc_elf_foreach_load_section
(
const
char
*
path
,
bcc_elf_load_sectioncb
callback
,
void
*
payload
)
{
Elf
*
e
=
NULL
;
int
fd
=
-
1
,
err
=
-
1
,
res
;
size_t
nhdrs
,
i
;
if
(
openelf
(
path
,
&
e
,
&
fd
)
<
0
)
goto
exit
;
if
(
elf_getphdrnum
(
e
,
&
nhdrs
)
!=
0
)
goto
exit
;
GElf_Phdr
header
;
for
(
i
=
0
;
i
<
nhdrs
;
i
++
)
{
if
(
!
gelf_getphdr
(
e
,
(
int
)
i
,
&
header
))
continue
;
if
(
header
.
p_type
!=
PT_LOAD
||
!
(
header
.
p_flags
&
PF_X
))
continue
;
res
=
callback
(
header
.
p_vaddr
,
header
.
p_memsz
,
header
.
p_offset
,
payload
);
if
(
res
<
0
)
{
err
=
1
;
goto
exit
;
}
}
err
=
0
;
exit:
if
(
e
)
elf_end
(
e
);
if
(
fd
>=
0
)
close
(
fd
);
return
err
;
}
static
int
loadaddr
(
Elf
*
e
,
uint64_t
*
addr
)
{
size_t
phnum
,
i
;
...
...
src/cc/bcc_elf.h
View file @
a8f6db91
...
...
@@ -39,13 +39,18 @@ typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *,
// Callback returning a negative value indicates to stop the iteration
typedef
int
(
*
bcc_elf_symcb
)(
const
char
*
,
uint64_t
,
uint64_t
,
void
*
);
// Segment virtual address, memory size, file offset, payload
// Callback return
s
a negative value indicates to stop the iteration
// Callback return
ing
a negative value indicates to stop the iteration
typedef
int
(
*
bcc_elf_load_sectioncb
)(
uint64_t
,
uint64_t
,
uint64_t
,
void
*
);
// Iterate over all USDT probes noted in a binary module
// Returns -1 on error, and 0 on success
int
bcc_elf_foreach_usdt
(
const
char
*
path
,
bcc_elf_probecb
callback
,
void
*
payload
);
// Iterate over all executable load sections of an ELF
// Returns -1 on error, 1 if stopped by callback, and 0 on success
int
bcc_elf_foreach_load_section
(
const
char
*
path
,
bcc_elf_load_sectioncb
callback
,
void
*
payload
);
int
bcc_elf_loadaddr
(
const
char
*
path
,
uint64_t
*
address
);
// Iterate over symbol table of a binary module
// Parameter "option" points to a bcc_symbol_option struct to indicate wheather
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment