Jump to content
  • Advertisement
Sign in to follow this  
fosh

parsing java classfiles - reading a 4 byte unsigned integer

This topic is 4580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. Im currently writing something to calculate some metrics given a classfile, and am having trouble reading the 4-byte unsigned attribute_count field in one of the structures. How exactly can you go about doing this? The lack of unsigned types in java makes it a bit fiddly. ive been trying int Data1 = Data.readUnsignedInt() ; int Data2 = Data.readUnsignedInt() ; long Final = (Data1 << 16) || (Data2) ; I think this doesn't work because of the high-order bit being interpreted as the sign bit tho. Im not really sure how java stores integer values (2's complement?!) so i dont know where to go from here. any help would be appreciated Scott

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What you are currently doing doesnt make much sense. But i seam to remeber that you can just read all ints it as a signed Int (according to the class file spec).

Share this post


Link to post
Share on other sites
You would be able to if it was a normal length signed integer but its not.

Share this post


Link to post
Share on other sites
Java int is guaranteed by standard to be exactly 4 bytes of 8 bits each, representing a signed value by 2s complement. I really don't understand how you can know anything about the classfile structure and thus refer to a field labelled "attribute_count", but not know this and be able to figure out how to work with it. Hint: try the *other* chapters in the JLS.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!