Skip to content

Commit

Permalink
Add methods for Wala framework
Browse files Browse the repository at this point in the history
  • Loading branch information
sarpsahinalp committed Nov 24, 2024
1 parent f01a37d commit 6b95748
Show file tree
Hide file tree
Showing 30 changed files with 446 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package de.tum.cit.ase.ares.api.architecture.java.wala;

import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.MethodReference;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BytecodeConverter {

public static void main(String[] args) throws IOException {
// Example method signature list
List<String> methodSignatures = Files.readAllLines(Path.of("C:\\Users\\sarps\\IdeaProjects\\Ares2\\src\\main\\resources\\de\\tum\\cit\\ase\\ares\\api\\templates\\architecture.java\\wala\\methods\\walamethods.txt"));

// Process each method signature
for (String signature : methodSignatures) {
System.out.println(parseMethodSignature(signature));
}
}

// Parse method signature and generate MethodReference
public static String parseMethodSignature(String signature) {
// Regular expression to match method signatures
String regex = "(.*)\\.(.*)\\((.*)\\)\\s+\\((.*)\\)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(signature);

if (matcher.matches()) {
String className = matcher.group(1); // Convert '.' to '/'
String methodName = matcher.group(2);
String paramTypes = matcher.group(3); // Extract parameters
String packageOfClass = matcher.group(4); // Extract return type

// Build the method signature format for WALA
String methodSignature = buildMethodSignature(paramTypes);

return packageOfClass + "." + className + "." + methodName + "(" + methodSignature + ")";
} else {
System.err.println("Could not parse signature: " + signature);
return null;
}
}

// Build the method signature for WALA (bytecode type format)
public static String buildMethodSignature(String paramTypes) {
StringBuilder signature = new StringBuilder();

// Process parameter types (e.g., "Ljava/io/File;")
if (paramTypes != null && !paramTypes.isEmpty()) {
for (String param : paramTypes.split(",")) {
signature.append(toBytecodeType(param.trim()));
}
}

return signature.toString();
}

// Convert Java type to bytecode type descriptor
public static String toBytecodeType(String javaType) {
// Handle common Java types and return the corresponding bytecode descriptor
switch (javaType) {
case "String": return "Ljava/lang/String;";
case "File": return "Ljava/io/File;";
case "Path": return "Ljava/nio/file/Path;";
case "URI": return "Ljava/net/URI;";
case "OpenOption": return "Ljava/nio/file/OpenOption;";
case "ByteBuffer": return "Ljava/nio/ByteBuffer;";
case "Redirect": return "Ljava/lang/ProcessBuilder$Redirect;";
case "int": return "I";
case "boolean": return "Z";
case "long":
return "J";
case "float":
return "F";
case "double":
return "D";
case "byte":
return "B";
case "char":
return "C";
case "short":
return "S";
case "void":
return "V";
case "ProtectionDomain": return "Ljava/security/ProtectionDomain;";
case "DataFlavor": return "Ljava/awt/datatransfer/DataFlavor;";
case "Transferable": return "Ljava/awt/datatransfer/Transferable;";
case "List": return "Ljava/util/List;";
case "Flags": return "Lsun/nio/fs/Flags;";
case "Charset": return "Ljava/nio/charset/Charset;";
case "DocFlavor": return "Ljavax/print/DocFlavor;";
case "List<?>": return "Ljava/util/List;";
default:
if (javaType.startsWith("Set")) return "Ljava/util/Set;";
if (javaType.startsWith("Map")) return "Ljava/util/Map;";
return "L" + javaType.replace('.', '/') + ";"; // Default case for other objects
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,4 @@ sun.swing.FilePane.getNewFolderAction()
sun.swing.FilePane.getViewMenu()
sun.swing.FilePane.propertyChange(java.beans.PropertyChangeEvent)
sun.swing.FilePane.setViewType(int)
sun.swing.FilePane.usesShellFolder(javax.swing.JFileChooser)
java.awt.Desktop.browse(Ljava/net/URI;)
java.awt.Desktop.browseFileDirectory(Ljava/io/File;)
java.awt.Desktop.edit(Ljava/io/File;)
java.awt.Desktop.mail(Ljava/net/URI;)
java.awt.Desktop.open
java.awt.Desktop.print(Ljava/io/File;)
java.awt.Desktop.setOpenFileHandler
sun.swing.FilePane.usesShellFolder(javax.swing.JFileChooser)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
java.lang.Runtime.exec
java.lang.Process
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
DataTransferer.castToFiles(List<?>, ProtectionDomain) (sun.awt.datatransfer)
DataTransferer.removeSuspectedData(DataFlavor, Transferable, String) (sun.awt.datatransfer)
ofFile(Path) in BodyPublishers in HttpRequest (java.net.http)
ofFileDownload(Path, OpenOption...) in BodyHandlers in HttpResponse (java.net.http)
ofFile(Path) in BodyHandlers in HttpResponse (java.net.http)
ofFile(Path) in BodySubscribers in HttpResponse (java.net.http)
Desktop.browse(URI) (java.awt)
Desktop.browseFileDirectory(File) (java.awt)
Desktop.edit(File) (java.awt)
Desktop.mail() (java.awt)
Desktop.mail(URI) (java.awt)
Desktop.open(File) (java.awt)
Desktop.openHelpViewer() (java.awt)
Desktop.print(File) (java.awt)
Desktop.setOpenFileHandler(OpenFilesHandler) (java.awt)
Desktop.setOpenURIHandler(OpenURIHandler) (java.awt)
Desktop.setOpenFileHandler(OpenFilesHandler) (java.awt)
JarFileFactory.getCachedJarFile(URL) (sun.net.www.protocol.jar)
FileURLConnection.getPermission()(2 usages) (sun.net.www.protocol.file)
ImageIO.hasCachePermission() (javax.imageio)
PlatformMBeanFinder in ManagementFactory (java.lang.management)
PrintJob2D.throwPrintToFile() (sun.print)
RasterPrinterJob.throwPrintToFile() (sun.print)
Desktop.moveToTrash(File) (java.awt)
File.delete() (java.io)
File.deleteOnExit() (java.io)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixPath.checkDelete() (sun.nio.fs)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
File.canExecute() (java.io)
ProcessBuilder.start(Redirect[]) (java.lang)
UnixFileSystemProvider.checkAccess(Path, AccessMode...) (sun.nio.fs)
UnixUserDefinedFileAttributeView.delete(String) (sun.nio.fs)
UnixUserDefinedFileAttributeView.list() (sun.nio.fs)
UnixUserDefinedFileAttributeView.read(String, ByteBuffer) (sun.nio.fs)
UnixUserDefinedFileAttributeView.size(String) (sun.nio.fs)
UnixUserDefinedFileAttributeView.write(String, ByteBuffer) (sun.nio.fs)
File.canRead() (java.io)
File.exists() (java.io)
File.getFreeSpace() (java.io)
File.getTotalSpace() (java.io)
File.getUsableSpace() (java.io)
File.isDirectory() (java.io)
File.isFile() (java.io)
File.isHidden() (java.io)
File.lastModified() (java.io)
File.length() (java.io)
File.normalizedList() (java.io)
FileImageSource.FileImageSource(String) (sun.awt.image)
FileInputStream.FileInputStream(File) (java.io)
FileServerHandler.FileServerHandler(Path, UnaryOperator<String>) (sun.net.httpserver.simpleserver)
HashedPasswordManager.loadPasswords() (com.sun.jmx.remote.security)
JarFileFactory.getCachedJarFile(URL) (sun.net.www.protocol.jar)
ProcessBuilder.start(Redirect[]) (java.lang)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
readNext() in FileStoreIterator in UnixFileSystem (sun.nio.fs)
ShellFolderManager.checkFile(File, SecurityManager)(2 usages) (sun.awt.shell)
SunToolkit.checkPermissions(String) (sun.awt)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixFileSystem.listRoots() (java.io)
UnixPath.checkRead() (sun.nio.fs)
URLClassPath.check(URL) (jdk.internal.loader)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
Anonymous in getRootDirectories() in UnixFileSystem.iterator() (sun.nio.fs)
UnixFileSystemProvider.readSymbolicLink(Path) (sun.nio.fs)
File.canWrite() (java.io)
File.createNewFile() (java.io)
File.createTempFile(String, String, File) (java.io)
File.mkdir() (java.io)
File.renameTo(File)(2 usages) (java.io)
File.setExecutable(boolean, boolean) (java.io)
File.setLastModified(long) (java.io)
File.setReadable(boolean, boolean) (java.io)
File.setReadOnly() (java.io)
File.setWritable(boolean, boolean) (java.io)
FileOutputStream.FileOutputStream(File, boolean) (java.io)
HotSpotDiagnostic.dumpHeap(String, boolean) (com.sun.management.internal)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixPath.checkWrite() (sun.nio.fs)
UnixPrintJob.getAttributeValues(DocFlavor) (sun.print)
Desktop.moveToTrash(File) (java.awt)
File.delete() (java.io)
File.deleteOnExit() (java.io)
FileManager.moveToTrash(File) (com.apple.eio)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixPath.checkDelete() (sun.nio.fs)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
File.canRead() (java.io)
File.exists() (java.io)
File.getFreeSpace() (java.io)
File.getTotalSpace() (java.io)
File.getUsableSpace() (java.io)
File.isDirectory() (java.io)
File.isFile() (java.io)
File.isHidden() (java.io)
File.lastModified() (java.io)
File.length() (java.io)
File.normalizedList() (java.io)
FileImageSource.FileImageSource(String) (sun.awt.image)
FileInputStream.FileInputStream(File) (java.io)
FileManager.getFileCreator(String) (com.apple.eio)
FileManager.getFileType(String) (com.apple.eio)
FileManager.revealInFinder(File) (com.apple.eio)
FileServerHandler.FileServerHandler(Path, UnaryOperator<String>) (sun.net.httpserver.simpleserver)
HashedPasswordManager.loadPasswords() (com.sun.jmx.remote.security)
JarFileFactory.getCachedJarFile(URL) (sun.net.www.protocol.jar)
ProcessBuilder.start(Redirect[]) (java.lang)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
readNext() in FileStoreIterator in UnixFileSystem (sun.nio.fs)
ShellFolderManager.checkFile(File, SecurityManager)(2 usages) (sun.awt.shell)
SunToolkit.checkPermissions(String) (sun.awt)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixFileSystem.listRoots() (java.io)
UnixPath.checkRead() (sun.nio.fs)
URLClassPath.check(URL) (jdk.internal.loader)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
File.canWrite() (java.io)
File.createNewFile() (java.io)
File.createTempFile(String, String, File) (java.io)
File.mkdir() (java.io)
File.renameTo(File)(2 usages) (java.io)
File.setExecutable(boolean, boolean) (java.io)
File.setLastModified(long) (java.io)
File.setReadable(boolean, boolean) (java.io)
File.setReadOnly() (java.io)
File.setWritable(boolean, boolean) (java.io)
FileManager.setFileCreator(String, int) (com.apple.eio)
FileManager.setFileType(String, int) (com.apple.eio)
FileManager.setFileTypeAndCreator(String, int, int) (com.apple.eio)
FileOutputStream.FileOutputStream(File, boolean) (java.io)
HotSpotDiagnostic.dumpHeap(String, boolean) (com.sun.management.internal)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
UnixChannelFactory.open(int, UnixPath, String, Flags, int) (sun.nio.fs)
UnixPath.checkWrite() (sun.nio.fs)
UnixPrintJob.getAttributeValues(DocFlavor) (sun.print)
Desktop.moveToTrash(File) (java.awt)
File.delete() (java.io)
File.deleteOnExit() (java.io)
WindowsChannelFactory.open(String, String, Flags, long) (sun.nio.fs)
WindowsPath.checkDelete() (sun.nio.fs)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
File.canExecute() (java.io)
ProcessBuilder.start(Redirect[]) (java.lang)
ProcessImpl.ProcessImpl(String[], String, String, long[], boolean, boolean) (java.lang)
WindowsFileSystemProvider.checkAccess(Path, AccessMode...) (sun.nio.fs)
WindowsUserDefinedFileAttributeView.delete(String) (sun.nio.fs)
WindowsUserDefinedFileAttributeView.list() (sun.nio.fs)
WindowsUserDefinedFileAttributeView.read(String, ByteBuffer) (sun.nio.fs)
WindowsUserDefinedFileAttributeView.size(String) (sun.nio.fs)
WindowsUserDefinedFileAttributeView.write(String, ByteBuffer) (sun.nio.fs)
File.canRead() (java.io)
File.exists() (java.io)
File.getFreeSpace() (java.io)
File.getTotalSpace() (java.io)
File.getUsableSpace() (java.io)
File.isDirectory() (java.io)
File.isFile() (java.io)
File.isHidden() (java.io)
File.lastModified() (java.io)
File.length() (java.io)
File.normalizedList() (java.io)
FileImageSource.FileImageSource(String) (sun.awt.image)
FileInputStream.FileInputStream(File) (java.io)
FileServerHandler.FileServerHandler(Path, UnaryOperator<String>) (sun.net.httpserver.simpleserver)
HashedPasswordManager.loadPasswords() (com.sun.jmx.remote.security)
JarFileFactory.getCachedJarFile(URL) (sun.net.www.protocol.jar)
ProcessBuilder.start(Redirect[]) (java.lang)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
ShellFolderManager.checkFile(File, SecurityManager)(2 usages) (sun.awt.shell)
SunToolkit.checkPermissions(String) (sun.awt)
Win32ShellFolder2.getFileSystemPath(int) (sun.awt.shell)
Win32ShellFolder2.listFiles(boolean) (sun.awt.shell)
Win32ShellFolderManager2.checkFile(File, SecurityManager)(2 usages) (sun.awt.shell)
WindowsAclFileAttributeView.checkAccess(WindowsPath, boolean, boolean) (sun.nio.fs)
WindowsChannelFactory.open(String, String, Flags, long) (sun.nio.fs)
WindowsFileSystem.getRootDirectories() (sun.nio.fs)
WindowsPath.checkRead() (sun.nio.fs)
WindowsPath.register(WatchService, Kind<?>[], Modifier...)(2 usages) (sun.nio.fs)
WinNTFileSystem.access(String) (java.io)
WinNTFileSystem.resolve(File) (java.io)
ZipFile.ZipFile(File, int, Charset) (java.util.zip)
WindowsFileSystemProvider.readSymbolicLink(Path) (sun.nio.fs)
File.canWrite() (java.io)
File.createNewFile() (java.io)
File.createTempFile(String, String, File) (java.io)
File.mkdir() (java.io)
File.renameTo(File)(2 usages) (java.io)
File.setExecutable(boolean, boolean) (java.io)
File.setLastModified(long) (java.io)
File.setReadable(boolean, boolean) (java.io)
File.setReadOnly() (java.io)
File.setWritable(boolean, boolean) (java.io)
FileOutputStream.FileOutputStream(File, boolean) (java.io)
HotSpotDiagnostic.dumpHeap(String, boolean) (com.sun.management.internal)
ProcessImpl.newFileOutputStream(File, boolean) (java.lang)
RandomAccessFile.RandomAccessFile(File, String, boolean) (java.io)
Win32PrintJob.getAttributeValues(DocFlavor) (sun.print)
WindowsAclFileAttributeView.checkAccess(WindowsPath, boolean, boolean) (sun.nio.fs)
WindowsChannelFactory.open(String, String, Flags, long) (sun.nio.fs)
WindowsPath.checkWrite() (sun.nio.fs)
WPrinterJob.getPrintToFileEnabled() (sun.awt.windows)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Desktop.checkQuitPermission() (java.awt)
JFrame.setDefaultCloseOperation(int) (javax.swing)
Runtime.exit(int) (java.lang)
Runtime.halt(int) (java.lang)
Loading

0 comments on commit 6b95748

Please sign in to comment.