Skip to content

Commit

Permalink
Fix TryItem writing
Browse files Browse the repository at this point in the history
  • Loading branch information
vova7878 committed Jun 3, 2024
1 parent 1de81bf commit 071c9aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/v7878/dex/CodeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public void write(WriteContext context, RandomOutput out) {
out.position(insns_start + insns_size);

if (tries_size != 0) {
tries.sort(TryItem.COMPARATOR);

out.alignPositionAndFillZeros(TryItem.ALIGNMENT);

RandomOutput tries_out = out.duplicate(out.position());
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/v7878/dex/TryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@
import com.v7878.dex.util.SparseArray;
import com.v7878.misc.Checks;

import java.util.Comparator;
import java.util.Map;
import java.util.Objects;

public final class TryItem implements Mutable {

public static final Comparator<TryItem> COMPARATOR = (a, b) -> {
int out = Integer.compare(a.start_addr, b.start_addr);
if (out != 0) {
return out;
}

// a.start_addr == b.start_addr, but a != b
throw new IllegalStateException("try items are overlapping: " + a + " " + b);
};

public static final int SIZE = 8;
public static final int ALIGNMENT = 4;

Expand Down

0 comments on commit 071c9aa

Please sign in to comment.