8 Replies - 1348 Views - Last Post: 30 December 2010 - 06:02 PM Rate Topic: -----

#1 Guest_Jerinho*


Reputation:

Decompile JAVA Class

Posted 30 December 2010 - 02:56 PM

hi happy new year

please help me i want to either decompile the java class file (.class) or at least change its methods' access specifier to public. i cant use them since they're private, but i really in need. if i to use any reversing app please tell me where i have to dld it. anyway thanx for ur coming help :helpsmilie:

Is This A Good Question/Topic? 0

Replies To: Decompile JAVA Class

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,469
  • Joined: 27-December 08

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:01 PM

Google Java decompiler.
Was This Post Helpful? 0
  • +
  • -

#3 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:08 PM

Actually decompiling the class won't get you anywhere, but to do so one can use the javap program that comes with the JDK. What you need to use is RTTI(Runtime Type Information), which allows you to change the access specifier of a runtime class field or method. Note this method is not exactly the nicest way to access something, seeing that the developer of the class could change anything of the private class in any newer releases of the JDK. So the portability of code that "hacks" into private methods are very bad. Similar methods can be used to access member fields and constructors (and create an object dynamically). This method also throws a lot of errors, so you might want to look more into this and determine if you really want to use it.
class AccessPrivate{
	public static void main(String[] args) throws Exception {
		Class cls = ThatClass.class;//Specify the class using the class constant.
		cls = Class.forName("ThatClass");//Specify the class using the dynamic forName(), that loads the class if not already.
		cls = new ThatClass().getClass();//Specify the class by accessing it through one of it's instances.
		
		Method m = cls.getDeclaredMethod(String.class, Object.class, etc.);//Getting "declared" methods includes private and protected ones.
		m.setAccessible(true);//Allow access to the method even if private.
		
		Object returnValue = m.invoke("The String", new Object(), etc.); //Invoke the method and get it's return value.
		
		if( returnValue==null ){
			/* Method returns nothing, either null or the return type is void.*/ 
		}else{
			/* Use the value. */
		}
	}
}


You can learn a lot about RTTI through the Class Object JDK doc

This post has been edited by Jimmy.Li: 30 December 2010 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:19 PM

View PostJimmy.Li, on 30 December 2010 - 04:08 PM, said:

Actually decompiling the class won't get you anywhere,

Sure, once decompiled find the method you want, change it's access to public, and just recompile :)
Was This Post Helpful? 0
  • +
  • -

#5 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:24 PM

View Postpbl, on 30 December 2010 - 02:19 PM, said:

Sure, once decompiled find the method you want, change it's access to public, and just recompile :)

Yes, but that's assuming that the decompiled class isn't in a JAR file and doesn't use package access to reference other classes in it's package. If you recompile this class, it won't exactly be in the same package anymore. (Unless of course, you put it into the original package by rebuilding the JAR file). This would be even harder if the class was actually part of the standard Java packages. :)

This post has been edited by Jimmy.Li: 30 December 2010 - 03:28 PM

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:29 PM

You extract all the files from the .jar
Decompile the one you want to change
Change it
Recompile it
re-jar the whole thing

Done it many times
Was This Post Helpful? 0
  • +
  • -

#7 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:33 PM

View Postpbl, on 30 December 2010 - 02:29 PM, said:

You extract all the files from the .jar
Decompile the one you want to change
Change it
Recompile it
re-jar the whole thing

Done it many times

That is why many JAR files are encouraged to be signed XD ... But nevertheless, I suppose this would work - not that it's entirely the best solution to these type of problems. :)
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Decompile JAVA Class

Posted 30 December 2010 - 03:42 PM

Was the OP question.
Was This Post Helpful? 0
  • +
  • -

#9 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: Decompile JAVA Class

Posted 30 December 2010 - 06:02 PM

jar files are just a zip folder of the classes and a manifest file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1