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
bf48f2a9
Commit
bf48f2a9
authored
6 years ago
by
Jason Hiser
Browse files
Options
Downloads
Patches
Plain Diff
changed to use libtransform::insertAssembly...
Former-commit-id: 0f9ce47988c9f3b8b02d06baf5d1404653a874de
parent
1e5fabc3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libtransform/include/transform.hpp
+2
-0
2 additions, 0 deletions
libtransform/include/transform.hpp
libtransform/src/transform.cpp
+10
-0
10 additions, 0 deletions
libtransform/src/transform.cpp
tools/hook_start/hook_start.cpp
+40
-40
40 additions, 40 deletions
tools/hook_start/hook_start.cpp
with
52 additions
and
40 deletions
libtransform/include/transform.hpp
+
2
−
0
View file @
bf48f2a9
...
...
@@ -52,6 +52,8 @@ class Transform {
void
addCallbackHandler64
(
Instruction_t
*
p_instr
,
string
p_callbackHandler
,
int
p_numArgs
);
void
addInstruction
(
Instruction_t
*
p_instr
,
string
p_dataBits
,
Instruction_t
*
p_fallThrough
,
Instruction_t
*
p_target
);
Instruction_t
*
carefullyInsertBefore
(
Instruction_t
*
&
p_target
,
Instruction_t
*
&
p_new
);
Instruction_t
*
insertAssemblyBefore
(
Instruction_t
*
before
,
const
string
&
the_asm
,
Instruction_t
*
target
=
nullptr
);
Instruction_t
*
insertAssemblyAfter
(
Instruction_t
*
after
,
const
string
&
the_asm
,
Instruction_t
*
target
=
nullptr
);
void
addPushRegister
(
Instruction_t
*
p_instr
,
RegisterName
,
Instruction_t
*
p_fallThrough
);
void
addPopRegister
(
Instruction_t
*
p_instr
,
RegisterName
,
Instruction_t
*
p_fallThrough
);
...
...
This diff is collapsed.
Click to expand it.
libtransform/src/transform.cpp
+
10
−
0
View file @
bf48f2a9
...
...
@@ -121,6 +121,16 @@ cerr << "(2) carefullyInsertBefore: @: 0x" << std::hex << p_instrumented->GetAdd
#endif
}
Instruction_t
*
Transform
::
insertAssemblyBefore
(
Instruction_t
*
before
,
const
string
&
the_asm
,
Instruction_t
*
target
)
{
return
IRDBUtility
::
insertAssemblyBefore
(
getFileIR
(),
before
,
the_asm
,
target
);
}
Instruction_t
*
Transform
::
insertAssemblyAfter
(
Instruction_t
*
before
,
const
string
&
the_asm
,
Instruction_t
*
target
)
{
return
IRDBUtility
::
insertAssemblyAfter
(
getFileIR
(),
before
,
the_asm
,
target
);
}
void
Transform
::
addPushf
(
Instruction_t
*
p_pushf_i
,
Instruction_t
*
p_fallThrough
)
{
string
dataBits
;
...
...
This diff is collapsed.
Click to expand it.
tools/hook_start/hook_start.cpp
+
40
−
40
View file @
bf48f2a9
...
...
@@ -46,7 +46,7 @@ void HookStart::LoadElf()
Instruction_t
*
HookStart
::
add_instrumentation
(
Instruction_t
*
site
)
{
Relocation_t
*
zipr_reloc
=
new
Relocation_t
;
FileIR_t
*
firp
=
getFileIR
();
//
FileIR_t *firp = getFileIR();
virtual_offset_t
postCallbackReturn
=
getAvailableAddress
();
char
pushRetBuf
[
100
],
movIdBuf
[
100
],
...
...
@@ -65,60 +65,60 @@ Instruction_t *HookStart::add_instrumentation(Instruction_t *site)
*
callback
=
NULL
,
*
post_callback
=
NULL
;
site
=
insertAssemblyBefore
(
firp
,
tmp
,
"push rsp"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rbp"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rdi"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rsi"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rdx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rcx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rbx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push rax"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r8"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r9"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r10"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r11"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r12"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r13"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r14"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"push r15"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pushf"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
movIdBuf
);
site
=
insertAssemblyBefore
(
tmp
,
"push rsp"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rbp"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rdi"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rsi"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rdx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rcx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rbx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push rax"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r8"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r9"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r10"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r11"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r12"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r13"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r14"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"push r15"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pushf"
);
tmp
=
insertAssemblyAfter
(
tmp
,
movIdBuf
);
/*
* Let's put a relocation on here!
*/
tmp
->
GetRelocations
().
insert
(
zipr_reloc
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
movRaxBuf
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
movRspBuf
);
tmp
=
insertAssemblyAfter
(
tmp
,
movRaxBuf
);
tmp
=
insertAssemblyAfter
(
tmp
,
movRspBuf
);
/*
* The "bogus" return address that we push here
* will be popped by the callback handler
* invocation code in zipr.
*/
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
pushRetBuf
);
// push <ret addr>
tmp
=
insertAssemblyAfter
(
tmp
,
pushRetBuf
);
// push <ret addr>
callback
=
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"call 0"
);
callback
=
tmp
=
insertAssemblyAfter
(
tmp
,
"call 0"
);
callback
->
SetTarget
(
callback
);
callback
->
SetCallback
(
m_callback_name
);
post_callback
=
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"popf"
);
post_callback
=
tmp
=
insertAssemblyAfter
(
tmp
,
"popf"
);
post_callback
->
GetAddress
()
->
SetVirtualOffset
(
postCallbackReturn
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r15"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r14"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r13"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r12"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r11"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r10"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r9"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop r8"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rax"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rbx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rcx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rdx"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rsi"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rdi"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"pop rbp"
);
tmp
=
insertAssemblyAfter
(
firp
,
tmp
,
"lea rsp, [rsp+8]"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r15"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r14"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r13"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r12"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r11"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r10"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r9"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop r8"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rax"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rbx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rcx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rdx"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rsi"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rdi"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"pop rbp"
);
tmp
=
insertAssemblyAfter
(
tmp
,
"lea rsp, [rsp+8]"
);
tmp
->
SetFallthrough
(
site
);
...
...
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