0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 11:51:17 +03:00

refactor xors

This commit is contained in:
bird_egop 2025-04-13 19:35:28 +03:00
parent 30676b36a1
commit b0ade45f1b
7 changed files with 15 additions and 42 deletions

View File

@ -13,6 +13,9 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Aud_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F15_003F87bd9007_003Fud_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Audis86_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F95_003F953bbb0f_003Fudis86_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">C:\Users\Admin\AppData\Local\JetBrains\Rider2024.3\resharper-host\temp\Rider\vAny\CoverageData\_ParkanPlayground.1073341822\Snapshot\snapshot.utdcvr</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=47ebaefe_002Da806_002D4565_002Dabe7_002D4f14ac675135/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;X86DisassemblerTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="&amp;lt;X86DisassemblerTests&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=87a33e46_002D2816_002D434f_002D972a_002D703eb7a78476/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;And&gt;&#xD;
@ -20,7 +23,5 @@
&lt;Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="&amp;lt;X86DisassemblerTests&amp;gt;" /&gt;&#xD;
&lt;/And&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ea256cae_002Df513_002D419e_002D992a_002D13b500b3c433/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;X86DisassemblerTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="&amp;lt;X86DisassemblerTests&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String>
</wpf:ResourceDictionary>

View File

@ -67,10 +67,8 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
return false;
}
// Read the immediate value and sign-extend it
byte imm8 = Decoder.ReadByte();
// Sign-extend to 16 bits by converting to sbyte first
short imm16 = (short)((sbyte)imm8);
// Read the immediate value and sign-extend it to 16 bits
short imm16 = (sbyte)Decoder.ReadByte();
// Format the immediate value
string immStr = $"0x{(ushort)imm16:X4}";

View File

@ -67,10 +67,8 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
return false;
}
// Read the immediate value and sign-extend it
byte imm8 = Decoder.ReadByte();
// Sign-extend to 32 bits by converting to sbyte first
int imm32 = (int)((sbyte)imm8);
// Read the immediate value and sign-extend it to 32 bits
int imm32 = (sbyte)Decoder.ReadByte();
// Format the immediate value
string immStr;
@ -79,15 +77,10 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
// For negative values, show the full sign-extended 32-bit value
immStr = $"0x{imm32:X8}";
}
else if (imm8 == 0)
{
// For zero, use the expected format
immStr = "0x00";
}
else
{
// For positive values, show without leading zeros
immStr = $"0x{imm8:X}";
immStr = $"0x{imm32:X2}";
}
// Set the operands

View File

@ -68,8 +68,7 @@ public class XorImmWithRm8Handler : InstructionHandler
}
// Read the immediate value
byte imm8 = CodeBuffer[position];
Decoder.SetPosition(position + 1);
byte imm8 = Decoder.ReadByte();
// Format the immediate value
string immStr = $"0x{imm8:X2}";

View File

@ -45,16 +45,7 @@ public class XorMemRegHandler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3);
byte rm = (byte)(modRM & 0x07);
// Decode the destination operand
string destOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Get the source register
string srcReg = GetRegister32(reg);

View File

@ -45,16 +45,7 @@ public class XorRegMemHandler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3);
byte rm = (byte)(modRM & 0x07);
// Decode the source operand
string srcOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, srcOperand) = ModRMDecoder.ReadModRM();
// Get the destination register
string destReg = GetRegister32(reg);

View File

@ -281,6 +281,6 @@ public class Group1InstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("xor", instruction.Mnemonic);
Assert.Equal("esi, 0x00000042", instruction.Operands);
Assert.Equal("esi, 0x42", instruction.Operands);
}
}