Skip to content

Commit 3820384

Browse files
committed
[addition] fix a bug with renaming strings. Added encode strings, but it will only encode one string per line this will be fixed soon
1 parent 510957c commit 3820384

File tree

17 files changed

+312
-78
lines changed

17 files changed

+312
-78
lines changed

Output.py

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

assets/Classes.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Example,w3cBfsFHVWpvzEtdqCEHLX
1+
Example,w3FfEMSoZGDSAcEhfDZozB

assets/Vars.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test,w3VbHCrluAxxlunUtKpNqz
1+
test,w3zcvDodboCrfsjNQephoV

assets/config.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ insert_obfStrings = true
1717
obfString_amount = 5
1818

1919
# Encoder Settings
20-
encode_imports = true
2120
encoded_list_garbage_length = 20
2221
encoder_type = bin
2322
binary_splitter = %
2423
# bin = binary
2524
# hex = hexadecimal
2625
# base64 = base64
2726
encode_strings = true
27+
encode_imports = true
28+
encode_code = false
29+
2830

2931
map_path = assets

assets/test3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Example():
44
def __init__(self):
5-
print("test")
5+
print("#test#") # test
66
print(random.seed(7))
77

88
test = Example()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.madmeg.api.obfuscator;
2+
3+
import java.io.UnsupportedEncodingException;
4+
import java.math.BigInteger;
5+
import java.nio.charset.StandardCharsets;
6+
import java.util.ArrayList;
7+
import java.util.Base64;
8+
import java.util.List;
9+
10+
/**
11+
* @author Madmegsox1
12+
* @since 24/12/2021
13+
*/
14+
15+
public final class EncodingUtils {
16+
public static String stringToHex(String toConvert){
17+
return String.format("%040x", new BigInteger(1, toConvert.getBytes(StandardCharsets.UTF_8)));
18+
}
19+
20+
public static String stringToBase64(String toConvert){
21+
try {
22+
return Base64.getEncoder()
23+
.encodeToString(toConvert.getBytes(StandardCharsets.UTF_8.toString()));
24+
} catch(UnsupportedEncodingException ex) {
25+
throw new RuntimeException(ex);
26+
}
27+
}
28+
29+
public static String stringToBinary(String input) {
30+
StringBuilder result = new StringBuilder();
31+
char[] chars = input.toCharArray();
32+
for (char aChar : chars) {
33+
result.append(
34+
String.format("%8s", Integer.toBinaryString(aChar))
35+
.replaceAll(" ", "0")
36+
);
37+
}
38+
return result.toString();
39+
}
40+
41+
public static String prettyBinary(String binary, int blockSize, String separator) {
42+
43+
List<String> result = new ArrayList<>();
44+
int index = 0;
45+
while (index < binary.length()) {
46+
result.add(binary.substring(index, Math.min(index + blockSize, binary.length())));
47+
index += blockSize;
48+
}
49+
50+
return String.join(separator, result);
51+
}
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.madmeg.api.obfuscator;
2+
3+
/**
4+
* @author Madmegsox1
5+
* @since 29/12/2021
6+
*
7+
* bunch of shit code but idk
8+
*/
9+
10+
public final class FindString {
11+
private final String line;
12+
private String foundLine;
13+
private int start;
14+
private final boolean keepChar;
15+
16+
public FindString(String line, boolean keepChar){
17+
this.line = line;
18+
this.start = -1;
19+
this.keepChar = keepChar;
20+
this.foundLine = find();
21+
}
22+
23+
private String find(){
24+
if(!line.contains("\"") && !line.contains("'"))return "";
25+
boolean open = false;
26+
boolean open2 = false;
27+
28+
final StringBuilder toReturn = new StringBuilder();
29+
for(int i = 0; i < line.length(); i++){
30+
final char val = line.charAt(i);
31+
if(val == '"' && !open2){
32+
open = !open;
33+
if(!keepChar) {
34+
continue;
35+
}else if(!open){
36+
toReturn.append('"');
37+
}
38+
}
39+
if(val == '\'' && !open){
40+
open2 = !open2;
41+
if(!keepChar) {
42+
continue;
43+
}else if(!open2){
44+
toReturn.append("'");
45+
}
46+
}
47+
48+
if(open || open2){
49+
if(start == -1){
50+
start = i;
51+
}
52+
toReturn.append(val);
53+
}
54+
}
55+
return toReturn.toString();
56+
}
57+
58+
public String getFoundLine() {
59+
return foundLine;
60+
}
61+
62+
public int getStart() {
63+
return start;
64+
}
65+
}

src/main/java/org/madmeg/api/obfuscator/tasks/TaskFactory.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public void runTasks(){
2121

2222
@Override
2323
public void poolTasks(){
24-
2524
if(Core.CONFIG.isRemoveComments()){
2625
this.queueTask(new RemoveComments(Loader.FILE));
2726
}
@@ -37,15 +36,14 @@ public void poolTasks(){
3736
if(Core.CONFIG.isClassNames()){
3837
this.queueTask(new RenameClass(Loader.FILE));
3938
}
40-
41-
if(Core.CONFIG.isEncodeStrings()){
42-
43-
}
4439
if(Core.CONFIG.isInsertGarbage()){
4540
this.queueTask(new AddGarbage(Loader.FILE));
4641
}
47-
if(Core.CONFIG.isInsertObfStrings()){
48-
42+
if(Core.CONFIG.isEncodeStrings()){
43+
this.queueTask(new EncodeString(Loader.FILE));
44+
}
45+
if(Core.CONFIG.isEncodeCode()){
46+
//this.queueTask(new EncodeCode(Loader.FILE));
4947
}
5048

5149
// TODO add save obf file

src/main/java/org/madmeg/impl/config/Config.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public final class Config {
1818
private int garbageAmount;
1919
private int garbageLength;
2020
private boolean insertObfStrings;
21-
private int obfStringAmount;
2221
private boolean removeComments;
2322

2423

@@ -27,6 +26,7 @@ public final class Config {
2726
private String encoderType;
2827
private String binarySplitter;
2928
private boolean encodeStrings;
29+
private boolean encodeCode;
3030
private String mapPath;
3131

3232
public Config(){}
@@ -133,14 +133,6 @@ public void setGarbageAmount(int garbageAmount) {
133133
this.garbageAmount = garbageAmount;
134134
}
135135

136-
public boolean isInsertObfStrings() {
137-
return insertObfStrings;
138-
}
139-
140-
public void setInsertObfStrings(boolean insertObfStrings) {
141-
this.insertObfStrings = insertObfStrings;
142-
}
143-
144136
/**
145137
* @return the number of lines taken up by garbage {@link org.madmeg.impl.tasks.AddGarbage}
146138
*/
@@ -155,14 +147,6 @@ public void setGarbageLength(int garbageLength) {
155147
this.garbageLength = garbageLength;
156148
}
157149

158-
public int getObfStringAmount() {
159-
return obfStringAmount;
160-
}
161-
162-
public void setObfStringAmount(int obfStringAmount) {
163-
this.obfStringAmount = obfStringAmount;
164-
}
165-
166150
/**
167151
* @return if the obfuscator should remove comments {@link org.madmeg.impl.tasks.RemoveComments}
168152
*/
@@ -239,6 +223,14 @@ public void setEncodeStrings(boolean encodeStrings) {
239223
this.encodeStrings = encodeStrings;
240224
}
241225

226+
public boolean isEncodeCode() {
227+
return encodeCode;
228+
}
229+
230+
public void setEncodeCode(boolean encodeCode) {
231+
this.encodeCode = encodeCode;
232+
}
233+
242234
public String getMapPath() {
243235
return mapPath;
244236
}

src/main/java/org/madmeg/impl/config/ConfigLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ public void load(File file) {
5555
case "insert_garbage" -> config.setInsertGarbage(isTrue(data[1]));
5656
case "garbage_amount" -> config.setGarbageAmount(Integer.parseInt(data[1]));
5757
case "garbage_length" -> config.setGarbageLength(Integer.parseInt(data[1]));
58-
case "insert_obfStrings" -> config.setInsertObfStrings(isTrue(data[1]));
59-
case "obfString_amount" -> config.setObfStringAmount(Integer.parseInt(data[1]));
6058
case "remove_comments" -> config.setRemoveComments(isTrue(data[1]));
6159
case "encode_imports" -> config.setEncodeImports(isTrue(data[1]));
6260
case "encoded_list_garbage_length" -> config.setEncodedListGarbageLength(Integer.parseInt(data[1]));
6361
case "encoder_type" -> config.setEncoderType(data[1]);
6462
case "binary_splitter" -> config.setBinarySplitter(data[1]);
6563
case "encode_strings" -> config.setEncodeStrings(isTrue(data[1]));
64+
case "encode_code" -> config.setEncodeCode(isTrue(data[1]));
6665
case "map_path" -> config.setMapPath(data[1]);
6766
}
6867
}

0 commit comments

Comments
 (0)