⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elfparts.txt

📁 ELFkickers是一组elf工具
💻 TXT
字号:
The basic idea behind the elfparts library is to simplify the processof assembling the various components of an ELF file. The "parts" of anELF file that the library deals with are pretty much equivalent tosections, excepting a few of the part types (namely, the ELF header,the program header table, and the section header table itself).The basic process entails filling in a blueprint with the descriptionof what the file should look like, and then proceeding through fourstages of gradually building up the actual contents, after which theimage may be saved to an actual file.The first piece of data in the blueprint is the filetype field, whichspecifies the type of file to create. This field should be set toET_REL for an object file, ET_EXEC for an executable, or ET_DYN for ashared library.The other piece of information in a blueprint structure is an arrayof elfpart structures. This is the parts list. The caller shouldallocate the elfpart array, and fill it in with the desired types ofparts, in the order that they are to appear in the file. (For example,the first element in the parts list will always be an ELF header.)There can be more than one instance of a given type, presuming thatthe ELF standard permits it.The library exports a number of elfpart structures. By copying thesestructures into the elements of the parts list, the type of eachelement is determined. These structures are empty except for the firstfour fields, which are function pointers. They correspond directly tothe previously mentioned four stages of building up the file image.The caller does not call them directly, however; the library exportsfour functions, each of which move all the parts in the parts listthrough the various stages.newparts() is the first function, and is usually called immediatelyafter setting up the blueprint. At this stage, each part sets up itsinitial state.After calling newparts(), the caller should "attach" parts that needto know about each other. Generally, this means supplying a pointer toone part in the link field of another.The following linkages need to be made:* A hash needs to be linked to the dynamic symbol table (dynsym).* Symbol tables (dynsym or symtab) need to be linked to a string table  (dynstr or strtab).* A section header string table (shstrtab) needs to be linked to the  section header table (shdrtab).* Relocation section (rel or rela) need to also be linked to a symbol  table (symtab).In addition, relocation sections should have their info field set tothe index of the part (usually one of the progbits types) that theyapply to.Finally, note that if a program header table and/or a section headertable is included, then the first part in the parts list must be anELF header (which should be the case anyway, but these two partsrequire it).If the caller wishes, they may remove parts from the parts list atthis stage by setting the shtype field in the elfpart structure tozero.initparts() is called after this, and completes the initialization ofthe component parts. This is the second stage. After initparts() hasreturned, the caller may begin to fill in the actual contents of eachpart.The parts of type progbits (namely, the types text, data, bss, andprogbits) are not filled in by the library; the caller should do thatdirectly. The elfpart field named part is a void pointer, and thecaller should use this field to hold a pointer to memory containingthe desired contents. Likewise, the size field should contain thecontent's total size. Alternately, if the contents are an array, thecaller can fill in the entsize and count fields instead, which specifythe size of each array element and the number of elementsrespectively.The progbits type itself sets the flags field to PF_R (i.e.,read-only). If the caller wants such a part to include the PF_Xswitch, they should either OR this value in directly, or use the morespecific text type. Likewise for the data type and the PF_W(writeable) flag.Currently, the elfparts library does not actually support a proper bsstype (i.e., one whose contents are not added to the file).The other part types are not filled in directly, but via functionssupplied by the library. See elfparts.h for documentation on thesefunctions.fillparts() brings the file image to the third stage, and shouldgenerally be called after the caller has finished adding content.This function causes the various parts to "fill up"; after thisfunction returns, each part will be at the size it will have in thecompleted file.At this point, the caller may continue to build up the parts of typeprogbits, but the other parts should already contain everything theyneed. When the caller is finished, the computeoffsets() function should becalled. This function determines the actual positions in the fileimage for each part, and, if applicable, the addresses for the partsthat will be loaded into memory. This information is stored in theoffset and addr fields of the elfpart structure.The computeoffsets() function must be called during this stage. Oncethis function has been called, the caller may still fill in the actualcontents of various parts (and in fact various bits of informationcannot be set until the file offsets and memory addresses are known).However, the caller must not add or remove anything from the contents:the size of each part should remain unchanged.completeparts() brings the file image to the fourth and final stage.This function causes the contents of the various parts to take ontheir final form. After this function returns, the caller may continueto make changes within the parts of type progbits, but only if nothingelse in the file is dependent on the changes.At any time after this point, the user may call the outputelf()function. The completed image will be written to the given filename,and the job is done.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -