pexxigen.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,044 行 · 第 1/5 页
C
2,044 行
{ PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext); PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext); } return AUXESZ;}void_bfd_XXi_swap_lineno_in (abfd, ext1, in1) bfd *abfd; PTR ext1; PTR in1;{ LINENO *ext = (LINENO *) ext1; struct internal_lineno *in = (struct internal_lineno *) in1; in->l_addr.l_symndx = bfd_h_get_32 (abfd, (bfd_byte *) ext->l_addr.l_symndx); in->l_lnno = GET_LINENO_LNNO (abfd, ext);}unsigned int_bfd_XXi_swap_lineno_out (abfd, inp, outp) bfd *abfd; PTR inp; PTR outp;{ struct internal_lineno *in = (struct internal_lineno *) inp; struct external_lineno *ext = (struct external_lineno *) outp; bfd_h_put_32 (abfd, in->l_addr.l_symndx, (bfd_byte *) ext->l_addr.l_symndx); PUT_LINENO_LNNO (abfd, in->l_lnno, ext); return LINESZ;}void_bfd_XXi_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1) bfd *abfd; PTR aouthdr_ext1; PTR aouthdr_int1;{ struct internal_extra_pe_aouthdr *a; PEAOUTHDR *src = (PEAOUTHDR *) (aouthdr_ext1); AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1; struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1; aouthdr_int->magic = bfd_h_get_16 (abfd, (bfd_byte *) aouthdr_ext->magic); aouthdr_int->vstamp = bfd_h_get_16 (abfd, (bfd_byte *) aouthdr_ext->vstamp); aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize); aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize); aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize); aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry); aouthdr_int->text_start = GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);#ifndef COFF_WITH_pep /* PE32+ does not have data_start member! */ aouthdr_int->data_start = GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);#endif a = &aouthdr_int->pe; a->ImageBase = GET_OPTHDR_IMAGE_BASE (abfd, (bfd_byte *) src->ImageBase); a->SectionAlignment = bfd_h_get_32 (abfd, (bfd_byte *) src->SectionAlignment); a->FileAlignment = bfd_h_get_32 (abfd, (bfd_byte *) src->FileAlignment); a->MajorOperatingSystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MajorOperatingSystemVersion); a->MinorOperatingSystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MinorOperatingSystemVersion); a->MajorImageVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MajorImageVersion); a->MinorImageVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MinorImageVersion); a->MajorSubsystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MajorSubsystemVersion); a->MinorSubsystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MinorSubsystemVersion); a->Reserved1 = bfd_h_get_32 (abfd, (bfd_byte *) src->Reserved1); a->SizeOfImage = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfImage); a->SizeOfHeaders = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfHeaders); a->CheckSum = bfd_h_get_32 (abfd, (bfd_byte *) src->CheckSum); a->Subsystem = bfd_h_get_16 (abfd, (bfd_byte *) src->Subsystem); a->DllCharacteristics = bfd_h_get_16 (abfd, (bfd_byte *) src->DllCharacteristics); a->SizeOfStackReserve = GET_OPTHDR_SIZE_OF_STACK_RESERVE (abfd, (bfd_byte *) src->SizeOfStackReserve); a->SizeOfStackCommit = GET_OPTHDR_SIZE_OF_STACK_COMMIT (abfd, (bfd_byte *) src->SizeOfStackCommit); a->SizeOfHeapReserve = GET_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd, (bfd_byte *) src->SizeOfHeapReserve); a->SizeOfHeapCommit = GET_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd, (bfd_byte *) src->SizeOfHeapCommit); a->LoaderFlags = bfd_h_get_32 (abfd, (bfd_byte *) src->LoaderFlags); a->NumberOfRvaAndSizes = bfd_h_get_32 (abfd, (bfd_byte *) src->NumberOfRvaAndSizes); { int idx; for (idx = 0; idx < 16; idx++) { /* If data directory is empty, rva also should be 0. */ int size = bfd_h_get_32 (abfd, (bfd_byte *) src->DataDirectory[idx][1]); a->DataDirectory[idx].Size = size; if (size) { a->DataDirectory[idx].VirtualAddress = bfd_h_get_32 (abfd, (bfd_byte *) src->DataDirectory[idx][0]); } else a->DataDirectory[idx].VirtualAddress = 0; } } if (aouthdr_int->entry) { aouthdr_int->entry += a->ImageBase;#ifndef COFF_WITH_pep aouthdr_int->entry &= 0xffffffff;#endif } if (aouthdr_int->tsize) { aouthdr_int->text_start += a->ImageBase;#ifndef COFF_WITH_pep aouthdr_int->text_start &= 0xffffffff;#endif }#ifndef COFF_WITH_pep /* PE32+ does not have data_start member! */ if (aouthdr_int->dsize) { aouthdr_int->data_start += a->ImageBase; aouthdr_int->data_start &= 0xffffffff; }#endif#ifdef POWERPC_LE_PE /* These three fields are normally set up by ppc_relocate_section. In the case of reading a file in, we can pick them up from the DataDirectory. */ first_thunk_address = a->DataDirectory[12].VirtualAddress; thunk_size = a->DataDirectory[12].Size; import_table_size = a->DataDirectory[1].Size;#endif}/* A support function for below. */static voidadd_data_entry (abfd, aout, idx, name, base) bfd *abfd; struct internal_extra_pe_aouthdr *aout; int idx; char *name; bfd_vma base;{ asection *sec = bfd_get_section_by_name (abfd, name); /* add import directory information if it exists */ if ((sec != NULL) && (coff_section_data (abfd, sec) != NULL) && (pei_section_data (abfd, sec) != NULL)) { /* If data directory is empty, rva also should be 0 */ int size = pei_section_data (abfd, sec)->virt_size; aout->DataDirectory[idx].Size = size; if (size) { aout->DataDirectory[idx].VirtualAddress = (sec->vma - base) & 0xffffffff; sec->flags |= SEC_DATA; } }}unsigned int_bfd_XXi_swap_aouthdr_out (abfd, in, out) bfd *abfd; PTR in; PTR out;{ struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in; pe_data_type *pe = pe_data (abfd); struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr; PEAOUTHDR *aouthdr_out = (PEAOUTHDR *) out; bfd_vma sa, fa, ib; if (pe->force_minimum_alignment) { if (!extra->FileAlignment) extra->FileAlignment = PE_DEF_FILE_ALIGNMENT; if (!extra->SectionAlignment) extra->SectionAlignment = PE_DEF_SECTION_ALIGNMENT; } if (extra->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) extra->Subsystem = pe->target_subsystem; sa = extra->SectionAlignment; fa = extra->FileAlignment; ib = extra->ImageBase; if (aouthdr_in->tsize) { aouthdr_in->text_start -= ib;#ifndef COFF_WITH_pep aouthdr_in->text_start &= 0xffffffff;#endif } if (aouthdr_in->dsize) { aouthdr_in->data_start -= ib;#ifndef COFF_WITH_pep aouthdr_in->data_start &= 0xffffffff;#endif } if (aouthdr_in->entry) { aouthdr_in->entry -= ib;#ifndef COFF_WITH_pep aouthdr_in->entry &= 0xffffffff;#endif }#define FA(x) (((x) + fa -1 ) & (- fa))#define SA(x) (((x) + sa -1 ) & (- sa)) /* We like to have the sizes aligned. */ aouthdr_in->bsize = FA (aouthdr_in->bsize); extra->NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES; /* first null out all data directory entries .. */ memset (extra->DataDirectory, sizeof (extra->DataDirectory), 0); add_data_entry (abfd, extra, 0, ".edata", ib); /* Don't call add_data_entry for .idata$2 or .idata$5. It's done in bfd_coff_final_link where all the required information is available. */ /* However, until other .idata fixes are made (pending patch), the entry for .idata is needed for backwards compatability. FIXME. */ add_data_entry (abfd, extra, 1, ".idata", ib); add_data_entry (abfd, extra, 2, ".rsrc", ib); add_data_entry (abfd, extra, 3, ".pdata", ib); /* For some reason, the virtual size (which is what's set by add_data_entry) for .reloc is not the same as the size recorded in this slot by MSVC; it doesn't seem to cause problems (so far), but since it's the best we've got, use it. It does do the right thing for .pdata. */ if (pe->has_reloc_section) add_data_entry (abfd, extra, 5, ".reloc", ib); { asection *sec; bfd_vma dsize = 0; bfd_vma isize = SA(abfd->sections->filepos); bfd_vma tsize = 0; for (sec = abfd->sections; sec; sec = sec->next) { int rounded = FA(sec->_raw_size); if (sec->flags & SEC_DATA) dsize += rounded; if (sec->flags & SEC_CODE) tsize += rounded; /* The image size is the total VIRTUAL size (which is what is in the virt_size field). Files have been seen (from MSVC 5.0 link.exe) where the file size of the .data segment is quite small compared to the virtual size. Without this fix, strip munges the file. */ isize += SA (FA (pei_section_data (abfd, sec)->virt_size)); } aouthdr_in->dsize = dsize; aouthdr_in->tsize = tsize; extra->SizeOfImage = isize; } extra->SizeOfHeaders = abfd->sections->filepos; bfd_h_put_16 (abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->standard.magic);#define LINKER_VERSION 256 /* That is, 2.56 */ /* This piece of magic sets the "linker version" field to LINKER_VERSION. */ bfd_h_put_16 (abfd, LINKER_VERSION / 100 + (LINKER_VERSION % 100) * 256, (bfd_byte *) aouthdr_out->standard.vstamp); PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->standard.tsize); PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->standard.dsize); PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->standard.bsize); PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->standard.entry); PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start, (bfd_byte *) aouthdr_out->standard.text_start);#ifndef COFF_WITH_pep /* PE32+ does not have data_start member! */ PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start, (bfd_byte *) aouthdr_out->standard.data_start);#endif PUT_OPTHDR_IMAGE_BASE (abfd, extra->ImageBase, (bfd_byte *) aouthdr_out->ImageBase); bfd_h_put_32 (abfd, extra->SectionAlignment, (bfd_byte *) aouthdr_out->SectionAlignment); bfd_h_put_32 (abfd, extra->FileAlignment, (bfd_byte *) aouthdr_out->FileAlignment); bfd_h_put_16 (abfd, extra->MajorOperatingSystemVersion, (bfd_byte *) aouthdr_out->MajorOperatingSystemVersion); bfd_h_put_16 (abfd, extra->MinorOperatingSystemVersion, (bfd_byte *) aouthdr_out->MinorOperatingSystemVersion); bfd_h_put_16 (abfd, extra->MajorImageVersion, (bfd_byte *) aouthdr_out->MajorImageVersion); bfd_h_put_16 (abfd, extra->MinorImageVersion, (bfd_byte *) aouthdr_out->MinorImageVersion); bfd_h_put_16 (abfd, extra->MajorSubsystemVersion, (bfd_byte *) aouthdr_out->MajorSubsystemVersion); bfd_h_put_16 (abfd, extra->MinorSubsystemVersion, (bfd_byte *) aouthdr_out->MinorSubsystemVersion); bfd_h_put_32 (abfd, extra->Reserved1, (bfd_byte *) aouthdr_out->Reserved1); bfd_h_put_32 (abfd, extra->SizeOfImage, (bfd_byte *) aouthdr_out->SizeOfImage); bfd_h_put_32 (abfd, extra->SizeOfHeaders, (bfd_byte *) aouthdr_out->SizeOfHeaders); bfd_h_put_32 (abfd, extra->CheckSum, (bfd_byte *) aouthdr_out->CheckSum); bfd_h_put_16 (abfd, extra->Subsystem, (bfd_byte *) aouthdr_out->Subsystem); bfd_h_put_16 (abfd, extra->DllCharacteristics, (bfd_byte *) aouthdr_out->DllCharacteristics); PUT_OPTHDR_SIZE_OF_STACK_RESERVE (abfd, extra->SizeOfStackReserve, (bfd_byte *) aouthdr_out->SizeOfStackReserve); PUT_OPTHDR_SIZE_OF_STACK_COMMIT (abfd, extra->SizeOfStackCommit, (bfd_byte *) aouthdr_out->SizeOfStackCommit); PUT_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd, extra->SizeOfHeapReserve, (bfd_byte *) aouthdr_out->SizeOfHeapReserve); PUT_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd, extra->SizeOfHeapCommit, (bfd_byte *) aouthdr_out->SizeOfHeapCommit); bfd_h_put_32 (abfd, extra->LoaderFlags, (bfd_byte *) aouthdr_out->LoaderFlags); bfd_h_put_32 (abfd, extra->NumberOfRvaAndSizes, (bfd_byte *) aouthdr_out->NumberOfRvaAndSizes); { int idx; for (idx = 0; idx < 16; idx++) { bfd_h_put_32 (abfd, extra->DataDirectory[idx].VirtualAddress, (bfd_byte *) aouthdr_out->DataDirectory[idx][0]); bfd_h_put_32 (abfd, extra->DataDirectory[idx].Size, (bfd_byte *) aouthdr_out->DataDirectory[idx][1]); } } return AOUTSZ;}unsigned int_bfd_XXi_only_swap_filehdr_out (abfd, in, out) bfd *abfd; PTR in; PTR out;{ int idx; struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in; struct external_PEI_filehdr *filehdr_out = (struct external_PEI_filehdr *) out; if (pe_data (abfd)->has_reloc_section) filehdr_in->f_flags &= ~F_RELFLG; if (pe_data (abfd)->dll) filehdr_in->f_flags |= F_DLL; filehdr_in->pe.e_magic = DOSMAGIC; filehdr_in->pe.e_cblp = 0x90; filehdr_in->pe.e_cp = 0x3; filehdr_in->pe.e_crlc = 0x0; filehdr_in->pe.e_cparhdr = 0x4; filehdr_in->pe.e_minalloc = 0x0; filehdr_in->pe.e_maxalloc = 0xffff; filehdr_in->pe.e_ss = 0x0; filehdr_in->pe.e_sp = 0xb8; filehdr_in->pe.e_csum = 0x0; filehdr_in->pe.e_ip = 0x0; filehdr_in->pe.e_cs = 0x0; filehdr_in->pe.e_lfarlc = 0x40; filehdr_in->pe.e_ovno = 0x0; for (idx = 0; idx < 4; idx++) filehdr_in->pe.e_res[idx] = 0x0; filehdr_in->pe.e_oemid = 0x0; filehdr_in->pe.e_oeminfo = 0x0; for (idx = 0; idx < 10; idx++) filehdr_in->pe.e_res2[idx] = 0x0; filehdr_in->pe.e_lfanew = 0x80; /* This next collection of data are mostly just characters. It appears to be constant within the headers put on NT exes. */ filehdr_in->pe.dos_message[0] = 0x0eba1f0e; filehdr_in->pe.dos_message[1] = 0xcd09b400;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?