View Javadoc

1   // RelocEntry.java, created Wed Mar  6 18:38:47 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Linker.ELF;
5   
6   import java.io.IOException;
7   
8   /***
9    *
10   * @author  John Whaley <jwhaley@alum.mit.edu>
11   * @version $Id: RelocEntry.java 1451 2004-03-09 06:27:08Z jwhaley $
12   */
13  public class RelocEntry implements ELFConstants {
14  
15      protected int offset;
16      protected SymbolTableEntry e;
17      protected byte type;
18      
19      public RelocEntry(int offset, SymbolTableEntry e, byte type) {
20          this.offset = offset; this.e = e; this.type = type;
21      }
22  
23      public final int getOffset() { return offset; }
24      public final int getSymbolTableIndex() { return e.getIndex(); }
25      public final int getType() { return type; }
26      public final int getInfo() { return (e.getIndex() << 8) | (type & 0xFF); }
27      
28      public void write(ELF file) throws IOException {
29          file.write_addr(getOffset());
30          file.write_word(getInfo());
31      }
32      
33      public static RelocEntry read(ELF file, Section.SymTabSection s) throws IOException {
34          int offset = file.read_addr();
35          int info = file.read_word();
36          int stindex = (info >>> 8);
37          byte type = (byte)info;
38          SymbolTableEntry e = s.getSymbolTableEntry(stindex);
39          return new RelocEntry(offset, e, type);
40      }
41      
42      public static int getEntrySize() { return 8; }
43  }