2015-11-11 04:16:45 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
|
|
|
|
|
|
|
|
import org.objectweb.asm.ClassReader;
|
|
|
|
import org.objectweb.asm.ClassWriter;
|
|
|
|
import org.objectweb.asm.tree.ClassNode;
|
2018-01-31 15:03:53 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
2015-11-19 03:30:59 +00:00
|
|
|
|
2015-11-11 04:16:45 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author sc4re
|
|
|
|
*/
|
|
|
|
public class Refactorer {
|
|
|
|
|
|
|
|
protected HookMap hooks;
|
|
|
|
|
|
|
|
public Refactorer() {
|
|
|
|
hooks = new HookMap();
|
|
|
|
}
|
2018-01-31 15:41:24 +00:00
|
|
|
|
2015-11-11 04:16:45 +00:00
|
|
|
public HookMap getHooks() {
|
|
|
|
return hooks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if (getHooks() == null)
|
|
|
|
return;
|
2018-01-31 15:41:24 +00:00
|
|
|
|
2015-11-11 04:16:45 +00:00
|
|
|
RefactorMapper mapper = new RefactorMapper(getHooks());
|
2021-04-12 22:31:22 +00:00
|
|
|
//Map<String, ClassNode> refactored = new HashMap<>();
|
2015-11-11 04:16:45 +00:00
|
|
|
for (ClassNode cn : BytecodeViewer.getLoadedClasses()) {
|
2021-04-12 22:31:22 +00:00
|
|
|
//String oldName = cn.name;
|
2015-11-11 04:16:45 +00:00
|
|
|
ClassReader cr = new ClassReader(getClassNodeBytes(cn));
|
|
|
|
ClassWriter cw = new ClassWriter(cr, 0);
|
2021-04-12 20:19:12 +00:00
|
|
|
RemappingClassAdapter rca = new RemappingClassAdapter(cw, mapper);
|
2015-11-11 04:16:45 +00:00
|
|
|
cr.accept(rca, ClassReader.EXPAND_FRAMES);
|
|
|
|
cr = new ClassReader(cw.toByteArray());
|
2018-01-31 15:41:24 +00:00
|
|
|
cn = new ClassNode();
|
2015-11-11 04:16:45 +00:00
|
|
|
cr.accept(cn, 0);
|
2021-04-12 22:31:22 +00:00
|
|
|
//refactored.put(oldName, cn);
|
2015-11-11 04:16:45 +00:00
|
|
|
}
|
|
|
|
/*for (Map.Entry<String, ClassNode> factor : refactored.entrySet()) {
|
|
|
|
BytecodeViewer.relocate(factor.getKey(), factor.getValue());
|
|
|
|
}*/
|
|
|
|
mapper.printMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte[] getClassNodeBytes(ClassNode cn) {
|
|
|
|
ClassWriter cw = new ClassWriter(0);
|
|
|
|
cn.accept(cw);
|
2021-04-12 22:31:22 +00:00
|
|
|
return cw.toByteArray();
|
2015-11-11 04:16:45 +00:00
|
|
|
}
|
|
|
|
}
|