@@ -138,9 +138,10 @@ internal static bool HasIntegerNumberExtendedType()
138
138
if ( value == null )
139
139
return null ;
140
140
141
+ tagAddress = address + Schema . LuaValueData . typeAddress . GetValueOrDefault ( 0 ) ;
142
+
141
143
if ( double . IsNaN ( value . Value ) )
142
144
{
143
- tagAddress = address + Schema . LuaValueData . typeAddress . GetValueOrDefault ( 0 ) ;
144
145
typeTag = DebugHelpers . ReadIntVariable ( process , tagAddress , batch ) ;
145
146
}
146
147
else
@@ -164,9 +165,10 @@ internal static bool HasIntegerNumberExtendedType()
164
165
if ( value == null )
165
166
return null ;
166
167
168
+ tagAddress = address + ( ulong ) DebugHelpers . GetPointerSize ( process ) ;
169
+
167
170
if ( double . IsNaN ( value . Value ) )
168
171
{
169
- tagAddress = address + ( ulong ) DebugHelpers . GetPointerSize ( process ) ;
170
172
typeTag = DebugHelpers . ReadIntVariable ( process , tagAddress , batch ) ;
171
173
}
172
174
else
@@ -632,6 +634,37 @@ internal static LuaValueDataBase ReadValueOfType(DkmProcess process, int typeTag
632
634
return null ;
633
635
}
634
636
637
+ internal static bool WriteTypeTag ( DkmProcess process , ulong tagAddress , int tagValue )
638
+ {
639
+ if ( Schema . LuaValueData . available )
640
+ {
641
+ // Handle NAN trick
642
+ if ( Schema . LuaValueData . doubleAddress . HasValue )
643
+ {
644
+ if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , tagValue | 0x7FF7A500 ) )
645
+ return false ;
646
+ }
647
+ else
648
+ {
649
+ if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , tagValue ) )
650
+ return false ;
651
+ }
652
+ }
653
+ else if ( luaVersion == 502 && ! DebugHelpers . Is64Bit ( process ) )
654
+ {
655
+ // union { struct { Value v__; int tt__; } i; double d__; } u
656
+ if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , tagValue | 0x7FF7A500 ) ) // Handle NAN trick
657
+ return false ;
658
+ }
659
+ else
660
+ {
661
+ if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , tagValue ) )
662
+ return false ;
663
+ }
664
+
665
+ return true ;
666
+ }
667
+
635
668
internal static bool TryWriteValue ( DkmProcess process , DkmStackWalkFrame stackFrame , DkmInspectionSession inspectionSession , ulong tagAddress , ulong valueAddress , LuaValueDataBase value , out string errorText )
636
669
{
637
670
if ( tagAddress == 0 || valueAddress == 0 )
@@ -648,7 +681,7 @@ bool Failed(string text, out string errorText_)
648
681
649
682
if ( value is LuaValueDataNil )
650
683
{
651
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) LuaExtendedType . Nil ) )
684
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) LuaExtendedType . Nil ) )
652
685
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
653
686
654
687
if ( ! DebugHelpers . TryWriteIntVariable ( process , valueAddress , 0 ) )
@@ -661,15 +694,15 @@ bool Failed(string text, out string errorText_)
661
694
{
662
695
if ( LuaHelpers . luaVersion == 504 )
663
696
{
664
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) ( sourceBool . value ? LuaExtendedType . BooleanTrue : LuaExtendedType . Boolean ) ) )
697
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) ( sourceBool . value ? LuaExtendedType . BooleanTrue : LuaExtendedType . Boolean ) ) )
665
698
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
666
699
667
700
if ( ! DebugHelpers . TryWriteIntVariable ( process , valueAddress , 0 ) )
668
701
return Failed ( "Failed to modify target process memory (value)" , out errorText ) ;
669
702
}
670
703
else
671
704
{
672
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) LuaExtendedType . Boolean ) )
705
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) LuaExtendedType . Boolean ) )
673
706
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
674
707
675
708
if ( ! DebugHelpers . TryWriteIntVariable ( process , valueAddress , sourceBool . value ? 1 : 0 ) )
@@ -684,7 +717,7 @@ bool Failed(string text, out string errorText_)
684
717
if ( sourceNumber . extendedType == GetFloatNumberExtendedType ( ) || ! LuaHelpers . HasIntegerNumberExtendedType ( ) )
685
718
{
686
719
// Write tag first here, unioned value will go over it when neccessary
687
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) GetFloatNumberExtendedType ( ) ) )
720
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) GetFloatNumberExtendedType ( ) ) )
688
721
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
689
722
690
723
if ( ! DebugHelpers . TryWriteDoubleVariable ( process , valueAddress , sourceNumber . value ) )
@@ -696,7 +729,7 @@ bool Failed(string text, out string errorText_)
696
729
697
730
if ( sourceNumber . extendedType == GetIntegerNumberExtendedType ( ) && LuaHelpers . HasIntegerNumberExtendedType ( ) )
698
731
{
699
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) GetIntegerNumberExtendedType ( ) ) )
732
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) GetIntegerNumberExtendedType ( ) ) )
700
733
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
701
734
702
735
if ( ! DebugHelpers . TryWriteIntVariable ( process , valueAddress , ( int ) sourceNumber . value ) )
@@ -742,15 +775,15 @@ bool Failed(string text, out string errorText_)
742
775
if ( ! registryAddress . HasValue )
743
776
return Failed ( "Failed to create Lua string value" , out errorText ) ;
744
777
745
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) value . extendedType ) )
778
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) value . extendedType ) )
746
779
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
747
780
748
781
if ( ! DebugHelpers . TryWritePointerVariable ( process , valueAddress , registryAddress . Value ) )
749
782
return Failed ( "Failed to modify target process memory (value)" , out errorText ) ;
750
783
}
751
784
else
752
785
{
753
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) value . extendedType ) )
786
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) value . extendedType ) )
754
787
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
755
788
756
789
ulong luaStringOffset = LuaHelpers . GetStringDataOffset ( process ) ;
@@ -785,7 +818,7 @@ bool Failed(string text, out string errorText_)
785
818
786
819
bool collectable = LuaHelpers . luaVersion == 501 ? false : ( value is LuaValueDataTable || value is LuaValueDataLuaFunction || value is LuaValueDataExternalClosure || value is LuaValueDataUserData || value is LuaValueDataThread ) ;
787
820
788
- if ( ! DebugHelpers . TryWriteIntVariable ( process , tagAddress , ( int ) value . extendedType + ( collectable ? 64 : 0 ) ) )
821
+ if ( ! WriteTypeTag ( process , tagAddress , ( int ) value . extendedType + ( collectable ? 64 : 0 ) ) )
789
822
return Failed ( "Failed to modify target process memory (tag)" , out errorText ) ;
790
823
791
824
if ( ! DebugHelpers . TryWritePointerVariable ( process , valueAddress , targetAddress ) )
0 commit comments