@@ -15,9 +15,7 @@ You should have received a copy of the GNU General Public License
1515
1616using System ;
1717using System . Collections . Generic ;
18- using System . Globalization ;
1918using System . Linq ;
20- using System . Text . RegularExpressions ;
2119using de4dot . blocks ;
2220using de4dot . blocks . cflow ;
2321using dnlib . DotNet ;
@@ -429,15 +427,16 @@ private bool FindStartEnd(IList<Instruction> instrs, out int startIndex, out int
429427 for ( var y = newEndIndex ; y >= 0 ; y -- )
430428 if ( instrs [ y ] . IsBr ( ) )
431429 {
432- var offset =
433- int . Parse (
434- Regex . Match (
435- instrs [ y ] . Operand . ToString ( ) ?? throw new InvalidOperationException ( ) ,
436- "IL_(.*?): .*?" ) . Groups [ 1 ] . Value ,
437- NumberStyles . HexNumber ) ;
438- var instr = instrs . FirstOrDefault ( x => ( int ) x . Offset == offset ) ;
439- if ( instr == null )
440- break ;
430+ if ( instrs [ y ] . Operand is not Instruction instr )
431+ continue ;
432+ if ( instrs . IndexOf ( instr ) < y )
433+ {
434+ if ( instrs [ y - 1 ] . Operand is not Instruction )
435+ continue ;
436+ instr = instrs [ y - 1 ] . Operand as Instruction ;
437+ if ( instrs . IndexOf ( instr ) < y )
438+ continue ;
439+ }
441440 newStartIndex = instrs . IndexOf ( instr ) ;
442441 ckStartIndex = newStartIndex ;
443442 break ;
@@ -818,15 +817,16 @@ private bool FindStartEnd(IList<Instruction> instrs, out int startIndex, out int
818817 for ( var y = newEndIndex ; y >= 0 ; y -- )
819818 if ( instrs [ y ] . IsBr ( ) )
820819 {
821- var offset =
822- int . Parse (
823- Regex . Match (
824- instrs [ y ] . Operand . ToString ( ) ?? throw new InvalidOperationException ( ) ,
825- "IL_(.*?): .*?" ) . Groups [ 1 ] . Value ,
826- NumberStyles . HexNumber ) ;
827- var instr = instrs . FirstOrDefault ( x => ( int ) x . Offset == offset ) ;
828- if ( instr == null )
829- break ;
820+ if ( instrs [ y ] . Operand is not Instruction instr )
821+ continue ;
822+ if ( instrs . IndexOf ( instr ) < y )
823+ {
824+ if ( instrs [ y - 1 ] . Operand is not Instruction )
825+ continue ;
826+ instr = instrs [ y - 1 ] . Operand as Instruction ;
827+ if ( instrs . IndexOf ( instr ) < y )
828+ continue ;
829+ }
830830 newStartIndex = instrs . IndexOf ( instr ) ;
831831 ckStartIndex = newStartIndex ;
832832 break ;
@@ -1043,15 +1043,16 @@ private bool FindStartEnd(IList<Instruction> instrs, out int startIndex, out int
10431043 for ( var y = newEndIndex ; y >= 0 ; y -- )
10441044 if ( instrs [ y ] . IsBr ( ) )
10451045 {
1046- var offset =
1047- int . Parse (
1048- Regex . Match (
1049- instrs [ y ] . Operand . ToString ( ) ?? throw new InvalidOperationException ( ) ,
1050- "IL_(.*?): .*?" ) . Groups [ 1 ] . Value ,
1051- NumberStyles . HexNumber ) ;
1052- var instr = instrs . FirstOrDefault ( x => ( int ) x . Offset == offset ) ;
1053- if ( instr == null )
1054- break ;
1046+ if ( instrs [ y ] . Operand is not Instruction instr )
1047+ continue ;
1048+ if ( instrs . IndexOf ( instr ) < y )
1049+ {
1050+ if ( instrs [ y - 1 ] . Operand is not Instruction )
1051+ continue ;
1052+ instr = instrs [ y - 1 ] . Operand as Instruction ;
1053+ if ( instrs . IndexOf ( instr ) < y )
1054+ continue ;
1055+ }
10551056 newStartIndex = instrs . IndexOf ( instr ) ;
10561057 ckStartIndex = newStartIndex ;
10571058 break ;
0 commit comments