001    // This file is part of the program FRYSK.
002    //
003    // Copyright 2005, Red Hat Inc.
004    //
005    // FRYSK is free software; you can redistribute it and/or modify it
006    // under the terms of the GNU General Public License as published by
007    // the Free Software Foundation; version 2 of the License.
008    //
009    // FRYSK is distributed in the hope that it will be useful, but
010    // WITHOUT ANY WARRANTY; without even the implied warranty of
011    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012    // General Public License for more details.
013    // 
014    // You should have received a copy of the GNU General Public License
015    // along with FRYSK; if not, write to the Free Software Foundation,
016    // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
017    // 
018    // In addition, as a special exception, Red Hat, Inc. gives You the
019    // additional right to link the code of FRYSK with code not covered
020    // under the GNU General Public License ("Non-GPL Code") and to
021    // distribute linked combinations including the two, subject to the
022    // limitations in this paragraph. Non-GPL Code permitted under this
023    // exception must only link to the code of FRYSK through those well
024    // defined interfaces identified in the file named EXCEPTION found in
025    // the source code files (the "Approved Interfaces"). The files of
026    // Non-GPL Code may instantiate templates or use macros or inline
027    // functions from the Approved Interfaces without causing the
028    // resulting work to be covered by the GNU General Public
029    // License. Only Red Hat, Inc. may make changes or additions to the
030    // list of Approved Interfaces. You must obey the GNU General Public
031    // License in all respects for all of the FRYSK code and other code
032    // used in conjunction with FRYSK except the Non-GPL Code covered by
033    // this exception. If you modify this file, you may extend this
034    // exception to your version of the file, but you are not obligated to
035    // do so. If you do not wish to provide this exception without
036    // modification, you must delete this exception statement from your
037    // version and license this file solely under the GPL without
038    // exception.
039    package lib.dwfl;
040    
041    /**
042     * An ElfSection is a descriptor o an Elf file section
043     */
044    public class ElfSection {
045    
046            private long pointer;
047            private Elf parent;
048            
049            public ElfSection(long ptr, Elf parent){
050                    this.pointer = ptr;
051                    this.parent = parent;
052            }
053            
054            public long getPointer(){
055                    return this.pointer;
056            }
057            
058            /**
059             * @return The index of this section.
060             */
061            public long getIndex(){
062                    return elf_ndxscn();
063            }
064            
065            /**
066             * 
067             * @return The header for this ElfSection
068             */
069            public ElfSectionHeader getSectionHeader(){
070                    return elf_getshdr();
071            }
072            
073            /**
074             * Flags the section with the provided flags
075             * @param command An {@see ElfCommand}
076             * @param flags The flag to use
077             * @return The new flag value
078             */
079            public ElfFlags flag(ElfCommand command, ElfFlags flags){
080                    return ElfFlags.intern(elf_flagscn(command.getValue(), flags.getValue()));
081            }
082            
083            /**
084             * Flags the section header with the provided flags
085             * @param command An {@see ElfCommand}
086             * @param flags The flags to use
087             * @return The new flag value
088             */
089            public ElfFlags flagHeader(ElfCommand command, ElfFlags flags){
090                    return ElfFlags.intern(elf_flagshdr(command.getValue(), flags.getValue()));
091            }
092            
093            /**
094             * 
095             *  @return The ElfData contained in this section
096             */
097            public ElfData getData(){
098                    long val = elf_getdata();
099                    if(val != 0)
100                            return new ElfData(elf_getdata(), parent);
101                    else return null;
102            }
103            
104            /**
105             * 
106             * @return The uninterpreted ElfData in this section
107             */
108            public ElfData getRawData(){
109                    return new ElfData(elf_rawdata(), parent);
110            }
111            
112            /**
113             * 
114             * @return Creates a new ElfData for this section
115             */
116            public ElfData createNewElfData(){
117                    return new ElfData(elf_newdata(), parent);
118            }
119            
120            protected Elf getParent(){
121                    return this.parent;
122            }
123    
124            
125            /**
126             * 
127             * Updates the class data back to the native elf
128             * data structures.
129             *
130             */
131            public int update(ElfSectionHeader header) {
132                    return elf_updateshdr (header);
133            }
134            
135            protected native int elf_updateshdr(ElfSectionHeader header);
136            protected native long elf_ndxscn();
137            protected native ElfSectionHeader elf_getshdr();
138            protected native int elf_flagscn(int __cmd, int __flags);
139            protected native int elf_flagshdr(int __cmd, int __flags);
140            protected native long elf_getdata();
141            protected native long elf_rawdata();
142            protected native long elf_newdata();
143    }