Skip to content

Commit

Permalink
update to current sootUp develop; still things to do/uncomment/incorp…
Browse files Browse the repository at this point in the history
…orate again
  • Loading branch information
swissiety committed Dec 15, 2023
1 parent 56b3a0a commit cabebcb
Show file tree
Hide file tree
Showing 14 changed files with 549 additions and 308 deletions.
79 changes: 40 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,51 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<!--
<sootup.groupid>org.soot-oss</sootup.groupid>
<sootup.version>1.1.2-SNAPSHOT</sootup.version>
-->
<sootup.groupid>com.github.soot-oss.SootUp</sootup.groupid>
<sootup.version>develop-SNAPSHOT</sootup.version>

</properties>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.sourcecode</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.bytecode</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.jimple.parser</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.callgraph</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.analysis</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.magpiebridge</groupId>
<artifactId>magpiebridge</artifactId>
<version>0.1.123-SNAPSHOT</version>
<!--<version>language_extensibility-SNAPSHOT</version>-->
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
<version>0.21.1</version>
</dependency>

<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
<version>0.21.1</version>
</dependency>

<dependency>
<groupId>${sootup.groupid}</groupId>
<artifactId>sootup.core</artifactId>
<version>${sootup.version}</version>
</dependency>
<dependency>
<groupId>${sootup.groupid}</groupId>
<artifactId>sootup.java.core</artifactId>
<version>${sootup.version}</version>
</dependency>
<dependency>
<groupId>${sootup.groupid}</groupId>
<artifactId>sootup.jimple.parser</artifactId>
<version>${sootup.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
Expand Down
121 changes: 45 additions & 76 deletions src/main/java/com/github/swissiety/jimplelsp/JimpleLsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,65 @@
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.function.Supplier;
import magpiebridge.core.MagpieServer;
import magpiebridge.core.ServerConfiguration;
import magpiebridge.util.MagpieMessageLogger;

import org.apache.commons.cli.*;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.validation.ReflectiveMessageValidator;
import org.eclipse.lsp4j.launch.LSPLauncher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;
import org.graalvm.polyglot.Language;

/** @author Markus Schmidt */
/**
* @author Markus Schmidt
*/
public class JimpleLsp {

private static final String DEFAULT_PORT = "2403";
private static CommandLine cmd = null;

public static void main(String... args) throws IOException, InterruptedException {
Options cliOptions =
new Options()
.addOption(
"s",
"socket",
false,
MessageFormat.format("run in socket mode, standard port is {0}", DEFAULT_PORT))
.addOption(
"p",
"port",
true,
MessageFormat.format(
"sets the port for socket mode, standard port is {0}", DEFAULT_PORT));

CommandLineParser parser = new DefaultParser();

try {
cmd = parser.parse(cliOptions, args);
} catch (ParseException e) {
e.printStackTrace();
System.exit(1);
}
private static final String DEFAULT_PORT = "2403";
private static CommandLine cmd = null;

Supplier<MagpieServer> createServer =
() -> {
ServerConfiguration config = new ServerConfiguration();
config.setDoAnalysisBySave(false);
config.setDoAnalysisByOpen(false);
config.setShowConfigurationPage(true, true);
config.setMagpieMessageLogger(
new MagpieMessageLogger() {
@Override
public Function<MessageConsumer, MessageConsumer> getWrapper() {
return (MessageConsumer c) -> {
MessageConsumer wrappedConsumer =
message -> {
String timeStamp =
new SimpleDateFormat("[HH:mm:ss:SS]").format(new Date());
// don't print! otherwise it breaks in stdio mode!
// System.err.println(timeStamp + message);
new ReflectiveMessageValidator(c).consume(message);
};
return wrappedConsumer;
};
}
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
Options cliOptions =
new Options()
.addOption(
"s",
"socket",
false,
MessageFormat.format("run in socket mode, standard port is {0}", DEFAULT_PORT))
.addOption(
"p",
"port",
true,
MessageFormat.format(
"sets the port for socket mode, standard port is {0}", DEFAULT_PORT));

@Override
public void cleanUp() {}
});
CommandLineParser parser = new DefaultParser();

// to disable unnecessarily showing the control panel
config.setShowConfigurationPage(false, false);
try {
cmd = parser.parse(cliOptions, args);
} catch (ParseException e) {
e.printStackTrace();
System.exit(1);
}

MagpieServer server = new JimpleLspServer(config);
/* TODO: e.g. extract apk on demand
Map<String, String> conf = new HashMap<>();
conf.put("Extract Apk", "extractJimpleFromAPK");
server.setConfigurationOptions(conf);
JimpleLspServer server = new JimpleLspServer();

// TODO: Magpie: reuse supported language definitions
String language = "jimple";
ServerAnalysis analysis = new JimpleServerAnalysis();
server.addAnalysis(Either.forLeft(analysis), language);
*/
/* if (cmd.hasOption("socket")) {
int port = Integer.parseInt(cmd.getOptionValue("port", DEFAULT_PORT));
System.out.println("Socket:" + port);
// FIXME LanguageServer.launchOnSocketPort(port, createServer);
} else */ {

return server;
};
Launcher<LanguageClient> l = LSPLauncher.createServerLauncher(server, System.in, System.out);
Future<?> startListening = l.startListening();
server.connectClient(l.getRemoteProxy());
startListening.get();

if (cmd.hasOption("socket")) {
int port = Integer.parseInt(cmd.getOptionValue("port", DEFAULT_PORT));
System.out.println("Socket:" + port);
MagpieServer.launchOnSocketPort(port, createServer);
} else {
createServer.get().launchOnStdio();
}
}
}
}
Loading

0 comments on commit cabebcb

Please sign in to comment.