未验证 提交 3a6d645e 编写于 作者: J Jan S 提交者: GitHub

fix(res): do not rename resources names for building res-map.txt (PR #1035)

fix: do not rename resources names for building res-map.txt
allow loading of resources.arsc from android.jar files
res-map.txt bases on resources.arsc from API 3, 4, 7-30 (taken from https://github.com/Sable/android-platforms)
上级 e65468b9
...@@ -11,6 +11,8 @@ import java.util.List; ...@@ -11,6 +11,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -51,13 +53,29 @@ public class ConvertArscFile { ...@@ -51,13 +53,29 @@ public class ConvertArscFile {
RootNode root = new RootNode(new JadxArgs()); // not really needed RootNode root = new RootNode(new JadxArgs()); // not really needed
rewritesCount = 0; rewritesCount = 0;
for (Path resFile : inputPaths) { for (Path resFile : inputPaths) {
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(resFile))) { LOG.info("Processing {}", resFile);
ResTableParser resTableParser = new ResTableParser(root); ResTableParser resTableParser = new ResTableParser(root, true);
resTableParser.decode(inputStream); if (resFile.getFileName().toString().endsWith(".jar")) {
Map<Integer, String> singleResMap = resTableParser.getResStorage().getResourcesNames(); // Load resources.arsc from android.jar
mergeResMaps(resMap, singleResMap); try (ZipFile zip = new ZipFile(resFile.toFile())) {
LOG.info("{} entries count: {}, after merge: {}", resFile.getFileName(), singleResMap.size(), resMap.size()); ZipEntry entry = zip.getEntry("resources.arsc");
if (entry == null) {
LOG.error("Failed to load \"resources.arsc\" from {}", resFile);
continue;
}
try (InputStream inputStream = zip.getInputStream(entry)) {
resTableParser.decode(inputStream);
}
}
} else {
// Load resources.arsc from extracted file
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(resFile))) {
resTableParser.decode(inputStream);
}
} }
Map<Integer, String> singleResMap = resTableParser.getResStorage().getResourcesNames();
mergeResMaps(resMap, singleResMap);
LOG.info("{} entries count: {}, after merge: {}", resFile.getFileName(), singleResMap.size(), resMap.size());
} }
LOG.info("Output entries count: {}", resMap.size()); LOG.info("Output entries count: {}", resMap.size());
LOG.info("Total rewrites count: {}", rewritesCount); LOG.info("Total rewrites count: {}", rewritesCount);
......
...@@ -27,7 +27,7 @@ import jadx.core.xmlgen.entry.ValuesParser; ...@@ -27,7 +27,7 @@ import jadx.core.xmlgen.entry.ValuesParser;
public class ResTableParser extends CommonBinaryParser { public class ResTableParser extends CommonBinaryParser {
private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class); private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class);
private static final Pattern VALID_RES_KEY_PATTERN = Pattern.compile("[\\w\\d-_.]+"); private static final Pattern VALID_RES_KEY_PATTERN = Pattern.compile("\\$+[\\w\\d-_.]+");
private static final class PackageChunk { private static final class PackageChunk {
private final int id; private final int id;
...@@ -59,12 +59,21 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -59,12 +59,21 @@ public class ResTableParser extends CommonBinaryParser {
} }
} }
/**
* No renaming, pattern checking or name generation. Required for res-map.txt building
*/
private final boolean useRawResName;
private final RootNode root; private final RootNode root;
private final ResourceStorage resStorage = new ResourceStorage(); private final ResourceStorage resStorage = new ResourceStorage();
private String[] strings; private String[] strings;
public ResTableParser(RootNode root) { public ResTableParser(RootNode root) {
this(root, false);
}
public ResTableParser(RootNode root, boolean useRawResNames) {
this.root = root; this.root = root;
this.useRawResName = useRawResNames;
} }
public void decode(InputStream inputStream) throws IOException { public void decode(InputStream inputStream) throws IOException {
...@@ -291,6 +300,9 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -291,6 +300,9 @@ public class ResTableParser extends CommonBinaryParser {
} }
private String getResName(int resRef, String origKeyName) { private String getResName(int resRef, String origKeyName) {
if (this.useRawResName) {
return origKeyName;
}
String renamedKey = resStorage.getRename(resRef); String renamedKey = resStorage.getRename(resRef);
if (renamedKey != null) { if (renamedKey != null) {
return renamedKey; return renamedKey;
......
...@@ -10686,6 +10686,7 @@ ...@@ -10686,6 +10686,7 @@
010b0009=animator/leanback_setup_fragment_close_exit 010b0009=animator/leanback_setup_fragment_close_exit
010b000a=animator/leanback_setup_fragment_open_enter 010b000a=animator/leanback_setup_fragment_open_enter
010b000b=animator/leanback_setup_fragment_open_exit 010b000b=animator/leanback_setup_fragment_open_exit
010b000c=xml/time_zones_by_country
010c0000=interpolator/accelerate_quad 010c0000=interpolator/accelerate_quad
010c0001=interpolator/decelerate_quad 010c0001=interpolator/decelerate_quad
010c0002=interpolator/accelerate_cubic 010c0002=interpolator/accelerate_cubic
...@@ -10740,6 +10741,23 @@ ...@@ -10740,6 +10741,23 @@
010d0001=mipmap/sym_def_app_icon_foreground 010d0001=mipmap/sym_def_app_icon_foreground
010d0002=mipmap/sym_def_app_icon_maskable 010d0002=mipmap/sym_def_app_icon_maskable
010d0003=mipmap/sym_def_app_icon_maskable 010d0003=mipmap/sym_def_app_icon_maskable
010d0004=bool/config_bypass_keyguard_if_slider_open
010d0005=bool/config_automatic_brightness_available
010d0006=bool/config_annoy_dianne
010d0007=bool/config_unplugTurnsOnScreen
010d0008=bool/config_animateScreenLights
010d0009=bool/config_deskDockEnablesAccelerometer
010d000a=bool/config_carDockEnablesAccelerometer
010d000b=bool/config_batterySdCardAccessibility
010d000c=bool/config_use_strict_phone_number_comparation
010d000d=bool/config_disableMenuKeyInLockScreen
010d000e=bool/config_swipeDisambiguation
010d000f=bool/config_filterTouchEvents
010d0010=bool/config_filterJumpyTouchEvents
010d0011=bool/config_bluetooth_sco_off_call
010d0012=bool/config_sip_wifi_only
010d0013=bool/skip_restoring_network_selection
010d0014=bool/lockscreen_isPortrait
010e0000=integer/config_shortAnimTime 010e0000=integer/config_shortAnimTime
010e0001=integer/config_mediumAnimTime 010e0001=integer/config_mediumAnimTime
010e0002=integer/config_longAnimTime 010e0002=integer/config_longAnimTime
...@@ -11040,6 +11058,7 @@ ...@@ -11040,6 +11058,7 @@
010f000f=xml/sms_short_codes 010f000f=xml/sms_short_codes
010f0010=xml/storage_list 010f0010=xml/storage_list
010f0011=xml/time_zones_by_country 010f0011=xml/time_zones_by_country
010f0012=plurals/wifi_available_detailed
01100000=raw/loaderror 01100000=raw/loaderror
01100001=raw/nodomain 01100001=raw/nodomain
01100002=raw/color_fade_frag 01100002=raw/color_fade_frag
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册