disasm 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,13 @@ static VALUE t_init(VALUE self)
8
8
  return INT2FIX(x86_init(opt_none, NULL, NULL));
9
9
  }
10
10
 
11
- static VALUE t_disassemble2yield(VALUE self, VALUE _data, VALUE _rva, VALUE _offset, VALUE _syntax)
11
+ static VALUE t_disassemble2yield(
12
+ VALUE self,
13
+ VALUE _data,
14
+ VALUE _rva,
15
+ VALUE _offset,
16
+ VALUE _syntax,
17
+ VALUE _allow_invalid)
12
18
  {
13
19
  x86_insn_t insn;
14
20
  int size, line_len;
@@ -22,6 +28,7 @@ static VALUE t_disassemble2yield(VALUE self, VALUE _data, VALUE _rva, VALUE _off
22
28
  unsigned int offset = FIX2INT(_offset);
23
29
  int syntax = FIX2INT(_syntax);
24
30
  int n_ok = 0; // number of successfully disassembled instructions
31
+ int allow_invalid = (_allow_invalid == Qtrue);
25
32
 
26
33
  if(!buf || !bufsize) return INT2FIX(0);
27
34
 
@@ -46,10 +53,15 @@ static VALUE t_disassemble2yield(VALUE self, VALUE _data, VALUE _rva, VALUE _off
46
53
  rb_yield_values(2, rb_str_new(line, line_len), INT2FIX(offset+rva));
47
54
  offset += size;
48
55
  n_ok++;
56
+ } else if( allow_invalid ) {
57
+ // invalid instruction : allowed
58
+ line_len = x86_format_insn(&insn, line, LINE_SIZE, syntax);
59
+ rb_yield_values(2, rb_str_new(line, line_len), INT2FIX(offset+rva));
60
+ offset += 1;
49
61
  } else {
50
- // invalid instruction
62
+ // invalid instruction : raise exception
51
63
  char err_buf[1024];
52
- sprintf(err_buf, "raise InvalidInstruction.new(0x%x, 0x%x)", offset, offset+rva);
64
+ sprintf(err_buf, "raise InvalidOpcode.new(0x%x, 0x%x)", offset, offset+rva);
53
65
  rb_eval_string(err_buf);
54
66
  //rb_raise(ex,"invalid instruction at offset 0x%x (VA 0x%x)", offset, offset+rva);
55
67
  break;
@@ -65,5 +77,5 @@ void Init_disasm_ext() {
65
77
  x86_init(opt_none, NULL, NULL);
66
78
  mDisasm = rb_define_module("Disasm");
67
79
  rb_define_singleton_method(mDisasm, "init", t_init, 0);
68
- rb_define_singleton_method(mDisasm, "disassemble2yield", t_disassemble2yield, 4);
80
+ rb_define_singleton_method(mDisasm, "disassemble2yield", t_disassemble2yield, 5);
69
81
  }
@@ -1,3 +1,11 @@
1
1
  require 'mkmf'
2
- have_library 'disasm'
2
+
3
+ unless have_library('disasm')
4
+ abort "libdisasm is missing, please install from http://bastard.sourceforge.net/libdisasm.html"
5
+ end
6
+
7
+ unless have_header('libdis.h')
8
+ abort "libdis.h is missing, please install libdisasm from http://bastard.sourceforge.net/libdisasm.html"
9
+ end
10
+
3
11
  create_makefile 'disasm_ext'
data/lib/disasm.rb CHANGED
@@ -3,7 +3,7 @@ require 'disasm_ext'
3
3
  module Disasm
4
4
 
5
5
  class Exception < ::Exception; end
6
- class InvalidInstruction < Exception
6
+ class InvalidOpcode < Exception
7
7
  attr_accessor :offset, :va
8
8
 
9
9
  def initialize offset, va
@@ -31,13 +31,15 @@ module Disasm
31
31
  else 1 # default to native syntax
32
32
  end
33
33
 
34
+ allow_invalid = params[:allow_invalid] ? true : false
35
+
34
36
  if block_given?
35
- disassemble2yield(data, rva, offset, syntax) do |x,va|
37
+ disassemble2yield(data, rva, offset, syntax, allow_invalid) do |x,va|
36
38
  yield x,va
37
39
  end
38
40
  else
39
41
  r = []
40
- disassemble2yield(data, rva, offset, syntax) do |x|
42
+ disassemble2yield(data, rva, offset, syntax, allow_invalid) do |x|
41
43
  r << x
42
44
  end
43
45
  r
@@ -1,3 +1,3 @@
1
1
  module Disasm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-04-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: x86 disassembler
15
15
  email: