Is it possible to get the java .class
file from a database?
I mean java classes, which was loaded via loadjava
tool with -r -s -v -g
parameters.
How to do this?
Edit: I need it in readable form ;)
Take a look at the DBMS_JAVA
package.
With DBMS_JAVA
you can export both .java
and .class
files, using:
export_source
- to export .java
file
PROCEDURE export_source(name VARCHAR2, schema VARCHAR2, blob BLOB)
PROCEDURE export_source(name VARCHAR2, blob BLOB)
PROCEDURE export_source(name VARCHAR2, clob CLOB)
export_class
- to export .class
file
PROCEDURE export_class(name VARCHAR2, schema VARCHAR2, blob BLOB)
PROCEDURE export_class(name VARCHAR2, blob BLOB)
Here you can find some examples on how to use that to read the source of .java
files.
Sorry, if it's a lil bit too late, but I've recently struggled with the same problem and maybe it can help someone.
First of all, if you have grant to load javaclass code via export_class, than all you need after you've exported it is to decompile it with javap.exe. You need to open cmd.exe (if you work on Windows), print there path to javap.exe on your computer, than after space "-c -s -verbose" and than after another space path to the *class file you've created. Something like that:
C:\Programm Files\Java\JDK\bin\javap.exe -c -s -verbose C:\Exports\file.class
You will have decompiled bytecode. It's readable, although you need to know JVM instructions.
Secondly, if you don't have grant to read it and by some reasons you don't want to get it, you can extract javaclass code another way. All javaclass codes are stored in the table sys.idl_ub1$ in long raw format. So you get the code like that:
select a.obj#,a.code,b.name
from sys.idl_ub1$ a
inner join sys.obj$ b on a.obj#=b.obj#
and b.name = 'Name of your class'
You open the code in text editor and save it. Unfortunately you can't just decompile it right after this, cause code in this table helds some extra data at the beginning, and javap.exe will give an error. So you should open it in notepad and try to delete symbols at the beginning until java.exe will be able to decompile it. In my case I have to look at symbols like that:
Êþº¾
and to delete all data before them. But I'm not sure whether it will work for all cases. And after that you will get decompiled bytecode. :)
I had the same problem, but after a few searches on google I solve it. Probably will help someone. Just an exemple
DECLARE
b CLOB;
c varchar2(2000);
i integer:= 255;
begin
DBMS_LOB.createtemporary(b, false);
DBMS_JAVA.export_resource('<object_name>', '<schema_name>', b);
DBMS_OUTPUT.PUT_LINE('java_resource:');
DBMS_LOB.read(b, i, 1, c);
DBMS_OUTPUT.PUT_LINE(c);
end;