Skip to content

Commit

Permalink
More deterministic output
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
ThexXTURBOXx committed Mar 28, 2023
1 parent dd5cc4e commit 34cdd5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import org.objectweb.asm.AnnotationVisitor;
Expand All @@ -67,7 +66,7 @@ public static class ClzCtx {
public String buildHexDecodeMethodName(String x) {
if (hexDecodeMethodNamePrefix == null) {
byte[] d = new byte[4];
new Random().nextBytes(d);
Dex2jar.random.nextBytes(d);
hexDecodeMethodNamePrefix = "$d2j$hex$" + IR2JConverter.hexEncode(d);
}
return hexDecodeMethodNamePrefix + "$decode_" + x;
Expand Down
16 changes: 16 additions & 0 deletions dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
import java.nio.file.spi.FileSystemProvider;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;

public final class Dex2jar {

/**
* For rather deterministic output, we use a fixed seed for random number generator.
* This field is freely writable by any thread. Use carefully.
*/
public static Random random = new Random(0);

private DexExceptionHandler exceptionHandler;

private final BaseDexFileReader reader;
Expand Down Expand Up @@ -279,6 +286,15 @@ public Dex2jar skipExceptions(boolean b) {
return this;
}

public Dex2jar setRandom(Random random) {
Dex2jar.random = random;
return this;
}

public Dex2jar resetRandom() {
return setRandom(new Random(0));
}

public static Dex2jar from(byte[] in) throws IOException {
return from(MultiDexFileReader.open(in));
}
Expand Down

0 comments on commit 34cdd5e

Please sign in to comment.