I'm doing a wargame and I need to analyze a java app. So the app loads a corrupted class file, converts it to an array of bytes, does something with it, and then loads the class properly using that array. I need to analyze the class so I wanted to save it as a separate class file to decompile it later using jd-gui. I use the following code to save the array:
FileOutputStream output = new FileOutputStream(new File("class.class"));
output.write(arrayOfByte);
But the class doesn't get decompiled afterwards. What else do I have to do to make it readable by the decompiler?
UPDATE:
What I meant by corrupted, was that the class file is actually incomplete, the app completes the class and makes it a valid class file inside and then loads it. The programmer has done this to prevent the class from being decompiled and read. This isn't really needed for the question but I thought it would be better if I clarified.
Make sure you writing the class java byte code correctly into the path for Example
say class fully qualified name including class name is com.test.Sample you should write the class byte code under folder com\test\Sample.class.
Further you make sure that the FileOutputStream is closed properly after writing the byte code.
// use fully qualified class name
FileOutputStream output = new FileOutputStream(new File("c:\\com\\test\\Sample.class"));
output.write(arrayOfByte);
output.close();