gpt4 book ai didi

com.googlecode.d2j.util.zip.ZipFile类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 16:53:31 30 4
gpt4 key购买 nike

本文整理了Java中com.googlecode.d2j.util.zip.ZipFile类的一些代码示例,展示了ZipFile类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile类的具体详情如下:
包路径:com.googlecode.d2j.util.zip.ZipFile
类名称:ZipFile

ZipFile介绍

[英]This is code is get from Android 4.4.2 intent to read as more zip as possible Ignore GPBF_ENCRYPTED_FLAG Allow duplicate ZipEntry Allow Nul byte in ZipEntry name
[中]这是来自Android 4.4.2的代码,旨在尽可能多地读取zip忽略GPBF_加密_标志允许重复ZipEntry允许ZipEntry名称中的Nul字节

代码示例

代码示例来源:origin: pxb1988/dex2jar

public static BaseDexFileReader open(byte[] data) throws IOException {
  if (data.length < 3) {
    throw new IOException("File too small to be a dex/zip");
  }
  if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
    return new DexFileReader(data);
  } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
    TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();
    try (ZipFile zipFile = new ZipFile(data)) {
      for (ZipEntry e : zipFile.entries()) {
        String entryName = e.getName();
        if (entryName.startsWith("classes") && entryName.endsWith(".dex")) {
          if (!dexFileReaders.containsKey(entryName)) { // only the first one
            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));
          }
        }
      }
    }
    if (dexFileReaders.size() == 0) {
      throw new IOException("Can not find classes.dex in zip file");
    } else if (dexFileReaders.size() == 1) {
      return dexFileReaders.firstEntry().getValue();
    } else {
      return new MultiDexFileReader(dexFileReaders.values());
    }
  }
  throw new IOException("the src file not a .dex or zip file");
}

代码示例来源:origin: pxb1988/dex2jar

/**
   * read the dex file from byte array, if the byte array is a zip stream, it will return the content of classes.dex
   * in the zip stream.
   * 
   * @param data
   * @return the content of classes.dex
   * @throws IOException
   */
  public static byte[] readDex(byte[] data) throws IOException {
    if (data.length < 3) {
      throw new IOException("File too small to be a dex/zip");
    }
    if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
      return data;
    } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
      try (ZipFile zipFile = new ZipFile(data)) {
        ZipEntry classes = zipFile.findFirstEntry("classes.dex");
        if (classes != null) {
          return toByteArray(zipFile.getInputStream(classes));
        } else {
          throw new IOException("Can not find classes.dex in zip file");
        }
      }
    }
    throw new IOException("the src file not a .dex or zip file");
  }
}

代码示例来源:origin: pxb1988/dex2jar

public ZipEntry findFirstEntry(String entryName) {
  if (entryName == null) {
    throw new NullPointerException("entryName == null");
  }
  ZipEntry ze = findFirstEntry0(entryName);
  if (ze == null) {
    ze = findFirstEntry0(entryName + "/");
  }
  return ze;
}

代码示例来源:origin: pxb1988/dex2jar

ZipEntry(ByteBuffer it0, boolean skipCommentsAndExtra) throws IOException {
  ByteBuffer it = (ByteBuffer) it0.slice().order(ByteOrder.LITTLE_ENDIAN).limit(CENHDR);
  ZipFile.skip(it0, CENHDR);
  int sig = it.getInt();
  if (sig != CENSIG) {
    ZipFile.throwZipException("Central Directory Entry", sig);
      ZipFile.skip(it0, extraLength);
    } else {
      extra = new byte[extraLength];
      ZipFile.skip(it0, commentByteCount);
    } else {
      byte[] commentBytes = new byte[commentByteCount];

代码示例来源:origin: pxb1988/dex2jar

public ZipFile(ByteBuffer in) throws IOException {
  raf = in.asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN);
  readCentralDir();
}

代码示例来源:origin: pxb1988/dex2jar

/**
 * Returns an input stream on the data of the specified {@code android.ZipEntry}.
 * 
 * @param entry
 *            the android.ZipEntry.
 * @return an input stream of the data contained in the {@code android.ZipEntry}.
 * @throws java.io.IOException
 *             if an {@code IOException} occurs.
 * @throws IllegalStateException
 *             if this zip file has been closed.
 */
public InputStream getInputStream(ZipEntry entry) throws IOException {
  long entryDataStart = getEntryDataStart(entry);
  ByteBuffer is = (ByteBuffer) raf.duplicate().position((int) entryDataStart);
  if (entry.compressionMethod == ZipEntry.STORED) {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.size);
    return new ByteBufferBackedInputStream(buf);
  } else {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN)
        .limit((int) entry.compressedSize);
    int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
    return new ZipInflaterInputStream(new ByteBufferBackedInputStream(buf), new Inflater(true), bufSize, entry);
  }
}

代码示例来源:origin: pxb1988/dex2jar

int numEntries = raf.getShort() & 0xffff;
int totalNumEntries = raf.getShort() & 0xffff;
skip(raf, 4); // Ignore centralDirSize.
long centralDirOffset = ((long) raf.getInt()) & 0xffffffffL;
int commentLength = raf.getShort() & 0xffff;
  } else {
    if (skipCommentsAndExtra) {
      skip(raf, commentLength);
    } else {
      byte[] commentBytes = new byte[commentLength];

代码示例来源:origin: SparkInLee/dexdiff

ZipEntry(ByteBuffer it0, boolean skipCommentsAndExtra) throws IOException {
  ByteBuffer it = (ByteBuffer) it0.slice().order(ByteOrder.LITTLE_ENDIAN).limit(CENHDR);
  ZipFile.skip(it0, CENHDR);
  int sig = it.getInt();
  if (sig != CENSIG) {
    ZipFile.throwZipException("Central Directory Entry", sig);
      ZipFile.skip(it0, extraLength);
    } else {
      extra = new byte[extraLength];
      ZipFile.skip(it0, commentByteCount);
    } else {
      byte[] commentBytes = new byte[commentByteCount];

代码示例来源:origin: pxb1988/dex2jar

public ZipFile(File fd) throws IOException {
  RandomAccessFile randomAccessFile = new RandomAccessFile(fd, "r");
  file = randomAccessFile;
  raf = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, fd.length());
  readCentralDir();
}

代码示例来源:origin: SparkInLee/dexdiff

/**
 * Returns an input stream on the data of the specified {@code android.ZipEntry}.
 * 
 * @param entry
 *            the android.ZipEntry.
 * @return an input stream of the data contained in the {@code android.ZipEntry}.
 * @throws java.io.IOException
 *             if an {@code IOException} occurs.
 * @throws IllegalStateException
 *             if this zip file has been closed.
 */
public InputStream getInputStream(ZipEntry entry) throws IOException {
  long entryDataStart = getEntryDataStart(entry);
  ByteBuffer is = (ByteBuffer) raf.duplicate().position((int) entryDataStart);
  if (entry.compressionMethod == ZipEntry.STORED) {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN).limit((int) entry.size);
    return new ByteBufferBackedInputStream(buf);
  } else {
    final ByteBuffer buf = (ByteBuffer) is.slice().order(ByteOrder.LITTLE_ENDIAN)
        .limit((int) entry.compressedSize);
    int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
    return new ZipInflaterInputStream(new ByteBufferBackedInputStream(buf), new Inflater(true), bufSize, entry);
  }
}

代码示例来源:origin: SparkInLee/dexdiff

int numEntries = raf.getShort() & 0xffff;
int totalNumEntries = raf.getShort() & 0xffff;
skip(raf, 4); // Ignore centralDirSize.
long centralDirOffset = ((long) raf.getInt()) & 0xffffffffL;
int commentLength = raf.getShort() & 0xffff;
    skip(raf, commentLength);
  } else {
    byte[] commentBytes = new byte[commentLength];

代码示例来源:origin: pxb1988/dex2jar

try (ZipOutputStream zos = new AutoSTOREDZipOutputStream(Files.newOutputStream(output))) {
  byte[] data = Files.readAllBytes(new File(remainingArgs[0]).toPath());
  try(com.googlecode.d2j.util.zip.ZipFile zipFile = new com.googlecode.d2j.util.zip.ZipFile(data)) {
    for (com.googlecode.d2j.util.zip.ZipEntry e : zipFile.entries()) {
      ZipEntry nEntry = new ZipEntry(e.getName());
        try (InputStream is = zipFile.getInputStream(e)) {
          while (true) {
            int c = is.read(buffer);

代码示例来源:origin: SparkInLee/dexdiff

/**
   * read the dex file from byte array, if the byte array is a zip stream, it will return the content of classes.dex
   * in the zip stream.
   * 
   * @param data
   * @return the content of classes.dex
   * @throws IOException
   */
  public static byte[] readDex(byte[] data) throws IOException {
    if (data.length < 3) {
      throw new IOException("File too small to be a dex/zip");
    }
    if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
      return data;
    } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
      try (ZipFile zipFile = new ZipFile(data)) {
        ZipEntry classes = zipFile.findFirstEntry("classes.dex");
        if (classes != null) {
          return toByteArray(zipFile.getInputStream(classes));
        } else {
          throw new IOException("Can not find classes.dex in zip file");
        }
      }
    }
    throw new IOException("the src file not a .dex or zip file");
  }
}

代码示例来源:origin: SparkInLee/dexdiff

public ZipFile(ByteBuffer in) throws IOException {
  raf = in.asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN);
  readCentralDir();
}

代码示例来源:origin: SparkInLee/dexdiff

public ZipEntry findFirstEntry(String entryName) {
  if (entryName == null) {
    throw new NullPointerException("entryName == null");
  }
  ZipEntry ze = findFirstEntry0(entryName);
  if (ze == null) {
    ze = findFirstEntry0(entryName + "/");
  }
  return ze;
}

代码示例来源:origin: pxb1988/dex2jar

@Test
public void test0() throws IOException {
  byte[] data = ZipUtil.toByteArray(BadZipEntryFlagTest.class.getResourceAsStream("/bad.zip"));
  try (ZipFile zip = new ZipFile(data)) {
    for (com.googlecode.d2j.util.zip.ZipEntry e : zip.entries()) {
      System.out.println(e);
      if (!e.isDirectory()) {
        zip.getInputStream(e).read();
      }
    }
  }
}

代码示例来源:origin: SparkInLee/dexdiff

public ZipFile(File fd) throws IOException {
  RandomAccessFile randomAccessFile = new RandomAccessFile(fd, "r");
  file = randomAccessFile;
  raf = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, fd.length());
  readCentralDir();
}

代码示例来源:origin: SparkInLee/dexdiff

public static BaseDexFileReader open(byte[] data) throws IOException {
  if (data.length < 3) {
    throw new IOException("File too small to be a dex/zip");
  }
  if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
    return new DexFileReader(data);
  } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
    TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();
    try (ZipFile zipFile = new ZipFile(data)) {
      for (ZipEntry e : zipFile.entries()) {
        String entryName = e.getName();
        if (entryName.startsWith("classes") && entryName.endsWith(".dex")) {
          if (!dexFileReaders.containsKey(entryName)) { // only the first one
            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));
          }
        }
      }
    }
    if (dexFileReaders.size() == 0) {
      throw new IOException("Can not find classes.dex in zip file");
    } else if (dexFileReaders.size() == 1) {
      return dexFileReaders.firstEntry().getValue();
    } else {
      return new MultiDexFileReader(dexFileReaders.values());
    }
  }
  throw new IOException("the src file not a .dex or zip file");
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com