org.jf.dexlib2.dexbacked.raw.OdexHeaderItem Java Examples

The following examples show how to use org.jf.dexlib2.dexbacked.raw.OdexHeaderItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes,
		@Nonnull InputStream is) throws IOException {
	if (!is.markSupported()) {
		throw new IllegalArgumentException("InputStream must support mark");
	}
	is.mark(8);
	byte[] partialHeader = new byte[8];
	try {
		ByteStreams.readFully(is, partialHeader);
	} catch (EOFException ex) {
		throw new NotADexFile("File is too short");
	} finally {
		is.reset();
	}

	verifyMagic(partialHeader);

	is.reset();
	byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE];
	ByteStreams.readFully(is, odexBuf);
	int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
	if (dexOffset > OdexHeaderItem.ITEM_SIZE) {
		ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE);
	}

	byte[] dexBuf = ByteStreams.toByteArray(is);

	return new DexBackedOdexFile(opcodes, odexBuf, dexBuf);
}
 
Example #2
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private static void verifyMagic(byte[] buf) {
	if (!OdexHeaderItem.verifyMagic(buf)) {
		StringBuilder sb = new StringBuilder("Invalid magic value:");
		for (int i = 0; i < 8; i++) {
			sb.append(String.format(" %02x", buf[i]));
		}
		throw new NotAnOdexFile(sb.toString());
	}
}
 
Example #3
Source File: DexBackedOdexFile.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes,
		@Nonnull InputStream is) throws IOException {
	if (!is.markSupported()) {
		throw new IllegalArgumentException("InputStream must support mark");
	}
	is.mark(8);
	byte[] partialHeader = new byte[8];
	try {
		ByteStreams.readFully(is, partialHeader);
	} catch (EOFException ex) {
		throw new NotADexFile("File is too short");
	} finally {
		is.reset();
	}

	verifyMagic(partialHeader);

	is.reset();
	byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE];
	ByteStreams.readFully(is, odexBuf);
	int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
	if (dexOffset > OdexHeaderItem.ITEM_SIZE) {
		ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE);
	}

	byte[] dexBuf = ByteStreams.toByteArray(is);

	return new DexBackedOdexFile(opcodes, odexBuf, dexBuf);
}
 
Example #4
Source File: DexBackedOdexFile.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
private static void verifyMagic(byte[] buf) {
	if (!OdexHeaderItem.verifyMagic(buf)) {
		StringBuilder sb = new StringBuilder("Invalid magic value:");
		for (int i = 0; i < 8; i++) {
			sb.append(String.format(" %02x", buf[i]));
		}
		throw new NotAnOdexFile(sb.toString());
	}
}
 
Example #5
Source File: DexBackedOdexFile.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes,
		@Nonnull InputStream is) throws IOException {
	if (!is.markSupported()) {
		throw new IllegalArgumentException("InputStream must support mark");
	}
	is.mark(8);
	byte[] partialHeader = new byte[8];
	try {
		ByteStreams.readFully(is, partialHeader);
	} catch (EOFException ex) {
		throw new NotADexFile("File is too short");
	} finally {
		is.reset();
	}

	verifyMagic(partialHeader);

	is.reset();
	byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE];
	ByteStreams.readFully(is, odexBuf);
	int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
	if (dexOffset > OdexHeaderItem.ITEM_SIZE) {
		ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE);
	}

	byte[] dexBuf = ByteStreams.toByteArray(is);

	return new DexBackedOdexFile(opcodes, odexBuf, dexBuf);
}
 
Example #6
Source File: DexBackedOdexFile.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
private static void verifyMagic(byte[] buf) {
	if (!OdexHeaderItem.verifyMagic(buf)) {
		StringBuilder sb = new StringBuilder("Invalid magic value:");
		for (int i = 0; i < 8; i++) {
			sb.append(String.format(" %02x", buf[i]));
		}
		throw new NotAnOdexFile(sb.toString());
	}
}
 
Example #7
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes,
		@Nonnull InputStream is) throws IOException {
	if (!is.markSupported()) {
		throw new IllegalArgumentException("InputStream must support mark");
	}
	is.mark(8);
	byte[] partialHeader = new byte[8];
	try {
		ByteStreams.readFully(is, partialHeader);
	} catch (EOFException ex) {
		throw new NotADexFile("File is too short");
	} finally {
		is.reset();
	}

	verifyMagic(partialHeader);

	is.reset();
	byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE];
	ByteStreams.readFully(is, odexBuf);
	int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
	if (dexOffset > OdexHeaderItem.ITEM_SIZE) {
		ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE);
	}

	byte[] dexBuf = ByteStreams.toByteArray(is);

	return new DexBackedOdexFile(opcodes, odexBuf, dexBuf);
}
 
Example #8
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private static void verifyMagic(byte[] buf) {
	if (!OdexHeaderItem.verifyMagic(buf)) {
		StringBuilder sb = new StringBuilder("Invalid magic value:");
		for (int i = 0; i < 8; i++) {
			sb.append(String.format(" %02x", buf[i]));
		}
		throw new NotAnOdexFile(sb.toString());
	}
}
 
Example #9
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public List<String> getDependencies() {
	if (this.getReader() == null) {
		final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
		final int dependencyOffset = OdexHeaderItem
				.getDependenciesOffset(odexBuf) - dexOffset;

		BaseDexBuffer buf = new BaseDexBuffer(this.buf);
		int dependencyCount = buf.readInt(dependencyOffset
				+ DEPENDENCY_COUNT_OFFSET);

		return new VariableSizeList<String>(this, dependencyOffset
				+ DEPENDENCY_START_OFFSET, dependencyCount) {
			@Override
			protected String readNextItem(@Nonnull DexReader reader,
					int index) {
				int length = reader.readInt();
				int offset = reader.getOffset();
				reader.moveRelative(length + 20);
				try {
					return new String(DexBackedOdexFile.this.buf, offset,
							length - 1, "US-ASCII");
				} catch (UnsupportedEncodingException ex) {
					throw new RuntimeException(ex);
				}
			}
		};
	} else {
		File file = new File("/system/framework/");
		File[] filelist = file.listFiles(new FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				// TODO Auto-generated method stub
				if(pathname.getAbsolutePath().endsWith(".jar"))
				   return true;
				else 
				   return false;
			}
		});
		List<String> list = new ArrayList<String>(filelist.length);
		for(int i = 0; i<filelist.length; i++){
			list.add(filelist[i].getAbsolutePath());
		}
		return list;
		
	}
}
 
Example #10
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public int getOdexVersion() {
	return OdexHeaderItem.getVersion(odexBuf);
}
 
Example #11
Source File: DexBackedOdexFile.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public List<String> getDependencies() {
	if (this.getReader() == null) {
		final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
		final int dependencyOffset = OdexHeaderItem
				.getDependenciesOffset(odexBuf) - dexOffset;

		BaseDexBuffer buf = new BaseDexBuffer(this.buf);
		int dependencyCount = buf.readInt(dependencyOffset
				+ DEPENDENCY_COUNT_OFFSET);

		return new VariableSizeList<String>(this, dependencyOffset
				+ DEPENDENCY_START_OFFSET, dependencyCount) {
			@Override
			protected String readNextItem(@Nonnull DexReader reader,
					int index) {
				int length = reader.readInt();
				int offset = reader.getOffset();
				reader.moveRelative(length + 20);
				try {
					return new String(DexBackedOdexFile.this.buf, offset,
							length - 1, "US-ASCII");
				} catch (UnsupportedEncodingException ex) {
					throw new RuntimeException(ex);
				}
			}
		};
	} else {
		File file = new File("/system/framework/");
		File[] filelist = file.listFiles(new FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				// TODO Auto-generated method stub
				if(pathname.getAbsolutePath().endsWith(".jar"))
				   return true;
				else 
				   return false;
			}
		});
		List<String> list = new ArrayList<String>(filelist.length);
		for(int i = 0; i<filelist.length; i++){
			list.add(filelist[i].getAbsolutePath());
		}
		return list;
		
	}
}
 
Example #12
Source File: DexBackedOdexFile.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public int getOdexVersion() {
	return OdexHeaderItem.getVersion(odexBuf);
}
 
Example #13
Source File: DexBackedOdexFile.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public List<String> getDependencies() {
	if (this.getReader() == null) {
		final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
		final int dependencyOffset = OdexHeaderItem
				.getDependenciesOffset(odexBuf) - dexOffset;

		BaseDexBuffer buf = new BaseDexBuffer(this.buf);
		int dependencyCount = buf.readInt(dependencyOffset
				+ DEPENDENCY_COUNT_OFFSET);

		return new VariableSizeList<String>(this, dependencyOffset
				+ DEPENDENCY_START_OFFSET, dependencyCount) {
			@Override
			protected String readNextItem(@Nonnull DexReader reader,
					int index) {
				int length = reader.readInt();
				int offset = reader.getOffset();
				reader.moveRelative(length + 20);
				try {
					return new String(DexBackedOdexFile.this.buf, offset,
							length - 1, "US-ASCII");
				} catch (UnsupportedEncodingException ex) {
					throw new RuntimeException(ex);
				}
			}
		};
	} else {
		File file = new File("/system/framework/");
		File[] filelist = file.listFiles(new FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				// TODO Auto-generated method stub
				if(pathname.getAbsolutePath().endsWith(".jar"))
				   return true;
				else 
				   return false;
			}
		});
		List<String> list = new ArrayList<String>(filelist.length);
		for(int i = 0; i<filelist.length; i++){
			list.add(filelist[i].getAbsolutePath());
		}
		return list;
		
	}
}
 
Example #14
Source File: DexBackedOdexFile.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public int getOdexVersion() {
	return OdexHeaderItem.getVersion(odexBuf);
}
 
Example #15
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public List<String> getDependencies() {
	if (this.getReader() == null) {
		final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
		final int dependencyOffset = OdexHeaderItem
				.getDependenciesOffset(odexBuf) - dexOffset;

		BaseDexBuffer buf = new BaseDexBuffer(this.buf);
		int dependencyCount = buf.readInt(dependencyOffset
				+ DEPENDENCY_COUNT_OFFSET);

		return new VariableSizeList<String>(this, dependencyOffset
				+ DEPENDENCY_START_OFFSET, dependencyCount) {
			@Override
			protected String readNextItem(@Nonnull DexReader reader,
					int index) {
				int length = reader.readInt();
				int offset = reader.getOffset();
				reader.moveRelative(length + 20);
				try {
					return new String(DexBackedOdexFile.this.buf, offset,
							length - 1, "US-ASCII");
				} catch (UnsupportedEncodingException ex) {
					throw new RuntimeException(ex);
				}
			}
		};
	} else {
		File file = new File("/system/framework/");
		File[] filelist = file.listFiles(new FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				// TODO Auto-generated method stub
				if(pathname.getAbsolutePath().endsWith(".jar"))
				   return true;
				else 
				   return false;
			}
		});
		List<String> list = new ArrayList<String>(filelist.length);
		for(int i = 0; i<filelist.length; i++){
			list.add(filelist[i].getAbsolutePath());
		}
		return list;
		
	}
}
 
Example #16
Source File: DexBackedOdexFile.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public int getOdexVersion() {
	return OdexHeaderItem.getVersion(odexBuf);
}