I need to determine that whether a given file is a class file or not. Suppose I change the extension to .exe/.xml or some other, I need to determine whether that given file, if a class file will be parsed differently and if it would be some other, it’ll be parsed in that manner.
How can I read the class file format?
I suspect BCEL lets you do this. Checking now…
EDIT: Yes, it does. You can use the ClassParser class; the
parsemethod will throw aClassFormatExceptionif the file isn’t really a Java class file.EDIT: Okay, so you need to know from C#. Three options:
The CAFEBABE test is very easy:
It’s not exactly pretty… there are alternatives with
BinaryReaderetc as well.