Home arrow static arrow Java Programming [Archive] - Bytecode info
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Bytecode info
This topic has 23 replies on 2 pages.    « Previous | 1 | 2 |

Posts:8,813
Registered: 10/4/00
Re: Bytecode info  
Aug 3, 2004 3:54 AM (reply 15 of 23)



 
Here's a class of mine. You didn't have enough info
CA FE BA BE - u4 magic;
00 00 - u2 minor_version;
00 2E - u2 major_version;
00 6C - u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
0A - u1 tag - CONSTANT_Methodref 10
00 21 - u2 class_index;
00 37 - u2 name_and_type_index;

07 - u1 - CONSTANT_Class 7
00 38 - u2 name_index;
etc for 6C -3 more entries

I guess I need sleep...
 

Posts:11,200
Registered: 7/22/99
Re: Bytecode info  
Aug 3, 2004 3:55 AM (reply 16 of 23)



 
CA FE BA BE - magic
00 00 - minor version
00 2E - major version
00 7D <- constant pool count, you have 124 constant pool entries
01 <- start of first cp_info structure, this is a constant_utf8_info entry
00 2D <- lenght of entry (see constant_utf8_info), 45 characters
63 6F 6D <- first 3 letters, "com"
...
much much later you should expect to see this:
00 00 <- "this_class", index to the constant pool
 

Posts:29,016
Registered: 23.07.02
Re: Bytecode info  
Aug 3, 2004 4:03 AM (reply 17 of 23)



 
Thanks, all of you. I think I see a bit clearer. So this_class is not the "com/mycompany/mytool/classname" string I expected, and what I just mentioned is just another constant belonging to the table...
 

Posts:8,813
Registered: 10/4/00
Re: Bytecode info  
Aug 3, 2004 4:09 AM (reply 18 of 23)



 
this_class
The value of the this_class item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info (�4.4.1) structure representing the class or interface defined by this class file.

It's just not going to be as easy to find it as you thought.
 

Posts:11,200
Registered: 7/22/99
Re: Bytecode info  
Aug 3, 2004 4:16 AM (reply 19 of 23)



 
Yep, it's a hairy file format, not nice to edit by hand ... you have to read the whole constant pool before you can have an idea where things are.

What do you need this for, loading a class dynamically without knowing its fully qualified name?
 

Posts:29,016
Registered: 23.07.02
Re: Bytecode info  
Aug 3, 2004 4:43 AM (reply 20 of 23)



 
Yep, it's a hairy file format, not nice to edit by
hand ... you have to read the whole constant pool
before you can have an idea where things are.

That's what I figured out, and so I trashed that feature. I can still add it later...

What do you need this for, loading a class dynamically
without knowing its fully qualified name?

Now that would be cool for plugin invocation, great idea.. But I'm writing a tool that traverses a given classpath (directories or JARs) for class files. When I find a file, I'd like to verify its position in the directory structure versus its package - making sure that it's a correctly placed (and therewith useful) class or singing out a warning if otherwise.
 

Posts:8,813
Registered: 10/4/00
Re: Bytecode info  
Aug 3, 2004 4:48 AM (reply 21 of 23)



 
Looks like it might turn into just a few lines of code with [url http://jakarta.apache.org/bcel/]BCEL[/url] as silk.m suggested.
 

Posts:29,016
Registered: 23.07.02
Re: Bytecode info  
Aug 3, 2004 4:49 AM (reply 22 of 23)



 
Looks like it might turn into just a few lines of code
with [url http://jakarta.apache.org/bcel/]BCEL[/url]
as silk.m suggested.

Maybe. But I have to look at the license issues and stuff first. Don't have the time for that, right now, but I bookmarked that project.
 

Posts:11,200
Registered: 7/22/99
Re: Bytecode info  
Aug 4, 2004 1:06 AM (reply 23 of 23)



 
Now that would be cool for plugin invocation, great
idea.. But I'm writing a tool that traverses a given
classpath (directories or JARs) for class files. When
I find a file, I'd like to verify its position in the
directory structure versus its package - making sure
that it's a correctly placed (and therewith useful)
class or singing out a warning if otherwise.

How about simply trying to load the class with the name that
corresponds to the file path? If the name is not correct you'll
get an exception.
 
This topic has 23 replies on 2 pages.    « Previous | 1 | 2 |