Ejemplo n.º 1
0
// Method reads all (interesting)directory entries from Iges Cad-file
// and stores them into attribute "directory" (container)
int
InputIges::readDirectory()
{
  fieldBuffer[1+DIR_FLD_LEN] = '\0';
  lineBuffer[SEC_ID_POS] = ' ';

  while (!infile.eof() && lineBuffer[SEC_ID_POS] != 'D')
    readFileLine(infile, lineBuffer);

  if (infile.eof())
    return 0;

  IgesDirectoryEntry* de;
  int cur_file_pos = infile.tellg();

  while (!infile.eof() && lineBuffer[SEC_ID_POS] == 'D') {
    de = readDirectoryEntry(lineBuffer);

    //-Add geometry-use types to directory
    //if (de->status.useFlag == 0)
    //  addToDirectory(de);

    // Currently all entries are added to directory.
    // The problem is: what entries could be excluded? !!!
    addToDirectory(de);

    //-Read the first line of next entry
    cur_file_pos = infile.tellg();
    readFileLine(infile, lineBuffer);
  }
  return cur_file_pos;
}
Ejemplo n.º 2
0
bool ICOImageDecoder::processDirectoryEntries()
{
    // Read directory entries.
    ASSERT(m_decodedOffset == sizeOfDirectory);
    if ((m_decodedOffset > m_data->size()) || ((m_data->size() - m_decodedOffset) < (m_dirEntries.size() * sizeOfDirEntry)))
        return false;
    for (IconDirectoryEntries::iterator i(m_dirEntries.begin()); i != m_dirEntries.end(); ++i)
        *i = readDirectoryEntry();  // Updates m_decodedOffset.

    // Make sure the specified image offsets are past the end of the directory
    // entries.
    for (IconDirectoryEntries::iterator i(m_dirEntries.begin()); i != m_dirEntries.end(); ++i) {
        if (i->m_imageOffset < m_decodedOffset)
            return setFailed();
    }

    // Arrange frames in decreasing quality order.
    std::sort(m_dirEntries.begin(), m_dirEntries.end(), compareEntries);

    // The image size is the size of the largest entry.
    const IconDirectoryEntry& dirEntry = m_dirEntries.first();
    // Technically, this next call shouldn't be able to fail, since the width
    // and height here are each <= 256, and |m_frameSize| is empty.
    return setSize(dirEntry.m_size.width(), dirEntry.m_size.height());
}
Ejemplo n.º 3
0
/*!
 *****************************************************************************
 * \brief
 *    Read the ImageFileDirectory.
 *
 *****************************************************************************
*/
static int readImageFileDirectory (Tiff * t)
{
    uint32 i;
    uint32 nEntries = t->getU16( t);

    for (i=0; i < nEntries; ++i)
    {
        readDirectoryEntry( t);
    }
    return 0;
}
Ejemplo n.º 4
0
/**
 * @brief Reads a folder listing, prints all items and adds all subdirectories to the global queue
 * @param offset where the first directory entry of the folder structure begins
 */
void listDirectory(unsigned int offset) {

    // do not read into next cluster
    long maxOffset = offset + (bootsector->BPB.sectorspercluster * bootsector->BPB.sectorsize);
    long newOffset = offset;
    lseek(handle, newOffset, SEEK_SET);

    // the reference point in the list where we want to add the subdirectories
    // by default, we want to add subdirectories to the top so that we get depth-first search
    DIRENTRY* referencePoint = firstDirItem->directoryEntry;

    // this is where we read into
    DIRENTRY* directoryEntry;

    // in case we have to handle VFAT / LFN entries, prepare the buffer
    char LFN[260];

    while((newOffset < maxOffset) && (directoryEntry = readDirectoryEntry())) {
        // we need to preserve the offset in case any operations move the file pointer
        //newOffset = tell(handle);
        newOffset = lseek(handle, 0, SEEK_CUR);

        if(memcmp(directoryEntry->name, dot, 8) == 0) {
            char buf2[1024];
            absoluteDirectoryPath(directoryEntry, buf2);
            printf("Directory of %s\n", buf2);
        }

        if(directoryEntry->attr == DIRENTRY_ATTR_VFAT) {
            printf("this is a VFAT entry!\n");
            handleLFN(directoryEntry, LFN);
        }else{
            printDirectoryEntry(directoryEntry);
        }

        if(isDirectory(directoryEntry)) {
            // add subdirectories to the queue
            // please ignore the current directory entry ('.') and parent ('..')
            if((memcmp(directoryEntry->name, dot, 8) != 0) && (memcmp(directoryEntry->name, dotdot, 8) != 0)) {
                dir_insert(referencePoint, directoryEntry);
                referencePoint = directoryEntry;
                //dir_push_back(directoryEntry);
            }
        }

        lseek(handle, newOffset, SEEK_SET);
    }

}
Ejemplo n.º 5
0
/**
 * @brief parentDirectory
 * @param currentDirectoryEntry
 * @return parent DIRENTRY*
 */
DIRENTRY* parentDirectory(DIRENTRY* currentDirectoryEntry) {
    lseek(handle, getclusteroffset(currentDirectoryEntry->firstcluser), SEEK_SET);

    DIRENTRY* directoryEntry = 0;
    DIRENTRY* parentDirectoryEntry = 0;

    // read current directory, find parent entry ('..')
    while(directoryEntry = readDirectoryEntry()) {
        if(memcmp(directoryEntry->name, dotdot, 8) == 0) {
            parentDirectoryEntry = directoryEntry;
            break;
        }
    }

    return parentDirectoryEntry;
}
Ejemplo n.º 6
0
/**
 * @brief Retrieves the current folder's name (handy if you only have a '.' entry at hand)
 * @param currentDirectoryEntry
 * @param buf is a buffer big enough to hold the folder name
 */
void currentFolderName(DIRENTRY* currentDirectoryEntry, char* buf) {

    DIRENTRY* directoryEntry;
    DIRENTRY* parentDirectoryEntry = 0;

    parentDirectoryEntry = parentDirectory(currentDirectoryEntry);

    // read parent directory, find entry that matches current (original) folder's first cluster
    lseek(handle, getclusteroffset(parentDirectoryEntry->firstcluser), SEEK_SET);

    while(directoryEntry = readDirectoryEntry()) {
        if(directoryEntry->firstcluser == currentDirectoryEntry->firstcluser) {
            formatDirectoryEntryName(directoryEntry, buf);
            return;
        }
    }
}
Ejemplo n.º 7
0
bool ICOImageDecoder::processDirectoryEntries() {
  // Read directory entries.
  ASSERT(m_decodedOffset == sizeOfDirectory);
  if ((m_decodedOffset > m_data->size()) ||
      ((m_data->size() - m_decodedOffset) <
       (m_dirEntriesCount * sizeOfDirEntry)))
    return false;

  // Enlarge member vectors to hold all the entries.
  m_dirEntries.resize(m_dirEntriesCount);
  m_bmpReaders.resize(m_dirEntriesCount);
  m_pngDecoders.resize(m_dirEntriesCount);

  for (IconDirectoryEntries::iterator i(m_dirEntries.begin());
       i != m_dirEntries.end(); ++i)
    *i = readDirectoryEntry();  // Updates m_decodedOffset.

  // Make sure the specified image offsets are past the end of the directory
  // entries.
  for (IconDirectoryEntries::iterator i(m_dirEntries.begin());
       i != m_dirEntries.end(); ++i) {
    if (i->m_imageOffset < m_decodedOffset)
      return setFailed();
  }

  DEFINE_THREAD_SAFE_STATIC_LOCAL(
      blink::CustomCountHistogram, dimensionsLocationHistogram,
      new blink::CustomCountHistogram(
          "Blink.DecodedImage.EffectiveDimensionsLocation.ICO", 0, 50000, 50));
  dimensionsLocationHistogram.count(m_decodedOffset - 1);

  // Arrange frames in decreasing quality order.
  std::sort(m_dirEntries.begin(), m_dirEntries.end(), compareEntries);

  // The image size is the size of the largest entry.
  const IconDirectoryEntry& dirEntry = m_dirEntries.first();
  // Technically, this next call shouldn't be able to fail, since the width
  // and height here are each <= 256, and |m_frameSize| is empty.
  return setSize(dirEntry.m_size.width(), dirEntry.m_size.height());
}
Ejemplo n.º 8
0
/*
 * Caches a directory block
 */
void CachedDirectory::cacheDirectoryBlock(int blockNumber) {
	// read the directory header
	cachedDirectoryLastBlockHeader = readDirectoryHeader(blockNumber);
	// calculate number of entries
	int numberOfEntries = (superBlock->getBlockSize() - cachedDirectoryLastBlockHeader.data.startOfLastNode) / directoryEntrySize;
	// read the directory names
	string names = readDirectoryEntryNames(blockNumber, numberOfEntries, cachedDirectoryLastBlockHeader.data.endOfLastName);
	string currentName = "";// cache the root directory
	unsigned int namesPointer = 0;
	// read entries
	for (int i=numberOfEntries-1;i>-1;i--) {
		DirectoryEntryData entry = readDirectoryEntry(blockNumber, i);
		namesPointer = entry.data.nameOffset - directoryHeaderSize;
		while (namesPointer < names.length() && names.at(namesPointer)!='\0') {
			currentName += names.at(namesPointer);
			namesPointer++;
		}
		cache.insert({currentName,entry.data.iNodeRef});
		currentName.clear();
		namesPointer++;
	}
}
Ejemplo n.º 9
0
int main (int argc, const char * argv[]) {
	FILE* fp;// = fopen("samplefat.bin", "rb");

	if (argc == 2) {
		fp = fopen(argv[1], "rb");
		if(fp == NULL)
		{
			printf("Invalid file path.\n");
			return 0;
		}
	}
	else {
		printf("usage: %s %s\n", argv[0], "sample.bin");
		return 1;
	}
	
	BootStrapSector bss;
	readBootStrapSector(&bss, fp);

	if(bss.magic55AA[0] != 0x55 || bss.magic55AA[1] !=0xAA)
	{
		printf("Invalid FAT-12 file.\n");
		return 1;
	}

	sector_t rootDirectorySector = FIRST_FAT_SECTOR + bss.numSectorsInFAT * bss.numCopiesFAT;
	size_t numSectorsInDirectory = bss.numEntriesRootDir * 32 / bss.numBytesPerSector;
	sector_t firstClusterSector = rootDirectorySector + numSectorsInDirectory;
	seekToSector(fp, rootDirectorySector, bss.numBytesPerSector);
	
	// Extract
	int i;
	int fileCounter = 0;

	seekToSector(fp, rootDirectorySector, bss.numBytesPerSector);
	printf("Extracting...\n");	
	
	for (i = 0; i < bss.numEntriesRootDir; i++)
	{
		DirectoryEntry de;
		readDirectoryEntry(&de, fp);
		if (isFile(&de))
		{
			fileCounter++;
			long offsetToNextDirectoryEntry = ftell(fp);
			printf("%s.%s%s", de.filename, de.file_extension, (i < bss.numEntriesRootDir ? ", " : "\n"));
			FILE* fat_file_p = fopen(de.filename, "wb");
			UINT16 curCluster = de.start_cluster;
			//printf("%x\n", curCluster);
			BYTE buffer[bss.numBytesPerSector * bss.numSectorsPerCluster];
			int fileSize = de.file_size;
			while (curCluster < 0xFF8 && fileSize > 0)
			{
				readCluster(fp, curCluster, firstClusterSector, bss.numBytesPerSector, bss.numSectorsPerCluster, buffer);
				//}
				if(fileSize < bss.numBytesPerSector * bss.numSectorsPerCluster)
				{
					fwrite(buffer, sizeof(BYTE), fileSize, fat_file_p);
				}
				else
				{
					fwrite(buffer, sizeof(BYTE), sizeof(buffer), fat_file_p);
				}
				
				seekToSector(fp, FIRST_FAT_SECTOR, bss.numBytesPerSector);
				curCluster = extract12File(fp, curCluster);
				fileSize -= bss.numBytesPerSector * bss.numSectorsPerCluster;
			}
			fclose(fat_file_p);
			fseek(fp, offsetToNextDirectoryEntry, SEEK_SET);
		}
	}
	printf("\nExtracted: %i files\n", fileCounter);

	fclose(fp);

    return 0;
}