Skip to content

Instantly share code, notes, and snippets.

@redknightlois
Last active July 12, 2016 18:29
Show Gist options
  • Save redknightlois/38e08de004d9d7bfa77abdaab0b67ae1 to your computer and use it in GitHub Desktop.
Save redknightlois/38e08de004d9d7bfa77abdaab0b67ae1 to your computer and use it in GitHub Desktop.
Try-Catch
00007FFAEE230B92 sub esp,20h
00007FFAEE230B95 mov rcx,7FFB4DA35CC8h
00007FFAEE230B9F call 00007FFB4DF47FB0
00007FFAEE230BA4 mov rsi,rax
00007FFAEE230BA7 mov rcx,rsi
00007FFAEE230BAA call 00007FFB4D3EA1D0
00007FFAEE230BAF mov rcx,rsi
00007FFAEE230BB2 call 00007FFB4DD0DD70
int i = 0;
00007FFAEE240B20 sub rsp,28h
if (TryCanThrow())
00007FFAEE240B24 call 00007FFAEE240078
00007FFAEE240B29 test eax,eax
00007FFAEE240B2B je 00007FFAEE240B34
{
i++;
00007FFAEE240B2D mov ecx,1
00007FFAEE240B32 jmp 00007FFAEE240B39
else
{
i = 100;
00007FFAEE240B34 mov ecx,64h
}
Console.WriteLine(i);
00007FFAEE240B39 call 00007FFAEE2406E0
00007FFAEE240B3E nop
00007FFAEE240B3F add rsp,28h
00007FFAEE240B43 ret
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool TryCanThrow()
{
if (errorCondition == true)
return false;
else
return true;
}
public static void Main(string[] args)
{
int i = 0;
if (TryCanThrow())
{
i++;
}
else
{
i = 100;
}
Console.WriteLine(i);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void CanThrow()
{
throw new NotImplementedException();
}
public static void Main(string[] args)
{
int i = 0;
try
{
CanThrow();
i++;
}
catch (NotImplementedException)
{
i = 100;
}
Console.WriteLine(i);
}
int i = 0;
00007FFAEE240B22 sub esp,30h
00007FFAEE240B25 lea rbp,[rsp+30h]
00007FFAEE240B2A mov qword ptr [rbp-10h],rsp
try
{
CanThrow();
00007FFAEE240B2E call 00007FFAEE240078
i++;
00007FFAEE240B33 mov dword ptr [rbp-4],1
Console.WriteLine(i);
00007FFAEE240B3A mov ecx,dword ptr [rbp-4]
Console.WriteLine(i);
00007FFAEE240B3D call 00007FFAEE2406E0
00007FFAEE240B42 nop
00007FFAEE240B43 lea rsp,[rbp]
00007FFAEE240B47 pop rbp
00007FFAEE240B48 ret
int i = 0;
00007FFAEE240B49 push rbp
00007FFAEE240B4A sub rsp,30h
00007FFAEE240B4E mov rbp,qword ptr [rcx+20h]
00007FFAEE240B52 mov qword ptr [rsp+20h],rbp
00007FFAEE240B57 lea rbp,[rbp+30h]
{
i = 100;
00007FFAEE240B5B mov dword ptr [rbp-4],64h
00007FFAEE240B62 lea rax,[7FFAEE240B3Ah]
00007FFAEE240B69 add rsp,30h
00007FFAEE240B6D pop rbp
00007FFAEE240B6E ret
int i = 0;
00007FFAEE220B20 sub rsp,28h
00007FFAEE220B24 call 00007FFAEE220078
i++;
00007FFAEE220B29 mov ecx,1
00007FFAEE220B2E call 00007FFAEE2206E0
00007FFAEE220B33 nop
00007FFAEE220B34 add rsp,28h
00007FFAEE220B38 ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment