-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java-frontend: add discovery logic for all sink methods
Signed-off-by: Arthur Chan <[email protected]>
- Loading branch information
1 parent
0753a31
commit 7d04038
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontends/java/src/main/java/ossf/fuzz/introspector/soot/utils/SinkDiscoveryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Fuzz Introspector Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
/////////////////////////////////////////////////////////////////////////// | ||
|
||
package ossf.fuzz.introspector.soot.utils; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import soot.SootClass; | ||
import soot.SootMethod; | ||
|
||
public class SinkDiscoveryUtils { | ||
/** | ||
* The method loop through all methods and classes for the target | ||
* project and discover all sink methods existed in the project. | ||
* | ||
* @param sinkMethodMap the sink methods and classes to look for | ||
* @param projectClassMethodMap all methods and classes in the project | ||
* @return a list of sink methods exist in the project | ||
*/ | ||
public static List<SootMethod> discoverAllSinks(Map<String, Set<String>> sinkMethodMap, Map<SootClass, List<SootMethod>> projectClassMethodMap) { | ||
List<SootMethod> sinkMethods = new LinkedList<SootMethod>(); | ||
|
||
// Loop through all classes and methods of the project | ||
for (SootClass c : projectClassMethodMap.keySet()) { | ||
// Only process classes with sink methods | ||
if (sinkMethodMap.containsKey(c.getName()) { | ||
// Temporary SootMethod list to avoid concurrent modification | ||
List<SootMethod> mList = new LinkedList<SootMethod>(); | ||
mList.addAll(classMethodMap.get(c)); | ||
for (SootMethod m : mList) { | ||
if (sinkMethodMap.get(c.getName()).contains(m.getName())) { | ||
// Add the found sink method to the result list | ||
sinkMethods.add(m); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return sinkMethods; | ||
} | ||
} |