Skip to content

Commit

Permalink
fix(gui): show correct content of binary resources in hex view (#2160)…
Browse files Browse the repository at this point in the history
… (PR #2166)
  • Loading branch information
jpstotz committed Apr 24, 2024
1 parent 07dde05 commit 37a42d1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/codearea/HexArea.java
Expand Up @@ -15,7 +15,10 @@
import org.slf4j.LoggerFactory;

import jadx.api.ICodeInfo;
import jadx.api.ResourcesLoader;
import jadx.core.utils.exceptions.JadxException;
import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JResource;
import jadx.gui.ui.panel.ContentPanel;
import jadx.gui.utils.UiUtils;

Expand Down Expand Up @@ -48,7 +51,18 @@ public HexArea(ContentPanel contentPanel, JNode node) {

@Override
public void load() {
byte[] bytes = binaryNode.getCodeInfo().getCodeStr().getBytes(StandardCharsets.UTF_8);
byte[] bytes = null;
if (binaryNode instanceof JResource) {
JResource jResource = ((JResource) binaryNode);
try {
bytes = ResourcesLoader.decodeStream(jResource.getResFile(), (size, is) -> is.readAllBytes());
} catch (JadxException e) {
LOG.error("Failed to directly load resource binary data {}: {}", jResource.getName(), e.getMessage());
}
}
if (bytes == null) {
bytes = binaryNode.getCodeInfo().getCodeStr().getBytes(StandardCharsets.UTF_8);
}
setBytes(bytes);
if (getBytes().length > 0) {
// We set the caret after the first byte to prevent it from being highlighted
Expand Down

0 comments on commit 37a42d1

Please sign in to comment.