Get Java class content from oracle database

Can i get java file .class

from database?
I mean java classes that were loaded with a tool loadjava

with parameters -r -s -v -g

.

How to do it?

Edit: I need this in a human readable form;)

+3


source to share


3 answers


Take a look at the package DBMS_JAVA

.
With, DBMS_JAVA

you can export files .java

and .class

using:

  • export_source

    - 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

    - 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 of how to use it to read the source files .java

.

+3


source


I had the same problem but after a few google searches I am solving it. Probably help someone. Just an example



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;

      

0


source


Sorry if it's too late, but I recently ran into the same problem and maybe this can help someone.

First of all, if you have permission to download the javaclass code via export_class, all you need to do after export is to decompile it using javap.exe. You need to open cmd.exe (if you are on Windows), print there the path to javap.exe on your computer than after the space "-c -s -verbose" and than after another space to the * class file you created Something 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 the JVM instructions.

Secondly, if you do not have a grant to read it and for some reason you do not want to receive it, you can extract the javaclass code in another way. All javaclass codes are stored in the sys.idl_ub1 $ table in long raw format. So you end up with code like this:

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 a text editor and save it. Unfortunately, you cannot just decompile it right after that, because the code in this table contains some extra data at the beginning and javap.exe will throw an error. So you have to open it in notepad and try to remove the characters at the beginning until java.exe can decompile it. In my case, I have to look at symbols like this:

Êþº¾

      

and delete all data in front of them. But I'm not sure if this will work for all cases. And after that you get the decompiled bytecode. :)

0


source







All Articles