Skip to content

Commit 2a77c34

Browse files
committed
deepcut works with pyGhida
1 parent 22c0a93 commit 2a77c34

17 files changed

Lines changed: 461 additions & 216 deletions

codecut-gui/src/main/java/codecutguiv2/CodeCutGUIPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import ghidra.program.model.symbol.*;
8585
import ghidra.program.util.ChangeManager;
8686
import ghidra.program.util.DefinedDataIterator;
87+
import ghidra.program.util.DefinedStringIterator;
8788
import ghidra.program.util.GhidraProgramUtilities;
8889
import ghidra.program.util.ProgramChangeRecord;
8990
import ghidra.program.util.ProgramLocation;
@@ -1069,7 +1070,8 @@ private void getModuleStrings() {
10691070
Accumulator<ProgramLocation> accumulator = new ListAccumulator<>();
10701071

10711072
Swing.allowSwingToProcessEvents();
1072-
for (Data stringInstance : DefinedDataIterator.definedStrings(currentProgram)) {
1073+
// 09032025 Vivian, changed to accommodate updated ghidra api
1074+
for (Data stringInstance : DefinedStringIterator.forProgram(currentProgram)) {
10731075
Address strAddr = stringInstance.getAddress();
10741076
ReferenceIterator refIterator = refManager.getReferencesTo(strAddr);
10751077
while (refIterator.hasNext()) {

codecut-gui/src/main/java/graphcut/GraphCutLayout.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public AbstractVisualGraphLayout<GraphCutVertex, GraphCutEdge> createClonedLayou
6565
return newLayout;
6666
}
6767

68-
@Override
6968
protected Point2D getVertexLocation(GraphCutVertex v, Column col, Row<GraphCutVertex> row, Rectangle bounds) {
7069
return getCenteredVertexLocation(v, col, row, bounds);
7170
}
-399 KB
Binary file not shown.
6 KB
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# @category CodeCut
2+
# @menupath CodeCut.DeepCut (Run)
3+
# @toolbar codecut.png
4+
# @runtime PyGhidra
5+
6+
# (C) 2022 The Johns Hopkins University Applied Physics Laboratory LLC
7+
# (JHU/APL). All Rights Reserved.
8+
#
9+
# This material may be only be used, modified, or reproduced by or for
10+
# the U.S. Government pursuant to the license rights granted under the
11+
# clauses at DFARS 252.227-7013/7014 or FAR 52.227-14. For any other
12+
# permission, please contact the Office of Technology Transfer at
13+
# JHU/APL.
14+
#
15+
# NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL
16+
# MAKES NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF
17+
# THE MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL
18+
# VIABILITY, AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER
19+
# EXPRESS OR IMPLIED, INCLUDING (BUT NOT LIMITED TO) ANY AND ALL IMPLIED
20+
# WARRANTIES OF PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
21+
# PURPOSE, AND NON-INFRINGEMENT OF INTELLECTUAL PROPERTY OR OTHER THIRD
22+
# PARTY RIGHTS. ANY USER OF THE MATERIAL ASSUMES THE ENTIRE RISK AND
23+
# LIABILITY FOR USING THE MATERIAL. IN NO EVENT SHALL JHU/APL BE LIABLE
24+
# TO ANY USER OF THE MATERIAL FOR ANY ACTUAL, INDIRECT, CONSEQUENTIAL,
25+
# SPECIAL OR OTHER DAMAGES ARISING FROM THE USE OF, OR INABILITY TO USE,
26+
# THE MATERIAL, INCLUDING, BUT NOT LIMITED TO, ANY DAMAGES FOR LOST
27+
# PROFITS.
28+
#
29+
# HAVE A NICE DAY.
30+
31+
# This material is based upon work supported by the Defense Advanced Research
32+
# Projects Agency (DARPA) and Naval Information Warfare Center Pacific (NIWC Pacific)
33+
# under Contract Number N66001-20-C-4024.
34+
35+
import sys
36+
import json
37+
38+
print("started DeepCutRun")
39+
40+
41+
from dependency_bootstrap import DependencyManager
42+
43+
# list the packages you need
44+
# dictionary of "import name" : "pip name"
45+
# for when they differ, e.g. "sklearn": "scikit-learn"
46+
deps = DependencyManager(
47+
{"networkx": "networkx",
48+
"scipy": "scipy",
49+
"torch": "torch",
50+
"torch_geometric": "torch-geometric"})
51+
52+
# make sure they're installed
53+
if not deps.ensure_or_prompt():
54+
println("[DeepCut] Required Python packages not available, exiting.")
55+
exit(1)
56+
57+
from deepcut import Deepcut
58+
59+
# Pass Ghidra context + args into your package entry point
60+
# run(currentProgram, state, monitor, *args)
61+
62+
def main():
63+
args = list(getScriptArgs())
64+
65+
with open(args[0], "r") as f:
66+
fcg = json.load(f)
67+
68+
model_path = args[2]
69+
d = Deepcut(fcg, model_path)
70+
71+
with open(args[1], "w") as f:
72+
json.dump(d.module_list(), f)
73+
74+
print("Successfully exported module boundaries")
75+
76+
if __name__ == "__main__":
77+
main()
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# © 2021 The Johns Hopkins University Applied Physics Laboratory LLC
1+
# (C) 2022 The Johns Hopkins University Applied Physics Laboratory LLC
22
# (JHU/APL). All Rights Reserved.
33
#
44
# This material may be only be used, modified, or reproduced by or for
@@ -7,7 +7,7 @@
77
# permission, please contact the Office of Technology Transfer at
88
# JHU/APL.
99
#
10-
# NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED AS IS. JHU/APL
10+
# NO WARRANTY, NO LIABILITY. THIS MATERIAL IS PROVIDED "AS IS." JHU/APL
1111
# MAKES NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF
1212
# THE MATERIALS, INCLUDING THEIR SAFETY, EFFECTIVENESS, OR COMMERCIAL
1313
# VIABILITY, AND DISCLAIMS ALL WARRANTIES IN THE MATERIAL, WHETHER
@@ -88,12 +88,6 @@ def __init__(self, num_features, num_edge_features, dim=32):
8888
self.out2 = torch.nn.Linear(dim, 4)
8989

9090
def forward(self, x, edge_attr, edge_index, batch):
91-
# x, edge_attr, edge_index, batch = (
92-
# data.x,
93-
# data.edge_attr,
94-
# data.edge_index,
95-
# data.batch,
96-
# )
9791

9892
x = F.relu(self.init_mlp(x))
9993
x = self.init_bn(x)
@@ -118,20 +112,14 @@ def forward(self, x, edge_attr, edge_index, batch):
118112
edge_attr = self.e_mlp3(edge_attr)
119113
edge_attr = self.ebn2(edge_attr) # oops typo this should be a 3
120114

121-
#x = x[edge_index[0]] + x[edge_index[1]] + edge_attr
122-
#x = F.softmax(x, dim=1)
123-
#edge_attr = F.softmax(edge_attr, dim=1)
124115
x = torch.cat([x[edge_index[0]], x[edge_index[1]], edge_attr], dim=1)
125116

126117
x = F.relu(self.out1(x))
127118
x = self.out_bn(x)
128119
x = self.out2(x)
129120

130-
#ret = torch.max(x, dim=1)[0]
131121
ret = torch.mean(x, dim=1)
132122

133-
#ret = torch.max(x[edge_index[0]] + x[edge_index[1]], dim=1)[0]
134-
#ret = torch.mean(x[edge_index[0]] + x[edge_index[1]], dim=1)
135123
return ret
136124

137125
def load_gnn(model_file):
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)