提交 8eef4a90 编写于 作者: S sergey-wowwow 提交者: skylot

fix: saves all resources (#375)

上级 87f50ab5
......@@ -30,21 +30,4 @@ public enum ResourceType {
}
return UNKNOWN;
}
public static boolean isSupportedForUnpack(ResourceType type) {
switch (type) {
case CODE:
case LIB:
case FONT:
case UNKNOWN:
return false;
case MANIFEST:
case XML:
case ARSC:
case IMG:
return true;
}
return false;
}
}
......@@ -105,6 +105,12 @@ public final class ResourcesLoader {
case IMG:
return ResContainer.singleImageFile(rf.getName(), inputStream);
case CODE:
case LIB:
case FONT:
case UNKNOWN:
return ResContainer.singleBinaryFile(rf.getName(), inputStream);
default:
if (size > LOAD_SIZE_LIMIT) {
return ResContainer.singleFile(rf.getName(),
......
......@@ -5,11 +5,13 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
......@@ -30,6 +32,8 @@ public class ResContainer implements Comparable<ResContainer> {
private CodeWriter content;
@Nullable
private BufferedImage image;
@Nullable
private InputStream binary;
private ResContainer(String name, List<ResContainer> subFiles) {
this.name = name;
......@@ -62,6 +66,17 @@ public class ResContainer implements Comparable<ResContainer> {
}
return resContainer;
}
public static ResContainer singleBinaryFile(String name, InputStream content) {
ResContainer resContainer = new ResContainer(name, Collections.emptyList());
try {
resContainer.binary = new ByteArrayInputStream(IOUtils.toByteArray(content));
}
catch(IOException e) {
LOG.warn("Contents of the binary resource '{}' not saved, got exception {}", name, e);
}
return resContainer;
}
public static ResContainer multiFile(String name) {
return new ResContainer(name, new ArrayList<>());
......@@ -79,6 +94,11 @@ public class ResContainer implements Comparable<ResContainer> {
public CodeWriter getContent() {
return content;
}
@Nullable
public InputStream getBinary() {
return binary;
}
public void setContent(@Nullable CodeWriter content) {
this.content = content;
......
......@@ -3,10 +3,14 @@ package jadx.core.xmlgen;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.mockito.internal.util.io.IOUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -30,9 +34,6 @@ public class ResourcesSaver implements Runnable {
@Override
public void run() {
if (!ResourceType.isSupportedForUnpack(resourceFile.getType())) {
return;
}
ResContainer rc = resourceFile.loadContent();
if (rc != null) {
saveResources(rc);
......@@ -89,6 +90,20 @@ public class ResourcesSaver implements Runnable {
cw.save(outFile);
return;
}
InputStream binary = rc.getBinary();
if(binary != null) {
try {
outFile.getParentFile().mkdirs();
FileOutputStream binaryFileStream = new FileOutputStream(outFile);
IOUtils.copy(binary, binaryFileStream);
binaryFileStream.close();
binary.close();
}
catch(IOException e) {
LOG.warn("Resource '{}' not saved, got exception {}", rc.getName(), e);
}
return;
}
LOG.warn("Resource '{}' not saved, unknown type", rc.getName());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册