コード例 #1
0
ファイル: DebugDirectory.cpp プロジェクト: CBaiz/PeLib
	/**
	* Rebuilds the current debug directory.
	* @param vBuffer Buffer where the rebuilt directory is stored.
	**/
	void DebugDirectory::rebuild(std::vector<byte>& vBuffer) const
	{
		OutputBuffer obBuffer(vBuffer);
		
		for (unsigned int i=0;i<m_vDebugInfo.size();i++)
		{
			obBuffer << m_vDebugInfo[i].idd.Characteristics;
			obBuffer << m_vDebugInfo[i].idd.TimeDateStamp;
			obBuffer << m_vDebugInfo[i].idd.MajorVersion;
			obBuffer << m_vDebugInfo[i].idd.MinorVersion;
			obBuffer << m_vDebugInfo[i].idd.Type;
			obBuffer << m_vDebugInfo[i].idd.SizeOfData;
			obBuffer << m_vDebugInfo[i].idd.AddressOfRawData;
			obBuffer << m_vDebugInfo[i].idd.PointerToRawData;
		}
	}
コード例 #2
0
ファイル: ComHeaderDirectory.cpp プロジェクト: 4nykey/rockbox
	/**
	* Rebuilds the current COM+ descriptor.
	* @param vBuffer Buffer where the COM+ descriptor will be written to.
	**/
	void ComHeaderDirectory::rebuild(std::vector<byte>& vBuffer) const
	{
		OutputBuffer obBuffer(vBuffer);
		
		obBuffer << m_ichComHeader.cb;
		obBuffer << m_ichComHeader.MajorRuntimeVersion;
		obBuffer << m_ichComHeader.MinorRuntimeVersion;
		obBuffer << m_ichComHeader.MetaData.VirtualAddress;
		obBuffer << m_ichComHeader.MetaData.Size;
		obBuffer << m_ichComHeader.Flags;
		obBuffer << m_ichComHeader.EntryPointToken;
		obBuffer << m_ichComHeader.Resources.VirtualAddress;
		obBuffer << m_ichComHeader.Resources.Size;
		obBuffer << m_ichComHeader.StrongNameSignature.VirtualAddress;
		obBuffer << m_ichComHeader.StrongNameSignature.Size;
		obBuffer << m_ichComHeader.CodeManagerTable.VirtualAddress;
		obBuffer << m_ichComHeader.CodeManagerTable.Size;
		obBuffer << m_ichComHeader.VTableFixups.VirtualAddress;
		obBuffer << m_ichComHeader.VTableFixups.Size;
		obBuffer << m_ichComHeader.ExportAddressTableJumps.VirtualAddress;
		obBuffer << m_ichComHeader.ExportAddressTableJumps.Size;
		obBuffer << m_ichComHeader.ManagedNativeHeader.VirtualAddress;
		obBuffer << m_ichComHeader.ManagedNativeHeader.Size;
	}
コード例 #3
0
  /**
  * Rebuilds the BoundImport directory. The rebuilded BoundImport directory can then be
  * written back to a PE file.
  * @param vBuffer Buffer where the rebuilt BoundImport directory will be stored.
  * @param fMakeValid If this flag is true a valid directory will be produced.
  **/
  void BoundImportDirectory::rebuild(std::vector<byte>& vBuffer, bool fMakeValid) const
  {
    std::map<std::string, word> filename_offsets;
    
    OutputBuffer obBuffer(vBuffer);
    
    word ulNameOffset = static_cast<word>((totalModules() + 1) * PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size());
    
    for (unsigned int i=0;i<m_vIbd.size();i++)
    {
      obBuffer << m_vIbd[i].ibdDescriptor.TimeDateStamp;

      // Recalculate the offsets if a valid directory is wanted.
      if (fMakeValid)
      {
        if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end())
        {
          filename_offsets[m_vIbd[i].strModuleName] = ulNameOffset;
          obBuffer << ulNameOffset;
          ulNameOffset += static_cast<word>(m_vIbd[i].strModuleName.size() + 1);
        }
        else
        {
          obBuffer << filename_offsets[m_vIbd[i].strModuleName];
        }
      }
      else // Otherwise just copy the old values into the buffer.
      {
        obBuffer << m_vIbd[i].ibdDescriptor.OffsetModuleName;
      }

      obBuffer << m_vIbd[i].ibdDescriptor.NumberOfModuleForwarderRefs;
      
      for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++)
      {
        obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.TimeDateStamp;
        
        if (fMakeValid)
        {
          if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end())
          {
            filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName] = ulNameOffset;
            obBuffer << ulNameOffset;
            ulNameOffset += static_cast<word>(m_vIbd[i].moduleForwarders[j].strModuleName.size() + 1);
          }
          else
          {
            obBuffer << filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName];
          }
        }
        else // Otherwise just copy the old values into the buffer.
        {
          obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.OffsetModuleName;
        }

        obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.NumberOfModuleForwarderRefs;
      }
    }
    
    obBuffer << static_cast<dword>(0);
    obBuffer << static_cast<word>(0);
    obBuffer << static_cast<word>(0);

    for (unsigned int i=0;i<m_vIbd.size();i++)
    {
      if (filename_offsets.find(m_vIbd[i].strModuleName) != filename_offsets.end())
      {
        obBuffer.add(getModuleName(i).c_str(), static_cast<unsigned long>(getModuleName(i).size() + 1));
        filename_offsets.erase(m_vIbd[i].strModuleName);
      }
      
      for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++)
      {
        if (filename_offsets.find(getModuleName(i, j)) != filename_offsets.end())
        {
          obBuffer.add(getModuleName(i, j).c_str(), static_cast<unsigned long>(getModuleName(i, j).size() + 1));
          filename_offsets.erase(getModuleName(i, j));
        }
      }
    }
  }