class RegularExpression::Compiler::X86::Compiled

Attributes

buffer[R]

Public Class Methods

new(buffer) click to toggle source
# File lib/regular_expression/compiler/x86.rb, line 9
def initialize(buffer)
  @buffer = buffer
end

Public Instance Methods

disasm() click to toggle source
# File lib/regular_expression/compiler/x86.rb, line 13
def disasm
  output = StringIO.new

  crabstone = Crabstone::Disassembler.new(Crabstone::ARCH_X86, Crabstone::MODE_64)
  crabstone.disasm(buffer.memory.to_s(buffer.pos), buffer.memory.to_i).each do |insn|
    output.printf(
      "0x%<address>x:\t%<instruction>s\t%<details>s\n",
      address: insn.address,
      instruction: insn.mnemonic,
      details: insn.op_str
    )
  end

  output.string
end
to_proc() click to toggle source
# File lib/regular_expression/compiler/x86.rb, line 29
def to_proc
  function = buffer.to_function([Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T], Fiddle::TYPE_SIZE_T)

  lambda do |string|
    value = function.call(string, string.length)
    value if value != string.length + 1
  end
end