Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] Hex view data error #2160

Closed
1 of 3 tasks
Asteri5m opened this issue Apr 23, 2024 · 10 comments · Fixed by #2166
Closed
1 of 3 tasks

[gui] Hex view data error #2160

Asteri5m opened this issue Apr 23, 2024 · 10 comments · Fixed by #2166
Labels
bug GUI Issues in jadx-gui module

Comments

@Asteri5m
Copy link

Issue details

When looking at the resource file, the hex view's data content is different from what I saw using the 010 Editor. When I use the algorithm in the program to decrypt, only the latter data is available
image

Jadx version

1.5.0

Java version

21.0.3

OS

  • Windows
  • Linux
  • macOS
@Asteri5m Asteri5m added bug GUI Issues in jadx-gui module labels Apr 23, 2024
@jpstotz
Copy link
Collaborator

jpstotz commented Apr 23, 2024

Ist it possible to provide the APK file that contains the shown libc.so? Or at least a screenshot of 7-Zip having the APK opened and showing the libc.so entry with size, compressed size and compression method.

@Asteri5m
Copy link
Author

Asteri5m commented Apr 23, 2024 via email

@jpstotz
Copy link
Collaborator

jpstotz commented Apr 23, 2024

@Asteri5m Sorry I don't see any file. It seems like posting attachments via e-mail to Github issues is not possible.

@Asteri5m
Copy link
Author

@jpstotz
Copy link
Collaborator

jpstotz commented Apr 24, 2024

The main problem is that the HexArea that display the hex data is getting the data to be displayed from a String that is then decoded as UTF-8 string to a byte[]:

byte[] bytes = binaryNode.getCodeInfo().getCodeStr().getBytes(StandardCharsets.UTF_8);

For binary files, the unicode decoding can modify the data which is most likely the reason you have described in this issue. Binary data should never be saved in a String...

I think for a JResource node with ZipRef it would be more feasible to directly load the raw file data from the ZIP file instead of using the loaded data from the node.

I made a quick test using the following code and it loads the correct hex data. @skylot Do you see any side effects when loading the hex data directly from the ZIP file?

	public void load() {
		byte[] bytes = null;
		if (binaryNode instanceof JResource) {
			JResource jResource = ((JResource) binaryNode);
			ResourceFile.ZipRef zipRef = jResource.getResFile().getZipRef();
			if (zipRef != null) {
				try (ZipFile zipFile = new ZipFile(zipRef.getZipFile())) {
					ZipEntry entry = zipFile.getEntry(zipRef.getEntryName());
					if (entry == null) {
						throw new RuntimeException("Zip entry not found: " + zipRef);
					}
					if (ZipSecurity.isValidZipEntry(entry)) {
						try (InputStream inputStream = ZipSecurity.getInputStreamForEntry(zipFile, entry)) {
							bytes = inputStream.readAllBytes();
						}
					}
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		if (bytes == null) {
			bytes = binaryNode.getCodeInfo().getCodeStr().getBytes(StandardCharsets.UTF_8);
		}
....

@skylot
Copy link
Owner

skylot commented Apr 24, 2024

Binary data should never be saved in a String

I agree, this is should be avoided at all.

Do you see any side effects when loading the hex data directly from the ZIP file?

I think this is fine, but it is better to not duplicate such big chunk of code and reuse loading code from

public static <T> T decodeStream(ResourceFile rf, ResourceDecoder<T> decoder) throws JadxException {

Another approach is to make loading similar to ImagePanel. It is store byte array in ResContainer with type DECODED_DATA
private BufferedImage loadImage(JResource res) {

and loading of data is done here:
case IMG:
return decodeImage(rf, inputStream);

Anyway, both ways are fine, because all resource code loading is a mess and should be simplified and refactored 🤣

@Asteri5m
Copy link
Author

It seems that the problem has been resolved. I hope to update this bug and release a new release as soon as possible. This feature is still very practical. Like

@jpstotz
Copy link
Collaborator

jpstotz commented Apr 24, 2024

From my perspective the direct way using ResourcesLoader.decodeStream would be the best as the other ways seem to base on ResourceLoader.loadContent which also considers the type of the resource which is not what we want for a hex view.

@jpstotz
Copy link
Collaborator

jpstotz commented Apr 24, 2024

@Asteri5m You don't have to wait for a new version to be released. Once my PR is merged into the code base the Github CI system will build a new unstable version which you can then download here: unstable download (also mentioned in the main project README.md).

@skylot
Copy link
Owner

skylot commented Apr 24, 2024

resource code loading is a mess and should be simplified and refactored 🤣

Looks like @AndreiKud already start refactoring in PR #2165 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug GUI Issues in jadx-gui module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants