Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lx01.projects.obmap;
- import java.io.File;
- import java.nio.file.Files;
- import java.util.List;
- import static lx01.projects.jd.JavaDecompiler.decompile;
- public class ObfuscationMapper {
- public static void main (String[] args) {
- if (args.length < 4) throw new IllegalArgumentException ("Usage: \"java -jar [jar file] [file to be mapped] [file with mappings] [output file] [decompile (true or false)]\"");
- File sourceFile = new File(args[0]);
- File mappingsFile = new File(args[1]);
- File out = new File(args[2]);
- boolean decompile = args[3] == true;
- String source = decompile ? decompile(source) : concat(Files.readAllLines(source.toPath()));
- Mapping.Set mappings = readMappings(Files.readAllLines(mappingsFile.toPath()));
- Mapper.map(source, mappings, out);
- }
- private static String concat (List<String> strings) {
- String s = "";
- strings.forEach((s2) -> { s = s.concat(s2); });
- return s;
- }
- private static Mapping.Set readMappings (List<String> strings) {
- Mapping.Set mappings = new Mapping.Set();
- strings.forEach((s) -> { mappings.put(readMapping(s)); });
- return mappings;
- }
- private static Mapping readMapping (String mapping) {
- String[] m = mapping.split("->");
- return new Mapping.Builder().setTarget(m[0]).setResult(m[1]).build();
- }
- }
- //
- package lx01.projects.obmap;
- import java.util.Set;
- public class Mapping {
- private String target;
- private String output;
- public Mapping () {}
- public void setTarget (String nt) {
- this.target = nt;
- }
- public String getTarget () {
- return this.target;
- }
- public void setOutput (String no) {
- this.output = no;
- }
- public String getOutput () {
- return this.output;
- }
- public static class Builder {
- private Mapping m = new Mapping();
- public Builder () {};
- public Builder setTarget (String nt) {
- this.m.setTarget(nt);
- return this;
- }
- public Builder setOutput (String no) {
- this.m.setOutput(no);
- return this;
- }
- }
- public static class Set {
- private Set<Mapping> mappings = Set.<Mapping>of();
- public Set () {}
- public void put (Mapping m) {
- this.mappings.put(m);
- }
- public boolean applies (String s) {
- for (Mapping m : this.mappings)
- if (s.contains(m.getTarget()))
- return true;
- return false;
- }
- public String applyAll (String s) {
- for (Mapping m : this.mappings)
- if (s.contains(m.getTarget()))
- s = s.replaceAll(m.getTarget(), m.getOutput());
- return s;
- }
- }
- }
- //
- package lx01.projects.obmap;
- public class Mapper {
- public static void map (String source, Mapping.Set mappings, File out) {
- try {
- new FileWriter(out).write(mappings.applyAll(s));
- } catch (Exception e) {
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement