decompiling .jar file using jd-cmd API - java

So I was searching for a command line tool to de-compile .jar files, I found this "jd-cmd" at https://github.com/kwart/jd-cmd and it worked fine, but now I saw it has an api that I can use, I can't seem to do it the wright way. I am working on intellij IDE, added the external jars to my project, all I want is that the output will be at a folder of my choice in the filesystem just like it works at the command line with no problems.
here's an example code I tried from the idea that didn't do the job:
import java.io.File;
import jd.core.input.JDInput;
import jd.core.input.ZipFileInput;
import jd.core.output.DirOutput;
import jd.core.output.JDOutput;
import jd.ide.intellij.JavaDecompiler;
public class App {
public static void main(String[] args) {
JavaDecompiler javaDecompiler = new JavaDecompiler();
//choose input plugin for your decompiled file (class, zip, directory)
JDInput jdIn = new ZipFileInput("path/to/myFavorityLib.jar");
//choose output plugin (zip, directory, console)
JDOutput jdOut = new DirOutput(new File("/tmp/decompiled"));
//decompile
jdIn.decompile(javaDecompiler, jdOut);
}
}
This code didnt generate decompiled files at "/tmp/decompiled"

ok, so i have managed to do it .
it was a dependency problem , the github developer mentioned that jd-lib folder should be added as a dependency library , but actually it dosent matter that much ,you need to add a jar file :after doing all the instructions and downloding what ever maven will give you, at the folder jd-cli there a downloaded jar "jd-cli.jar" , use this as a dependency for your project and it work just fine!

Related

Encryption of simple string using jasypt through terminal

I am trying to encrypt a simple string using jasypt. It is working correctly when I use eclipse IDE but has some problem when I try through the terminal.
Output through Eclipse IDE Screenshot
Below is the code which I use.
package com.jasypt.encryption.demo;
import org.jasypt.util.text.BasicTextEncryptor;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class BasicDemo {
public static void main(String[] args) throws IOException {
String secretkey = "home#123";
String message = "This is a confidential message. Be Careful !!";
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(secretkey);
String encrMess = basicTextEncryptor.encrypt(message);
System.out.println(encrMess);
String decrMess =basicTextEncryptor.decrypt(encrMess);
System.out.println(decrMess);
}
}
I navigate to the folder which contains pom.xml file and enter following commands in terminal
1) mvn package
2) mvn install
3) java -cp target/demo-0.0.1-SNAPSHOT.jar com.jasypt.encryption.demo.BasicDemo
I get BUILD SUCCESS message and jar file is successfully created but I get some error when I run 3rd command.
Error Screenshot
Please excuse and suggest something if I am making some very basic mistake or using redundant lines of code as I am new to java.
Welcome to StackOverflow!
When you compile your program with Maven (which is actually not a compiler but a package manager that can also call the Java compiler behind the scenes) Maven takes care of downloading and managing the dependencies that your program uses, in this case it is Jasypt.
When you then try to start the program with plain java the information about the dependecies that are necessary to run your program is lost, just because Maven is no longer part of the game. Therefore you have to give the Java runtime a hint where to find the Jasypt dependency, just as you did with your demo-jar. During the compilation process Maven stored the Jasypt jar on your drive, in a folder called local Maven repository.
You now can simply add the path to this jar to your classpath and everything will run:
java -cp target/demo-0.0.1-SNAPSHOT.jar:<path to your Maven repository>/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar com.jasypt.encryption.demo.BasicDemo
(The version of the Jasypt library may differ on your machine.)
If you have a lot of dependencies it will become cumbersome to add them all manually to the classpath. Maven can also take care for you of this task, with the help of the Exec-plugin. Instead of starting java directly let Maven do the plumbing for you:
mvn exec:java -Dexec.mainClass="com.jasypt.encryption.demo.BasicDemo"
You could also check this thread for more details about this plugin and its options

VLJC imports not being recognized

I'm trying to use VLCJ for the first time and I downloaded the dist they have at their site's tutorial.
I unzipped the dist inside of my project's source folder, then went to my IDE (Netbeans) and went into Libraries and added all of the .jar files that were now laying in the src folder.
However, I still get the error about the IDE not recognizing these libraries.
package uk.co.caprica.vlcj.factory does not exist
Furthermore, I'd like to know. If I share this code with someone who has never touched neither VLC nor VLCJ, will they be able to run the program with their IDE and see the video that its supposed to play? One of my concern's is that apparently the user needs to have VLC installed.
import java.awt.event.*;
import javax.swing.*;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
public class Tower {
public static void main(String[] args) {
MediaPlayerFactory factory = new MediaPlayerFactory();
}

Importing voce.jar into a java file properly

I have downloaded a voice/text API for java from
http://voce.sourceforge.net/
However being semi new to java I am unsure how to use all these jar files in my code, have tried several things like import voce, import java.voce, package (my folder name with the voce jar inside).
However I am getting no luck.
Code I am trying is
import java.voce;
public class SpeechInterface
{
public static void main(String[] args){
voce.SpeechInterface.synthesize("hello world");
}
}
Error I get is that it cant find voce(since I am obviously doing this wrong). Have looked through stackoverflow but was unable to find a question that answers this. I imagine there is one like this already but I can not find it. Closest I could find was the importing voce to C, but that wasn't to helpful.
The jar file is in same directory as the java file.
try using
import voce.*
If you look at http://voce.sourceforge.net/api/java/_speech_interface_8java-source.html
It mentions the package as (package voce).
Here under the Tab no 10. You can find how to add a Jar file to Dr.Java IDE,
Then as Kakarot Mention , you should to write
import.voce.*;
if you need all the classes of package voce,
or write
import.voce.classname
to import a specific class.

Using the Stanford NLP libraries from within R, using the rJava package

Does anybody have any experience with using StanfordCoreNLP ( http://nlp.stanford.edu/software/corenlp.shtml through rJava in R? I’ve been struggling to get it to work for two days now, and think I’ve exhausted Google and previous questions on StackOverflow.
Essentially I’m trying to use the StanfordNLP libraries from within R. I have zero Java experience, but experience with other languages, so understand the basics about classes and objects etc.
From what I can see, the demo .java file that comes with the libraries seems to show that to use the classes from within Java, you’d import the libraries and then create a new object, along the lines of:
import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.*;
public class demo {
etc.
etc.
StanfordCoreNLP pipeline = new StanfordCoreNLP();
etc.
From within R, I’ve tried calling some standard java functions; this works fine, which makes me think it’s the way I’m trying to access the Stanford libraries that’s causing the issue.
I extracted the Stanford ZIP to h:\stanfordcore, so the .jar files are all in the root of this directory. As well as the various other files contained in the zip, it contains the main .jar files:
joda-time.jar
stanford-corenlp-1.3.4.jar
stanford-corenlp-1.3.4-javadoc.jar
stanford-corenlp-1.3.4-models.jar
joda-time-2.1-sources.jar
jollyday-0.4.7-sources.jar
stanford-corenlp-1.3.4-sources.jar
xom.jar
jollyday.jar
If I try to access the NLP tools from the command line, it works fine.
From within R, I initalized the JVM and set the classpath variable:
.jinit(classpath = " h:/stanfordcore", parameters = getOption("java.parameters"),silent = FALSE, force.init = TRUE)
After this, if I use the command
.jclassPath()
This shows that the directory containing the required .jar files has been added and gives this output in R:
[1] "H:\RProject-2.15.1\library\rJava\java" "h:\ stanfordcore"
However, when I try create a new object (not sure if this is the right Java terminology) I get an error.
I’ve tried creating the object in dozens of different ways (basically shooting in the dark though), but the most promising (simply because it seems to actually find the class is):
pipeline <- .jnew(class="edu/stanford/nlp/pipeline/StanfordCoreNLP",check=TRUE,silent=FALSE)
I know this finds the class, because if I change the class parameter to something not listed in the API, I get a cannot find class error.
As it stands, however, I get the error:
Error in .jnew(class = "edu/stanford/nlp/pipeline/StanfordCoreNLP", check = TRUE, :
java.lang.NoClassDefFoundError: Could not initialize class edu.stanford.nlp.pipeline.StanfordCoreNLP
My Googling indicates that this might be something to do with not finding a required .jar file, but I’m completely stuck. Am I missing something obvious?
If anyone can point me even a little in the right direction, I’d be incredibly grateful.
Thanks in advance!
Peter
Your classpath is wrong - you are using a directory but you have JAR files. You have to either unpack all JAR files in the directory you specify (unusual) or you have to add all the JAR files to the class path (more common). [And you'll have to fix your typos, obviously, but I assume those come form the fact that you were not using copy/paste]
PS: please use stats-rosuda-devel mailing list if you want more timely answers.
Success!
After hours of tinkering, I managed to find a work-around. If anyone is interested, this is what I did:
Using Eclipse, I started a new project.
I then created a directory called ‘lib’ under the root of the project and copied all the Stanford .jar files into this directory.
After this, I edited the properties of the project in Eclipse, went to ‘Java Build Path’, clicked the libraries tab.
I then choose to import the Java system libraries.
I also clicked ‘Add External Jars’ and selected all the Stanford jars from the lib directory.
I then created intetermediary Java classes to call the Stanford classes (rather than trying to call them directly from R).
Example:
import java.lang.Object;
import java.util.Properties;
import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.*;
public class NLP {
public static void main(String[] args) {
Properties props = new Properties();
props.put("annotators", "tokenize");
StanfordCoreNLP coreNLP = new StanfordCoreNLP(props);
}
}
This doesn’t return anything, but shows how a Stanford object can be created.
Build the project using Eclipse.
From within R, then set the working directory to the Java project's /bin directory (this isn’t strictly necessary, as you can add the classpath directory instead, but it simplifies things).
Then the object can be created in R with:
.jinit(classpath = ".") // This initilizes the JVM
obj = .jnew("NLP")
After this any methods you’ve created within the intermediary java classes can be called with:
Name_of_var_to_store_return_value = . jcall(class name, signature type, method, paramters)
I still didn’t figure out why I can’t call the Stanford classes directly from R, but this method works. I suspect that #ChristopherManning is right and my problem is down to calling the external jar from R. By building it from scratch, the Stanford jars are linked during the build, so I guess that’s what fixed it.

The import javazoom cannot be resolved

hi all
i use the javazoom.jl.player.Player package but it is says The import javazoom cannot be resolved. i am using eclipse and doing Android project. i clean the project still the same error is shown. please correct me.
If eclipse can't resolve a package fragment of an import statement, then it tells you (with that error), that there is no library on the classpath that contains a class from that package (or from a package whose name starts with the missing part).
An easy way for standard java/eclipse:
create a folder lib in your projects root directory (with the eclipse workbench!)
copy and paste the jar into that folder
right-click the copied jar and select "add to build path".
This should eliminate the compiler errors immediately.
(Previous part of the answer)
Taking the error message literally, it looks like you have a line of code like that:
import javazoom;
This would be wrong, because we don't import packages but classes from a package. To import all classes from the javazoom package, we'd say:
import javazoom.*;
You should download the .jar of jLayer ( http://www.javazoom.net/javalayer/sources.html )
And add into classpath in the way Andreas_D told you.

Categories