Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(legacy): AltManager move up/move down #5499

Merged
merged 6 commits into from
Feb 1, 2025

Conversation

MukjepScarlet
Copy link
Contributor

No description provided.

@MukjepScarlet MukjepScarlet changed the title feat(AltManager): move up/move down feat(legacy): AltManager move up/move down Jan 31, 2025
@opZywl
Copy link

opZywl commented Feb 1, 2025

Add suporte for cookie

@MukjepScarlet
Copy link
Contributor Author

Add suporte for cookie

What cookie?

@opZywl
Copy link

opZywl commented Feb 1, 2025

Add suporte for cookie

What cookie?

cookie login.

@opZywl
Copy link

opZywl commented Feb 1, 2025

like it

public class CookieLogin {
private static final String useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36";

private static final Gson gson = new Gson();

public static LoginData loginWithCookie(File cookieFile) {
    try {
        String[] cookiesText = FileUtils.readFileToString(cookieFile, StandardCharsets.UTF_8).split("\n");
        StringBuilder sb = new StringBuilder();
        for (String str1 : cookiesText) {
            String name = str1.split("\t")[5].trim();
            String value = str1.split("\t")[6].trim();
            sb.append(name).append("=").append(value).append("; ");
        }
        String cookie = sb.toString();
        String location = getNextLocation((new URI("https://sisu.xboxlive.com/connect/XboxLive/?state=login&cobrandId=8058f65d-ce06-4c30-9559-473c9275a65d&tid=896928775&ru=https://www.minecraft.net/en-us/login&aid=1142970254")).toURL(), "PHPSESSID=0");
        String location2 = getNextLocation((new URI(location.replace(" ", "%20"))).toURL(), cookie);
        String location3 = getNextLocation((new URI(location2)).toURL(), cookie);
        String accessToken = location3.split("accessToken=")[1];
        String decoded = (new String(Base64.getDecoder().decode(accessToken), StandardCharsets.UTF_8)).split("\"rp://api.minecraftservices.com/\",")[1];
        String token = decoded.split("\"Token\":\"")[1].split("\"")[0];
        String uhs = decoded.split(Pattern.quote("{\"DisplayClaims\":{\"xui\":[{\"uhs\":\""))[1].split("\"")[0];
        String xbl = "XBL3.0 x=" + uhs + ";" + token;
        String output = postExternal("https://api.minecraftservices.com/authentication/login_with_xbox", "{\"identityToken\":\"" + xbl + "\",\"ensureLegacyEnabled\":true}", true);
        String mcToken = ((JsonObject)gson.fromJson(output, JsonObject.class)).get("access_token").getAsString();
        HttpsURLConnection connection = (HttpsURLConnection)(new URI("https://api.minecraftservices.com/minecraft/profile")).toURL().openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Authorization", "Bearer " + mcToken);
        JsonObject profileResponse = (JsonObject)gson.fromJson(IOUtils.toString(connection.getInputStream()), JsonObject.class);
        return new LoginData(mcToken, null, profileResponse.get("id").getAsString(), profileResponse.get("name").getAsString());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Failed to login with cookie " + cookieFile.getName().replaceAll(".txt", "."));
        e.printStackTrace();
        return null;
    }
}

public static String getNextLocation(URL url, String cookie) throws IOException {
    HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
    connection.setRequestProperty("Accept-Encoding", "*");
    connection.setRequestProperty("Accept-Language", "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7");
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
    connection.setRequestProperty("Cookie", cookie);
    connection.setInstanceFollowRedirects(false);
    connection.connect();
    return connection.getHeaderField("Location");
}

public static String postExternal(String url, String post, boolean json) {
    try {
        HttpsURLConnection connection = (HttpsURLConnection)(new URI(url)).toURL().openConnection();
        connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        byte[] out = post.getBytes(StandardCharsets.UTF_8);
        int length = out.length;
        connection.setFixedLengthStreamingMode(length);
        connection.addRequestProperty("Content-Type", json ? "application/json" : "application/x-www-form-urlencoded; charset=UTF-8");
        connection.addRequestProperty("Accept", "application/json");
        connection.connect();
        OutputStream os = connection.getOutputStream();
        try {
            os.write(out);
            if (os != null)
                os.close();
        } catch (Throwable throwable) {
            if (os != null)
                try {
                    os.close();
                } catch (Throwable throwable1) {
                    throwable.addSuppressed(throwable1);
                }
            throw throwable;
        }
        int responseCode = connection.getResponseCode();
        InputStream stream = (responseCode / 100 == 2 || responseCode / 100 == 3) ? connection.getInputStream() : connection.getErrorStream();
        if (stream == null) {
            System.err.println(responseCode + ": " + url);
            System.out.println(IOUtils.toString(connection.getInputStream()));
            return null;
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        StringBuilder response = new StringBuilder();
        String lineBuffer;
        while ((lineBuffer = reader.readLine()) != null)
            response.append(lineBuffer);
        reader.close();
        return response.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

public static class LoginData {
    public String mcToken;

    public String newRefreshToken;

    public String uuid;

    public String username;

    public LoginData(String mcToken, String newRefreshToken, String uuid, String username) {
        this.mcToken = mcToken;
        this.newRefreshToken = newRefreshToken;
        this.uuid = uuid;
        this.username = username;
    }
}

}

@EclipsesDev
Copy link
Contributor

like it

public class CookieLogin { private static final String useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36";

private static final Gson gson = new Gson();

public static LoginData loginWithCookie(File cookieFile) {
    try {
        String[] cookiesText = FileUtils.readFileToString(cookieFile, StandardCharsets.UTF_8).split("\n");
        StringBuilder sb = new StringBuilder();
        for (String str1 : cookiesText) {
            String name = str1.split("\t")[5].trim();
            String value = str1.split("\t")[6].trim();
            sb.append(name).append("=").append(value).append("; ");
        }
        String cookie = sb.toString();
        String location = getNextLocation((new URI("https://sisu.xboxlive.com/connect/XboxLive/?state=login&cobrandId=8058f65d-ce06-4c30-9559-473c9275a65d&tid=896928775&ru=https://www.minecraft.net/en-us/login&aid=1142970254")).toURL(), "PHPSESSID=0");
        String location2 = getNextLocation((new URI(location.replace(" ", "%20"))).toURL(), cookie);
        String location3 = getNextLocation((new URI(location2)).toURL(), cookie);
        String accessToken = location3.split("accessToken=")[1];
        String decoded = (new String(Base64.getDecoder().decode(accessToken), StandardCharsets.UTF_8)).split("\"rp://api.minecraftservices.com/\",")[1];
        String token = decoded.split("\"Token\":\"")[1].split("\"")[0];
        String uhs = decoded.split(Pattern.quote("{\"DisplayClaims\":{\"xui\":[{\"uhs\":\""))[1].split("\"")[0];
        String xbl = "XBL3.0 x=" + uhs + ";" + token;
        String output = postExternal("https://api.minecraftservices.com/authentication/login_with_xbox", "{\"identityToken\":\"" + xbl + "\",\"ensureLegacyEnabled\":true}", true);
        String mcToken = ((JsonObject)gson.fromJson(output, JsonObject.class)).get("access_token").getAsString();
        HttpsURLConnection connection = (HttpsURLConnection)(new URI("https://api.minecraftservices.com/minecraft/profile")).toURL().openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Authorization", "Bearer " + mcToken);
        JsonObject profileResponse = (JsonObject)gson.fromJson(IOUtils.toString(connection.getInputStream()), JsonObject.class);
        return new LoginData(mcToken, null, profileResponse.get("id").getAsString(), profileResponse.get("name").getAsString());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Failed to login with cookie " + cookieFile.getName().replaceAll(".txt", "."));
        e.printStackTrace();
        return null;
    }
}

public static String getNextLocation(URL url, String cookie) throws IOException {
    HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
    connection.setRequestProperty("Accept-Encoding", "*");
    connection.setRequestProperty("Accept-Language", "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7");
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
    connection.setRequestProperty("Cookie", cookie);
    connection.setInstanceFollowRedirects(false);
    connection.connect();
    return connection.getHeaderField("Location");
}

public static String postExternal(String url, String post, boolean json) {
    try {
        HttpsURLConnection connection = (HttpsURLConnection)(new URI(url)).toURL().openConnection();
        connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        byte[] out = post.getBytes(StandardCharsets.UTF_8);
        int length = out.length;
        connection.setFixedLengthStreamingMode(length);
        connection.addRequestProperty("Content-Type", json ? "application/json" : "application/x-www-form-urlencoded; charset=UTF-8");
        connection.addRequestProperty("Accept", "application/json");
        connection.connect();
        OutputStream os = connection.getOutputStream();
        try {
            os.write(out);
            if (os != null)
                os.close();
        } catch (Throwable throwable) {
            if (os != null)
                try {
                    os.close();
                } catch (Throwable throwable1) {
                    throwable.addSuppressed(throwable1);
                }
            throw throwable;
        }
        int responseCode = connection.getResponseCode();
        InputStream stream = (responseCode / 100 == 2 || responseCode / 100 == 3) ? connection.getInputStream() : connection.getErrorStream();
        if (stream == null) {
            System.err.println(responseCode + ": " + url);
            System.out.println(IOUtils.toString(connection.getInputStream()));
            return null;
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        StringBuilder response = new StringBuilder();
        String lineBuffer;
        while ((lineBuffer = reader.readLine()) != null)
            response.append(lineBuffer);
        reader.close();
        return response.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

public static class LoginData {
    public String mcToken;

    public String newRefreshToken;

    public String uuid;

    public String username;

    public LoginData(String mcToken, String newRefreshToken, String uuid, String username) {
        this.mcToken = mcToken;
        this.newRefreshToken = newRefreshToken;
        this.uuid = uuid;
        this.username = username;
    }
}

}

should be in different pr

@mems01 mems01 added this to the b100 milestone Feb 1, 2025
@mems01 mems01 added 🔥 enhancement New feature or request 🌕 legacy labels Feb 1, 2025
@mems01 mems01 merged commit edf8a17 into CCBlueX:legacy Feb 1, 2025
1 check passed
@MukjepScarlet MukjepScarlet deleted the feat/l/altmanager branch February 1, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥 enhancement New feature or request 🌕 legacy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants