Class: Resedit::MZCommand
- Inherits:
-
AppCommand
- Object
- AppCommand
- Resedit::MZCommand
- Defined in:
- lib/resedit/app/mz_command.rb
Instance Attribute Summary
Attributes inherited from AppCommand
#names, #ohash, #opts, #params, #type
Instance Method Summary collapse
- #append(params) ⇒ Object
- #change(params) ⇒ Object
- #close(params) ⇒ Object
- #cur ⇒ Object
- #dasm(params) ⇒ Object
- #dump(params) ⇒ Object
- #expr(params) ⇒ Object
- #getfile(id) ⇒ Object
- #help(params) ⇒ Object
- #hex(params) ⇒ Object
- #info(params = nil) ⇒ Object
-
#initialize ⇒ MZCommand
constructor
A new instance of MZCommand.
- #job(params) ⇒ Object
- #reloc(params) ⇒ Object
- #relocfind(params) ⇒ Object
- #replace(params) ⇒ Object
- #revert(params) ⇒ Object
- #save(params) ⇒ Object
- #stringfind(params) ⇒ Object
- #use(params) ⇒ Object
Methods inherited from AppCommand
#addOption, #addParam, #log, #logd, #loge, #parseParams, #run
Constructor Details
#initialize ⇒ MZCommand
Returns a new instance of MZCommand.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resedit/app/mz_command.rb', line 8 def initialize super(['mz']) addParam('cmd', "mz command","") addParam('p1', "mz command parameter","") addParam('p2', "mz command parameter","") addParam('p3', "mz command parameter","") addParam('p4', "mz command parameter","") addParam('p5', "mz command parameter","") addOption('help', 'h', false, 'help on mz commands') @cmds = { "help"=>[method(:help), "show help on mz commands", {"command" => "command to show help on"}], "use"=>[method(:use), "select mz file", {"file" => "path to mz file"}], "save"=>[method(:save), "save current file",{"filename" => "filename fir saving", "final"=>"don't save changes"}], "close"=>[method(:close), "close file", {"file" => "path or id of file to close"}], "print"=>[method(:info), "print info about mz objects", {"what" => "files/header/reloc/changes", "how" => "original/modified"}], "append"=>[method(:append), "add bytes to current file", {"value" => "value", "type" => "value type", "where" => "append offset. default: above ss:sp"}], "replace"=>[method(:replace), "replace added bytes", {"value" => "value", "type"=>"value type"}], "change"=>[method(:change), "change bytes at offset", {"ofs" => "data ofset", "value" => "value", "disp" => "code/file", "type"=>"value type"}], "reloc"=>[method(:reloc), "add relocation", {"offset" => "reloc offset", "target" => "address reloc points to"}], "revert"=>[method(:revert), "revert changes", {"ofs"=>"change offset/all"}], "hex"=>[method(:hex), "print hex file", {"ofs" => "data offset", "size" => "data size", "how"=>"original/modified", "disp" => "code/file"}], "dasm"=>[method(:dasm), "print disasm", {"ofs" => "data offset", "size" => "data size", "how"=>"original/modified"}], "eval"=>[method(:expr), "print expression", {"expr" => "expression"}], "dump"=>[method(:dump), "dump exe parts", {"out" => "output filename", "parts"=>"list of parts", "how"=>"original/modified"}], "relocfind"=>[method(:relocfind), "find relocation with value", {"value" => "value", "type"=>"value type"}], "stringfind"=>[method(:stringfind), "search for strings in exe", {"size"=>"min string size"}], } @shorters = {"p"=>"print", "e"=>"eval"} @files = [] @cur = nil end |
Instance Method Details
#append(params) ⇒ Object
135 136 137 |
# File 'lib/resedit/app/mz_command.rb', line 135 def append(params) cur().append(params['value'], params['type']) end |
#change(params) ⇒ Object
145 146 147 |
# File 'lib/resedit/app/mz_command.rb', line 145 def change(params) cur().change(params['ofs'], params['value'], params['disp'], params['type']) end |
#close(params) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/resedit/app/mz_command.rb', line 112 def close(params) mz = getfile(params['file']) raise "File not found: "+fn if nil == mz @files -= [mz] @cur = nil if @cur == mz mz.close() mz = nil @cur = @files[0] if !@cur && @files.length > 0 info() end |
#cur ⇒ Object
124 125 126 127 |
# File 'lib/resedit/app/mz_command.rb', line 124 def cur() raise "No MZ selected." if !@cur return @cur end |
#dasm(params) ⇒ Object
171 172 173 |
# File 'lib/resedit/app/mz_command.rb', line 171 def dasm(params) cur().dasm(params['ofs'], params['size'], params['how']) end |
#dump(params) ⇒ Object
180 181 182 |
# File 'lib/resedit/app/mz_command.rb', line 180 def dump(params) cur().dump(params['out'], params['parts'], params['how']) end |
#expr(params) ⇒ Object
175 176 177 178 |
# File 'lib/resedit/app/mz_command.rb', line 175 def expr(params) env = @cur && @cur.env ? @cur.env : Env.new() puts env.s2i(params['expr']) end |
#getfile(id) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/resedit/app/mz_command.rb', line 63 def getfile(id) return @cur if id == nil #env = !@cur ? Env.new(self) : @cur.env env = Env.new() i,res = env.s2i_nt(id) if res raise "Bad file id: " + i.to_s if @files.length < i || i < 0 return @files[i] end @files.each{|mz| return mz if mz.is?(id) } return nil end |
#help(params) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/resedit/app/mz_command.rb', line 41 def help(params) if params['command'] raise "Unknown mz command: " + params['command'] if !@cmds[params['command']] cmd = @cmds[params['command']] puts(params['command'] + "\t-" + cmd[1]) if cmd[2] puts puts("params:") cmd[2].each{|k,v| puts k + "\t-" + v } end else puts("available mz commands:") @cmds.each{|k,v| puts k + "\t-" + v[1] } end puts end |
#hex(params) ⇒ Object
166 167 168 |
# File 'lib/resedit/app/mz_command.rb', line 166 def hex(params) cur().hex(params['ofs'], params['size'], params['how'], params['disp']) end |
#info(params = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resedit/app/mz_command.rb', line 79 def info(params=nil) what = params['what'] if params if what == nil || what == "files" if @files.length != 0 curid = -1 puts "Opened files:" @files.each.with_index{|mz,i| puts "#{i}:\t#{mz.path}" curid=i if mz == @cur } puts "Current file: (#{curid}) #{@cur.path}" puts else puts "No files opened" end else raise "MZ file not loaded" if !@cur @cur.print(what, params['how']) end end |
#job(params) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/resedit/app/mz_command.rb', line 185 def job(params) cmd = params['cmd'] cmd = @shorters[cmd] if @shorters[cmd] if cmd.length==0 || File.exist?(cmd) App::get().setShell('mz') return if cmd.length == 0 params['p1'] = cmd cmd = "use" end if cmd=="valueof" cur().valueof(params['p1'], params['p2']) return end if params['help'] params['command'] = params['help'] help(params) return end raise "Unknown command: "+cmd if !@cmds[cmd] scmd = @cmds[cmd] if scmd[2] scmd[2].keys.each.with_index{|k,i| params[k] = params["p#{i+1}"] params[k] = nil if params[k].length == 0 } end scmd[0].call(params) end |
#reloc(params) ⇒ Object
149 150 151 |
# File 'lib/resedit/app/mz_command.rb', line 149 def reloc(params) cur().reloc(params['offset'],params['target']) end |
#relocfind(params) ⇒ Object
153 154 155 |
# File 'lib/resedit/app/mz_command.rb', line 153 def relocfind(params) cur().relocfind(params['value'], params['type']) end |
#replace(params) ⇒ Object
140 141 142 |
# File 'lib/resedit/app/mz_command.rb', line 140 def replace(params) cur().replace(params['value'], params['type']) end |
#revert(params) ⇒ Object
161 162 163 |
# File 'lib/resedit/app/mz_command.rb', line 161 def revert(params) cur().revert(params['ofs']) end |
#save(params) ⇒ Object
130 131 132 |
# File 'lib/resedit/app/mz_command.rb', line 130 def save(params) cur().save(params['filename'], params['final']) end |
#stringfind(params) ⇒ Object
157 158 159 |
# File 'lib/resedit/app/mz_command.rb', line 157 def stringfind(params) cur().stringfind(params['size']) end |