class TurboRex::CStruct::CStructBuilder
Attributes
s[R]
struct_name[R]
Public Class Methods
create_method(method_name, &block)
click to toggle source
# File lib/turborex/cstruct.rb, line 448 def self.create_method(method_name, &block) define_method(method_name, &block) end
new(arch = 'x86')
click to toggle source
# File lib/turborex/cstruct.rb, line 312 def initialize(arch = 'x86') @s = ::Rex::Struct2::CStructTemplate.new @arch = arch define_variable_length_type end
Public Instance Methods
ATOM(field, init_value = 0, endian = 'v')
docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types docs.microsoft.com/en-us/cpp/cpp/data-type-ranges?redirectedfrom=MSDN&view=vs-2019 The data type range follows Microsoft VC/C++ compiler data model llp64 on 64-bit arch
Alias for: word
__int64(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 354 def __int64(field, init_value = 0, endian = 'v') add_object('int64' + endian, field, init_value) end
add_object(type, field, init_value)
click to toggle source
# File lib/turborex/cstruct.rb, line 429 def add_object(type, field, init_value) if field.count == 1 @s.template << [type, field.to_s, init_value] else struct_temp = ::Rex::Struct2::CStructTemplate.new field.count.times do |i| struct_temp.template << [type, field.to_s + '_' + i.to_s, init_value] end @s.template << ['template', field.to_s, struct_temp] end end
alias_singleton_method(alias_sym, method)
click to toggle source
# File lib/turborex/cstruct.rb, line 416 def alias_singleton_method(alias_sym, method) self.singleton_class.send(:alias_method, alias_sym, method) end
build(name)
click to toggle source
# File lib/turborex/cstruct.rb, line 442 def build(name) set_struct_name(name) self end
char(field, init_value = 0)
click to toggle source
# File lib/turborex/cstruct.rb, line 318 def char(field, init_value = 0) add_object('int8', field, init_value) end
define_variable_length_type()
click to toggle source
# File lib/turborex/cstruct.rb, line 420 def define_variable_length_type arch_32? ? alias_singleton_method(:ULONG_PTR, :uint) : alias_singleton_method(:ULONG_PTR, :uint64) arch_32? ? alias_singleton_method(:ULONG_PTR_T, :uint) : alias_singleton_method(:ULONG_PTR_T, :uint64) end
dword(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 346 def dword(field, init_value = 0, endian = 'v') add_object('uint32' + endian, field, init_value) end
Also aliased as: DWORD
from_str(s)
click to toggle source
# File lib/turborex/cstruct.rb, line 460 def from_str(s) struct = @s.make_struct struct.from_s(s) struct end
int(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 334 def int(field, init_value = 0, endian = 'v') add_object('int32' + endian, field, init_value) end
int64(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 350 def int64(field, init_value = 0, endian = 'v') add_object('int64' + endian, field, init_value) end
make(opts = {})
click to toggle source
# File lib/turborex/cstruct.rb, line 456 def make(opts = {}) @s.make_struct(opts[:pack], opts[:align]) end
pvoid(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 362 def pvoid(field, init_value = 0, endian = 'v') case @arch when 'x86' add_object('uint32' + endian, field, init_value) when 'x64' add_object('uint64' + endian, field, init_value) end end
Also aliased as: PVOID
set_struct_name(name)
click to toggle source
# File lib/turborex/cstruct.rb, line 452 def set_struct_name(name) @struct_name = name end
short(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 326 def short(field, init_value = 0, endian = 'v') # 'v' is little-endian, 'n' is big-endian add_object('int16' + endian, field, init_value) end
struct() { || ... }
click to toggle source
# File lib/turborex/cstruct.rb, line 425 def struct(&block) yield end
uchar(field, init_value = 0)
click to toggle source
# File lib/turborex/cstruct.rb, line 322 def uchar(field, init_value = 0) add_object('uint8', field, init_value) end
uint(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 338 def uint(field, init_value = 0, endian = 'v') add_object('uint32' + endian, field, init_value) end
uint64(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 358 def uint64(field, init_value = 0, endian = 'v') add_object('uint64' + endian, field, init_value) end
ushort(field, init_value = 0, endian = 'v')
click to toggle source
# File lib/turborex/cstruct.rb, line 330 def ushort(field, init_value = 0, endian = 'v') add_object('uint16' + endian, field, init_value) end
Private Instance Methods
arch_32?()
click to toggle source
# File lib/turborex/cstruct.rb, line 468 def arch_32? @arch == 'x86' end
arch_64?()
click to toggle source
# File lib/turborex/cstruct.rb, line 472 def arch_64? !arch_32? end