Skip to content

Instantly share code, notes, and snippets.

@MostParsingVex
Created August 21, 2017 08:43
Show Gist options
  • Save MostParsingVex/e825ad434fd5fda187463d8144b96769 to your computer and use it in GitHub Desktop.
Save MostParsingVex/e825ad434fd5fda187463d8144b96769 to your computer and use it in GitHub Desktop.
XMM register preserving SIGILL probe for AES-NI instructions on x86 and AMD64. Should work on Linux, BSD, OSX, Windows
#include<stdio.h>
#include<setjmp.h>
#include<signal.h>
jmp_buf state;
void sigill_handler( int i ) {
signal( SIGILL, SIG_DFL );
longjmp( state, 1 );
}
//register preserving aesenc/aesdec sequence
#if(unix)
const
#else //windows
#pragma section("foo", execute)
__declspec(allocate("foo"))
#endif
char aesni[]="\x66\x0F\x38\xDD\xC1\x66\x0F\x38\xDF\xC1\xc3";
int aesnidetect( ) {
signal( SIGILL, sigill_handler );
int r = setjmp( state );
if( !r ) ((void(*)())(char*)aesni)();
return !r;
}
int main(){
puts( aesnidetect()?"YES":"NO" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment