Module: Ragweed::Rasm

Included in:
Blocks, Blocks
Defined in:
lib/ragweed/rasm/isa.rb,
lib/ragweed/rasm.rb,
lib/ragweed/rasm/bblock.rb

Overview

Rasm: a half-assed X86 assembler.

Rasm implements a small subset of the X86 instruction set, and only in simple encodings.

However, Rasm implements enough X86 to do interesting things. I wrote it to inject trampoline functions and detours into remote processes. This is Ruby code; you’d never use it where performance matters. It’s not enough to write a decent compiler, but it’s enough to fuck up programs.

Defined Under Namespace

Classes: Add, And, Arith, BadArg, Bblock, Call, Cmp, Dec, Immed, Inc, IncDec, Instruction, Insuff, Int, Iret, Ja, Jae, Jb, Jbe, Jc, Jcc, Je, Jg, Jge, Jl, Jle, Jmp, Jna, Jnae, Jnb, Jnbe, Jnc, Jne, Jng, Jnge, Jnl, Jnle, Jno, Jnp, Jns, Jnz, Jo, Jp, Jpe, Jpo, Js, Jz, Label, Lea, Leave, Mov, Nop, Not, NotImp, Or, Pop, Popad, Popf, Push, Pushad, Pushf, Register, Ret, Retn, Sal, Sar, Shift, Shl, Shr, Sub, Subprogram, Test, TooMan, Xor

Constant Summary collapse

VERSION =

:stopdoc:

File.read(File.join(File.dirname(__FILE__),"..","..","VERSION")).strip
LIBPATH =
::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
Eax =

Clone these to get access to the GPRs. There’s a very clean way to do this in Ruby, with like, module_eval or something, but… time’s a wasting.

Register.new(Register::EAX)
Ecx =
Register.new(Register::ECX)
Edx =
Register.new(Register::EDX)
Ebx =
Register.new(Register::EBX)
Esp =
Register.new(Register::ESP)
Ebp =
Register.new(Register::EBP)
Esi =
Register.new(Register::ESI)
Edi =
Register.new(Register::EDI)
Addl =
Add
Subl =
Sub

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object




21
22
23
# File 'lib/ragweed/rasm/isa.rb', line 21

def method_missing(meth, *args)
  Ragweed::Rasm.const_get(meth).new *args
end

Class Method Details

.eax(opts = {}) ⇒ Object



150
# File 'lib/ragweed/rasm/isa.rb', line 150

def eax(opts={}); Register.eax opts; end

.ebp(opts = {}) ⇒ Object



155
# File 'lib/ragweed/rasm/isa.rb', line 155

def ebp(opts={}); Register.ebp opts; end

.ebx(opts = {}) ⇒ Object



153
# File 'lib/ragweed/rasm/isa.rb', line 153

def ebx(opts={}); Register.ebx opts; end

.ecx(opts = {}) ⇒ Object



151
# File 'lib/ragweed/rasm/isa.rb', line 151

def ecx(opts={}); Register.ecx opts; end

.edi(opts = {}) ⇒ Object



157
# File 'lib/ragweed/rasm/isa.rb', line 157

def edi(opts={}); Register.edi opts; end

.edx(opts = {}) ⇒ Object



152
# File 'lib/ragweed/rasm/isa.rb', line 152

def edx(opts={}); Register.edx opts; end

.esi(opts = {}) ⇒ Object



156
# File 'lib/ragweed/rasm/isa.rb', line 156

def esi(opts={}); Register.esi opts; end

.esp(opts = {}) ⇒ Object



154
# File 'lib/ragweed/rasm/isa.rb', line 154

def esp(opts={}); Register.esp opts; end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



20
21
22
# File 'lib/ragweed/rasm.rb', line 20

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



28
29
30
# File 'lib/ragweed/rasm.rb', line 28

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



42
43
44
45
46
47
48
49
# File 'lib/ragweed/rasm.rb', line 42

def self.require_all_libs_relative_to( fname, dir = nil )
  self.require_utils
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
  
  Dir.glob(search_me).sort.each {|rb| require rb}
end

.require_utilsObject

Utility function to load utility classes and extensions



33
34
35
# File 'lib/ragweed/rasm.rb', line 33

def self.require_utils
  %w{utils sbuf}.each{|r| require self.libpath(r)+'.rb'}
end

.versionObject

Returns the version string for the library.



12
13
14
# File 'lib/ragweed/rasm.rb', line 12

def self.version
  VERSION
end