Skip to content

Commit

Permalink
fix: new exclusion system
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Dec 18, 2024
1 parent 43bb9fb commit 18d4aae
Show file tree
Hide file tree
Showing 17 changed files with 1,313 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public DefaultConfig(Config config, String path) {
}

public List<String> getExemptions() {
return getStringList("exempt", Arrays.asList(DefaultExempts.DEFAULT_EXEMPTS));
return getStringList("exempt", new ArrayList<>());
}

public List<String> getExemptionsv2() {
return getStringList("exclude", Arrays.asList(DefaultExempts.DEFAULT_EXEMPTS_V2));
}

public boolean getBoolean(String path, final boolean dflt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,73 @@ public class DefaultExempts {
"class{^org\\/w3c}",
"class{^software\\/amazon}",
};

public static final String[] DEFAULT_EXEMPTS_V2 = {
// Original mappings
"@class com.apache.*",
"@class com.google.*",
"@class com.sun.*",
"@class java.*",
"@class javax.*",
"@class jdk.*",
"@class kotlin.*",
"@class org.apache.*",
"@class org.bouncycastle.*",
"@class org.eclipse.*",
"@class org.hibernate.*",
"@class org.jcp.*",
"@class org.joda.*",
"@class org.json.*",
"@class org.jsoup.*",
"@class org.mapleir.*",
"@class org.objectweb.*",
"@class org.slf4j.*",
"@class org.springframework.*",
"@class org.xml.*",
"@class org.yaml.*",
"@class sun.*",
"@class net.minecraft.*",
"@class net.sf.*",
"@class net.sourceforge.*",
"@class net.dv8tion.*",
"@class it.unimi.dsi.fastutil.*",

// Additional common dependencies
"@class com.fasterxml.*",
"@class com.iwebpp.*",
"@class com.neovisionaries.*",
"@class com.sun.*",
"@class gnu.*",
"@class okhttp3.*",
"@class okio.*",
"@class org.apache.*",
"@class org.intellij.*",
"@class org.jetbrains.*",
"@class org.java_websocket.*",
"@class org.slf4j.*",
"@class tomp2p.*",

// Additional useful frameworks and libraries
"@class ch.qos.logback.*",
"@class com.squareup.*",
"@class com.thoughtworks.*",
"@class io.netty.*",
"@class jakarta.*",
"@class net.bytebuddy.*",
"@class org.aspectj.*",
"@class org.assertj.*",
"@class org.checkerframework.*",
"@class org.codehaus.*",
"@class org.hamcrest.*",
"@class org.junit.*",
"@class org.mockito.*",
"@class org.mozilla.*",
"@class org.objenesis.*",
"@class org.openjfx.*",
"@class org.postgresql.*",
"@class org.reactivestreams.*",
"@class org.skyscreamer.*",
"@class org.w3c.*",
"@class software.amazon.*"
};
}
13 changes: 11 additions & 2 deletions dev.skidfuscator.obfuscator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ dependencies {
implementation 'org.yaml:snakeyaml:1.33'

testImplementation files("$buildDir/classes/jasm/test")
testImplementation 'org.mockito:mockito-core:4.2.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
}

tasks.withType(JavaCompile) {
options.compilerArgs += [
'--add-exports', 'java.base/jdk.internal.reflect=ALL-UNNAMED',
'--add-exports', 'java.base/jdk.internal.util=ALL-UNNAMED'
]
}

test {
useJUnitPlatform()
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dev.skidfuscator.obfuscator.event.impl.transform.method.*;
import dev.skidfuscator.obfuscator.event.impl.transform.skid.*;
import dev.skidfuscator.obfuscator.exempt.ExemptManager;
import dev.skidfuscator.obfuscator.exempt.v2.ExclusionParser;
import dev.skidfuscator.obfuscator.hierarchy.Hierarchy;
import dev.skidfuscator.obfuscator.hierarchy.SkidHierarchy;
import dev.skidfuscator.obfuscator.io.apk.ApkInputSource;
Expand Down Expand Up @@ -447,11 +448,7 @@ protected void _importConfig() {
protected void _importExempt() {
/* Importation and exemptions */
LOGGER.post("Importing exemptions...");
/*
* This is the parsing bit. We initiate a progress bar and
* simply just call the exempt analysis which builds the
* exclusion call and caches it.
*/

try(final ProgressWrapper progressBar = ProgressUtil.progressCheck(
config.getExemptions().size(),
"Imported " + config.getExemptions().size() + " exclusions"
Expand All @@ -462,6 +459,16 @@ protected void _importExempt() {
}
}

try(final ProgressWrapper progressBar = ProgressUtil.progressCheck(
config.getExemptionsv2().size(),
"Imported " + config.getExemptions().size() + " exclusions v2"
)) {
for (String s : config.getExemptionsv2()) {
exemptAnalysis.add(ExclusionParser.parsePatternExclusion(s));
progressBar.tick();
}
}

LOGGER.log("Imported: \n " + exemptAnalysis.toString());
LOGGER.log("Finished importing exemptions");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public boolean test(final ClassNode classNode) {
* @return the boolean
*/
public boolean test(final MethodNode methodNode) {
assert testers.containsKey(ExclusionType.METHOD) : "Trying to test with null method tester";
if (test(methodNode.getOwnerClass()))
return true;

assert testers.containsKey(ExclusionType.METHOD) : "Trying to test with null method tester";
return testers.poll(ExclusionType.METHOD).test(methodNode);
}

Expand All @@ -46,8 +48,10 @@ public boolean test(final MethodNode methodNode) {
* @return the boolean
*/
public boolean test(final FieldNode fieldNode) {
assert testers.containsKey(ExclusionType.FIELD) : "Trying to test with null field tester";
if (test(fieldNode.getOwnerClass()))
return true;

assert testers.containsKey(ExclusionType.FIELD) : "Trying to test with null field tester";
return testers.poll(ExclusionType.FIELD).test(fieldNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public void add(String exempt) {
globalExempt.add(exempt);
}

public void add(Exclusion exclusion) {
globalExempt.add(exclusion);
}

public void add(ClassNode exclusion) {
globalExempt.add(exclusion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public void add(final String exclusionStr) {
//System.out.println(this);
}

public void add(final Exclusion exclusion) {
exclusions.add(exclusion);
}

@Override
public void add(ClassNode exclusion) {
classCache.put(exclusion, true);
Expand Down
Loading

0 comments on commit 18d4aae

Please sign in to comment.