@@ -2103,7 +2103,7 @@ static void ZydisSetAttributes(ZydisDecoderState* state, ZydisDecodedInstruction
2103
2103
break ;
2104
2104
}
2105
2105
}
2106
- if (state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_MPX ] &&
2106
+ if (( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_MPX )) &&
2107
2107
instruction -> attributes & ZYDIS_ATTRIB_ACCEPTS_BND )
2108
2108
{
2109
2109
instruction -> attributes |= ZYDIS_ATTRIB_HAS_BND ;
@@ -2167,7 +2167,7 @@ static void ZydisSetAttributes(ZydisDecoderState* state, ZydisDecodedInstruction
2167
2167
if (def -> accepts_NOTRACK )
2168
2168
{
2169
2169
instruction -> attributes |= ZYDIS_ATTRIB_ACCEPTS_NOTRACK ;
2170
- if (state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_CET ] &&
2170
+ if (( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_CET )) &&
2171
2171
(state -> prefixes .offset_notrack >= 0 ))
2172
2172
{
2173
2173
instruction -> attributes |= ZYDIS_ATTRIB_HAS_NOTRACK ;
@@ -4777,31 +4777,31 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
4777
4777
break ;
4778
4778
#endif
4779
4779
case ZYDIS_NODETYPE_FILTER_MODE_AMD :
4780
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_AMD_BRANCHES ] ? 1 : 0 ;
4780
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_AMD_BRANCHES )) ;
4781
4781
break ;
4782
4782
case ZYDIS_NODETYPE_FILTER_MODE_KNC :
4783
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_KNC ] ? 1 : 0 ;
4783
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_KNC )) ;
4784
4784
break ;
4785
4785
case ZYDIS_NODETYPE_FILTER_MODE_MPX :
4786
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_MPX ] ? 1 : 0 ;
4786
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_MPX )) ;
4787
4787
break ;
4788
4788
case ZYDIS_NODETYPE_FILTER_MODE_CET :
4789
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_CET ] ? 1 : 0 ;
4789
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_CET )) ;
4790
4790
break ;
4791
4791
case ZYDIS_NODETYPE_FILTER_MODE_LZCNT :
4792
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_LZCNT ] ? 1 : 0 ;
4792
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_LZCNT )) ;
4793
4793
break ;
4794
4794
case ZYDIS_NODETYPE_FILTER_MODE_TZCNT :
4795
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_TZCNT ] ? 1 : 0 ;
4795
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_TZCNT )) ;
4796
4796
break ;
4797
4797
case ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD :
4798
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_WBNOINVD ] ? 1 : 0 ;
4798
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_WBNOINVD )) ;
4799
4799
break ;
4800
4800
case ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE :
4801
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_CLDEMOTE ] ? 1 : 0 ;
4801
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_CLDEMOTE )) ;
4802
4802
break ;
4803
4803
case ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH :
4804
- index = state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_IPREFETCH ] ? 1 : 0 ;
4804
+ index = !!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_IPREFETCH )) ;
4805
4805
break ;
4806
4806
default :
4807
4807
if (node_type & ZYDIS_NODETYPE_DEFINITION_MASK )
@@ -4854,7 +4854,7 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
4854
4854
(instruction -> meta .category == ZYDIS_CATEGORY_RET )));
4855
4855
instruction -> meta .exception_class = definition -> exception_class ;
4856
4856
4857
- if (!state -> decoder -> decoder_mode [ ZYDIS_DECODER_MODE_MINIMAL ] )
4857
+ if (!( state -> decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_MINIMAL )) )
4858
4858
{
4859
4859
ZydisSetAttributes (state , instruction , definition );
4860
4860
switch (instruction -> encoding )
@@ -4899,23 +4899,15 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
4899
4899
ZyanStatus ZydisDecoderInit (ZydisDecoder * decoder , ZydisMachineMode machine_mode ,
4900
4900
ZydisStackWidth stack_width )
4901
4901
{
4902
- static const ZyanBool decoder_modes [ZYDIS_DECODER_MODE_MAX_VALUE + 1 ] =
4903
- {
4902
+ static const ZyanU32 decoder_modes =
4904
4903
#ifdef ZYDIS_MINIMAL_MODE
4905
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_MINIMAL
4906
- #else
4907
- ZYAN_FALSE , // ZYDIS_DECODER_MODE_MINIMAL
4904
+ (1 << ZYDIS_DECODER_MODE_MINIMAL ) |
4908
4905
#endif
4909
- ZYAN_FALSE , // ZYDIS_DECODER_MODE_AMD_BRANCHES
4910
- ZYAN_FALSE , // ZYDIS_DECODER_MODE_KNC
4911
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_MPX
4912
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_CET
4913
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_LZCNT
4914
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_TZCNT
4915
- ZYAN_FALSE , // ZYDIS_DECODER_MODE_WBNOINVD
4916
- ZYAN_TRUE , // ZYDIS_DECODER_MODE_CLDEMOTE
4917
- ZYAN_FALSE // ZYDIS_DECODER_MODE_IPREFETCH
4918
- };
4906
+ (1 << ZYDIS_DECODER_MODE_MPX ) |
4907
+ (1 << ZYDIS_DECODER_MODE_CET ) |
4908
+ (1 << ZYDIS_DECODER_MODE_LZCNT ) |
4909
+ (1 << ZYDIS_DECODER_MODE_TZCNT ) |
4910
+ (1 << ZYDIS_DECODER_MODE_CLDEMOTE );
4919
4911
4920
4912
if (!decoder )
4921
4913
{
@@ -4945,7 +4937,7 @@ ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode
4945
4937
4946
4938
decoder -> machine_mode = machine_mode ;
4947
4939
decoder -> stack_width = stack_width ;
4948
- ZYAN_MEMCPY ( & decoder -> decoder_mode , & decoder_modes , sizeof ( decoder_modes )) ;
4940
+ decoder -> decoder_mode = decoder_modes ;
4949
4941
4950
4942
return ZYAN_STATUS_SUCCESS ;
4951
4943
}
@@ -4964,7 +4956,14 @@ ZyanStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode,
4964
4956
}
4965
4957
#endif
4966
4958
4967
- decoder -> decoder_mode [mode ] = enabled ;
4959
+ if (enabled )
4960
+ {
4961
+ decoder -> decoder_mode |= (1 << mode );
4962
+ }
4963
+ else
4964
+ {
4965
+ decoder -> decoder_mode &= ~(1 << mode );
4966
+ }
4968
4967
4969
4968
return ZYAN_STATUS_SUCCESS ;
4970
4969
}
@@ -4981,7 +4980,7 @@ ZyanStatus ZydisDecoderDecodeFull(const ZydisDecoder* decoder,
4981
4980
{
4982
4981
return ZYDIS_STATUS_NO_MORE_DATA ;
4983
4982
}
4984
- if (decoder -> decoder_mode [ ZYDIS_DECODER_MODE_MINIMAL ] )
4983
+ if (decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_MINIMAL ) )
4985
4984
{
4986
4985
return ZYAN_STATUS_MISSING_DEPENDENCY ; // TODO: Introduce better status code
4987
4986
}
@@ -5059,7 +5058,7 @@ ZyanStatus ZydisDecoderDecodeOperands(const ZydisDecoder* decoder,
5059
5058
return ZYAN_STATUS_INVALID_ARGUMENT ;
5060
5059
}
5061
5060
5062
- if (decoder -> decoder_mode [ ZYDIS_DECODER_MODE_MINIMAL ] )
5061
+ if (decoder -> decoder_mode & ( 1 << ZYDIS_DECODER_MODE_MINIMAL ) )
5063
5062
{
5064
5063
return ZYAN_STATUS_MISSING_DEPENDENCY ; // TODO: Introduce better status code
5065
5064
}
0 commit comments