2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespace X86Disassembler.X86;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/// <summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/// Represents an x86 instruction
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/// </summary>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public class Instruction
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// <summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /// Gets or sets the address of the instruction
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// </summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    public uint Address { get; set; }
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// <summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /// Gets or sets the mnemonic of the instruction
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// </summary>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public string Mnemonic { get; set; } = string.Empty;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// <summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /// Gets or sets the operands of the instruction
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// </summary>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public string Operands { get; set; } = string.Empty;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// <summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /// Gets or sets the raw bytes of the instruction
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// </summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 23:40:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    public byte[] RawBytes { get; set; } = [];
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// <summary>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// Returns a string representation of the instruction
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /// </summary>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /// <returns>A string representation of the instruction</returns>
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public override string ToString()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 19:57:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // Format the address
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string addressStr = $"{Address:X8}";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Format the raw bytes
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string bytesStr = string.Empty;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        foreach (byte b in RawBytes)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            bytesStr += $"{b:X2} ";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Pad the bytes string to a fixed width
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bytesStr = bytesStr.PadRight(30);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Format the instruction
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string instructionStr = Mnemonic;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!string.IsNullOrEmpty(Operands))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            instructionStr += " " + Operands;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return $"  {addressStr}  {bytesStr}{instructionStr}";
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-12 18:41:40 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |