/**
   * Writes the Item's creation date to the Items Random Access File
   *
   * @param file - the Item's Random Access File
   */
  private void writeCreationDate(RandomAccessFile file) {
    try {
      file.writeShort(getCreationDate().get(Calendar.YEAR));
      file.writeByte(getCreationDate().get(Calendar.MONTH));
      file.writeByte(getCreationDate().get(Calendar.DAY_OF_MONTH));
    } catch (Exception e) {

    }
  }
  /**
   * Writes the Item location to the Items Random Access File
   *
   * @param file - the Item's Random Access File
   */
  private void writeLocationToFile(RandomAccessFile file) {
    try {
      file.writeByte(1); // Write the warehouse number
      file.writeByte(getLocation().getAisle()); // Write the aisle number
      file.writeByte(getLocation().getColumn()); // Write the column number
      file.writeChar(getLocation().getRow()); // Write the row number
    } catch (Exception e) {

    }
  }
示例#3
0
 public void saveMetaData() throws IOException {
   pageFile.seek(offset);
   pageFile.writeInt(nextPageId);
   pageFile.writeInt(currentFill);
   pageFile.writeInt(bloomfilter);
   pageFile.writeByte(type);
 }
 /* write a chunk data to the region file at specified sector number */
 private void write(int sectorNumber, byte[] data, int length) throws IOException {
   debugln(" " + sectorNumber);
   file.seek(sectorNumber * SECTOR_BYTES);
   file.writeInt(length + 1); // chunk length
   file.writeByte(VERSION_DEFLATE); // chunk version number
   file.write(data, 0, length); // chunk data
 }
示例#5
0
 // see DbFile.java for javadocs
 public void writePage(Page page) throws IOException {
   // some code goes here
   long offset = page.getId().pageNumber() * BufferPool.PAGE_SIZE;
   byte[] data = page.getPageData();
   try {
     raf.seek(offset);
     for (int i = 0; i < data.length; i++) {
       raf.writeByte(data[i]);
     }
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
 }
  /** write the first 32 bytes to file */
  public void write(RandomAccessFile ff) throws tinySQLException {
    try {
      // -----------------------------
      // write out the primary header
      ff.seek(FLAG_INDEX);
      ff.writeByte((byte) 0x03);

      setTimestamp(ff); // set current date YY MM DD (dBase is not Y2K save)

      setNumRecords(ff, 0);

      setHeaderLength(ff, numFields);

      setRecordLength(ff, recordLength);

      setReserved(ff);

    } catch (Exception e) {
      throw new tinySQLException(e.getMessage());
    }
  }
示例#7
0
文件: asm.java 项目: naxIO/nabaztag
  private static void writeFile(String sFile, byte[] bytes) {
    byte[] emptybuf = null;

    try {
      RandomAccessFile file = new RandomAccessFile(new File(sFile), "rw");

      file.seek(file.length()); // append

      int i = 0;

      for (i = 0; i < bytes.length; i++) {
        file.writeByte(bytes[i]);
      }

      log("Wrote " + i + " bytes to " + sFile);
      file.close();
      return;
    } catch (IOException es) {
      log("File not found.");
    }

    return;
  }
示例#8
0
  public static void main(String[] argv) {

    String victim = "Beginner"; // What's the name of the target?
    int fpointer = 0; // Where are we in the target class file?

    // How on earth do I use this thing?
    if (argv.length != 0) {
      System.out.println("Try \"java Attacker" + "\".");
      System.exit(1);
    }

    // If the target isn't writeable, then forget the whole deal.
    File testit = new File(victim + ".class");
    if (!(testit.canWrite())) {
      System.out.println(victim + ".class must be writeable.  Fix it!");
      System.exit(2);
    }
    try {
      RandomAccessFile target = new RandomAccessFile(victim + ".class", "rw");

      /* Adjust the proper attribute_length and code_length in order to maintain
      the hacked class file's verifiability. */

      // Increase the attacked method's attribute_lenth by 3.
      fpointer = 455;
      target.seek(fpointer);
      int changed_byte = (int) target.readUnsignedByte() + 3;
      target.seek(fpointer);
      target.writeByte(changed_byte);

      // Increase the attacked method's code_length by 3.
      fpointer = 463;
      target.seek(fpointer);
      changed_byte = (int) target.readUnsignedByte() + 3;
      target.seek(fpointer);
      target.writeByte(changed_byte);

      /* Insert the 3 bytes of code to make Beginner.class deviant */

      // Get to where we want to insert code.
      fpointer = 506;
      target.seek(fpointer);

      // Save the remainder of the target class file.
      int diff = (int) target.length() - fpointer;
      byte[] tail = new byte[diff];
      target.read(tail, 0, diff);

      // Insert the 3 bytes.
      target.seek(fpointer);
      target.writeByte(167);
      target.writeByte(255);
      target.writeByte(214);

      // Restore the tail.
      target.write(tail);

      // All the changes are made, so close the file and get out of here
      target.close();
    } catch (IOException ioe) {
    }
  }
示例#9
0
  public static void main(String args[]) throws Exception {

    int index;

    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    DatagramSocket clientSocket = new DatagramSocket();

    byte[] sendData = new byte[1024];
    byte[] receiveData = new byte[1024];

    // Pull the target host from the command line.
    InetAddress ipAddress = null;
    if (args.length > 0) {
      ipAddress = InetAddress.getByName(args[0]);
    } else {
      System.err.println("FATAL: You must specify a hast to connect to.");
      System.exit(1);
    }

    // Get the request string from input and send it off.
    String request = inFromUser.readLine();
    sendData = request.getBytes();
    DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, PORT);
    clientSocket.send(sendPacket);

    // Get the header packet.
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.receive(receivePacket);
    receiveData = receivePacket.getData();

    String[] words = new String[8];
    words = (new String(receiveData)).split("\\s+");

    int numBytes = Integer.parseInt(words[1]);

    boolean[] packets = new boolean[numBytes];

    File download_file = new File("downloaded_file");
    download_file.createNewFile();

    RandomAccessFile download = new RandomAccessFile(download_file, "rw");
    download.setLength(numBytes);

    clientSocket.setSoTimeout(1000);

    // Get the server's response.
    do {
      try {
        while (true) {
          receivePacket = new DatagramPacket(receiveData, receiveData.length);
          clientSocket.receive(receivePacket);
          receiveData = receivePacket.getData();

          // Convert the first two bytes back into the integer index of this packet.
          index = 256 * (receiveData[0] & 0xff) + (receiveData[1] & 0xff);
          packets[index] = true;
          download.seek(index * 1022);

          for (int i = 0; i < 1021; ++i) {
            download.writeByte(receiveData[i + 2]);
          }
        }
      } catch (Exception e) {
      }
    } while (moreToDo(packets));
  }