- Timestamp:
- Feb 26, 2000, 1:46:31 AM (26 years ago)
- Location:
- trunk/src/win32k
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/elf2lx/elf2lx.cpp
r1678 r2899 1 /* $Id: elf2lx.cpp,v 1. 1 1999-11-10 01:45:31bird Exp $1 /* $Id: elf2lx.cpp,v 1.2 2000-02-26 00:46:30 bird Exp $ 2 2 * 3 3 * Elf2Lx - implementation. 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT -
trunk/src/win32k/elf2lx/elfdumper.cpp
r2497 r2899 1 /* $Id: elfdumper.cpp,v 1. 1 2000-01-22 00:49:21bird Exp $1 /* $Id: elfdumper.cpp,v 1.2 2000-02-26 00:46:30 bird Exp $ 2 2 * 3 3 * ELF dumper utility 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 57 57 int dumpELFImage(void *pv); 58 58 int dumpELFHdr(Elf32_Ehdr *pHdr32); 59 59 60 int dumpELFSectionHeader(Elf32_Ehdr * pHdr32, int iShdr); 60 61 int dumpELFSectionHeaderTable(Elf32_Ehdr * pHdr32); … … 63 64 int dumpELFRelcations(Elf32_Ehdr * pHdr32, Elf32_Shdr * pShdr); 64 65 int dumpELFRelcationsA(Elf32_Ehdr * pHdr32, Elf32_Shdr * pShdr); 66 67 int dumpELFProgramHeader(Elf32_Ehdr * pHdr32, int iPhdr); 68 int dumpELFProgramHeaderTable(Elf32_Ehdr * pHdr32); 69 int dumpELFDynamicSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr); 70 int getELFDynmaicTagValue(Elf32_Dyn *pDyn, Elf32_Sword tag, Elf32_Word *pword); 71 int dumpELFInterpreterSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr); 72 int dumpELFNoteSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr); 73 74 65 75 66 76 /* output helpers */ … … 201 211 if (rc == 0) 202 212 rc = dumpELFSectionHeaderTable(pHdr32); 213 if (rc == 0) 214 rc = dumpELFProgramHeaderTable(pHdr32); 203 215 } 204 216 else … … 390 402 PRINTCASE(1,SHT_NUM); 391 403 default: 392 if (pShdr->sh_type >= SHT_LOPROC && pShdr->sh_type >= SHT_HIPROC)404 if (pShdr->sh_type >= SHT_LOPROC && pShdr->sh_type <= SHT_HIPROC) 393 405 printData(1, "Processor-specific"); 394 406 else if (pShdr->sh_type >= SHT_LOUSER && pShdr->sh_type <= SHT_HIUSER) … … 587 599 588 600 601 /** 602 * Dumps the program header tables. 603 * @returns 0 on success. Errorcode on error (-1). 604 * @param pHdr32 Pointer to the image. 605 * @author knut st. osmundsen 606 */ 607 int dumpELFProgramHeaderTable(Elf32_Ehdr * pHdr32) 608 { 609 int i; 610 int rc = 0; 611 612 printHeader("Program Header Table"); 613 614 for (i = 0; i < pHdr32->e_phnum && rc == 0; i++) 615 { 616 if (i > 0) 617 print(0,""); 618 rc = dumpELFProgramHeader(pHdr32, i); 619 } 620 return rc; 621 } 622 623 624 /** 625 * Dumps a program header of an ELF image. 626 * @returns 0 on success. Errorcode on error (-1). 627 * @param pHdr32 Pointer to the image. 628 * @param iPhdr Program header number. 629 * @author knut st. osmundsen 630 */ 631 int dumpELFProgramHeader(Elf32_Ehdr * pHdr32, int iPhdr) 632 { 633 Elf32_Phdr * pPhdr = (Elf32_Phdr*)((unsigned)pHdr32 + pHdr32->e_phoff + pHdr32->e_phentsize*iPhdr); 634 635 636 print(0, "Program Header", "no. %d offset 0x%08x", iPhdr, (unsigned)pPhdr - (unsigned)pHdr32); 637 638 print(1, "p_type", "0x%08x", pPhdr->p_type); 639 switch (pPhdr->p_type) 640 { 641 PRINTCASE(1,PT_NULL ); 642 PRINTCASE(1,PT_LOAD ); 643 PRINTCASE(1,PT_DYNAMIC); 644 PRINTCASE(1,PT_INTERP ); 645 PRINTCASE(1,PT_NOTE ); 646 PRINTCASE(1,PT_SHLIB ); 647 PRINTCASE(1,PT_PHDR ); 648 default: 649 if (pPhdr->p_type >= PT_LOPROC && pPhdr->p_type <= PT_HIPROC) 650 printData(1, "Processor-specific"); 651 else 652 printData(1, "unknown"); 653 } 654 print(1, "p_offset", "0x%08x", pPhdr->p_offset); 655 print(1, "p_vaddr", "0x%08x", pPhdr->p_vaddr); 656 print(1, "p_paddr", "0x%08x", pPhdr->p_paddr); 657 print(1, "p_filesz", "0x%08x", pPhdr->p_filesz); 658 print(1, "p_memsz", "0x%08x", pPhdr->p_memsz); 659 print(1, "p_flags", "0x%08x", pPhdr->p_flags); 660 printBeginLongData(1); 661 PRINTFLAG(pPhdr->p_flags, PF_X); 662 PRINTFLAG(pPhdr->p_flags, PF_W); 663 PRINTFLAG(pPhdr->p_flags, PF_R); 664 printEndLongData(); 665 print(1, "p_align", "0x%08x", pPhdr->p_align); 666 printBeginLongData(1); 667 if (pPhdr->p_align && 668 (pPhdr->p_vaddr % pPhdr->p_align != pPhdr->p_offset % pPhdr->p_align)) 669 printData(1, "alignment error?"); 670 printEndLongData(); 671 672 673 switch (pPhdr->p_type) 674 { 675 case PT_DYNAMIC: 676 dumpELFDynamicSegment(pHdr32, pPhdr); 677 break; 678 679 case PT_INTERP: 680 dumpELFInterpreterSegment(pHdr32, pPhdr); 681 break; 682 683 case PT_NOTE: 684 dumpELFNoteSegment(pHdr32, pPhdr); 685 break; 686 } 687 return 0; 688 } 689 690 691 /** 692 * Dumps a dynamic segment. 693 * @returns 0 on success. 694 * @param pHdr32 Pointer to ELF header (and base of the loaded file). 695 * @param pPhdr Pointer to program header. 696 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 697 */ 698 int dumpELFDynamicSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr) 699 { 700 Elf32_Word word; 701 Elf32_Addr base; 702 int i; 703 Elf32_Dyn * pDyn = (Elf32_Dyn*) ((unsigned)pHdr32 + pPhdr->p_offset); 704 Elf32_Phdr * pPhdrs = (Elf32_Phdr*)((unsigned)pHdr32 + pHdr32->e_phoff); 705 char * paszStrings; 706 707 /* find base address */ 708 i = 0; 709 while (i < pHdr32->e_phnum && pPhdrs->p_type != PT_LOAD) 710 { 711 i++; 712 pPhdrs = (Elf32_Phdr*)((unsigned)pPhdrs + pHdr32->e_phentsize); 713 } 714 if (i < pHdr32->e_phnum) 715 base = pPhdrs->p_vaddr; 716 717 /* find string table */ 718 if (getELFDynmaicTagValue(pDyn, DT_STRTAB, &word) == 0) 719 paszStrings = (char*)(word - base + (int)pHdr32); 720 else 721 paszStrings = NULL; /* no string table - funny! */ 722 723 /* 724 * Loop thru the entries. 725 */ 726 i = 0; 727 while (pDyn[i].d_tag != DT_NULL) 728 { 729 switch (pDyn[i].d_tag) 730 { 731 case DT_NULL: /* - - - Marks the end of the dynamic array. */ 732 break; 733 case DT_NEEDED: /* d_val * * Holds the string table offset of a null-terminated 734 string, giving the name of a needed library. The 735 offset is an index into the table recoreded in the 736 DT_STRTAB entry. */ 737 print(2, "DT_NEEDED", "0x%08x", pDyn[i].d_un.d_val); 738 if (paszStrings != NULL) 739 printData(2, "%s", paszStrings + pDyn[i].d_un.d_val); 740 else 741 printData(2, "(no string table)"); 742 break; 743 744 case DT_PLTRELSZ: 745 print(2, "DT_PLTRELSZ", "0x%08x", pDyn[i].d_un.d_val); 746 break; 747 748 case DT_PLTGOT: 749 print(2, "DT_PLTGOT", "0x%08x", pDyn[i].d_un.d_val); 750 break; 751 case DT_HASH: 752 print(2, "DT_HASH", "0x%08x", pDyn[i].d_un.d_val); 753 break; 754 case DT_STRTAB: 755 print(2, "DT_STRTAB", "0x%08x", pDyn[i].d_un.d_val); 756 break; 757 case DT_SYMTAB: 758 print(2, "DT_SYMTAB", "0x%08x", pDyn[i].d_un.d_val); 759 break; 760 case DT_RELA: 761 print(2, "DT_RELA", "0x%08x", pDyn[i].d_un.d_val); 762 break; 763 case DT_RELASZ: 764 print(2, "DT_RELASZ", "0x%08x", pDyn[i].d_un.d_val); 765 break; 766 case DT_RELAENT: 767 print(2, "DT_RELAENT", "0x%08x", pDyn[i].d_un.d_val); 768 break; 769 770 case DT_STRSZ: /* d_ptr + + This element holds the address of the string table. 771 Symbol names, library names, and other strings reside 772 in this table. */ 773 print(2, "DT_STRSZ", "0x%08x", pDyn[i].d_un.d_ptr); 774 break; 775 776 case DT_SYMENT: 777 print(2, "DT_SYMENT", "0x%08x", pDyn[i].d_un.d_val); 778 break; 779 780 case DT_INIT: /* d_ptr * * This element holds the address of the initialization function. */ 781 print(2, "DT_INIT", "0x%08x (init function)", pDyn[i].d_un.d_val); 782 break; 783 784 case DT_FINI: /* d_ptr * * This element holds the address of the termination function. */ 785 print(2, "DT_FINI", "0x%08x (term function)", pDyn[i].d_un.d_val); 786 break; 787 788 case DT_SONAME: /* d_val - * This element holds the string table offset of a 789 null-terminated string, giving the name of the shared 790 object. The offset is an index into the table recorded 791 in the DT_STRTAB entry. */ 792 793 print(2, "DT_SONAME", "0x%08x", pDyn[i].d_un.d_val); 794 if (paszStrings != NULL) 795 printData(2, "%s", paszStrings + pDyn[i].d_un.d_val); 796 else 797 printData(2, "(no string table)"); 798 break; 799 800 case DT_RPATH: /* d_val + + This element holds the string table offset of a null-terminated 801 search library search path string. The offset is an index int 802 the table recorded in the DT_STRTAB entry. */ 803 print(2, "DT_RPATH", "0x%08x", pDyn[i].d_un.d_val); 804 if (paszStrings != NULL) 805 printData(2, "%s", paszStrings + pDyn[i].d_un.d_val); 806 else 807 printData(2, "(no string table)"); 808 break; 809 810 case DT_SYMBOLIC: /* - - * This element's presence in a shared object library alters the 811 dynamic linker's symbol resolution algorithm for references 812 within the library. Instead of starting a symbol search with 813 the executable file, the dynamic linker starts from the shared 814 object file itself. If the shared object fails to supply the 815 referenced symbol, the dynamic linker then searches the 816 executable file and other shared objects as usual. */ 817 print(2, "DT_SYMBOLIC", "(%d)", pDyn[i].d_un.d_val); 818 printData(2, "Searches within the library before the executable."); 819 break; 820 821 case DT_REL: 822 print(2, "DT_REL", "0x%08x", pDyn[i].d_un.d_val); 823 break; 824 case DT_RELSZ: 825 print(2, "DT_RELSZ", "0x%08x", pDyn[i].d_un.d_val); 826 break; 827 case DT_RELENT: 828 print(2, "DT_RELENT", "0x%08x", pDyn[i].d_un.d_val); 829 break; 830 case DT_PLTREL: 831 print(2, "DT_PLTREL", "0x%08x", pDyn[i].d_un.d_val); 832 break; 833 case DT_DEBUG: 834 print(2, "DT_DEBUG", "0x%08x", pDyn[i].d_un.d_val); 835 break; 836 case DT_TEXTREL: 837 print(2, "DT_TEXTREL", "0x%08x", pDyn[i].d_un.d_val); 838 break; 839 case DT_JMPREL: 840 print(2, "DT_JMPREL", "0x%08x", pDyn[i].d_un.d_val); 841 break; 842 843 } 844 /* next */ 845 i++; 846 } 847 return 0; 848 } 849 850 851 /** 852 * 853 * @returns 0 on succes. 854 * @param pDyn Pointer to start of tag array. 855 * @param tag Tag type to find. 856 * @param pword Pointer to Elf32_Word which will hold the tag value if found. 857 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 858 */ 859 int getELFDynmaicTagValue(Elf32_Dyn *pDyn, Elf32_Sword tag, Elf32_Word *pword) 860 { 861 while (pDyn->d_tag != tag && pDyn->d_tag != DT_NULL) 862 pDyn++; 863 if (pDyn->d_tag != DT_NULL) 864 { 865 *pword = pDyn->d_un.d_val; 866 return 0; 867 } 868 return -1; 869 } 870 871 872 /** 873 * Dumps a Interpreter segment. 874 * @returns 0 on success. 875 * @param pHdr32 Pointer to ELF header (and base of the loaded file). 876 * @param pPhdr Pointer to program header. 877 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 878 */ 879 int dumpELFInterpreterSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr) 880 { 881 print(2, "Interpreter name", "%s", (char*)pHdr32 + pPhdr->p_offset); 882 return 0; 883 } 884 885 886 /** 887 * Dumps a note segment. 888 * @returns 0 on success. 889 * @param pHdr32 Pointer to ELF header (and base of the loaded file). 890 * @param pPhdr Pointer to program header. 891 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 892 */ 893 int dumpELFNoteSegment(Elf32_Ehdr * pHdr32, Elf32_Phdr * pPhdr) 894 { 895 pPhdr = pPhdr; 896 pHdr32 = pHdr32; 897 return 0; 898 } 899 900 589 901 590 902 -
trunk/src/win32k/include/elf.h
r2826 r2899 1 /* $Id: elf.h,v 1. 4 2000-02-18 20:52:35bird Exp $1 /* $Id: elf.h,v 1.5 2000-02-26 00:46:30 bird Exp $ 2 2 * 3 3 * ELF stuff. 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 242 242 * ELF Program Header 243 243 */ 244 typedef struct 245 { 246 Elf32_Word p_type; 247 Elf32_Off p_offset; 248 Elf32_Addr p_vaddr; 249 Elf32_Addr p_paddr; 250 Elf32_Word p_filesz; 251 Elf32_Word p_memsz; 252 Elf32_Word p_flags; 253 Elf32_Word p_align; 244 typedef struct /* 0x20 */ 245 { 246 Elf32_Word p_type; /* 0x00 Tells what this header describes or how to interpret it. */ 247 Elf32_Off p_offset; /* 0x04 Offset of the first byte of this segment. */ 248 Elf32_Addr p_vaddr; /* 0x08 Virtual address of the segment. */ 249 Elf32_Addr p_paddr; /* 0x0c Physical address. Usually ignorable. */ 250 Elf32_Word p_filesz; /* 0x10 Count of bytes in the file image of this segment. Zero allowed. */ 251 Elf32_Word p_memsz; /* 0x14 Count of bytes in the memory image of this segment. Zero allowed. */ 252 Elf32_Word p_flags; /* 0x18 Flags relevant to the segement. */ 253 Elf32_Word p_align; /* 0x1c Alignment. 0 and 1 means no alignment. */ 254 254 } Elf32_Phdr; 255 256 /* p_type - segment types */ 257 #define PT_NULL 0 /* Unused header. */ 258 #define PT_LOAD 1 /* Loadable segment. p_filesz, p_memsz and p_vaddr applies. */ 259 #define PT_DYNAMIC 2 /* Dynamic linking information. */ 260 #define PT_INTERP 3 /* Interpreter path. */ 261 #define PT_NOTE 4 /* Auxiliary information. */ 262 #define PT_SHLIB 5 /* Reserved. */ 263 #define PT_PHDR 6 /* This header specifies the location and size of the program header table in file and memory. */ 264 #define PT_LOPROC 0x70000000 /* Reserved processor-specific semantics range start. */ 265 #define PT_HIPROC 0x7fffffff /* Reserved processor-specific semantics range end (included). */ 266 267 /* p_flags - permission flags */ 268 #define PF_X 1 /* Executable */ 269 #define PF_W 2 /* Writeable */ 270 #define PF_R 4 /* Readable */ 271 272 273 /* 274 * Dynamic Structure 275 */ 276 typedef struct /* 0x08 */ 277 { 278 Elf32_Sword d_tag; /* 0x00 Tag type. */ 279 union 280 { 281 Elf32_Word d_val; /* 0x04 Value, interpreted according to the tag type. */ 282 Elf32_Addr d_ptr; /* 0x04 Virtual address, interpreted according to the tag type. */ 283 } d_un; 284 } Elf32_Dyn; 285 286 /* d_tag - tag types */ /* d_un exe so: '-' is ignored; '+' is mandatory; '*' is optional. */ 287 #define DT_NULL 0 /* - - - Marks the end of the dynamic array. */ 288 #define DT_NEEDED 1 /* d_val * * This element holds the string table offset of a 289 null-terminated string, giving the name of a needed 290 library. The offset is an index into the table 291 recoreded in the DT_STRTAB entry. */ 292 #define DT_PLTRELSZ 2 /* d_val * * This element holds the total size, in bytes, of the 293 relocation entries associated with the procedure 294 linkage table. If an entry of type DT_JMPREL is 295 present, a DT_PLTRELSZ must accompany it. */ 296 #define DT_PLTGOT 3 /* d_ptr * * */ 297 #define DT_HASH 4 /* d_ptr + + */ 298 #define DT_STRTAB 5 /* d_ptr + + This element holds the address of the string table. 299 Symbol names, library names, and other strings reside 300 in this table. */ 301 #define DT_SYMTAB 6 /* d_ptr + + */ 302 #define DT_RELA 7 /* d_ptr + * */ 303 #define DT_RELASZ 8 /* d_val + * */ 304 #define DT_RELAENT 9 /* d_val + * */ 305 #define DT_STRSZ 10 /* d_val + + */ 306 #define DT_SYMENT 11 /* d_val + + */ 307 #define DT_INIT 12 /* d_ptr * * This element holds the address of the initialization function. */ 308 #define DT_FINI 13 /* d_ptr * * This element holds the address of the termination function. */ 309 #define DT_SONAME 14 /* d_val - * This element holds the string table offset of a 310 null-terminated string, giving the name of the shared 311 object. The offset is an index into the table recorded 312 in the DT_STRTAB entry. */ 313 #define DT_RPATH 15 /* d_val + + This element holds the string table offset of a null-terminated 314 search library search path string. The offset is an index int 315 the table recorded in the DT_STRTAB entry. */ 316 #define DT_SYMBOLIC 16 /* - - * This element's presence in a shared object library alters the 317 dynamic linker's symbol resolution algorithm for references 318 within the library. Instead of starting a symbol search with 319 the executable file, the dynamic linker starts from the shared 320 object file itself. If the shared object fails to supply the 321 referenced symbol, the dynamic linker then searches the 322 executable file and other shared objects as usual. */ 323 #define DT_REL 17 /* d_ptr + * */ 324 #define DT_RELSZ 18 /* d_val + * */ 325 #define DT_RELENT 19 /* d_val + * */ 326 #define DT_PLTREL 20 /* d_val * * */ 327 #define DT_DEBUG 21 /* d_ptr * - */ 328 #define DT_TEXTREL 22 /* - * * */ 329 #define DT_JMPREL 23 /* d_ptr * * */ 330 #define DT_LOPROC 0x70000000 /* Reserved processor-specific semantics range start. */ 331 #define DT_HIPROC 0x7fffffff /* Reserved processor-specific semantics range end (included). */ 255 332 256 333 #pragma pack() -
trunk/src/win32k/include/elf2lx.h
r1678 r2899 1 /* $Id: elf2lx.h,v 1. 1 1999-11-10 01:45:32bird Exp $1 /* $Id: elf2lx.h,v 1.2 2000-02-26 00:46:31 bird Exp $ 2 2 * 3 3 * Elf2Lx - Declaration. 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT
Note:
See TracChangeset
for help on using the changeset viewer.