Skip to content

Commit 8ae5478

Browse files
authored
Grant stack registers a higher score of writable constraints (#190)
* Grant stack registers a higher score of writable constraints * Replace slice with sub
1 parent fc6537a commit 8ae5478

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/one_gadget/gadget.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,19 @@ def calculate_score(expr)
7878
case expr
7979
when / & 0xf/ then 0.95
8080
when /GOT address/ then 0.9
81-
when /^writable/ then 0.81
82-
when / == NULL$/ then calculate_null_score(expr.slice(0...expr.rindex(' == NULL')))
83-
when / <= 0$/ then calculate_null_score(expr.slice(0...expr.rindex(' <= ')))
81+
when /^writable/ then calculate_writable_score(expr.sub('writable: ', ''))
82+
when / == NULL$/ then calculate_null_score(expr.sub(' == NULL', ''))
83+
when / <= 0$/ then calculate_null_score(expr.sub(' <= 0', ''))
8484
end
8585
end
8686

87+
def calculate_writable_score(identity)
88+
lmda = OneGadget::Emulators::Lambda.parse(identity)
89+
return 0.81 if lmda.deref_count != 0
90+
91+
OneGadget::ABI.stack_register?(lmda.obj) ? 0.95 : 0.81
92+
end
93+
8794
def calculate_null_score(identity)
8895
# remove <CAST>
8996
identity.sub!(/^\([s|u]\d+\)/, '')

0 commit comments

Comments
 (0)