Issues with obfuscation in Java using ZKM - java

Im trying to obfuscate an eclipse based java application. We are using ZKM script for Obfuscation.we recently added a new feature to the existing application where we have used the poi-3.9-20121203.jar third party jar and there are around 3 to 4 dependent jars for this. Im getting the below error when trying to obfuscate the code
Unexpected Error (D). Please report the problem to bugs#zelix.com
com.zelix.m7: Class 'org.apache.poi.ss.usermodel.Sheet' in file 'D:\workSpace\Test Ofucscation\Relea
se3\mit\plugins\com.ins.hi.stores_1.0.0.201404081434.jar!lib/poi-3.9- 20121203.jar!org/a
pache/poi/ss/usermodel/Sheet.class' has been opened and is implemented by class 'org.apache.poi.xssf
.usermodel.XSSFSheet' in file 'D:\workSpace\TestOfucscation\Release3\mit\plugins\poi-ooxml-3.9-2
0121203.jar!org/apache/poi/xssf/usermodel/XSSFSheet.class'. Class 'org.apache.poi.xssf.usermodel.XSS
FSheet' is used by the opened classes but it has not been opened. Either 'org.apache.poi.ss.usermod
el.Sheet' should not be opened or 'org.apache.poi.xssf.usermodel.XSSFSheet' must also be opened for
obfuscation. (B)
at com.zelix.w1.a(w1.java:361)
at com.zelix.w1.b(w1.java:95)
at com.zelix.rp.a(rp.java:7)
at com.zelix.rp.c(rp.java:113)
at com.zelix.rp.a(rp.java:101)
at com.zelix.q0.a(q0.java:128)
at com.zelix.q0.a(q0.java:160)
at com.zelix.zo.a(zo.java:463)
at com.zelix.zo.a(zo.java:710)
at com.zelix.zo.<init>(zo.java:351)
at com.zelix.f3.a(f3.java:1130)
at com.zelix.f3.a(f3.java:1249)
at com.zelix.i2.a(i2.java:15)
at com.zelix.q3.a(q3.java:222)
at com.zelix.x1.a(x1.java:1490)
at com.zelix.t1.a(t1.java:1793)
at com.zelix.t1.a(t1.java:39)
at com.zelix.oc.a(oc.java:96)
at com.zelix.nc.a(nc.java:89)
at com.zelix.mc.a(mc.java:22)
at com.zelix.ic.a(ic.java:5)
at com.zelix.ge.a(ge.java:3)
at com.zelix.ak.a(ak.java:291)
at com.zelix.ak.<init>(ak.java:438)
Below are the things that I have done
After including the new feature and third party jar in the application, I have updated the classpath of the third party jar& all the dependent jars under the classpath in the Obfuscation_Script.txt.
before executing the obfuscation script, i have replaced the poi-3.9.jar with only the classes that Im using in the classes that I have newly developed.
But im getting the above error when I run the obfuscation script.
Any help on this is much appreciated. Thanks in Advance.

In ZKM script, you have to include the dependent jar files for poi-3.9.jar.
classpath ".\lib\poi-3.9-FINAL\*.jar"

Related

How to import packages from the external Library in Java?

I'm a n00b coder. I found an interesting library and trying to start toying with it. Which is not going great. This library is from 99' and uses JUnit (which I'm unfamiliar with) so there is a lot of confusing stuff. But it seems like the source of my failing even more elementary. Namely I have troubles importing packages.
This library has a test called StandardEvalTest.java. I moved to it to main Java directory and now I'm trying and failing to launch it using JUnit.
This package path org.pokersource.game.Deck goes directly from the directory where the test StandardEvalTest.java sits.
I also added the main java directory to the PATH environmental variable. Which as I assumed will allow import to locate the package.
None of those two things help. Also I was suspecting that maybe Deck.java and Deck.class are not enough and I have to do some work to create a package from it. But as far as I can say from Oracle doc the only thing needed is a package name in the header. Which seems to be present.
So I'm out of moves. Please help!
PS: Some additional info inspired by #Dhrubo 's answer:
The test I'm trying to run indeed sits in the main java folder of the library. (I moved it here hoping that when running from here it would be easier to find the package)
If I'm trying to compile the test instead of running it with JUnit he seem to fail to find JUnit classes and other JUnit related stuff.
[Oh OK I'm an idiot! Dont't mind me]
You should include the package while running StandardEvalTest.java as below
javac -cp [classpath] org.pokersource.game.StandardEvalTest.java
and run it from package root directory, I am assuming it is custom java file that you want to compile. You run directory should be parent of your package directory.
** I also see, you are trying to compile StandardEvalTest.java instead of Deck.java ... then check your StandardEvalTest.java file whether it exists in desired location.

How to run only one (current) file and ignore others in intellij gradle project?

This must be a very simple task for many of you. Let me explain the scenario.
I recently started practicing questions on HackerRank. But, I found the platform not so friendly for debugging. No online platform is or can be because of its own limitations. HackerRank provides question and stub code for many of the problems on its problem page.
For example, let us consider, https://www.hackerrank.com/challenges/java-datatypes/problem
But, because of it's debugging limitations I can't make the best use of portal. Hence, I wrote a PHP script to scrape all the content from the website and generated problem statements in HTML/PDF formats and solutions in java format.
Here's the GitHub project for the same.
https://github.com/saint1729/hr-idea-integration
The main intention of this activity is to have an integration of the website with an IDE like Intellij IDEA. This is now complete.
I created a gradle project with existing sources. But, the project contains many java files (almost 500+ files and each file has it's own main method). My intention is to solve one problem at a time and see if it compiles and submit it using a REST API provided by HackerRank.
But, when I am trying to Right Click and Click on Solution.main() for every file, it tries to compile all files in the project and because there are some compilation issues with the project, I am unable to test my code for the current file. This is not productive for me.
Please let me know if it's possible to compile and run a single file in IDEA (without compiling the whole project). If the idea of creating a gradle project for this activity is not necessary, can somebody recommend me another efficient solution?
NOTE: Every scraped java file contains it's own main method. I know that a project can contain only 1 main method. But, I don't know a coherent solution to solve my problem.
If you want to continue using gradle, you create a module per solution.
Let's suppose you have 3 solutions. canyouaccess, duplicateword and java1darray.
So your repository looks like this:
java
canyouaccess
src/main/java
package
Solution.java
duplicateword
src/main/java
package
Solution.java
java1darray
src/main/java
package
Solution.java
build.gradle
settings.gradle
Each module can have its own main. Inside a settings.gradle file the modules can be defined or disabled by commenting it out.
Your build.gradle looks like this:
...
subprojects { project ->
apply plugin: "java"
sourceCompatibility = 11
}
...
For the settings.gradle looks like this:
include 'java:canyouaccees'
include 'java:dublicateword'
include 'java:java1darray'
Each module can be build separately, you could even group modules by creating a sub module structure.
And each module can have it's own debug configuration, where the module and the main is selected. If your set them as shared, they are stored in xml format under .idea/runConfigurations. So your script can create them as well.
Each module needs it's own gradle.build file, where the main class is declared.
jar {
manifest {
attributes('Main-Class': 'your.main.class.goes.here')
}
}
Something like this should do.

Optaplanner - Error when running executable jar but works fine from eclipse

I use eclipse for my optaplanner project development and I am able to execute my code from eclipse without any problem. To make this project as an executable, I exported it as a jar file using eclipse export wizard.
Then I run my jar from terminal using the command java -jar myOptaPlanner.jar, then, I get below error
WARN given scan urls are empty. set urls in the configuration
Exception in thread "main" java.lang.IllegalStateException: The scanAnnotatedClasses
(ScanAnnotatedClassesConfig()) did not find any classes with a PlanningSolution
annotation.
Maybe you forgot to annotate a class with a PlanningSolution annotation.
Maybe you're using special classloading mechanisms (OSGi, ...) and this is a bug.
If you can confirm that, report it to our issue tracker and workaround it by
defining the classes explicitly in the solver configuration.
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.loadSolutionClass(ScanAnnotatedClassesConfig.java:106)
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:86)
at org.optaplanner.core.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:270)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:216)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
at org.roster.app.WorkerRosteringApp.main(WorkerRosteringApp.java:36)
Is this really a bug or am I exporting it wrong?
Update: I tried to export jar using maven-shade-plugin and here also I am getting the same error.
Thanks
scanAnnotatedClasses doesn't seem to work in a jar file. Instead, use following workaround:
<solutionClass>path.to.your.SolutionClass</solutionClass>
<entityClass>path.to.your.EntityClassI</entityClass>
<entityClass>path.to.your.EntityClassII</entityClass>
and delete the scanAnnotatedClasses in your config file.
If you don't want to declare the solution and entity classes manually, including the packages containing the solution and entity classes also works as workaround:
<scanAnnotatedClasses>
<packageInclude>your.package.here</packageInclude>
</scanAnnotatedClasses>
Documentation about <packageInclude> can be found here

NoSuchMethodError after cleaning the project

I'm currently getting this error:
java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set;
at ee.ut.cs.Parser.accessLint(Parser.java:39)
I have tried cleaning the project to no awail.
I suspect I have an error in the src/plugin/parse-htmlraw/build.xml while creating the jar file but I'm not certain. I understand that this error is because the function does not exist at runtime, but the object is created which means that the class is there, just not that function. I decompiled the .class file in created jar and it has the necessary functions.
Code is available at https://github.com/jaansusi/WCAGgrader
Q: What is wrong with the build that produces this error?
The problem is that even if I put the necessary class files in the jar I create, they are not linked correctly and the class that's called in the jar can't locate functions inside the other classes. The class object JSONObject is created but the functions inside the JSONObject class can't be found.
If you do not find the problematic version, there is a possibility you get it (especially if you are using Spring) from the following dependency -
<artifactId>android-json</artifactId>
<groupId>com.vaadin.external.google</groupId>
excluding it worked for me,
An easy way of analyzing dependencies is the maven-helper plugin in Intellij, see here
Check for the version you have used.
There might be a case where 2 different versions are being used which in turn causes this error.
To their own maven local repository com\Google\code\gson\gson, see if there are two or more version about json, will have to do is to delete the old, and remember to look at any other place in the project is introduced into the old version of the dependence, if any, change the old version of the dependence to the new version is perfectly solved this problem

Hadoop NoSuchMethodError

Does anyone have any idea why something that used to work before all of a sudden started giving this error? please help
java.lang.NoSuchMethodError: org.apache.hadoop.mapred.Counters.findCounter(Ljava/lang/Enum;)Lorg/apache/hadoop/mapreduce/Counter;
at edu.umn.cs.spatialHadoop.operations.Sampler.sampleMapReduceWithRatio(Sampler.java:214)
at edu.umn.cs.spatialHadoop.operations.Sampler.sample(Sampler.java:543)
at edu.umn.cs.spatialHadoop.operations.Repartition.packInRectangles(Repartition.java:494)
at edu.umn.cs.spatialHadoop.operations.Repartition.packInRectangles(Repartition.java:463)
at edu.umn.cs.spatialHadoop.operations.Repartition.repartitionLocal(Repartition.java:590)
This has been working earlier but suddenly started giving this error. I am using hadoop version 1.2.1
Counter class is included in hadoop-mapreduce-client-core.jar. You must have downgraded it somehow.
If you are using a build tool (maven, gradle...), check your dependencies and make sure they haven't changed. In case of doubt, just apply the latest version.
Else, go to your hadoop-mapreduce-client-core.jar and either check if the method is inside or just get a newer version to replace it in your project.
from org/apache/hadoop/mapreduce/Counter I guess that the hadoop-mapreduce-client-core.jar is missing
This is because of latest compiled class and dependent jar available in the application are of different version. For example: Let Class A compiled with dependent jar X in place then later same Class A compiled in different environment withe dependent jar X1 which consist new method called Y in that. now the class will be compiled because new method Y is available in jar X1 when the same Class A is used in the environment with jar X in place then it leads to the NoSuchMethod Exception when trying to load the class in the class memory. Classloader does the verification of the dependent classes before loading the class in the class memory before invoking real exceution.
Everything were available all jar files and all. After an exhausting work thinking of whats wrong, i decided to reload everything afresh (i.e reload the hadoop files). Thanks to you guys for helping :)

Categories

Resources