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
3812935d
Commit
3812935d
authored
8 years ago
by
asj5b
Browse files
Options
Downloads
Patches
Plain Diff
Zero canary changes
Former-commit-id: e727dcb9465e3993ceb5a0b046d2f8972ffd00e0
parent
7bbcc429
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/transforms/Rewrite_Utility.cpp
+34
-0
34 additions, 0 deletions
tools/transforms/Rewrite_Utility.cpp
tools/transforms/Rewrite_Utility.hpp
+1
-0
1 addition, 0 deletions
tools/transforms/Rewrite_Utility.hpp
with
35 additions
and
0 deletions
tools/transforms/Rewrite_Utility.cpp
+
34
−
0
View file @
3812935d
...
...
@@ -352,10 +352,12 @@ Instruction_t* insertCanaryCheckBefore(FileIR_t* virp,Instruction_t *first, unsi
ss
<<
"cmp dword ["
<<
sp_reg
;
bool
esp_neg
=
false
;
if
(
esp_offset
<
0
)
{
ss
<<
"-"
;
esp_offset
=
esp_offset
*-
1
;
esp_neg
=
true
;
}
else
ss
<<
"+"
;
...
...
@@ -364,16 +366,48 @@ Instruction_t* insertCanaryCheckBefore(FileIR_t* virp,Instruction_t *first, unsi
//Insert the cmp before
Instruction_t
*
next
=
insertAssemblyBefore
(
virp
,
first
,
ss
.
str
());
//Then insert the jmp after the compare.
//The fallthrough of the inserted jmp will be a copy of the original
//instruction, still pointed to by "first".
insertDataBitsAfter
(
virp
,
first
,
getJnzDataBits
(),
fail_code
);
first
->
SetComment
(
"Canary Check: "
+
first
->
GetComment
());
//TODO: move canary zero to option
if
(
esp_neg
)
esp_offset
*=
-
1
;
insertCanaryZeroAfter
(
virp
,
first
,
esp_offset
,
fail_code
);
return
next
;
}
Instruction_t
*
insertCanaryZeroAfter
(
FileIR_t
*
virp
,
Instruction_t
*
first
,
int
esp_offset
,
Instruction_t
*
fail_code
)
{
stringstream
ss
;
const
char
*
sp_reg
=
"esp"
;
if
(
virp
->
GetArchitectureBitWidth
()
==
64
)
sp_reg
=
"rsp"
;
ss
<<
"mov dword ["
<<
sp_reg
;
if
(
esp_offset
<
0
)
{
ss
<<
"-"
;
esp_offset
=
esp_offset
*-
1
;
}
else
ss
<<
"+"
;
ss
<<
"0x"
<<
hex
<<
esp_offset
<<
"], 0x0"
;
//Insert the cmp before
Instruction_t
*
next
=
insertAssemblyAfter
(
virp
,
first
,
ss
.
str
());
first
->
SetComment
(
"Canary Zero: "
+
first
->
GetComment
());
return
next
;
}
Relocation_t
*
createNewRelocation
(
FileIR_t
*
firp
,
Instruction_t
*
insn
,
string
type
,
int
offset
)
{
Relocation_t
*
reloc
=
new
Relocation_t
;
...
...
This diff is collapsed.
Click to expand it.
tools/transforms/Rewrite_Utility.hpp
+
1
−
0
View file @
3812935d
...
...
@@ -74,6 +74,7 @@ Instruction_t* getHandlerCode(FileIR_t* virp, Instruction_t* fallthrough, mitiga
//Returns the pointer for the copied "first" instruction, which is at the
//end of the canary check block of instructions.
Instruction_t
*
insertCanaryCheckBefore
(
FileIR_t
*
virp
,
Instruction_t
*
first
,
unsigned
int
canary_val
,
int
ret_offset
,
Instruction_t
*
fail_code
);
Instruction_t
*
insertCanaryZeroAfter
(
FileIR_t
*
virp
,
Instruction_t
*
first
,
int
esp_offset
,
Instruction_t
*
fail_code
);
Relocation_t
*
createNewRelocation
(
FileIR_t
*
firp
,
Instruction_t
*
insn
,
string
type
,
int
offset
);
...
...
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