-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
398 additions
and
64 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
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
group = "com.liux.java.charles" | ||
version = "1.1.0-SNAPSHOT" | ||
|
||
allprojects { | ||
buildscript { | ||
repositories { | ||
maven { | ||
setUrl("https://maven.aliyun.com/repository/public/") | ||
} | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} | ||
repositories { | ||
maven { | ||
setUrl("https://maven.aliyun.com/repository/public/") | ||
} | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} |
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,41 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("java") | ||
id("application") | ||
id("org.jetbrains.kotlin.jvm") version "1.5.20" | ||
} | ||
|
||
group = rootProject.group | ||
version = rootProject.version | ||
java.sourceCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
implementation("commons-io:commons-io:2.10.0") | ||
implementation("org.javassist:javassist:3.28.0-GA") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
val fatJar = task("fatJar", type = Jar::class) { | ||
manifest { | ||
attributes["Main-Class"] = "com.liux.java.charles.crack.Main" | ||
} | ||
from(configurations.compileClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) | ||
with(tasks["jar"] as CopySpec) | ||
} | ||
tasks { | ||
"build" { | ||
dependsOn(fatJar) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/liux/java/charles/Main.kt → .../java/com/liux/java/charles/crack/Main.kt
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,41 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("java") | ||
id("application") | ||
id("org.jetbrains.kotlin.jvm") version "1.5.20" | ||
} | ||
|
||
group = rootProject.group | ||
version = rootProject.version | ||
java.sourceCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
|
||
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
val fatJar = task("fatJar", type = Jar::class) { | ||
manifest { | ||
attributes["Main-Class"] = "com.liux.java.charles.keygen.CharlesKeygenUI" | ||
} | ||
from(configurations.compileClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) | ||
with(tasks["jar"] as CopySpec) | ||
} | ||
tasks { | ||
"build" { | ||
dependsOn(fatJar) | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
keygen/src/main/java/com/liux/java/charles/keygen/CharlesKeygen.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,91 @@ | ||
package com.liux.java.charles.keygen; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.SecureRandom; | ||
import java.util.Formatter; | ||
import java.util.Random; | ||
|
||
public class CharlesKeygen { | ||
|
||
private static final Random RANDOM = new SecureRandom(); | ||
|
||
static final long RC5KEY_NAME = 0x7a21c951691cd470L; | ||
|
||
static final long RC5KEY_KEY = 0xb4f0e0ccec0eafadL; | ||
|
||
/** | ||
* magic by worked / banned key | ||
*/ | ||
static final int NAME_PREFIX = 0x54882f8a; | ||
|
||
private CharlesKeygen() { | ||
|
||
} | ||
|
||
static int calcPrefix(String name) { | ||
final byte[] bytes = name.replaceAll("[ \u180e ]", " ").getBytes(StandardCharsets.UTF_8); | ||
int length = bytes.length + 4; | ||
int padded = ((~length + 1) & (8 - 1)) + length; | ||
ByteBuffer input = ByteBuffer.allocate(padded).putInt(bytes.length).put(bytes); | ||
input.rewind(); | ||
|
||
SimpleRC5 rc5 = new SimpleRC5(RC5KEY_NAME); | ||
ByteBuffer output = ByteBuffer.allocate(padded); | ||
while (input.hasRemaining()) { | ||
output.putLong(rc5.encrypt(input.getLong())); | ||
} | ||
output.rewind(); | ||
|
||
int n = 0; | ||
for (byte b : output.array()) { | ||
n = rc5.rotateLeft(n ^ b, 0x3); | ||
} | ||
return n; | ||
} | ||
|
||
static int xor(final long n) { | ||
long n2 = 0L; | ||
for (int i = 56; i >= 0; i -= 8) { | ||
n2 ^= ((n >>> i) & 0xffL); | ||
} | ||
return Math.abs((int) (n2 & 0xffL)); | ||
} | ||
|
||
static String key(int prefix, int suffix) { | ||
long in = ((long) prefix << 32); | ||
switch (suffix >> 16) { | ||
case 0x0401: // user - v4 | ||
case 0x0402: // site - v4 | ||
case 0x0403: // multi-site - v4 | ||
in |= suffix; | ||
break; | ||
default: | ||
in |= (0x01000000 | (suffix & 0xffffff)); | ||
break; | ||
} | ||
long out = new SimpleRC5(RC5KEY_KEY).decrypt(in); | ||
return new Formatter().format("%02x%016x", xor(in), out).toString(); | ||
} | ||
|
||
public static String keygen(String name) { | ||
return keygen(name, RANDOM.nextInt()); | ||
} | ||
|
||
public static String keygen(String name, int suffix) { | ||
int prefix = calcPrefix(name) ^ NAME_PREFIX; | ||
return key(prefix, suffix); | ||
} | ||
|
||
public static void main(String[] names) { | ||
if (names.length == 0) { | ||
System.err.println("Usage: java -jar charles-keygen.jar name [,...]"); | ||
CharlesKeygenUI.main(names); | ||
} else { | ||
for (String name : names) { | ||
System.out.format("Name: %s, Key: %s%n", name, keygen(name)); | ||
} | ||
} | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
keygen/src/main/java/com/liux/java/charles/keygen/CharlesKeygenUI.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,81 @@ | ||
package com.liux.java.charles.keygen; | ||
|
||
import java.awt.*; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
|
||
public class CharlesKeygenUI extends JFrame implements DocumentListener { | ||
private final JTextField textFieldName; | ||
private final JTextField textFieldKey; | ||
|
||
public CharlesKeygenUI() { | ||
setSize(310, 120); | ||
setTitle("Charles Keygen"); | ||
setResizable(false); | ||
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
setLocation(screenSize.width / 2 - getSize().width / 2, screenSize.height / 2 - getSize().height / 2); | ||
|
||
JLabel labelName = new JLabel("Name: ", JLabel.TRAILING); | ||
labelName.setBounds(10, 10, 50, 30); | ||
JLabel labelKey = new JLabel("Key: ", JLabel.TRAILING); | ||
labelKey.setBounds(10, 50, 50, 30); | ||
|
||
textFieldName = new JTextField("Cracked", 20); | ||
textFieldName.setBounds(60, 10, 240, 30); | ||
textFieldName.getDocument().addDocumentListener(this); | ||
labelName.setLabelFor(textFieldName); | ||
|
||
textFieldKey = new JTextField(20); | ||
textFieldKey.setEditable(false); | ||
textFieldKey.setSize(300, 40); | ||
textFieldKey.setBounds(60, 50, 240, 30); | ||
int fontSize = textFieldKey.getFont().getSize(); | ||
textFieldKey.setFont(new Font(Font.MONOSPACED, Font.PLAIN, fontSize)); | ||
labelKey.setLabelFor(textFieldKey); | ||
|
||
setLayout(null); | ||
Container contentPane = getContentPane(); | ||
contentPane.add(labelName); | ||
contentPane.add(textFieldName); | ||
contentPane.add(labelKey); | ||
contentPane.add(textFieldKey); | ||
|
||
setDefaultCloseOperation(EXIT_ON_CLOSE); | ||
updateKey(); | ||
} | ||
|
||
@Override | ||
public void insertUpdate(DocumentEvent e) { | ||
updateKey(); | ||
} | ||
|
||
@Override | ||
public void removeUpdate(DocumentEvent e) { | ||
updateKey(); | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent e) { | ||
updateKey(); | ||
} | ||
|
||
private void updateKey() { | ||
String text = textFieldName.getText(); | ||
if (text.isEmpty()) { | ||
textFieldKey.setText(""); | ||
} else { | ||
textFieldKey.setText(CharlesKeygen.keygen(text)); | ||
} | ||
} | ||
|
||
public static void main(String[] arguments) { | ||
if (arguments.length > 0) { | ||
CharlesKeygen.main(arguments); | ||
} else { | ||
new CharlesKeygenUI().setVisible(true); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.