ALT+T,搜索文本This program is not registered,定位到相关指令附近
我们首先尝试将getstatic指令改成返回指令
点击getstatic,然后点击hex视图
可以看到B2 00 02对应这条指令
右键修改B2 为B1,然后右键应用更改
再切回IDA view视图
最后菜单点击Edit–>Patch Program–>Apply patches to input file,将更改应用到文件
在弹出的对话框点确定即可修改class文件
但是这么修改运行的时候会报错,可能是有一些栈和帧的校验
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
C:\Users\admin\Desktop>java nag Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.VerifyError: Expecting a stack map frame Exception Details: Location: nag.nag_screen()V @1: nop Reason: Error exists in the bytecode Bytecode: 0x0000000: b100 0212 03b6 0004 b1
at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
原作者在JDK1.7下不工作,我在1.8下也是,报的是栈帧映射异常
既然此路不通,那么就选另一条路,去掉nag()方法的调用
找到main方法
中间的
.line 8
invokestatic nag.nag_screen()V
这一句就是调用nag()方法,查看对应的hex视图
其中的B8 00 06就是调用这个方法
改成00 00 00(填充3个NOP指令)
对应的IDA view视图
变成了3个nop指令
最后菜单点击Edit–>Patch Program–>Apply patches to input file,将更改应用到文件
修改完看运行效果
修改成功
2. 再看第二个例子
这是一个简单的crackme的例子
1 2 3 4 5 6 7 8 9 10
publicclasspassword { publicstaticvoidmain(String[] args) { System.out.println("Please enter the password"); Stringinput= System.console().readLine(); if (input.equals("secret")) System.out.println("password is correct"); else System.out.println("password is not correct"); } }
C:\Users\admin\Desktop>java password Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 24 Exception Details: Location: password.main([Ljava/lang/String;)V @21: ifeq Reason: Expected stackmap frame at this location. Bytecode: 0x0000000: b200 0212 03b6 0004 b800 05b6 0006 4c2b 0x0000010: 1207 b600 0899 0003 b200 0212 09b6 0004 0x0000020: a700 0bb2 0002 120a b600 04b1 Stackmap Table: append_frame(@35,Object[#20]) same_frame(@43)
at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)