Hi everybody who is kind enough to read this.
Im working with a Java program, i didnt make it, but im refining it , the problem it’s that you can add files , but i want to validate so the added files are not compressed in any human known format so i dont want the people to be able to add a zip file or rar or 7z or gz , an so on.
can anyone help me with a idea, it’s this even possible?
thanks in advance.
*Edit:
The program its used by IT students , they add the files (.java,.class, .php, .doc, .mdb) of their source code, the paths are saved in strings, and at the end, the program zips the files, and send them to the teacher, know the instructor doesn’t want to receive zipped or compressed files, that’s the reason of the validation.
You basically do the java equivalent of the unix command
typeon the file’s bytes. Most files have an embedded fingerprint which gives hints to other programs as to what type of file it is. This fingerprint is typically called a “magic number”One (incomplete) list of magic numbers can be found here.
Some files don’t have magic numbers, in which case you have to look for other common items in the file which strongly hints it’s a file of the suspected type.
Relying on file name extensions will just have everyone eventually renaming the extension.