ConstantFolder - Long support
See original GitHub issueNeeded support for longs
in the ConstantFolder transformer (com.javadeobfuscator.deobfuscator.transformers.general.peephole)
This is my suggestion as it worked for me…
this example wasn’t handled correctly by the existing code:
LDC 6458377393085008524L
LDC 3104987515852103167L
LOR
BIPUSH 13
LSHL
LDC -236791030383386624L
LXOR
LDC 97L
BIPUSH 21
LUSHR
LDC 8147424378139406440L
LAND
BIPUSH 13
LSHL
BIPUSH 12
LSHL
LDC 100L
LXOR
example code supporting the long variant(s):
case LADD:
case LAND:
case LDIV:
case LMUL:
case LOR:
case LREM:
case LSHL:
case LSHR:
case LSUB:
case LUSHR:
case LXOR: {
List<Frame> frames = result.getFrames().get(ain);
if (frames == null) {
break;
}
Set<Long> results = new HashSet<>();
for (Frame frame0 : frames) {
MathFrame frame = (MathFrame) frame0;
if (frame.getTargets().size() != 2) {
throw new RuntimeException("weird: " + frame);
}
Frame top = frame.getTargets().get(0);
Frame bottom = frame.getTargets().get(1);
if (top instanceof LdcFrame && bottom instanceof LdcFrame) {
long bottomValue = ((Number) ((LdcFrame) bottom).getConstant()).longValue();
long topValue = ((Number) ((LdcFrame) top).getConstant()).longValue();
if (ain.getOpcode() == LADD) {
results.add(bottomValue + topValue);
} else if (ain.getOpcode() == LMUL) {
results.add(bottomValue * topValue);
} else if (ain.getOpcode() == LREM) {
results.add(bottomValue % topValue);
} else if (ain.getOpcode() == LSUB) {
results.add(bottomValue - topValue);
} else if (ain.getOpcode() == LDIV) {
results.add(bottomValue / topValue);
} else if (ain.getOpcode() == LSHL) {
results.add(bottomValue << topValue);
} else if (ain.getOpcode() == LSHR) {
results.add(bottomValue >> topValue);
} else if (ain.getOpcode() == LUSHR) {
results.add(bottomValue >>> topValue);
} else if (ain.getOpcode() == LXOR) {
results.add(bottomValue ^ topValue);
} else if (ain.getOpcode() == LOR) {
results.add(bottomValue | topValue);
} else if (ain.getOpcode() == LAND) {
results.add(bottomValue & topValue);
}
} else {
break opcodes;
}
}
if (results.size() == 1) {
InsnList replacement = new InsnList();
// i think we need two of these since we're dealing with long-type values..
// pop2 will remove two int(s) or one long. we don't want that behavior.
replacement.add(new InsnNode(POP)); // remove existing args from stack
replacement.add(new InsnNode(POP)); // remove existing args from stack
replacement.add(Utils.getLongInsn(results.iterator().next()));
replacements.put(ain, replacement);
folded.getAndIncrement();
}
break;
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ConstantFolder Class Reference - LLVM
ConstantFolder - Create constants with minimum, target independent, folding. Definition at line 30 of file ConstantFolder.h.
Read more >ConstantFolder - CS@Cornell
Visitor which performs constant folding. Constructor Summary. ConstantFolder(TypeSystem ts, NodeFactory nf). Method Summary. Node ...
Read more >clang-14 C parser does not accept integer constant 1E6L
error: expression requires 'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it ClangBuiltLinux/linux#1497.
Read more >[llvm-dev] single-threaded code-gen and how to make it ...
Can anyone help with some pointers? Any guidance is appreciated:) ntdll.dll!RtlReportCriticalFailure(long StatusCode, void * FailureInfo, unsigned long ...
Read more >ConstantFolder.h - Apple Open Source
llvm/Support/ConstantFolder.h - Constant folding helper -*- C++ -*-===// // // The ... This file defines the ConstantFolder class, a helper for IRBuilder.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For the opcodes LSHL, LSHR and LUSHR the second operand (in the code named bottom), actually on top of the stack is not a long, but an int. So you need POP POP2 for LSHL, LSHR and LUSHR and for the other long opcodes you need POP2 POP2
This has been added in the latest release.