Class: TurboRex::CStruct::NativeParser

Inherits:
Object
  • Object
show all
Defined in:
lib/turborex/cstruct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, opts = {}) ⇒ NativeParser

Returns a new instance of NativeParser.



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/turborex/cstruct.rb', line 481

def initialize(str, opts={})
  @cpu = opts[:cpu].new rescue nil || Metasm::Ia32.new
  @parser = @cpu.new_cparser

  if opts[:predefined] # TODO: more Predefined macros
    if opts[:cpu] == Metasm::Ia32
      @parser.lexer.define("_WIN32")
    elsif opts[:cpu] == Metasm::X86_64
      @parser.lexer.define("_WIN64")
      @parser.llp64
    end
  end

  @parser.send(opts[:data_model].to_s) if opts[:data_model]
  
  if opts[:visual_studio]
    @parser.prepare_visualstudio
  end

  if opts[:gcc]
    @parser.prepare_gcc
  end

  @include_path = opts[:include_path] || []
  perform_include_path
  @parser.lexer.warn_redefinition = false
  @parser.lexer.include_search_path = @include_path
  if opts[:file]
    @parser.parse_file opts[:file]
  elsif str
    @parser.parse str
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



527
528
529
# File 'lib/turborex/cstruct.rb', line 527

def method_missing(m, *args, &block)
  @parser.send(m, *args, &block)
end

Instance Attribute Details

#cpuObject (readonly)

Returns the value of attribute cpu.



479
480
481
# File 'lib/turborex/cstruct.rb', line 479

def cpu
  @cpu
end

#parserObject (readonly)

Returns the value of attribute parser.



478
479
480
# File 'lib/turborex/cstruct.rb', line 478

def parser
  @parser
end

Instance Method Details

#[](name) ⇒ Object



523
524
525
# File 'lib/turborex/cstruct.rb', line 523

def [](name)
  NativeStructProxy.new(@parser, name)
end

#find_c_struct(name) ⇒ Object



515
516
517
# File 'lib/turborex/cstruct.rb', line 515

def find_c_struct(name)
  @parser.find_c_struct(name)
end

#find_c_type(name) ⇒ Object



519
520
521
# File 'lib/turborex/cstruct.rb', line 519

def find_c_type(name)
  @parser.find_c_type(name)
end