Пример #1
0
HRESULT
PEFileT<T>::GetSectionHeader(UINT32 nIndex, IPESectionHeader **ppSectionHeader)
{
    LIBPE_ASSERT_RET(NULL != ppSectionHeader, E_POINTER);
    LIBPE_ASSERT_RET(nIndex < GetSectionCount(), E_INVALIDARG);
    return m_vSectionHeaders[nIndex].CopyTo(ppSectionHeader);
}
Пример #2
0
void * CELFFile::GetSectionPtr(int section_index,size_t offset)
{
   if (section_index >= GetSectionCount())
       return NULL;
   Elf32_Shdr * shdr = GetSectionHeader(section_index);
   return shdr->sh_offset + reinterpret_cast<char *>(GetImage()) + offset;
}
Пример #3
0
long CELFFile::GetNewSectionBase()
{
    long max = 0;
    for (int i = 0; i < GetSectionCount(); i++)
    {
        Elf32_Shdr* section_header = GetSectionHeader(i);
        if (max < section_header->sh_addr + section_header->sh_size)
        {
            max = section_header->sh_addr + section_header->sh_size;
        }
    }
    max = 0x1000-(max %0x1000) + max;
    max = max + (sizeof(Elf32_Shdr) * (GetSectionCount() + 1)) + size;

    return max;
}
int CMarmaladeMainOptionsHolder::ExpertMode(void) const
{
	bool bDetailed = false;

	int count = 0;

	const int iSectionCount = GetSectionCount();

	for (int i = 0; i < iSectionCount; i++)
	{
		const SECTION_RECORD* pRec = GetSectionInfo(i);
		if (!pRec)
			continue;

		CMarmaladeSettingsSection* pSection = dynamic_cast<CMarmaladeSettingsSection*>(pRec->pSection);
		if ((NULL != pSection) && IsSectionShown(pSection->SectionIndex()))
		{
			if (0 == count++)
			{
				bDetailed = pSection->IsDetailed();
			}
			else
			{
				if (pSection->IsDetailed() != bDetailed)
					return BST_INDETERMINATE;
			}
		}
	}

	return bDetailed ? BST_CHECKED : BST_UNCHECKED;
}
Пример #5
0
HRESULT
PEFileT<T>::GetSection(UINT32 nIndex, IPESection **ppSection)
{
    LIBPE_ASSERT_RET(NULL != ppSection, E_POINTER);
    LIBPE_ASSERT_RET(nIndex < GetSectionCount(), E_INVALIDARG);
    LIBPE_ASSERT_RET(NULL != m_vSectionHeaders[nIndex], E_FAIL);
    return m_vSectionHeaders[nIndex]->GetSection(ppSection);
}
Пример #6
0
long  CELFFile::GetSectionVa(int section_index,size_t offset)
{
   if (section_index >= GetSectionCount())
        return NULL;
   Elf32_Shdr * shdr = GetSectionHeader(section_index);
   return shdr->sh_addr + offset;

}
Пример #7
0
void * CELFFile::GetSectionData(int section_index,size_t * _size)
{
    if (section_index >= GetSectionCount())
       return NULL;
   Elf32_Shdr * shdr = GetSectionHeader(section_index);
   *_size = shdr->sh_size;
   return shdr->sh_offset + reinterpret_cast<char *>(GetImage());
}
Пример #8
0
// Returns the section for a given index
CCPACSWingSection& CCPACSWingSections::GetSection(int index) const
{
    index--;
    if (index < 0 || index >= GetSectionCount()) {
        throw CTiglError("Error: Invalid index in CCPACSWingSections::GetSection", TIGL_INDEX_ERROR);
    }
    return (*sections[index]);
}
Пример #9
0
u32 RSOView::GetExportAddress(const RSOExport& rso_export) const
{
  u32 address = 0;

  if (rso_export.section_index < GetSectionCount())
    address = GetSection(rso_export.section_index).offset + rso_export.code_offset;

  return address;
}
Пример #10
0
int CProjConfig::GetSectionList(list<string>& SectionList)
{
    SectionList.empty();
	for (SECTIONMAP::iterator i = m_MapOfSection.begin();
         i != m_MapOfSection.end(); i++)
	{
        SectionList.push_front(i->first);
	}

    return GetSectionCount();
}
Пример #11
0
PIMAGE_SECTION_HEADER CPEFile::GetSection(int index)  // done!
{
    int nCount = GetSectionCount();
    if (index >= nCount || index < 0)
        return NULL;

    PIMAGE_SECTION_HEADER pFirstSection = GetFirstSectionHeader();
    for (int i = 0; i < nCount; i++,pFirstSection++ )
        if (i == index)
            return pFirstSection;
    return NULL;
}
Пример #12
0
void * CELFFile::VaToPtr(long va)
{
    for (int i = 0; i < GetSectionCount();i++)
    {
        Elf32_Shdr *shdr = GetSectionHeader(i);
        if (va <= shdr->sh_addr + shdr->sh_size &&
                va >= shdr->sh_addr)
        {
            return  GetImage() + shdr->sh_offset + (va - shdr->sh_addr);
        }
    }
    return NULL;
}
Пример #13
0
Elf32_Shdr * CELFFile::GetSectionHeader(int index)
{
    Elf32_Ehdr * elf_header = GetElfHeader();
    if (index < GetSectionCount())
    {
      Elf32_Shdr * section_header = reinterpret_cast<Elf32_Shdr*>(
                                         (elf_header->e_shoff +
                                          reinterpret_cast<Elf32_Off>(GetImage())));
      return reinterpret_cast<Elf32_Shdr*>(
                                             reinterpret_cast<Elf32_Shdr*>(section_header) + index
                                             //elf_header->e_shentsize * index
                                             //sizeof(Elf32_Shdr) * index
                                             );
    }
    return NULL;

}
Пример #14
0
long CELFFile::GetSectionMinAddress()
{
    long max = 0;
    unsigned long min = -1;
    for (int i = 0; i < GetSectionCount(); i++)
    {
        Elf32_Shdr* section_header = GetSectionHeader(i);
        if (max < section_header->sh_addr + section_header->sh_size)
        {
            max = section_header->sh_addr + section_header->sh_size;
        }
        if (min < (unsigned long)(section_header->sh_addr) && section_header->sh_addr != 0)
        {
            min = section_header->sh_addr;
        }
    }
    return min;
}
Пример #15
0
HRESULT
PEFileT<T>::GetSectionByFOA(PEAddress nFOA, IPESection **ppSection)
{
    LIBPE_ASSERT_RET(NULL != ppSection, E_POINTER);

    UINT32 nSectionCount = GetSectionCount();
    for(UINT32 nSectionIndex = 0; nSectionIndex < nSectionCount; ++nSectionIndex) {
        LibPEPtr<IPESection> pSection;
        if(SUCCEEDED(GetSection(nSectionIndex, &pSection)) && NULL != pSection) {
            if(pSection->GetFOA() <= nFOA && nFOA <= pSection->GetFOA() + pSection->GetSizeInMemory()) {
                *ppSection = pSection.Detach();
                return S_OK;
            }
        }
    }

    return E_FAIL;
}
void CMarmaladeMainOptionsHolder::SetExpertMode(bool bExpert)
{
	const int count = GetSectionCount();

	for (int i = 0; i < count; i++)
	{
		const SECTION_RECORD* pRec = GetSectionInfo(i);
		if (NULL == pRec)
			continue;

		CMarmaladeSettingsSection* pSection = dynamic_cast<CMarmaladeSettingsSection*>(pRec->pSection);
		if (NULL != pSection)
		{
			if (pSection->IsDetailed())
			{
				ShowSection(i, bExpert);
			}
			else
			{
				ShowSection(i, !bExpert);
			}
		}
	}
}
Пример #17
0
// Returns number of pages
int CHTMLSection::Paginate(const WinHelper::CRect& rcPage)
{
	/*	Strategy:
			Using the page break data, attempt to place
			as much as possible on each page, and determine
			the extrema of the rectangle for each page.
			If an object does fit on the remainder of the page,
			AND it is larger than a page, split it onto the current
			page, otherwise, wait until the next page.
	*/
	//	Empty the pagination data
	m_arrPageRects.RemoveAll();
	const int nPageHeight = rcPage.Height();
	const int nPageBreaks = m_arrBreakSections.GetSize();

	// Handle the simple case where the whole thing fits on the first page
	if (GetHeight() <= nPageHeight)
	{
		m_arrPageRects.Add(rcPage);
	}
	else
	{
		int nBreakIndex;
		UINT nPageTop = 0, nPageBottom = 0;

		for (nBreakIndex = 0; nBreakIndex < nPageBreaks; ++nBreakIndex)
		{
			// See if the next break will fit on this page
			const int nSectionIndex = m_arrBreakSections[nBreakIndex] - 1;
			if (nSectionIndex < 0)
				continue;
			if ((UINT)nSectionIndex >= GetSectionCount())
				break;
			CSectionABC* psect = GetSectionAt(nSectionIndex);
			const UINT nNextY = psect->bottom;
			// See if it will fit. 
			if (nNextY < nPageTop + nPageHeight)
			{
				// It fits... keep going...
				nPageBottom = max(nPageBottom, nNextY);
			}
			else
			{
				// If the page is empty, or the object is taller
				// than the page height, split the object!
				if (nPageBottom == nPageTop || psect->Height() > nPageHeight)
				{
					// maximum page:
					nPageBottom = nPageTop + nPageHeight;
				}
				// Create a new page
				WinHelper::CRect rect(rcPage.left, nPageTop, rcPage.right, nPageBottom);
				m_arrPageRects.Add(rect);
				nPageBottom++;
				nPageTop = nPageBottom;
			}
		}
		// Handle the remainder...
		while (nPageBottom < (UINT)GetHeight())	// bottom of this
		{
			nPageBottom = nPageTop + nPageHeight;
			WinHelper::CRect rect(rcPage.left, nPageTop, rcPage.right, nPageBottom);
			m_arrPageRects.Add(rect);
			nPageBottom++;
			nPageTop = nPageBottom;
		}
	}
	return m_arrPageRects.GetSize();
}
Пример #18
0
void CELFFile::AddSegmentSection(char * new_section_name,size_t new_section_size,long new_section_flag)
{
    printf("new base:%x\n",GetNewSegmentSectionBase() );
    long new_section_addr = GetNewSegmentSectionBase();
    Elf32_Phdr * new_phdr_header = AddProgramHeader();


    new_phdr_header->p_align = 0x1000;//new_section_size + (0x1000 - (new_section_size % 0x1000));
    new_phdr_header->p_filesz = new_section_size;
    new_phdr_header->p_memsz = new_section_size;
    new_phdr_header->p_offset = size;
    new_phdr_header->p_flags = new_section_flag;//PF_X|PF_W|PF_R;
    new_phdr_header->p_vaddr = new_section_addr;
    new_phdr_header->p_type = PT_LOAD;
    new_phdr_header->p_paddr = new_section_addr;


    //asm("int3");
    ReallocImage(size+new_section_size);
    return ;
    if (buffer == NULL || new_section_size == 0)
        return;
    size_t old_size = size;
    Elf32_Shdr * t_shdr_header =  GetFirstSectionHeader() + GetSectionCount();
    if (reinterpret_cast<size_t>(t_shdr_header) - reinterpret_cast<size_t>(GetImage()) == old_size)
    {
        ReallocImage(size + new_section_size + sizeof(Elf32_Shdr));
    }
    else
    {
        ReallocImage(size + new_section_size );
    }


    Elf32_Ehdr * elf_header = GetElfHeader();

    Elf32_Shdr * string_section_header = GetSectionHeader( elf_header->e_shstrndx );

    size_t str_table_last_offset = string_section_header->sh_size + string_section_header->sh_offset;
    char * new_string_begin_addr = reinterpret_cast<char*>(GetImage()) + str_table_last_offset;
    strcpy(new_string_begin_addr,new_section_name);
    string_section_header->sh_size += strlen(new_section_name);
    //Elf32_Shdr * new_shdr_header = GetSectionHeader(GetSectionCount() - 1);
    //Elf32_Shdr * new_shdr_header = GetSectionHeader(0) + GetSectionCount();
    //printf ("last section:%s\n",GetStringTableStr( new_shdr_header->sh_name));
    Elf32_Shdr * new_shdr_header = reinterpret_cast<Elf32_Shdr*>(
                                         (elf_header->e_shoff +
                                          reinterpret_cast<Elf32_Off>(GetImage())));
    new_shdr_header += GetSectionCount();

    //new_shdr_header++;
    printf("Elf32_Shdr Size:%x\n",sizeof(Elf32_Shdr));
    if (reinterpret_cast<size_t>(new_shdr_header) - reinterpret_cast<size_t>(GetImage()) == old_size)
    {
        new_shdr_header->sh_offset = old_size + sizeof(Elf32_Shdr);
    }
    else
    {
        new_shdr_header->sh_offset = old_size;
    }

    printf("offset :%x\n",reinterpret_cast<size_t>(new_shdr_header) - reinterpret_cast<size_t>(GetImage()));
    new_shdr_header->sh_name = str_table_last_offset - string_section_header->sh_offset;
    printf ("last section:%s\n",GetStringTableStr( new_shdr_header->sh_name));
    new_shdr_header->sh_addr = GetNewSectionBase();
    new_shdr_header->sh_size = new_section_size;
    printf("size :%#x\n",new_shdr_header->sh_size);
    new_shdr_header->sh_flags = new_section_flag;

    //new_shdr_header->sh_offset = old_size;
    new_shdr_header->sh_type = 1;
    new_shdr_header->sh_link = 0;
    new_shdr_header->sh_info = 0;
    new_shdr_header->sh_addralign = 16;
    new_shdr_header->sh_entsize = 0;
    ++elf_header->e_shnum;


    /*
    Elf32_Phdr * new_phdr_header = GetProgramHeader(GetProgramCount() - 1);
    new_phdr_header++;
    printf("new_phdr_header offset:%#x\n",(size_t)new_phdr_header - (size_t)GetImage());
    new_phdr_header->p_align = 0x1000;//new_section_size + (0x1000 - (new_section_size % 0x1000));
    new_phdr_header->p_filesz = new_section_size;
    new_phdr_header->p_memsz = new_section_size;
    new_phdr_header->p_offset = new_shdr_header->sh_offset;
    new_phdr_header->p_flags = 5;
    new_phdr_header->p_vaddr = new_shdr_header->sh_addr;
    new_phdr_header->p_type = 1;
    new_phdr_header->p_paddr = new_phdr_header->p_vaddr;
    elf_header->e_phnum += 1;*/
}
Пример #19
0
void CELFFile::AddSection(char * new_section_name,size_t new_section_size,long new_section_flag)
{
    if (buffer == NULL || new_section_size == 0)
        return;
    size_t old_size = size;
    Elf32_Shdr * t_shdr_header =  GetFirstSectionHeader() + GetSectionCount();
    if (reinterpret_cast<size_t>(t_shdr_header) - reinterpret_cast<size_t>(GetImage()) == old_size)
    {
        ReallocImage(size + new_section_size + sizeof(Elf32_Shdr));
    }
    else
    {
        ReallocImage(size + new_section_size );
    }


    Elf32_Ehdr * elf_header = GetElfHeader();

    Elf32_Shdr * string_section_header = GetSectionHeader( elf_header->e_shstrndx );

    size_t str_table_last_offset = string_section_header->sh_size + string_section_header->sh_offset;
    char * new_string_begin_addr = reinterpret_cast<char*>(GetImage()) + str_table_last_offset;
    strcpy(new_string_begin_addr,new_section_name);
    string_section_header->sh_size += strlen(new_section_name);
    //Elf32_Shdr * new_shdr_header = GetSectionHeader(GetSectionCount() - 1);
    //Elf32_Shdr * new_shdr_header = GetSectionHeader(0) + GetSectionCount();
    //printf ("last section:%s\n",GetStringTableStr( new_shdr_header->sh_name));
    Elf32_Shdr * new_shdr_header = reinterpret_cast<Elf32_Shdr*>(
                                         (elf_header->e_shoff +
                                          reinterpret_cast<Elf32_Off>(GetImage())));
    new_shdr_header += GetSectionCount();

    //new_shdr_header++;
    printf("Elf32_Shdr Size:%x\n",sizeof(Elf32_Shdr));
    if (reinterpret_cast<size_t>(new_shdr_header) - reinterpret_cast<size_t>(GetImage()) == old_size)
    {
        new_shdr_header->sh_offset = old_size + sizeof(Elf32_Shdr);
    }
    else
    {
        new_shdr_header->sh_offset = old_size;
    }

    printf("offset :%x\n",reinterpret_cast<size_t>(new_shdr_header) - reinterpret_cast<size_t>(GetImage()));
    new_shdr_header->sh_name = str_table_last_offset - string_section_header->sh_offset;
    printf ("last section:%s\n",GetStringTableStr( new_shdr_header->sh_name));
    new_shdr_header->sh_addr = GetNewSectionBase();
    new_shdr_header->sh_size = new_section_size;
    printf("size :%#x\n",new_shdr_header->sh_size);
    new_shdr_header->sh_flags = new_section_flag;

    //new_shdr_header->sh_offset = old_size;
    new_shdr_header->sh_type = 1;
    new_shdr_header->sh_link = 0;
    new_shdr_header->sh_info = 0;
    new_shdr_header->sh_addralign = 16;
    new_shdr_header->sh_entsize = 0;
    ++elf_header->e_shnum;


}