forked from java-deobfuscator/deobfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-ConstantFolder long support -Remove illegal annotations -Fix error in Radon transformer v2
- Loading branch information
1 parent
72b6e57
commit 833c5ed
Showing
4 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...javadeobfuscator/deobfuscator/transformers/general/removers/IllegalAnnotationRemover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2017 Sam Sun <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.javadeobfuscator.deobfuscator.transformers.general.removers; | ||
|
||
import com.javadeobfuscator.deobfuscator.config.TransformerConfig; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.AnnotationNode; | ||
import org.objectweb.asm.util.CheckClassAdapter; | ||
import org.objectweb.asm.util.CheckFieldAdapter; | ||
import org.objectweb.asm.util.CheckMethodAdapter; | ||
|
||
import com.javadeobfuscator.deobfuscator.transformers.Transformer; | ||
|
||
public class IllegalAnnotationRemover extends Transformer<TransformerConfig> { | ||
@Override | ||
public boolean transform() throws Throwable { | ||
CheckClassAdapter classAdapter = new CheckClassAdapter(null); | ||
CheckMethodAdapter methodAdapter = new CheckMethodAdapter(null); | ||
CheckFieldAdapter fieldAdapter = new CheckFieldAdapter(null); | ||
classAdapter.visit(Opcodes.V1_5, 0, "java/lang/Object", null, null, null); | ||
classNodes().forEach(classNode -> { | ||
removeInvalidAnnotations(classAdapter, classNode.invisibleAnnotations, false); | ||
removeInvalidAnnotations(classAdapter, classNode.visibleAnnotations, true); | ||
classNode.methods.forEach(methodNode -> { | ||
removeInvalidAnnotations(methodAdapter, methodNode.invisibleAnnotations, false); | ||
removeInvalidAnnotations(methodAdapter, methodNode.visibleAnnotations, true); | ||
}); | ||
classNode.fields.forEach(fieldNode -> { | ||
removeInvalidAnnotations(fieldAdapter, fieldNode.invisibleAnnotations, false); | ||
removeInvalidAnnotations(fieldAdapter, fieldNode.visibleAnnotations, true); | ||
}); | ||
}); | ||
return true; | ||
} | ||
|
||
private void removeInvalidAnnotations(Object visitor, List<AnnotationNode> annots, boolean visible) | ||
{ | ||
if(annots == null) | ||
return; | ||
Iterator<AnnotationNode> itr = annots.iterator(); | ||
while(itr.hasNext()) | ||
{ | ||
AnnotationNode type = itr.next(); | ||
try { | ||
if(visitor instanceof CheckClassAdapter) | ||
((CheckClassAdapter)visitor).visitAnnotation(type.desc, visible); | ||
else if(visitor instanceof CheckMethodAdapter) | ||
((CheckMethodAdapter)visitor).visitAnnotation(type.desc, visible); | ||
else | ||
((CheckFieldAdapter)visitor).visitAnnotation(type.desc, visible); | ||
} catch (IllegalArgumentException | IllegalStateException ignored) { | ||
itr.remove(); | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...deobfuscator/deobfuscator/transformers/general/removers/IllegalTypeAnnotationRemover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2017 Sam Sun <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.javadeobfuscator.deobfuscator.transformers.general.removers; | ||
|
||
import com.javadeobfuscator.deobfuscator.config.TransformerConfig; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.TypeAnnotationNode; | ||
import org.objectweb.asm.util.CheckClassAdapter; | ||
import org.objectweb.asm.util.CheckFieldAdapter; | ||
import org.objectweb.asm.util.CheckMethodAdapter; | ||
|
||
import com.javadeobfuscator.deobfuscator.transformers.Transformer; | ||
|
||
public class IllegalTypeAnnotationRemover extends Transformer<TransformerConfig> { | ||
@Override | ||
public boolean transform() throws Throwable { | ||
CheckClassAdapter classAdapter = new CheckClassAdapter(null); | ||
CheckMethodAdapter methodAdapter = new CheckMethodAdapter(null); | ||
CheckFieldAdapter fieldAdapter = new CheckFieldAdapter(null); | ||
classAdapter.visit(Opcodes.V1_5, 0, "java/lang/Object", null, null, null); | ||
classNodes().forEach(classNode -> { | ||
removeInvalidTypeAnnotations(classAdapter, classNode.invisibleTypeAnnotations, false); | ||
removeInvalidTypeAnnotations(classAdapter, classNode.visibleTypeAnnotations, true); | ||
classNode.methods.forEach(methodNode -> { | ||
removeInvalidTypeAnnotations(methodAdapter, methodNode.invisibleTypeAnnotations, false); | ||
removeInvalidTypeAnnotations(methodAdapter, methodNode.visibleTypeAnnotations, true); | ||
}); | ||
classNode.fields.forEach(fieldNode -> { | ||
removeInvalidTypeAnnotations(fieldAdapter, fieldNode.invisibleTypeAnnotations, false); | ||
removeInvalidTypeAnnotations(fieldAdapter, fieldNode.visibleTypeAnnotations, true); | ||
}); | ||
}); | ||
return true; | ||
} | ||
|
||
private void removeInvalidTypeAnnotations(Object visitor, List<TypeAnnotationNode> typeAnnots, boolean visible) | ||
{ | ||
if(typeAnnots == null) | ||
return; | ||
Iterator<TypeAnnotationNode> itr = typeAnnots.iterator(); | ||
while(itr.hasNext()) | ||
{ | ||
TypeAnnotationNode type = itr.next(); | ||
try { | ||
if(visitor instanceof CheckClassAdapter) | ||
((CheckClassAdapter)visitor).visitTypeAnnotation(type.typeRef, type.typePath, type.desc, visible); | ||
else if(visitor instanceof CheckMethodAdapter) | ||
((CheckMethodAdapter)visitor).visitTypeAnnotation(type.typeRef, type.typePath, type.desc, visible); | ||
else | ||
((CheckFieldAdapter)visitor).visitTypeAnnotation(type.typeRef, type.typePath, type.desc, visible); | ||
} catch (IllegalArgumentException | IllegalStateException ignored) { | ||
itr.remove(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters