src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File hotspot Sdiff src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.tools.jaotc.binformat.pecoff;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.pecoff.PECoff;
  30 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;
  31 import jdk.tools.jaotc.binformat.pecoff.PECoffTargetInfo;
  32 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
  33 
  34 public class PECoffHeader {
  35     ByteBuffer header;
  36 
  37     public PECoffHeader() {
  38         header = PECoffByteBuffer.allocate(IMAGE_FILE_HEADER.totalsize);
  39 
  40         header.putChar(IMAGE_FILE_HEADER.Machine.off, IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64);
  41         header.putInt(IMAGE_FILE_HEADER.TimeDateStamp.off, (int)(System.currentTimeMillis()/1000));
  42         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, 0);
  43         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, 0);
  44         header.putChar(IMAGE_FILE_HEADER.SizeOfOptionalHeader.off, (char)0);
  45         header.putChar(IMAGE_FILE_HEADER.Characteristics.off, (char)0);
  46 
  47     }
  48 
  49     // Update header with the number of total sections
  50     public void setSectionCount(int count) {
  51         header.putChar(IMAGE_FILE_HEADER.NumberOfSections.off, (char)count);
  52     }
  53 
  54     // Update header with the number of total symbols
  55     public void setSymbolCount(int count) {
  56         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, count);
  57     }
  58 
  59     // Update header with the offset of symbol table
  60     public void setSymbolOff(int offset) {
  61         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, offset);
  62     }
  63 
  64     public byte[] getArray() {
  65         return header.array();
  66     }
  67 }
  68 


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.tools.jaotc.binformat.pecoff;
  25 
  26 import java.nio.ByteBuffer;

  27 

  28 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_FILE_HEADER;

  29 import jdk.tools.jaotc.binformat.pecoff.PECoffByteBuffer;
  30 
  31 final class PECoffHeader {
  32     private final ByteBuffer header;
  33 
  34     PECoffHeader() {
  35         header = PECoffByteBuffer.allocate(IMAGE_FILE_HEADER.totalsize);
  36 
  37         header.putChar(IMAGE_FILE_HEADER.Machine.off, IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64);
  38         header.putInt(IMAGE_FILE_HEADER.TimeDateStamp.off, (int) (System.currentTimeMillis() / 1000));
  39         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, 0);
  40         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, 0);
  41         header.putChar(IMAGE_FILE_HEADER.SizeOfOptionalHeader.off, (char) 0);
  42         header.putChar(IMAGE_FILE_HEADER.Characteristics.off, (char) 0);
  43 
  44     }
  45 
  46     // Update header with the number of total sections
  47     void setSectionCount(int count) {
  48         header.putChar(IMAGE_FILE_HEADER.NumberOfSections.off, (char) count);
  49     }
  50 
  51     // Update header with the number of total symbols
  52     void setSymbolCount(int count) {
  53         header.putInt(IMAGE_FILE_HEADER.NumberOfSymbols.off, count);
  54     }
  55 
  56     // Update header with the offset of symbol table
  57     void setSymbolOff(int offset) {
  58         header.putInt(IMAGE_FILE_HEADER.PointerToSymbolTable.off, offset);
  59     }
  60 
  61     byte[] getArray() {
  62         return header.array();
  63     }
  64 }

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoffHeader.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File