Class: Resedit::ExeBody

Inherits:
Changeable show all
Defined in:
lib/resedit/classes/exefile.rb

Direct Known Subclasses

BWBody, LEBody, MZBody

Constant Summary

Constants inherited from Changeable

Changeable::COL_CHANGED, Changeable::COL_ORIGINAL, Changeable::HOW_CHANGED, Changeable::HOW_ORIGINAL, Changeable::LOG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Changeable

#addData, #bytes, #change, #changed?, #colStr, #colVal, #curcol, #dbgdump, #debug, #fix, #getChanges, #getData, #hexify, #insert, #loadChanges, #mode, #parseHow, #print, #saveChanges, #saveData, #setData, #size, #undo, #unhexify

Constructor Details

#initialize(exe, file, size) ⇒ ExeBody

Returns a new instance of ExeBody.



132
133
134
135
136
# File 'lib/resedit/classes/exefile.rb', line 132

def initialize(exe, file, size)
    @exe = exe
    super(file, size)
    @addsz = 0
end

Instance Attribute Details

#exeObject (readonly)

Returns the value of attribute exe.



130
131
132
# File 'lib/resedit/classes/exefile.rb', line 130

def exe
  @exe
end

Instance Method Details

#addr2raw(addr) ⇒ Object



209
# File 'lib/resedit/classes/exefile.rb', line 209

def addr2raw(addr); raise "Not implemented" end

#addrFormatter(hofs) ⇒ Object



207
# File 'lib/resedit/classes/exefile.rb', line 207

def addrFormatter(hofs); nil end

#append(bytes, where = nil) ⇒ Object



210
# File 'lib/resedit/classes/exefile.rb', line 210

def append(bytes, where=nil); raise "NotImplemented" end

#dasm(ofs, size, how, mode) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/resedit/classes/exefile.rb', line 160

def dasm(ofs, size, how, mode)
    raise "Crabstone gem required to disasm." if $nocrabstone
    relocated = false
    if how && how[0]='r' || how[0]='R'
        relocated = true
        how = nil
    end
    mode(parseHow(how))
    cs = Disassembler.new(ARCH_X86, mode==16 ? MODE_16 : MODE_32)
    begin
        while true
            begin
                d = relocated ? readRelocated(ofs, size) : getData(ofs, size)
                cs.disasm(d, ofs).each {|i|
                    bts = i.bytes.map { |b| sprintf("%02X",b) }.join
                    inst = colStr(sprintf("%14s\t%s\t%s", bts, i.mnemonic, i.op_str), changed?(i.address, i.bytes.length))
                    printDasm(i, inst)
                }
                break
            rescue
                ofs-=1
            end
        end
    ensure
        cs.close()
    end
end

#findRelocValue(value) ⇒ Object



213
# File 'lib/resedit/classes/exefile.rb', line 213

def findRelocValue(value);  raise "NotImplemented" end

#findStrings(minsize) ⇒ Object



214
# File 'lib/resedit/classes/exefile.rb', line 214

def findStrings(minsize); raise "NotImplemented" end

#formatAddress(raw) ⇒ Object



156
157
158
# File 'lib/resedit/classes/exefile.rb', line 156

def formatAddress(raw)
    return sprintf("%08X", raw)
end

#hex(wr, ofs, size, how) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/resedit/classes/exefile.rb', line 147

def hex(wr, ofs, size, how)
    wr.addressFormatter = self
    if how && (how[0]='r' || how[0]='R')
        wr.addBytes(readRelocated(ofs, size))
        return
    end
    super(wr, ofs, size, how)
end

#printDasm(inst, str) ⇒ Object



143
144
145
# File 'lib/resedit/classes/exefile.rb', line 143

def printDasm(inst, str)
    printf("%08X %s\n",inst.address, str)
end

#raw2addr(ofs) ⇒ Object



208
# File 'lib/resedit/classes/exefile.rb', line 208

def raw2addr(ofs); raise "Not implemented" end

#readRelocated(ofs, size) ⇒ Object



212
# File 'lib/resedit/classes/exefile.rb', line 212

def readRelocated(ofs, size); raise "NotImplemented" end

#removeAppendObject



211
# File 'lib/resedit/classes/exefile.rb', line 211

def removeAppend(); raise "Not Implemented" end

#revert(what) ⇒ Object



138
139
140
141
# File 'lib/resedit/classes/exefile.rb', line 138

def revert(what)
    super(what)
    @addsz = 0
end

#textAt(pos, minlen, rexp = nil) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/resedit/classes/exefile.rb', line 188

def textAt(pos, minlen, rexp=nil)
    rexp = /^[[:print:][:space:]]+$/ if !rexp
    sz = size
    ln = [minlen+64, sz-pos].min
    return nil if ln<minlen
    data = getData(pos, ln)
    prev = 0
    while true
        zpos = data.index("\x00")
        return nil if zpos!=nil && zpos<minlen
        data = data[0,zpos] if zpos!=nil
        return nil if (data[prev..-1] =~ rexp) != 0
        return data if zpos != nil
        prev = data.length
        return nil if pos+prev+64 > size
        data += getData(pos+prev, 64)
    end
end