/// <summary> /// Set a Disassembler Option. /// </summary> /// <param name="hDisassembler"> /// A disassembler handle. /// </param> /// <param name="optionType"> /// A type of option to set. /// </param> /// <param name="optionValue"> /// A value to set the option to. /// </param> /// <exception cref="Gee.External.Capstone.CapstoneException"> /// Thrown if the option could not be set. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown if the disassembler handle is invalid, or if the option is invalid. /// </exception> /// <exception cref="System.NotSupportedException"> /// Thrown if the option is equal to <see cref="NativeDisassemblerOptionType.SetSkipDataConfig" />. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if the disassembler handle is disposed. /// </exception> internal static void SetDisassemblerOption(NativeDisassemblerHandle hDisassembler, NativeDisassemblerOptionType optionType, NativeDisassemblerOptionValue optionValue) { if (optionType == NativeDisassemblerOptionType.SetSkipDataConfig) { var detailMessage = $"A disassembler option ({optionType}) is unsupported."; throw new NotSupportedException(detailMessage); } // ... // // Throws an exception if the operation fails. var resultCode = NativeCapstoneImport.SetDisassemblerOption(hDisassembler, optionType, (IntPtr)optionValue); if (resultCode != NativeCapstoneResultCode.Ok) { if (resultCode == NativeCapstoneResultCode.InvalidHandle2) { var detailMessage = $"A disassembler handle ({nameof(hDisassembler)}) is invalid."; throw new ArgumentException(detailMessage, nameof(hDisassembler)); } else if (resultCode == NativeCapstoneResultCode.InvalidOption) { var detailMessage = $"An option ({nameof(optionType)}) is invalid."; throw new ArgumentException(detailMessage, nameof(optionType)); } else { var detailMessage = $"A disassembler option ({optionType}) could not be set."; throw new CapstoneException(detailMessage); } } }
/// <summary> /// Set Disassembler Instruction Mnemonic Option. /// </summary> /// <param name="hDisassembler"> /// A disassembler handle. /// </param> /// <param name="optionValue"> /// A value to set the instruction mnemonic option to. /// </param> /// <exception cref="Gee.External.Capstone.CapstoneException"> /// Thrown if the instruction mnemonic option could not be set. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown if the disassembler handle is invalid. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if the disassembler handle is disposed. /// </exception> internal static void SetInstructionMnemonicOption(NativeDisassemblerHandle hDisassembler, ref NativeInstructionMnemonicOptionValue optionValue) { var pOptionValue = IntPtr.Zero; try { pOptionValue = MarshalExtension.AllocHGlobal <NativeInstructionMnemonicOptionValue>(); Marshal.StructureToPtr(optionValue, pOptionValue, false); // ... // // Throws an exception if the operation fails. const NativeDisassemblerOptionType optionType = NativeDisassemblerOptionType.SetMnemonic; var resultCode = NativeCapstoneImport.SetDisassemblerOption(hDisassembler, optionType, pOptionValue); if (resultCode != NativeCapstoneResultCode.Ok) { if (resultCode == NativeCapstoneResultCode.InvalidHandle2) { var detailMessage = $"A disassembler handle ({nameof(hDisassembler)}) is invalid."; throw new ArgumentException(detailMessage, nameof(hDisassembler)); } else { var detailMessage = $"A disassembler option ({optionType}) could not be set."; throw new CapstoneException(detailMessage); } } } finally { if (pOptionValue != IntPtr.Zero) { Marshal.FreeHGlobal(pOptionValue); } } }
internal static void SetSkipDataOption(NativeDisassemblerHandle hDisassembler, ref NativeSkipDataOptionValue optionValue) { var pOptionValue = IntPtr.Zero; try { pOptionValue = MarshalExtension.AllocHGlobal <NativeSkipDataOptionValue>(); Marshal.StructureToPtr(optionValue, pOptionValue, false); // ... // // Throws an exception if the operation fails. const NativeDisassemblerOptionType optionType = NativeDisassemblerOptionType.SetSkipDataConfig; var resultCode = NativeCapstoneImport.SetDisassemblerOption(hDisassembler, optionType, pOptionValue); } finally { if (pOptionValue != IntPtr.Zero) { Marshal.FreeHGlobal(pOptionValue); } } }
/// <summary> /// Set Disassemble Mode Option. /// </summary> /// <param name="hDisassembler"> /// A disassembler handle. /// </param> /// <param name="disassembleMode"> /// A hardware mode for the disassembler to use. /// </param> /// <exception cref="Gee.External.Capstone.CapstoneException"> /// Thrown if the disassemble mode option could not be set. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown if the disassemble mode is invalid. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if the disassembler handle is disposed. /// </exception> internal static void SetDisassembleModeOption(NativeDisassemblerHandle hDisassembler, NativeDisassembleMode disassembleMode) { // ... // // Throws an exception if the operation fails. const NativeDisassemblerOptionType optionType = NativeDisassemblerOptionType.SetDisassembleMode; var resultCode = NativeCapstoneImport.SetDisassemblerOption(hDisassembler, optionType, (IntPtr)disassembleMode); if (resultCode != NativeCapstoneResultCode.Ok) { if (resultCode == NativeCapstoneResultCode.InvalidOption) { var detailMessage = $"An option ({nameof(optionType)}) is invalid."; throw new ArgumentException(detailMessage, nameof(optionType)); } else { var detailMessage = $"A disassembler option ({optionType}) could not be set."; throw new CapstoneException(detailMessage); } } }