1 /// Object-oriented wrapper of instruction groups 2 module capstone.instructiongroup; 3 4 import std.conv: to; 5 6 import capstone.capstone: Capstone; 7 8 import capstone.api: diet; 9 import capstone.error; 10 import capstone.internal.api: cs_group_name; 11 12 /// Architecture-independent instruction group base class 13 abstract class InstructionGroup { 14 private const Capstone cs; 15 package const int _id; 16 17 private this(in Capstone cs, in int id) { 18 this.cs = cs; 19 this._id = id; 20 } 21 22 /// Retrieves instruction group's id as plain integer 23 auto idAsInt() const {return _id;} 24 25 /** Returns friendly string representation of the instruction group's name 26 27 When in diet mode, this API is irrelevant because the engine does not store group names. 28 */ 29 string name() const { 30 if(diet) 31 throw new CapstoneException("Group names are not stored when running Capstone in diet mode", 32 ErrorCode.IrrelevantDataAccessInDietEngine); 33 return cs_group_name(cs.handle, _id).to!string; // TODO: Error handling 34 } 35 } 36 37 /** Class template for architecture-specific instruction groups 38 39 Note that all architecture-specific instances, like `X86InstructionGroup`, instantiate and derive from this one. 40 */ 41 abstract class InstructionGroupImpl(TId) : InstructionGroup if(is(TId == enum)) { 42 package this(in Capstone cs, in int id) { 43 super(cs, id); 44 } 45 46 /// Retrieves instruction group's id 47 auto id() const {return _id.to!TId;} 48 }