Skip to content

Commit 9be70cd

Browse files
committed
Implement --include-package
1 parent 469128c commit 9be70cd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/java/net/cvs0/Main.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public class Main implements Callable<Integer>
116116
@Option(names = {"--sequential-transformers"}, description = "Run transformers sequentially - each transformer processes all classes before the next starts (disabled by default)")
117117
private Boolean sequentialTransformers;
118118

119+
@Option(names = {"--include-package"}, description = "Include specific package for obfuscation (can be used multiple times, e.g., com.example, org.myapp)")
120+
private List<String> includePackages;
121+
119122
public static void main(String[] args)
120123
{
121124
try {
@@ -460,6 +463,16 @@ private ObfuscationConfig buildConfiguration() throws Exception
460463
builder.sequentialTransformers(sequentialTransformers);
461464
}
462465

466+
if (includePackages != null && !includePackages.isEmpty()) {
467+
for (String packageName : includePackages) {
468+
String normalizedPackage = packageName.replace('.', '/');
469+
builder.includePackage(normalizedPackage);
470+
if (verbose) {
471+
System.out.println("Including package for obfuscation: " + packageName + " (" + normalizedPackage + ")");
472+
}
473+
}
474+
}
475+
463476
// Set defaults if no rename options specified and no config file
464477
if (configFile == null && renameClasses == null && renameFields == null && renameMethods == null && renameLocalVariables == null && obfuscateConditions == null) {
465478
builder.renameClasses(true)

src/main/java/net/cvs0/config/ConfigValidator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,23 @@ private static boolean isValidPackageName(String packageName)
250250
return false;
251251
}
252252

253-
if (packageName.startsWith(".") || packageName.endsWith(".") || packageName.contains("..")) {
253+
boolean isDotNotation = packageName.contains(".");
254+
boolean isSlashNotation = packageName.contains("/");
255+
256+
if (isDotNotation && isSlashNotation) {
257+
return false;
258+
}
259+
260+
String separator = isDotNotation ? "\\." : "/";
261+
char sepChar = isDotNotation ? '.' : '/';
262+
263+
if (packageName.startsWith(String.valueOf(sepChar)) ||
264+
packageName.endsWith(String.valueOf(sepChar)) ||
265+
packageName.contains(sepChar + "" + sepChar)) {
254266
return false;
255267
}
256268

257-
String[] parts = packageName.split("\\.");
269+
String[] parts = packageName.split(separator);
258270
for (String part : parts) {
259271
if (part.isEmpty() || !Character.isJavaIdentifierStart(part.charAt(0))) {
260272
return false;

0 commit comments

Comments
 (0)