Skip to content

Commit

Permalink
fix(res): handle null values in android manifest parsing (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jan 13, 2025
1 parent 94915db commit 6860a8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
5 changes: 2 additions & 3 deletions jadx-core/src/main/java/jadx/core/export/TemplateFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import jadx.core.utils.exceptions.JadxRuntimeException;
Expand Down Expand Up @@ -49,8 +48,8 @@ private TemplateFile(String name, InputStream in) {
this.template = in;
}

public void add(String name, @NotNull Object value) {
values.put(name, value.toString());
public void add(String name, @Nullable Object value) {
values.put(name, String.valueOf(value));
}

public String build() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,37 @@ private ApplicationParams parseAttributes() {
String mainActivity = null;
String application = null;

@Nullable
Element manifest = (Element) androidManifest.getElementsByTagName("manifest").item(0);
@Nullable
Element usesSdk = (Element) androidManifest.getElementsByTagName("uses-sdk").item(0);

if (parseAttrs.contains(AppAttribute.APPLICATION_LABEL)) {
applicationLabel = getApplicationLabel();
}
if (parseAttrs.contains(AppAttribute.MIN_SDK_VERSION)) {
minSdkVersion = Integer.valueOf(usesSdk.getAttribute("android:minSdkVersion"));
}
if (parseAttrs.contains(AppAttribute.TARGET_SDK_VERSION)) {
String stringTargetSdk = usesSdk.getAttribute("android:targetSdkVersion");
if (!stringTargetSdk.isEmpty()) {
targetSdkVersion = Integer.valueOf(stringTargetSdk);
} else {
if (minSdkVersion == null) {
minSdkVersion = Integer.valueOf(usesSdk.getAttribute("android:minSdkVersion"));
if (usesSdk != null) {
if (parseAttrs.contains(AppAttribute.MIN_SDK_VERSION)) {
minSdkVersion = Integer.valueOf(usesSdk.getAttribute("android:minSdkVersion"));
}
if (parseAttrs.contains(AppAttribute.TARGET_SDK_VERSION)) {
String stringTargetSdk = usesSdk.getAttribute("android:targetSdkVersion");
if (!stringTargetSdk.isEmpty()) {
targetSdkVersion = Integer.valueOf(stringTargetSdk);
} else {
if (minSdkVersion == null) {
minSdkVersion = Integer.valueOf(usesSdk.getAttribute("android:minSdkVersion"));
}
targetSdkVersion = minSdkVersion;
}
targetSdkVersion = minSdkVersion;
}
}
if (parseAttrs.contains(AppAttribute.VERSION_CODE)) {
versionCode = Integer.valueOf(manifest.getAttribute("android:versionCode"));
}
if (parseAttrs.contains(AppAttribute.VERSION_NAME)) {
versionName = manifest.getAttribute("android:versionName");
if (manifest != null) {
if (parseAttrs.contains(AppAttribute.VERSION_CODE)) {
versionCode = Integer.valueOf(manifest.getAttribute("android:versionCode"));
}
if (parseAttrs.contains(AppAttribute.VERSION_NAME)) {
versionName = manifest.getAttribute("android:versionName");
}
}
if (parseAttrs.contains(AppAttribute.MAIN_ACTIVITY)) {
mainActivity = getMainActivityName();
Expand Down

0 comments on commit 6860a8b

Please sign in to comment.