mirror of
https://github.com/revanced/multidexlib2.git
synced 2025-05-05 08:54:31 +02:00
Add WrappingMultiDexFile interface
This commit is contained in:
parent
8670ec63a8
commit
9362e6bd47
@ -18,7 +18,7 @@ import org.jf.dexlib2.iface.DexFile;
|
|||||||
import org.jf.dexlib2.iface.MultiDexContainer;
|
import org.jf.dexlib2.iface.MultiDexContainer;
|
||||||
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
||||||
|
|
||||||
public class BasicMultiDexFile<T extends MultiDexContainer<? extends MultiDexFile>> implements MultiDexFile {
|
public class BasicMultiDexFile<T extends MultiDexContainer<? extends MultiDexFile>> implements WrappingMultiDexFile {
|
||||||
|
|
||||||
private final T container;
|
private final T container;
|
||||||
private final String entryName;
|
private final String entryName;
|
||||||
@ -50,4 +50,9 @@ public class BasicMultiDexFile<T extends MultiDexContainer<? extends MultiDexFil
|
|||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DexFile getWrappedDexFile() {
|
||||||
|
return dexFile;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,18 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.jf.dexlib2.Opcodes;
|
import org.jf.dexlib2.Opcodes;
|
||||||
import org.jf.dexlib2.iface.DexFile;
|
import org.jf.dexlib2.iface.DexFile;
|
||||||
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
|
||||||
|
|
||||||
public class DirectoryDexContainer extends AbstractMultiDexContainer<MultiDexFile> {
|
public class DirectoryDexContainer extends AbstractMultiDexContainer<WrappingMultiDexFile> {
|
||||||
|
|
||||||
public DirectoryDexContainer(File directory, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
public DirectoryDexContainer(File directory, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
||||||
Map<String, MultiDexFile> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
Map<String, WrappingMultiDexFile> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
||||||
String[] names = directory.list();
|
String[] names = directory.list();
|
||||||
if (names == null) throw new IOException("Cannot access directory: " + directory);
|
if (names == null) throw new IOException("Cannot access directory: " + directory);
|
||||||
for (String entryName : names) {
|
for (String entryName : names) {
|
||||||
File file = new File(directory, entryName);
|
File file = new File(directory, entryName);
|
||||||
if (file.isFile() && namer.isValidName(entryName)) {
|
if (file.isFile() && namer.isValidName(entryName)) {
|
||||||
DexFile dexFile = RawDexIO.readRawDexFile(file, opcodes);
|
DexFile dexFile = RawDexIO.readRawDexFile(file, opcodes);
|
||||||
MultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
WrappingMultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
||||||
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.jf.dexlib2.Opcodes;
|
import org.jf.dexlib2.Opcodes;
|
||||||
import org.jf.dexlib2.iface.DexFile;
|
import org.jf.dexlib2.iface.DexFile;
|
||||||
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
|
||||||
|
|
||||||
public class SingletonDexContainer extends AbstractMultiDexContainer<MultiDexFile> {
|
public class SingletonDexContainer extends AbstractMultiDexContainer<WrappingMultiDexFile> {
|
||||||
|
|
||||||
// I insist that some dex container entries do not have names
|
// I insist that some dex container entries do not have names
|
||||||
// even though dexlib2 does not allow null entry names.
|
// even though dexlib2 does not allow null entry names.
|
||||||
@ -33,8 +32,8 @@ public class SingletonDexContainer extends AbstractMultiDexContainer<MultiDexFil
|
|||||||
|
|
||||||
public SingletonDexContainer(String entryName, DexFile dexFile) {
|
public SingletonDexContainer(String entryName, DexFile dexFile) {
|
||||||
Opcodes opcodes = dexFile.getOpcodes();
|
Opcodes opcodes = dexFile.getOpcodes();
|
||||||
MultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
WrappingMultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
||||||
Map<String, MultiDexFile> entryMap = Collections.singletonMap(entryName, multiDexFile);
|
Map<String, WrappingMultiDexFile> entryMap = Collections.singletonMap(entryName, multiDexFile);
|
||||||
initialize(entryMap, opcodes);
|
initialize(entryMap, opcodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/main/java/lanchon/multidexlib2/WrappingMultiDexFile.java
Normal file
20
src/main/java/lanchon/multidexlib2/WrappingMultiDexFile.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* DexPatcher - Copyright 2015-2017 Rodrigo Balerdi
|
||||||
|
* (GNU General Public License version 3 or later)
|
||||||
|
*
|
||||||
|
* DexPatcher is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lanchon.multidexlib2;
|
||||||
|
|
||||||
|
import org.jf.dexlib2.iface.DexFile;
|
||||||
|
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
||||||
|
|
||||||
|
public interface WrappingMultiDexFile extends MultiDexFile {
|
||||||
|
|
||||||
|
DexFile getWrappedDexFile();
|
||||||
|
|
||||||
|
}
|
@ -21,9 +21,8 @@ import java.util.zip.ZipFile;
|
|||||||
|
|
||||||
import org.jf.dexlib2.Opcodes;
|
import org.jf.dexlib2.Opcodes;
|
||||||
import org.jf.dexlib2.iface.DexFile;
|
import org.jf.dexlib2.iface.DexFile;
|
||||||
import org.jf.dexlib2.iface.MultiDexContainer.MultiDexFile;
|
|
||||||
|
|
||||||
public class ZipFileDexContainer extends AbstractMultiDexContainer<MultiDexFile> {
|
public class ZipFileDexContainer extends AbstractMultiDexContainer<WrappingMultiDexFile> {
|
||||||
|
|
||||||
public static boolean isZipFile(File zip) {
|
public static boolean isZipFile(File zip) {
|
||||||
if (!zip.isFile()) return false;
|
if (!zip.isFile()) return false;
|
||||||
@ -37,7 +36,7 @@ public class ZipFileDexContainer extends AbstractMultiDexContainer<MultiDexFile>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ZipFileDexContainer(File zip, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
public ZipFileDexContainer(File zip, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
||||||
Map<String, MultiDexFile> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
Map<String, WrappingMultiDexFile> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
||||||
ZipFile zipFile = new ZipFile(zip);
|
ZipFile zipFile = new ZipFile(zip);
|
||||||
try {
|
try {
|
||||||
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
|
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
|
||||||
@ -52,7 +51,7 @@ public class ZipFileDexContainer extends AbstractMultiDexContainer<MultiDexFile>
|
|||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
MultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
WrappingMultiDexFile multiDexFile = new BasicMultiDexFile<>(this, entryName, dexFile);
|
||||||
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user