private static void driver(string fileName) { long length = GeneralUse.GetFileSize(fileName); var data = new byte[length]; data = GeneralUse.loadByteArray(fileName); //Create a list of file headers List <int> possibleHeaderIndexes = bmpListFunctions.getHeaderIndexes(data); List <byte[]> possibleHeaderBytes = bmpListFunctions.getPossibleHeaderBytesList(data, possibleHeaderIndexes); List <BmpFileHeader> fileHeaderHeap = new List <BmpFileHeader>(); for (int idx = 0; idx < possibleHeaderBytes.Count; idx++) { BmpFileHeader fileHeader = new BmpFileHeader(possibleHeaderBytes[idx], possibleHeaderIndexes[idx]); //BmpFileAccessors fileHeader = BmpFileHeaderList.setFileHeader(possibleHeaderBytes[idx], possibleHeaderIndexes[idx]); if (fileHeader.isValid()) { fileHeaderHeap.Add(fileHeader); } } fileHeaderHeap = bmpListFunctions.createSortedList(fileHeaderHeap); WriteAndHashData.Driver(data, fileHeaderHeap, fileName); Console.WriteLine("Press enter to exit"); Console.Read(); }
/*Returns a list of byte[] arrays that are the length of the * bitmap file header + the DIB header */ public static List <byte[]> getPossibleHeaderBytesList(byte[] data, List <int> headerIndexList) { List <byte[]> possibleHeaderBytesList = new List <byte[]>(); int dibHeaderSize; byte[] header; for (int i = 0; i < headerIndexList.Count; i++) { header = GeneralUse.FillByteArray(data, headerIndexList[i], 18); //Load with bitmap header + 4 to grab dib header size dibHeaderSize = BmpFileHeader.getDIBHeaderSize(header); header = GeneralUse.FillByteArray(data, headerIndexList[i], 14 + dibHeaderSize); //fill byte array with both bmp and dib header possibleHeaderBytesList.Add(header); } return(possibleHeaderBytesList); }
public static List <BmpFileHeader> createSortedList(List <BmpFileHeader> unsortedHeap) { //Simple insertion sort int j; for (int i = 1; i < unsortedHeap.Count; i++) { j = i; while (j > 0 && unsortedHeap[j - 1].maxIndex > unsortedHeap[j].maxIndex) { BmpFileHeader tmp = unsortedHeap[j - 1]; unsortedHeap[j - 1] = unsortedHeap[j]; unsortedHeap[j] = tmp; } } return(unsortedHeap); }