Commit 8eef4a90 authored by sergey-wowwow's avatar sergey-wowwow Committed by skylot

fix: saves all resources (#375)

parent 87f50ab5
...@@ -30,21 +30,4 @@ public enum ResourceType { ...@@ -30,21 +30,4 @@ public enum ResourceType {
} }
return UNKNOWN; 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 { ...@@ -105,6 +105,12 @@ public final class ResourcesLoader {
case IMG: case IMG:
return ResContainer.singleImageFile(rf.getName(), inputStream); return ResContainer.singleImageFile(rf.getName(), inputStream);
case CODE:
case LIB:
case FONT:
case UNKNOWN:
return ResContainer.singleBinaryFile(rf.getName(), inputStream);
default: default:
if (size > LOAD_SIZE_LIMIT) { if (size > LOAD_SIZE_LIMIT) {
return ResContainer.singleFile(rf.getName(), return ResContainer.singleFile(rf.getName(),
......
...@@ -5,11 +5,13 @@ import java.awt.image.BufferedImage; ...@@ -5,11 +5,13 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -30,6 +32,8 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -30,6 +32,8 @@ public class ResContainer implements Comparable<ResContainer> {
private CodeWriter content; private CodeWriter content;
@Nullable @Nullable
private BufferedImage image; private BufferedImage image;
@Nullable
private InputStream binary;
private ResContainer(String name, List<ResContainer> subFiles) { private ResContainer(String name, List<ResContainer> subFiles) {
this.name = name; this.name = name;
...@@ -63,6 +67,17 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -63,6 +67,17 @@ public class ResContainer implements Comparable<ResContainer> {
return 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) { public static ResContainer multiFile(String name) {
return new ResContainer(name, new ArrayList<>()); return new ResContainer(name, new ArrayList<>());
} }
...@@ -80,6 +95,11 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -80,6 +95,11 @@ public class ResContainer implements Comparable<ResContainer> {
return content; return content;
} }
@Nullable
public InputStream getBinary() {
return binary;
}
public void setContent(@Nullable CodeWriter content) { public void setContent(@Nullable CodeWriter content) {
this.content = content; this.content = content;
} }
......
...@@ -3,10 +3,14 @@ package jadx.core.xmlgen; ...@@ -3,10 +3,14 @@ package jadx.core.xmlgen;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
import org.apache.commons.io.FilenameUtils; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -30,9 +34,6 @@ public class ResourcesSaver implements Runnable { ...@@ -30,9 +34,6 @@ public class ResourcesSaver implements Runnable {
@Override @Override
public void run() { public void run() {
if (!ResourceType.isSupportedForUnpack(resourceFile.getType())) {
return;
}
ResContainer rc = resourceFile.loadContent(); ResContainer rc = resourceFile.loadContent();
if (rc != null) { if (rc != null) {
saveResources(rc); saveResources(rc);
...@@ -89,6 +90,20 @@ public class ResourcesSaver implements Runnable { ...@@ -89,6 +90,20 @@ public class ResourcesSaver implements Runnable {
cw.save(outFile); cw.save(outFile);
return; 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()); LOG.warn("Resource '{}' not saved, unknown type", rc.getName());
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment