Exemplo n.º 1
0
void PEFile::Dump(LPCTSTR filename)
{
    FileMapping mapping;
    if (!mapping.Create(filename, GENERIC_READ, FILE_SHARE_READ,
                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, PAGE_READONLY)) {
        throw Exception(LastError());
    }

    LPVOID pBase;
    if ((pBase = mapping.MapView(FILE_MAP_READ, 0, 0)) == NULL) {
        throw Exception(_T("Unable to map view of file."));
    }

    PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pBase;
    PIMAGE_FILE_HEADER pImgFileHdr = (PIMAGE_FILE_HEADER)pBase;

    if (pDosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
        throw Exception(_T(".EXE format not supported."));
    } else if (PECommon::IsValidMachineType(pImgFileHdr->Machine)) {
        if (pImgFileHdr->SizeOfOptionalHeader == 0)	{	// 0 optional header
            ObjectFile::Dump(pImgFileHdr);				// means it's an OBJ
        } else {
            throw Exception(_T("Unrecognized file format."));
        }
    } else if (memcmp(pBase, IMAGE_ARCHIVE_START,
                      IMAGE_ARCHIVE_START_SIZE) == 0) {
        LibraryFile archive;
        archive.Dump(pBase);
    } else {
        throw Exception(_T("Unrecognized file format."));
    }
}
Exemplo n.º 2
0
boost::shared_ptr<StorageMapping>
resolve_storagemapping_info(FileMapping const& fm)
{
  boost::shared_ptr<StorageMapping> result(
    new StorageMapping
  );
  
  FileMapping::const_iterator file_it = fm.begin();
  FileMapping::const_iterator const file_end = fm.end();

  std::pair<boost::shared_ptr<void>, int> ret = ism::match_on_active_side();
  // ++matching threads on the currently active ISM side, as ret.first increases
  // by one the reference counting on that ISM side;
  // this will not prevent the ISM from
  // switching over with pending matches
  // insisting onto the target slice, but before
  // starting yet another purchasing (in background),
  // no pending matching_threads must exist
  ism::ism_type const& the_ism = ism::get_ism(ism::se, ret.second /* side */);

  for ( ; file_it != file_end; ++file_it) {
    std::vector<std::string> const& sfns(file_it->second);
    std::vector<std::string>::const_iterator sfni = sfns.begin();
    std::vector<std::string>::const_iterator const sfne = sfns.end();

    for( ; sfni != sfne; ++sfni ) {
       std::string const name = resolve_storage_name(*sfni);
       if (name.empty()) {
         continue;
       }
       ism::ism_type::const_iterator it(
         the_ism.find(name)
       );
       
       if (it != the_ism.end()) {

         boost::shared_ptr<classad::ClassAd> se_ad( 
            boost::tuples::get<ism::ad_ptr_entry>(it->second)
         );

         StorageInfo& info = (*result)[name];
         info.links.push_back(file_it);
         insert_protocols(info.protocols, *se_ad);
         insert_ce_mount_points(info.ce_mounts, *se_ad);

       }
    }
  }

  return result;
}
Exemplo n.º 3
0
int32_t 	mfso::vread(int32_t fd, void *buff, uint32_t size)
{
  fdinfo*	fi;
  uint64_t	realsize;
  int32_t	bytesread;
  FileMapping*	fm = NULL;

  try
  {
    fi = this->__fdmanager->get(fd);
    if (fi->node != NULL)
      fm = this->mapFile(fi->node);
    if (fm != NULL)
    {
       uint64_t fileSize = fm->maxOffset();

       if (fi->node->size() <= fileSize)
       {
         if (size <= (fi->node->size() - fi->offset))
           realsize = size;
         else
           realsize = fi->node->size() - fi->offset;
       }
       else
       {
         if (size <= (fileSize - fi->offset))
           realsize = size;
         else
           realsize = fileSize - fi->offset;
       }
       bytesread = this->readFromMapping(fm, fi, buff, realsize);
       fm->delref();
       return bytesread;
    }
    else
    {
      return (0);
    }
  }
  catch(...)
  {
      //throw(vfsError("problem while reading file"));
  }
  if (fm)
    fm->delref();
  return (0);
}
Exemplo n.º 4
0
uint64_t	mfso::vseek(int32_t fd, uint64_t offset, int32_t whence)
{
  fdinfo*	fi;
  FileMapping*  fm;
  try
  {
     fi = this->__fdmanager->get(fd);
     fm = this->mapFile(fi->node);
     if (fm == NULL)
	throw std::string("can't allocate fm");
     if (whence == 0)
     {
       if (offset > fm->maxOffset())
       {
	 fm->delref();
         return ((uint64_t)-1);
       }
       else
         fi->offset = offset;
     }
     else if (whence == 1)
     {
       if ((fi->offset + offset) > fm->maxOffset())
       {
	 fm->delref();
         return ((uint64_t)-1);
       }
       else
         fi->offset += offset;
     }
     else if (whence == 2)
       fi->offset = fm->maxOffset();
     fm->delref();
     return (fi->offset);
  }
  catch(...)
  {
     std::cout << "problem while getting fd information" << std::endl;
  }
  if (fm != NULL)
    fm->delref();

  return ((uint64_t)-1);
}
Exemplo n.º 5
0
 explicit MOLoader(Path path)
   :mapping(new FileMapping(path)),
    file(mapping->error()
         ? NULL : new MOFile(mapping->data(), mapping->size())) {
 }
Exemplo n.º 6
0
void Scenario::toFile(const string &fileName) const
{
    using namespace xmlpp;
    using namespace Poco;

    // file mapping (for archives)
    FileMapping fileMapping;
    Document document;
    Element *root = document.create_root_node(ioConfig.rootName());
    root->set_attribute("version",ioConfig.version().shortVersion());
    root->set_attribute("interface",interfaceToString(uiInterface));
    Element *tmp;
    if (ioConfig.hasMetadata())
    {
       tmp = root->add_child("metadata");
       mMetadata.toXML(*tmp);
    }
    tmp = root->add_child(ioConfig.plotName());
    tPlot.toXML(ioConfig, *tmp, fileMapping);
    tmp = root->add_child("notes");
    tmp->add_child_text(nMain.text());
    tmp = root->add_child(ioConfig.propertiesName());
    lProperties.toXML(ioConfig, *tmp);
    tmp = root->add_child("characters");
    lCharacters.toXML(ioConfig, *tmp);
    tmp = root->add_child("history");
    tHistory.toXML(ioConfig, *tmp, fileMapping);
    tmp = root->add_child("music");
    tMusic.toXML(ioConfig, *tmp, fileMapping);
    tmp = root->add_child("effects");
    tEffects.toXML(ioConfig, *tmp, fileMapping);
    // saved XML file and temporary directory (if needed)
    string xmlFile(fileName);
    File tempDir;
    if (ioConfig.isArchived())
    {
        tempDir = TemporaryFile::tempName();
        tempDir.createDirectory();
        TemporaryFile::registerForDeletion(tempDir.path());
        xmlFile = tempDir.path() + "/scenario.xml";        
    }
    document.write_to_file_formatted(xmlFile, "UTF-8");
    if (ioConfig.isArchived())
    {
        // adding files to the archive
        for (FileMapping::Iterator it = fileMapping.begin(); it != fileMapping.end(); it++)
        {
            File file(it.file());
            // only if the file exists and is readable
            if (file.exists() && file.canRead())
            {
                Path path(tempDir.path());
                path.append(it.destination());
                File(path.parent()).createDirectory();
                file.copyTo(path.toString());
            }
        }
        // compressing it
        FileOutputStream output(fileName.c_str());
        Zip::Compress comp(output, true);
        comp.addRecursive(tempDir.path());
        comp.close();
        tempDir.remove(true);
    }
}
Exemplo n.º 7
0
 MOLoader(const TCHAR *path)
   :mapping(new FileMapping(path)),
    file(mapping->error()
         ? NULL : new MOFile(mapping->data(), mapping->size())) {
 }