Skip to content

Commit b74967d

Browse files
committed
[DEX] Fix: Update dex checksum for multi container (Fixes "Bad checksum" error for dex >= v040)
1 parent 60d2c27 commit b74967d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/com/reandroid/dex/sections/DexContainerBlock.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.reandroid.dex.common.SectionItem;
2323
import com.reandroid.dex.header.DexHeader;
2424
import com.reandroid.dex.header.DexVersion;
25+
import com.reandroid.utils.collection.ArrayUtil;
2526
import com.reandroid.utils.collection.ComputeIterator;
2627

2728
import java.io.File;
@@ -157,6 +158,36 @@ private void fixMinimumVersion() {
157158

158159
@Override
159160
public void refreshFull() {
161+
int[] checkSums = getCheckSums();
162+
boolean multiContainer = checkSums.length > 1;
163+
int repeat = size();
164+
for (int i = 0; i < repeat; i++) {
165+
refreshFullLayouts();
166+
if (multiContainer) {
167+
int[] changed = getCheckSums();
168+
if (ArrayUtil.areEqual(checkSums, changed)) {
169+
break;
170+
}
171+
refresh();
172+
checkSums = changed;
173+
changed = getCheckSums();
174+
if (ArrayUtil.areEqual(checkSums, changed)) {
175+
break;
176+
}
177+
checkSums = changed;
178+
}
179+
}
180+
}
181+
private int[] getCheckSums() {
182+
int size = size();
183+
int[] results = new int[size];
184+
for (int i = 0; i < size; i++) {
185+
DexLayoutBlock layoutBlock = get(i);
186+
results[i] = layoutBlock.getHeader().checksum.getValue();
187+
}
188+
return results;
189+
}
190+
private void refreshFullLayouts() {
160191
clearUnused();
161192
clearEmptyLayouts();
162193
for (DexLayoutBlock layoutBlock : this) {

0 commit comments

Comments
 (0)