Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipr Toolchain
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
Container Registry
Model registry
Operate
Environments
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
Open Source Software
Zipr Toolchain
Commits
4f46af7a
Commit
4f46af7a
authored
9 years ago
by
whh8b
Browse files
Options
Downloads
Patches
Plain Diff
Refactor GetPltCallTarget with better variable names.
Former-commit-id: def7ae0a1a02e311b821fda634ea38ed48dac9ca
parent
ad71105e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/hook_dynamic_call/hook_dynamic_calls.cpp
+58
-48
58 additions, 48 deletions
tools/hook_dynamic_call/hook_dynamic_calls.cpp
with
58 additions
and
48 deletions
tools/hook_dynamic_call/hook_dynamic_calls.cpp
+
58
−
48
View file @
4f46af7a
...
...
@@ -250,14 +250,22 @@ void HookDynamicCalls::SetToHook(map<string,int> to_hook)
m_to_hook
=
to_hook
;
}
/*
* TODO:
* We can rewrite this since when fix_calls changes
* a call to a push/jmp it already redirects through
* the @plt entry. In other words, the jmp points to
* the redirect and not to the name@plt.
* Got it? Thought so.
*/
bool
HookDynamicCalls
::
GetPltCallTarget
(
Instruction_t
*
insn
,
virtual_offset_t
&
target_addr
)
{
section
*
got_plt_section
=
NULL
;
Instruction_t
*
target
=
NULL
;
virtual_offset_t
target_target
=
0
;
string
target
_bits
;
Elf64_Addr
target_target_target
;
Elf64_Addr
target
;
Instruction_t
*
control_instruction
=
NULL
;
string
control_instruction
_bits
;
DISASM
d
;
LoadElf
();
got_plt_section
=
m_elfiop
->
sections
[
".got.plt"
];
...
...
@@ -276,13 +284,11 @@ bool HookDynamicCalls::GetPltCallTarget(Instruction_t *insn,
* Is this an instruction with a target?
* That's a must.
*/
if
(
!
(
target
=
insn
->
GetTarget
()))
if
(
!
(
control_instruction
=
insn
->
GetTarget
()))
return
false
;
/*
* a
*/
target_bits
=
target
->
GetDataBits
();
control_instruction_bits
=
control_instruction
->
GetDataBits
();
control_instruction
->
Disassemble
(
d
);
/*
* Determine the type of the operand
...
...
@@ -291,45 +297,54 @@ bool HookDynamicCalls::GetPltCallTarget(Instruction_t *insn,
*
* target_target: CALL_FIXED
*/
switch
((
uint8_t
)
target
_bits
[
0
])
switch
((
uint8_t
)
control_instruction
_bits
[
0
])
{
case
0xFF
:
target_target
=
*
((
uint32_t
*
)
&
target_bits
[
2
])
+
target_bits
.
length
();
break
;
{
virtual_offset_t
indirect_address
=
0
;
Elf64_Addr
dereferenced_indirect_address
;
/*
* Jmp indirect to an absolute address.
*/
cout
<<
"control instruction: "
<<
d
.
CompleteInstr
<<
endl
;
indirect_address
=
*
((
uint32_t
*
)
&
control_instruction_bits
[
2
])
+
control_instruction_bits
.
length
();
/*
* indirect_address contains the address
* of the target of control instruction,
* if one such exists.
*/
if
(
!
indirect_address
)
return
false
;
cout
<<
"indirect_address: 0x"
<<
std
::
hex
<<
indirect_address
<<
endl
;
/*
* Dereference the address at the target of the
* target to determine what /it/ points at.
* I.e., *CALL_FIXED
*/
dereferenced_indirect_address
=
ReadAddressInSectionAtOffset
(
got_plt_section
,
indirect_address
-
got_plt_section
->
get_address
());
cout
<<
"dereferenced_indirect_address: 0x"
<<
std
::
hex
<<
dereferenced_indirect_address
<<
endl
;
/*
* Subtract 0x6 since that is the offset
* from the start of the PLT entry to the
* so-called second half (which starts at L1)
*/
target_addr
=
dereferenced_indirect_address
-
0x6
;
return
true
;
}
default
:
cout
<<
"Not a handled control instruction opcode."
<<
endl
;
b
re
ak
;
re
turn
false
;
}
/*
* target_target contains the target of
* the target instruction, if one such
* exists.
*/
if
(
!
target_target
)
return
false
;
cout
<<
"target_target: 0x"
<<
std
::
hex
<<
target_target
<<
endl
;
/*
* Dereference the address at the target of the
* target to determine what /it/ points at.
* I.e., *CALL_FIXED
*/
target_target_target
=
ReadAddressInSectionAtOffset
(
got_plt_section
,
target_target
-
got_plt_section
->
get_address
());
cout
<<
"target_target_target: 0x"
<<
std
::
hex
<<
target_target_target
<<
endl
;
/*
* Subtract 0x6 since that is the offset
* from the start of the PLT entry to the
* so-called second half (which starts at L1)
*/
target_addr
=
target_target_target
-
0x6
;
return
true
;
return
false
;
}
int
HookDynamicCalls
::
execute
()
...
...
@@ -349,11 +364,6 @@ int HookDynamicCalls::execute()
{
Instruction_t
*
insn
=
*
it
;
virtual_offset_t
target
;
/*
* This is not quite done yet: Consider
* redirects that are rewritten as push/jmp
* combinations.
*/
if
(
GetPltCallTarget
(
insn
,
target
))
{
cout
<<
"target: "
<<
std
::
hex
<<
target
<<
endl
;
...
...
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