I need to make a simple check if a dds file is of valid format. I just need to do a general check of the dds file, so I do not need to check if it is a dxt1, dxt5, dx10 etc. For example if I have a png image and I rename the extensions to .dds the dds format will ofcourse be wrong and I would then need to tell the user that he is trying to use a dds file with a wrong format. However if I have a dds that indeed has a correct file format I will not need to do any further investigation since I do not care of what type of dds file it is (at this moment). So I do only have to read the parts of the dds file that will stay the same on ALL dds files. I'm thinking I could read the dds header and magic number in some way. I have to do the same validation for a png file and there I am reading the png header like this:
var png = new byte[] { 0x89, 0x50, 0x4e, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }
using (FileStream fs = new FileStream(fileToCheck, FileMode.Open, FileAccess.Read))
{
if (fs.Length > buffer.Length)
{
fs.Read(buffer, 0, buffer.Length);
fs.Position = (int)fs.Length - endBuffer.Length;
fs.Read(bufferEnd, 0, endBuffer.Length);
}
fs.Close();
}
for (int i = 0; i < png.Length; i++)
{
if (buffer[i] != png[i])
return false;
}
return true;
And I was looking if there is a similiar way to check the format of a dds file. I am new to this and the problem I am having is to know what bytes in the dds file that will always be the same for all dds files (so that I can check these bytes to see if the dds format is valid) and how I can implement the code in a simple way to check the dds format. Any help will be appreciated.
Edit: So thanks to @NaCl I have got the first part of the question answered. I now know what parts in the dds file that is required but I do not know how to locate it in the dds file. I have opened a lot of dds files with a hex editor but I am not very good at reverse engineering so I can't understand where the bytes that I need to check is located which will furthermore make me not to know how I can implement code to search for bytes at the specified positions (which I can do with the png file since I found much more document about that file) since I do not know at what position to go to.
If anybody can Point me in the right direction or help me in some other way I would appreciate it very much . Thanks.