日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

java逆向_Java逆向基础之异常

發(fā)布時(shí)間:2023/12/1 java 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java逆向_Java逆向基础之异常 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

異常

由之前月份處理修改的例子

//清單1IncorrectMonthException.javapublic?class?IncorrectMonthException?extends?Exception?{private?int?index;public?IncorrectMonthException(int?index)?{this.index?=?index;}public?int?getIndex()?{return?index;}}

//清單2Month2.javaclass?Month2?{public?static?String[]?months?=?{?"January",?"February",?"March",?"April",?"May",?"June",?"July",?"August","September",?"October",?"November",?"December"?};public?static?String?get_month(int?i)?throws?IncorrectMonthException?{if?(i??11)throw?new?IncorrectMonthException(i);return?months[i];};public?static?void?main(String[]?args)?{try?{System.out.println(get_month(100));}?catch?(IncorrectMonthException?e)?{System.out.println("incorrect?month?index:?"?+?e.getIndex());e.printStackTrace();}};}

編譯javac?Month2.java

只寫一個(gè)Month2.java,這里是IncorrectMonthException.java也會(huì)自動(dòng)編譯

反編譯javap?-c?-verbose?Month2.classjavap?-c?-verbose?IncorrectMonthException.class

IncorrectMonthException方法public?IncorrectMonthException(int);????descriptor:?(I)V????flags:?ACC_PUBLIC????Code:??????stack=2,?locals=2,?args_size=2?????????0:?aload_0?????????1:?invokespecial?#1??????????????????//?Method?java/lang/Exception."":()V?????????4:?aload_0?????????5:?iload_1?????????6:?putfield??????#2??????????????????//?Field?index:I?????????9:?return

本質(zhì)上,IncorrectMonthException類只是做了對(duì)象構(gòu)造,還有訪問器方法。IncorrectMonthException類是繼承于Exception類,所以,IncorrectMonthException類構(gòu)造之前,構(gòu)造父類Exception,然后傳遞整數(shù)給IncorrectMonthException類作為唯一的屬性值

getIndex方法public?int?getIndex();????descriptor:?()I????flags:?ACC_PUBLIC????Code:??????stack=1,?locals=1,?args_size=1?????????0:?aload_0?????????1:?getfield??????#2??????????????????//?Field?index:I?????????4:?ireturn

getIndex()只是一個(gè)訪問器,引用到IncorrectMonthException類,被傳到局部變量的索引值0的位置(this指針),用aload_0指令取得, 用getfield指令取得對(duì)象的整數(shù)值,用ireturn指令將其返回。

再看Month2.class的get_month方法public?static?java.lang.String?get_month(int)?throws?IncorrectMonthException;????descriptor:?(I)Ljava/lang/String;????flags:?ACC_PUBLIC,?ACC_STATIC????Code:??????stack=3,?locals=1,?args_size=1?????????0:?iload_0?????????1:?iflt??????????10?????????4:?iload_0?????????5:?bipush????????11?????????7:?if_icmple?????19????????10:?new???????????#2??????????????????//?class?IncorrectMonthException????????13:?dup????????14:?iload_0????????15:?invokespecial?#3??????????????????//?Method?IncorrectMonthException."":(I)V????????18:?athrow????????19:?getstatic?????#4??????????????????//?Field?months:[Ljava/lang/String;????????22:?iload_0????????23:?aaload????????24:?areturn

部分指令解釋

0: iload_0 //第0個(gè)變量(即變量i)壓入操作數(shù)棧

1: iflt 10 //當(dāng)棧頂int型數(shù)值小于0時(shí)跳轉(zhuǎn)到偏移塊10(這里是從棧頂彈出一個(gè)值進(jìn)行比較)

4: iload_0 //第0個(gè)變量(即變量i)壓入操作數(shù)棧

5: bipush 11 //將11壓入操作數(shù)棧

7: if_icmple 19 //會(huì)從棧中彈出兩個(gè)值進(jìn)行比較,如果第二個(gè)(變量i)小于或者等于第一個(gè)(數(shù)字11),那么跳轉(zhuǎn)到偏移位19

10: new #2 // class IncorrectMonthException //創(chuàng)建IncorrectMonthException對(duì)象的引用并壓入棧頂

13: dup //復(fù)制棧頂值壓入棧頂

14: iload_0 //第0個(gè)變量(即變量i)壓入操作數(shù)棧

15: invokespecial #3 // Method IncorrectMonthException."":(I)V //調(diào)用IncorrectMonthException的""方法,這里需要從棧頂彈出兩個(gè)值,1是IncorrectMonthException對(duì)象的引用,2是變量i

18: athrow //將棧頂?shù)漠惓伋?/p>

19: getstatic #4 // Field months:[Ljava/lang/String; //獲取靜態(tài)成員months數(shù)組的引用壓入棧

22: iload_0 //第0個(gè)變量(即變量i)壓入操作數(shù)棧

23: aaload //棧頂彈出兩個(gè)值,將引用型數(shù)組指定索引的值推送至棧頂,這里索引i為第一個(gè)彈出值,數(shù)組引用months為第二個(gè)彈出值,即months[i]的值送入棧頂

24: areturn //返回棧頂值

Month2.class的main方法public?static?void?main(java.lang.String[]);????descriptor:?([Ljava/lang/String;)V????flags:?ACC_PUBLIC,?ACC_STATIC????Code:??????stack=3,?locals=2,?args_size=1?????????0:?getstatic?????#5??????????????????//?Field?java/lang/System.out:Ljava/io/PrintStream;?????????3:?bipush????????100?????????5:?invokestatic??#6??????????????????//?Method?get_month:(I)Ljava/lang/String;?????????8:?invokevirtual?#7??????????????????//?Method?java/io/PrintStream.println:(Ljava/lang/String;)V????????11:?goto??????????47????????14:?astore_1????????15:?getstatic?????#5??????????????????//?Field?java/lang/System.out:Ljava/io/PrintStream;????????18:?new???????????#8??????????????????//?class?java/lang/StringBuilder????????21:?dup????????22:?invokespecial?#9??????????????????//?Method?java/lang/StringBuilder."":()V????????25:?ldc???????????#10?????????????????//?String?incorrect?month?index:????????27:?invokevirtual?#11?????????????????//?Method?java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;????????30:?aload_1????????31:?invokevirtual?#12?????????????????//?Method?IncorrectMonthException.getIndex:()I????????34:?invokevirtual?#13?????????????????//?Method?java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;????????37:?invokevirtual?#14?????????????????//?Method?java/lang/StringBuilder.toString:()Ljava/lang/String;????????40:?invokevirtual?#7??????????????????//?Method?java/io/PrintStream.println:(Ljava/lang/String;)V????????43:?aload_1????????44:?invokevirtual?#15?????????????????//?Method?IncorrectMonthException.printStackTrace:()V????????47:?return??????Exception?table:?????????from????to??target?type?????????????0????11????14???Class?IncorrectMonthException

注意Exception table:文字以及下面的表數(shù)據(jù)

異常表的第一行數(shù)據(jù)表示從0到11行若發(fā)生異常,則跳轉(zhuǎn)到偏移塊14的位置,同時(shí)也指明異常的類型為IncorrectMonthException類

異常從偏移塊14開始執(zhí)行,如果沒有這個(gè)異常表的數(shù)據(jù),則偏移塊14后的指令不會(huì)被執(zhí)行

這有個(gè)例子,IDA是如何顯示異常表:

原作者用的自己電腦里的random.class,這里用剛才的Month2.class替代.catch?IncorrectMonthException?from?met003_begin?to?met003_11?using?\met003_14

總結(jié)

以上是生活随笔為你收集整理的java逆向_Java逆向基础之异常的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。