-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEdhocDotProcessor.java
More file actions
72 lines (59 loc) · 2.74 KB
/
EdhocDotProcessor.java
File metadata and controls
72 lines (59 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.github.protocolfuzzing.edhocfuzzer;
import com.github.protocolfuzzing.edhocfuzzer.components.sul.mapper.config.EdhocMapperConfig;
import com.github.protocolfuzzing.protocolstatefuzzer.components.learner.LearnerResult;
import com.github.protocolfuzzing.protocolstatefuzzer.components.sul.mapper.config.MapperConfig;
import com.github.protocolfuzzing.protocolstatefuzzer.statefuzzer.core.config.StateFuzzerEnabler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class EdhocDotProcessor {
private static final Logger LOGGER = LogManager.getLogger();
public static void beautify(LearnerResult<?> learnerResult) {
if (learnerResult.isFromTest()) {
return;
}
if (learnerResult.isEmpty()) {
LOGGER.warn("Provided empty LearnerResult");
return;
}
if (learnerResult.getLearnedModelFile() == null) {
LOGGER.warn("Provided null learned model file in LearnerResult");
return;
}
StateFuzzerEnabler stateFuzzerEnabler = learnerResult.getStateFuzzerEnabler();
if (stateFuzzerEnabler == null) {
LOGGER.warn("Provided null StateFuzzerEnabler");
return;
}
String script = "scripts/beautify_model.sh";
String learnedModelPath = learnerResult.getLearnedModelFile().getAbsolutePath();
List<String> commandArgList = new ArrayList<>();
commandArgList.add(script);
commandArgList.add(learnedModelPath);
if (stateFuzzerEnabler.isFuzzingClient()) {
// SUL is a client implementation
MapperConfig mapperConfig = stateFuzzerEnabler.getSULConfig().getMapperConfig();
if (!(mapperConfig instanceof EdhocMapperConfig edhocMapperConfig)) {
LOGGER.error("MapperConfig of StateFuzzerEnabler is not EdhocMapperConfig");
return;
}
boolean isFuzzerInitiator = edhocMapperConfig.isInitiator();
// when Fuzzer is Initiator then SUL is Responder
// when Fuzzer is Responder then SUL is Initiator
String cIR = isFuzzerInitiator ? "--clientResponder" : "--clientInitiator";
commandArgList.add(1, cIR);
}
try {
LOGGER.info("Running {}", script);
new ProcessBuilder(commandArgList)
.redirectErrorStream(true)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor();
} catch (IOException | InterruptedException e) {
LOGGER.warn("Could not beautify {}: {}", learnedModelPath, e.getMessage());
}
}
}