crokus 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/crokus +0 -0
- data/lib/crokus/ast.rb +4 -0
- data/lib/crokus/cleaner.rb +8 -3
- data/lib/crokus/compiler.rb +2 -2
- data/lib/crokus/runner.rb +7 -1
- data/lib/crokus/trojan_inserter.rb +47 -8
- data/lib/crokus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7712eb73a1d5f62f9b9b7a63eae496dbd67a346b5a17b56b4e31d60fd9deee3d
|
4
|
+
data.tar.gz: fed83c851d88bc36a18bd060883644be97ffe4c6cddf7765aedd4a1c37da3add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d3dd5f960229807f20310e10554c69dd65e030c1f36460a78d49662d7abfa91e2f4aa9ac6fc6f6690276372b191c13c475042c2aeaaca23f898f4aaf841676
|
7
|
+
data.tar.gz: fb152f1af14c00705fc59940b99a8cf506898a37cfbadfee28eb9b61c3db6bd4b62b43b3622c3c0b77452561d415a82a0c88851ef66b45f79bd2ec776f51d3c4
|
data/bin/crokus
CHANGED
File without changes
|
data/lib/crokus/ast.rb
CHANGED
data/lib/crokus/cleaner.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
module Crokus
|
2
2
|
class Cleaner
|
3
3
|
def clean str_c
|
4
|
-
|
5
|
-
str_c.gsub!(";;",";")
|
6
4
|
str_c.gsub!(";)",")")
|
7
5
|
str_c.gsub!(/\n+\s*\;/,";")
|
8
6
|
str_c.gsub!(/\;\s*\:/,":")
|
9
|
-
|
7
|
+
str_c.gsub!(/\n\s+\{/,"{")
|
8
|
+
str_c.gsub!(/\;+/,";")
|
10
9
|
str_c
|
11
10
|
end
|
11
|
+
|
12
|
+
def debug str_c
|
13
|
+
puts "hit a key"
|
14
|
+
$stdin.gets.chomp
|
15
|
+
puts str_c
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
data/lib/crokus/compiler.rb
CHANGED
@@ -36,7 +36,7 @@ module Crokus
|
|
36
36
|
pretty_print
|
37
37
|
|
38
38
|
if options[:trojan]
|
39
|
-
return_code=insert_trojan
|
39
|
+
return_code=insert_trojan()
|
40
40
|
return return_code
|
41
41
|
end
|
42
42
|
|
@@ -107,7 +107,7 @@ module Crokus
|
|
107
107
|
|
108
108
|
def insert_trojan
|
109
109
|
puts "[+] inserting trojan" unless options[:mute]
|
110
|
-
infected_ast=TrojanInserter.new.insert(ast)
|
110
|
+
infected_ast=TrojanInserter.new(@options).insert(ast)
|
111
111
|
if infected_ast
|
112
112
|
code=PrettyPrinter.new.visit(infected_ast)
|
113
113
|
pp_c=@base_name+"_troj.c"
|
data/lib/crokus/runner.rb
CHANGED
@@ -69,8 +69,14 @@ module Crokus
|
|
69
69
|
options[:random] = params_filename
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
# optional argument for --trojan
|
73
|
+
parser.on('--trojan FUNC', "insert Syracuse Trojan in function FUNC") do |target_func|
|
74
|
+
if target_func.end_with?(".c")
|
75
|
+
puts "wrong argument for --trojan . It requires a function name as argument."
|
76
|
+
abort
|
77
|
+
end
|
73
78
|
options[:trojan] = true
|
79
|
+
options[:trojan_target_func]=target_func
|
74
80
|
end
|
75
81
|
|
76
82
|
parser.on("--vv", "verbose") do
|
@@ -5,6 +5,10 @@ module Crokus
|
|
5
5
|
|
6
6
|
class TrojanInserter < Transformer
|
7
7
|
|
8
|
+
def initialize options={}
|
9
|
+
@options=options
|
10
|
+
end
|
11
|
+
|
8
12
|
def insert ast
|
9
13
|
@nb_trojans=0
|
10
14
|
new_ast=transform(ast)
|
@@ -13,6 +17,12 @@ module Crokus
|
|
13
17
|
return new_ast
|
14
18
|
else
|
15
19
|
puts " "*1+"|--[?] insertion failed"
|
20
|
+
if func=@options[:trojan_target_func] and @target_reached.nil?
|
21
|
+
puts " "*5+"|-- no function named '#{func}' found"
|
22
|
+
end
|
23
|
+
if @failure_reason
|
24
|
+
puts " "*5+"|-- #{@failure_reason}"
|
25
|
+
end
|
16
26
|
end
|
17
27
|
nil
|
18
28
|
end
|
@@ -25,11 +35,20 @@ module Crokus
|
|
25
35
|
end
|
26
36
|
|
27
37
|
def visitFunction func,args=nil
|
28
|
-
puts " "*1+"|--[+] func #{func.name}"
|
29
38
|
func_troj=super(func,args)
|
30
|
-
|
31
|
-
|
32
|
-
|
39
|
+
if @options[:trojan_target_func].nil? or (name=@options[:trojan_target_func] and target_reached=(func.name.to_s==name))
|
40
|
+
puts " "*1+"|--[+] func #{func.name}"
|
41
|
+
if target_reached
|
42
|
+
@target_reached=true
|
43
|
+
end
|
44
|
+
success=insert_trojan(func_troj)
|
45
|
+
if success
|
46
|
+
# hannah request : add a _troj to the function :
|
47
|
+
func_troj.name=Ident.create(func.name.to_s+'_troj')
|
48
|
+
@rename_funcs||={} # take cares of future calls to func !
|
49
|
+
@rename_funcs[func.name.to_s]=func_troj.name.to_s
|
50
|
+
@nb_trojans+=1
|
51
|
+
end
|
33
52
|
end
|
34
53
|
func_troj
|
35
54
|
end
|
@@ -37,7 +56,7 @@ module Crokus
|
|
37
56
|
def insert_trojan func
|
38
57
|
if trojan=build_trojan(func)
|
39
58
|
bodies=bodies_collect(func)
|
40
|
-
puts "\t#bodies = #{bodies.size}"
|
59
|
+
#puts "\t#bodies = #{bodies.size}"
|
41
60
|
target_body=bodies.sample
|
42
61
|
stmts=target_body.stmts
|
43
62
|
nb_decls=stmts.select{|stmt| stmt.is_a? Decl}.size
|
@@ -48,6 +67,18 @@ module Crokus
|
|
48
67
|
success=false
|
49
68
|
end
|
50
69
|
|
70
|
+
def visitFunCall fcall,args=nil
|
71
|
+
name=fcall.name.accept(self)
|
72
|
+
if @rename_funcs # propagate func renaming applied during visitFunction
|
73
|
+
if @rename_funcs.keys.include?(name.to_s)
|
74
|
+
new_name=@rename_funcs[name.to_s]
|
75
|
+
name=Ident.create(new_name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
args=fcall.args.collect{|arg| arg.accept(self)}
|
79
|
+
FunCall.new(name,args)
|
80
|
+
end
|
81
|
+
|
51
82
|
def bodies_collect func
|
52
83
|
bodies=[]
|
53
84
|
bodies << func.body
|
@@ -86,7 +117,10 @@ module Crokus
|
|
86
117
|
def build_trojan func
|
87
118
|
trojan=Body.new
|
88
119
|
anchor_var=choose_anchor(func)
|
89
|
-
|
120
|
+
if anchor_var.nil?
|
121
|
+
@failure_reason="no int type variable found in function local declarations, needed in the trojan insertion process."
|
122
|
+
return
|
123
|
+
end
|
90
124
|
u_=Ident.new(Token.create("u_"))
|
91
125
|
v_=Ident.new(Token.create("v_"))
|
92
126
|
i_=Ident.new(Token.create("i_"))
|
@@ -124,8 +158,13 @@ module Crokus
|
|
124
158
|
def build_trigger func
|
125
159
|
args=find_int_arg(func)
|
126
160
|
arg_names=get_arg_names(args)
|
127
|
-
|
128
|
-
|
161
|
+
unless arg_names.size>1
|
162
|
+
@failure_reason="not enough args of type int in func '#{func.name}' to build a trigger."
|
163
|
+
return
|
164
|
+
end
|
165
|
+
arg1,arg2=arg_names.shuffle[0..1]
|
166
|
+
puts " "*5+"|--> trigger variables are : #{arg1},#{arg2}"
|
167
|
+
cond=Binary.new(Parenth.new(Binary.new(arg1,AND,arg2)),EQUAL,T42)
|
129
168
|
If.new(cond,nil)
|
130
169
|
end
|
131
170
|
|
data/lib/crokus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crokus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Christophe Le Lann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: distribution
|