Class: ASMREPL::Linux::ThreadState

Inherits:
Object
  • Object
show all
Defined in:
lib/asmrepl/linux.rb

Constant Summary collapse

FLAGS =
[
  ['CF', 'Carry Flag'],
  [nil, 'Reserved'],
  ['PF', 'Parity Flag'],
  [nil, 'Reserved'],
  ['AF', 'Adjust Flag'],
  [nil, 'Reserved'],
  ['ZF', 'Zero Flag'],
  ['SF', 'Sign Flag'],
  ['TF', 'Trap Flag'],
  ['IF', 'Interrupt Enable Flag'],
  ['DF', 'Direction Flag'],
  ['OF', 'Overflow Flag'],
  ['IOPL_H', 'I/O privilege level High bit'],
  ['IOPL_L', 'I/O privilege level Low bit'],
  ['NT', 'Nested Task Flag'],
  [nil, 'Reserved'],
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ ThreadState

Returns a new instance of ThreadState.



107
108
109
# File 'lib/asmrepl/linux.rb', line 107

def initialize buffer
  @to_ptr = buffer
end

Instance Attribute Details

#to_ptrObject (readonly)

Returns the value of attribute to_ptr.



105
106
107
# File 'lib/asmrepl/linux.rb', line 105

def to_ptr
  @to_ptr
end

Class Method Details

.mallocObject



101
102
103
# File 'lib/asmrepl/linux.rb', line 101

def self.malloc
  new Fiddle::Pointer.malloc sizeof
end

Instance Method Details

#[](name) ⇒ Object



95
96
97
98
99
# File 'lib/asmrepl/linux.rb', line 95

def [] name
  idx = fields.index(name)
  return unless idx
  to_ptr[Fiddle::SIZEOF_INT64_T * idx, Fiddle::SIZEOF_INT64_T].unpack1("l!")
end

#flagsObject



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/asmrepl/linux.rb', line 150

def flags
  flags = eflags
  f = []
  FLAGS.each do |abbrv, _|
    if abbrv && flags & 1 == 1
      f << abbrv
    end
    flags >>= 1
  end
  f
end

#to_sObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/asmrepl/linux.rb', line 115

def to_s
  buf = ""
  fields.first(8).zip(fields.drop(8).first(8)).each do |l, r|
    buf << "#{l.ljust(3)}  #{sprintf("%#018x", send(l))}"
    buf << "  "
    buf << "#{r.ljust(3)}  #{sprintf("%#018x", send(r))}\n"
  end

  buf << "\n"

  fields.drop(16).each do |reg|
    buf << "#{reg.ljust(8)}  #{sprintf("%#018x", send(reg))}\n"
  end
  buf
end