Parameterized Map not parameterized after proguard obfuscation - java

I am writing a plugin api for my application. The problem now is, that anything in my Maven Proguard config messed up the parameterized Maps, Lists and other parameterized objects.
So I have this code:
public final Map<String, PermissionGroup> getPermissionGroups() {
return Vars.PERMGROUPS;
}
Vars.PERMGROUPS is this:
public static final Map<String, PermissionGroup> PERMGROUPS = new HashMap<>();
So now, when I call getPermissionGroups I get a Map without parameters.
pom.xml
...
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-final.jar</outjar>
<includeDependency>true</includeDependency>
<options>
<option>-keep public class my.package.Main { public static void main(java.lang.String[]); }</option>
<option>-keep public class my.package.plugins.** { *; }</option>
<option>-keep public class my.package.wrapper.** { *; }</option>
<option>-dontusemixedcaseclassnames</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-verbose</option>
<option>-obfuscationdictionary dict.txt</option>
<option>-classobfuscationdictionary dict.txt</option>
<option>-packageobfuscationdictionary dict.txt</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
<assembly>
<inclusions>
...
</inclusions>
</assembly>
<archive>
<manifest>
<mainClass>my.package.Main</mainClass>
</manifest>
</archive>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.11</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
...
there are just 20000 random strings in dict.txt.

According to How do you stop Proguard from removing type parameters?. I just had to add -keepattributes Signature

Related

Use proguard to obfuscate one module in a multi-module project

I want to use proguard to obfuscate one module in a multi-module project and it doesn't run after obfuscation
The pom of the module needs to be obfuscated pom.xml :
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>${proguard.maven.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>${proguard.version}</proguardVersion>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-hx.jar</outjar>
<obfuscate>true</obfuscate>
<options>
<option>-dontshrink</option>
<option>-dontoptimize</option>
<option>-useuniqueclassmembernames</option>
<option>-adaptclassstrings</option>
<option>-dontusemixedcaseclassnames</option>
<option>-keepattributes
Exceptions,
InnerClasses,
Signature,
Deprecated,
SourceFile,
LineNumberTable,
*Annotation*,
EnclosingMethod
</option>
<option>-keepnames interface **</option>
<option>-keepparameternames</option>
<option>-keep
class com.ctcc.core.SSCSApplication {
public static void main(java.lang.String[]);
}
</option>
<option>-ignorewarnings</option>
<option>-keep interface * extends * { *; }</option>
<option>-keep class com.xxx.core.config.xxxxx</option>
<option>-keep class com.xxx.core.config.yyyyy</option>
<option>-keep class com.xxx.core.config.zzzzz</option>
<option>-keep class com.xxx.core.config.ccccc</option>
<option>-keep class com.xxx.core.config.ddddd</option>
<option>-keep class com.xxx.core.filter.LoggingBodyFilter</option>
<option>-keep class com.xxx.core.mapper.** { *; }</option>
<option>-keep class com.fasterxml.jackson.** { *; }</option>
<option>-keep class org.json.JSONObject.** {** put(java.lang.String,java.util.Map);}</option>
<option>-keep class org.gitlab4j.**</option>
<option>-keepclassmembers class * {
#org.springframework.context.annotation.Bean *;
#org.springframework.beans.factory.annotation.Autowired *;
#org.springframework.beans.factory.annotation.Value *;
}
</option>
<option>-dontwarn com.fasterxml.jackson.databind.**</option>
<option>-dontwarn com.fasterxml.jackson.**</option>
</options>
<injarNotExistsSkip>true</injarNotExistsSkip>
<libs>
<lib>${java.home}/jmods/java.base.jmod</lib>
<lib>${java.home}/jmods/java.datatransfer.jmod</lib>
<lib>${java.home}/jmods/java.prefs.jmod</lib>
<lib>${java.home}/jmods/java.xml.jmod</lib>
<lib>${java.home}/jmods/java.desktop.jmod</lib>
<lib>${java.home}/jmods/</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-base</artifactId>
<version>${proguard.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.xxx.core.SSCSApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After the package:
Internal structure in the obfuscated jar:
java -jar core-0.0.1-SNAPSHOT-hx.jar:
There is no main manifest attribute in core-0.0.1-SNAPSHOT-hx.jar

Java(JavaFX): Maven Proguard doesnt obfuscate FX Ids

I am using the Proguard plugin to obfuscate my project which is using JavaFX.
The problem is, that the Ids in the .fxml files arent obfuscated, so its not possible to connect to the controller.
Already tried on google, without sucess...
Any ideas?
Proguard configuration:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-final.jar</outjar>
<includeDependency>true</includeDependency>
<options>
<option>-keep public class com.skriptide.main.Main { public static void
main(java.lang.String[]); }
</option>
<option>-keepattributes Signature,*Annotation*,Exceptions</option>
<option>-dontusemixedcaseclassnames</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-verbose</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/ext/jfxrt.jar</lib>
<lib>${java.home}/lib/jfxswt.jar</lib>
</libs>
<assembly>
<inclusions>
<inclusion>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<library>true</library>
</inclusion>
<inclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<library>true</library>
</inclusion>
</inclusions>
</assembly>
<archive>
<manifest>
<mainClass>com.skriptide.main.Main</mainClass>
</manifest>
</archive>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.2.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Thanks
You have to instruct ProGuard also to rename obfuscated classnames in the .fxml files. Assuming that they are already contained in the original jar file, you can try to add the following option to your proguard configuration:
<options>
...
<option>-adaptresourcefilecontents **.fxml</option>
...
</options>

LifecycleExecutionException while using <proguardInclude></proguardInclude> tag in proguard-maven-plugin

I am using proguard-maven-plugin to obfuscate my jar. If I take plugin structure like this.
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.11</version>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<maxMemory>576m</maxMemory>
<proguardVersion>5.0</proguardVersion>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>build/lib/${project.build.finalName}.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<libs>
<lib>${java.home}/jre/lib/rt.jar</lib>
<lib>${java.home}/jre/lib/jce.jar</lib>
</libs>
<options>
<option>-keep public class * { protected *;}</option>
</options>
</configuration>
</plugin>
for this it works fine and give me a obfuscated jar, but when try give it proguard.conf file in <proguardInclude></proguardInclude> in this tag instead of
<options>
<option></option>
</options> this tag it throw an exception
"**org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.wvengen:proguard-maven-plugin:2.0.11:proguard (default) on project**"
:like
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.11</version>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<maxMemory>576m</maxMemory>
<proguardVersion>5.0</proguardVersion>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>build/lib/${project.build.finalName}.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<proguardInclude>${basedir}/proguard.conf</proguardInclude>
<libs>
<lib>${java.home}/jre/lib/rt.jar</lib>
<lib>${java.home}/jre/lib/jce.jar</lib>
</libs>
</configuration>
</plugin>
my proguard.conf contains -
keepattributes
Signature,LineNumberTable,*Annotation*,LocalVariableTable,SourceFile
-keep public class * { public protected *;}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class com/compny/blha/proj/Class/Container
{
}
-keep fields com/compny/blha/proj/Class/VersionUID long;
I got the solution, just I was need to change progaurd.conf like
-keepattributes
Signature,LineNumberTable,*Annotation*,LocalVariableTable,SourceFile
-keep public class * { public protected *;}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class com/compny/blha/proj/Class/Container
{
}
-keep fields com/compny/blha/proj/Class/VersionUID long;
I made mistake at "keepattributes" that should be "-keepattributes "

mvn proguard: Is there possible obfuscate dependency before copying

I have plugins configuration like below:
<project>
...
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>4.8</proguardVersion>
<obfuscate>true</obfuscate>
<includeDependency>true</includeDependency>
<injar>${project.artifactId}-${project.version}.jar</injar>
<outjar>${project.artifactId}-${project.version}-obf.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<maxMemory>256m</maxMemory>
<options>
<option>-keepclasseswithmembers class **, !some.specific.package.** { *; }</option>
<option>-keep public class some.specific.package.Main { public *; public static *; }</option>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-dontwarn org.apache.log4j.**</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/javaws.jar</lib>
<lib>${javafx_home}/lib/jfxrt.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.8</version>
</dependency>
</dependencies>
</plugin>
</build>
...
</project>
I want to obfuscate specific package some.specific.package for jar and their dependencies (before copying). Is there possible to do it?
did you try the command -keeppackagenames with negation (!) of the package you want to obfuscate? I tried teh following, with the result that just package org.neo4j.cineasts.domain was obfuscated. See below:
<configuration>
<proguardVersion>4.8</proguardVersion>
<obfuscate>true</obfuscate>
<includeDependency>true</includeDependency>
<injar>${project.artifactId}-${project.version}.jar</injar>
<outjar>${project.artifactId}-${project.version}-obf.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<maxMemory>256m</maxMemory>
<options>
<option>-keep public class org.neo4j.cineasts.controller.** { public *; public static *; }</option>
<option>-keeppackagenames !org.neo4j.cineasts.domain</option>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
</options>
<libs>
<lib>C:/devtools/Java/jdk1.6.0_29_64/jre/lib/rt.jar</lib>
<lib>C:/devtools/Java/jdk1.6.0_29_64/jre/lib/javaws.jar</lib>
</libs>
</configuration>
Bests, Michael

Maven, Proguard and assembly issues

I'm trying to get Maven working with ProGuard.
What I want to achieve is the following:
Run ProGuard over my source files and produce obfuscated classes
Create a manifest file that references the main class so that I can execute it as a jar
Unpack all of the associated library jars and create one huge jar containing them all. This file should only contact .class and .xml files only.
Assemble them into .zip and tar.gz files that include various README.txt files and so on.
So far I've got something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.class.path.MainClass</mainClass>
</manifest>
</archive>
<includes>
<include>**/*.class</include>
<include>**/*.xml</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<options>
<option>-allowaccessmodification</option>
</options>
<obfuscate>true</obfuscate>
<injar>classes</injar>
<outjar>${project.build.finalName}.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<proguardInclude>src/main/assembly/proguard.conf</proguardInclude>
<libs>
lib/rt.jar</lib>
</libs>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/bin.xml
</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
But I'm having no joy. Can anyone give me any vague pointers on this?
Thanks in advance,
Matt
Here is the configuration that had worked for me
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<options>
<option>-allowaccessmodification</option>
<option>-keep public class com.class.path.MainClass { public *; public static *; }</option>
</options>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-small.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
<addMavenDescriptor>false</addMavenDescriptor>
</configuration>
</plugin>
The final jar is the finalName-small.jar

Categories