rbdasm/dasm.c
//
// Performs a disassembly on the supplied buffer and returns an array of
// Instruction instances.
//
Performs a disassembly on the supplied buffer and returns an array of
Instruction instances.
Performs a disassembly on the supplied buffer and returns an array of Instruction instances .
static VALUE dasm_disassemble(VALUE self, VALUE buf)
{
	PDASM_OBJECT obj;
	INSTRUCTION  inst;
	VALUE        instructions = rb_ary_new();
	int          offset = 0, len;
	int          use_block = rb_block_given_p();
	buf = StringValue(buf);
	len = RSTRING(buf)->len;
	rb_dasm_cast(self, obj);
	while (offset < len)
	{
		VALUE	rb_inst;
		BYTE  *current = (BYTE *)(RSTRING(buf)->ptr + offset);
		if (!get_instruction(&inst, current, obj->mode))
			break;
		rb_inst = instruction_new(instr_klass, self, &inst, current);
		if (!use_block)
		{
			if (!offset)
				instructions = rb_ary_new();
			rb_ary_push(instructions, rb_inst);
		}
		else
			rb_yield_values(2, rb_inst, INT2FIX(offset));
		offset += inst.length;
	}
	return (!use_block) ? instructions : offset;
}
static VALUE dasm_disassemble ( VALUE self , VALUE buf ) { PDASM_OBJECT obj ; INSTRUCTION inst ; VALUE instructions = rb_ary_new ( ) ; int offset = 0 , len ; int use_block = rb_block_given_p ( ) ; buf = StringValue ( buf ) ; len = RSTRING ( buf ) -> len ; rb_dasm_cast ( self , obj ) ; while ( offset < len ) { VALUE rb_inst ; BYTE * current = ( BYTE * ) ( RSTRING ( buf ) -> ptr + offset ) ; if ( ! get_instruction ( & inst , current , obj -> mode ) ) break ; rb_inst = instruction_new ( instr_klass , self , & inst , current ) ; if ( ! use_block ) { if ( ! offset ) instructions = rb_ary_new ( ) ; rb_ary_push ( instructions , rb_inst ) ; } else rb_yield_values ( 2 , rb_inst , INT2FIX ( offset ) ) ; offset += inst . length ; } return ( ! use_block ) ? instructions : offset ; }
Performs a disassembly on the supplied buffer and returns an array of
Instruction instances.
Performs a disassembly on the supplied buffer and returns an array of Instruction instances .