Examples of IntFromByteArray


Examples of org.jbls.util.IntFromByteArray

      }
    }
  }

  private byte[] prepareModule(byte[] original, int base_address) {
    IntFromByteArray ifba = IntFromByteArray.LITTLEENDIAN;
    int counter;

    int length = ifba.getInteger(original, 0);
    byte[] module = new byte[length];

    System.out.println("Allocated " + length + " (0x"
        + PadString.padHex(length, 4) + ") bytes for new module.\n");

    /* Copy 40 bytes from the original module to the new one. */
    System.arraycopy(original, 0, module, 0, 40);

    int source_location = 0x28 + (ifba.getInteger(module, 0x24) * 12);
    int destination_location = ifba.getInteger(original, 0x28);
    int limit = ifba.getInteger(original, 0);

    boolean skip = false;

    System.out.println("Copying code sections to module.");
    while (destination_location < limit) {
      int count = ((original[source_location] & 0x0FF) << 0)
          | ((original[source_location + 1] & 0x0FF) << 8);

      source_location += 2;

      if (!skip) {
        System.arraycopy(original, source_location, module,
            destination_location, count);
        source_location += count;
      }
      skip = !skip;
      destination_location += count;
    }

    System.out.println("Adjusting references to global variables...");
    source_location = ifba.getInteger(original, 8);
    destination_location = 0;

    counter = 0;
    while (counter < ifba.getInteger(module, 0x0c)) {
      if (module[source_location] < 0) {
        /* This code is never used, so I am not 100% sure that it works. */
        destination_location = ((module[source_location + 0] & 0x07F) << 24)
            | ((module[source_location + 1] & 0x0FF) << 16)
            | ((module[source_location + 2] & 0x0FF) << 8)
            | ((module[source_location + 3] & 0x0FF) << 0);
        source_location += 4;
      } else {
        destination_location = destination_location
            + (module[source_location + 1] & 0x0FF)
            + (module[source_location] << 8);
        source_location += 2;
      }
      // System.out.println("Offset 0x" +
      // PadString.padHex(destination_location, 4) +
      // " (was 0x" + PadString.padHex(ifba.getInteger(module,
      // destination_location), 8) + ")");
      ifba.insertInteger(module, destination_location, ifba.getInteger(
          module, destination_location)
          + base_address);
      counter++;
    }

    System.out.println("Updating API library references...");
    counter = 0;
    limit = ifba.getInteger(module, 0x20);
    String library;

    for (counter = 0; counter < limit; counter++) {
      int proc_start = ifba.getInteger(module, 0x1c) + (counter * 8);
      library = getNTString(module, ifba.getInteger(module, proc_start));
      int proc_offset = ifba.getInteger(module, proc_start + 4);

      while (ifba.getInteger(module, proc_offset) != 0) {
        int proc = ifba.getInteger(module, proc_offset);
        int addr = -1 /* Modules.ERROR */;

        if (proc > 0) {
          String strProc = getNTString(module, proc);
          addr = -1; /* Modules.get(library, strProc); */

          if (addr != -1 /* Modules.ERROR */)
            System.out.println("Module " + library + "!" + strProc
                + " found @ 0x" + PadString.padHex(addr, 8));
        } else {
          proc = proc & 0x7FFFFFFF;
          System.out.println("Proc: ord(0x"
              + PadString.padHex(proc, 8) + ")");
        }
        ifba.insertInteger(module, proc_offset, addr); /*
                                 * TODO: Fix
                                 * this.
                                 */
        /*
         * Note: real code increments [ebx+8] here, which is used for
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.