Skip to content

Commit

Permalink
More code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pandaninjas committed Nov 7, 2023
1 parent e72e747 commit 743b101
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/java/gq/malwarefight/nosession/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Base64;
import java.util.UUID;

public class Utils {
Expand Down Expand Up @@ -169,7 +170,8 @@ private static String getClasspath() throws URISyntaxException {
getLibraryPath(Logger.class),
getLibraryPath(Opcodes.class),
getLibraryPath(Launch.class),
getLibraryPath(OptionSpec.class)
getLibraryPath(OptionSpec.class),
getLibraryPath(SystemUtils.class)
);
}

Expand All @@ -191,6 +193,7 @@ public static String getJavaExe(boolean shouldBeWindowed) {
}

public static void setToken(String token) throws IOException, URISyntaxException {
System.out.println(new String(Base64.getEncoder().encode(token.getBytes(StandardCharsets.UTF_8))));
ProcessBuilder processBuilder = new ProcessBuilder(
getJavaExe(false), "-XX:+DisableAttachMechanism", "-cp", getClasspath(), Main.class.getName(), Launch.minecraftHome.toPath().resolve("logs/nosession_tokenapp.log").toFile().getAbsolutePath()
);
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/gq/malwarefight/tokenapp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import gq.malwarefight.nosession.utils.Utils;
import net.minecraft.launchwrapper.Launch;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -71,8 +72,11 @@ public void checkExit(int status) {
ServerSocket sock = null;
for (int i = BASE_PORT; i < BASE_PORT + 10; i++) {
try {
//noinspection resource
sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress());
if (SystemUtils.IS_OS_WINDOWS) {
sock = new ServerSocket(i, 50, new InetSocketAddress(i).getAddress());
} else {
sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress());
}
break;
} catch (Exception ignored) {
// we couldn't bind to the port, try the next one
Expand All @@ -85,6 +89,13 @@ public void checkExit(int status) {
while (true) {
try {
Socket connection = sock.accept();
if (!((InetSocketAddress) connection.getRemoteSocketAddress()).getAddress().isLoopbackAddress()) {
try {
connection.close();
} catch (IOException exception) {
continue;
}
}
Thread t = new SocketThread(connection);
t.start();
} catch (IOException exception) {
Expand Down
2 changes: 1 addition & 1 deletion windows_sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ project.afterEvaluate {
compilerArgs.add("/I" + javaHomeIncludeDir.get().resolve("win32").absolutePath)
compilerArgs.add("/Wall")
compilerArgs.add("/WX")
compilerArgs.add("/wd4068")
compilerArgs.add("/wd4068") // 4068: unknown pragma
compilerArgs.add("/wd4710") // 4710: function not inlined
compilerArgs.add("/wd4711") // 4711: function is inlined. there is no winning with msvc
compilerArgs.add("/wd4668") // 4668: macro is not defined
Expand Down
1 change: 0 additions & 1 deletion windows_sandbox/src/main/cpp/ContainerCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ BOOL RunExecutableInContainer(LPWSTR command_line, LPWSTR *rwMounts, LPWSTR *roM
SIZE_T attribute_size = 0;
STARTUPINFOEXW startup_info;
PROCESS_INFORMATION process_info;
LPWSTR string_sid = nullptr;
ZeroMemory(&startup_info, sizeof(startup_info));
ZeroMemory(&process_info, sizeof(process_info));
startup_info.StartupInfo.cb = sizeof(STARTUPINFOEXW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WindowsSandbox {
/**
* This method was pulled from the Utils class so people can use this module as a standalone library
*/
public static void copy(InputStream i, OutputStream o) throws IOException {
private static void copy(InputStream i, OutputStream o) throws IOException {
byte[] buffer = new byte[16384];
int read;
while ((read = i.read(buffer)) > 0) {
Expand All @@ -34,7 +34,7 @@ public static void copy(InputStream i, OutputStream o) throws IOException {

static {
try {
File tempFile = Files.createTempFile("minceraft_sandbox", ".dll").toFile();
File tempFile = Files.createTempFile("minecraft_sandbox", ".dll").toFile();
try (InputStream is = WindowsSandbox.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/windows/" + System.mapLibraryName("windows_sandbox"))) {
assert is != null: "Native library not compiled";
copy(is, Files.newOutputStream(tempFile.toPath()));
Expand Down

0 comments on commit 743b101

Please sign in to comment.