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
- #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
- #replace(params) ⇒ Object
- #revert(params) ⇒ Object
- #save(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.
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 |
# File 'lib/resedit/app/mz_command.rb', line 9 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", {"value" => "value"}], "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"}], } @files = [] @cur = nil end |
Instance Method Details
#append(params) ⇒ Object
129 130 131 |
# File 'lib/resedit/app/mz_command.rb', line 129 def append(params) cur().append(params['value'], params['type']) end |
#change(params) ⇒ Object
139 140 141 |
# File 'lib/resedit/app/mz_command.rb', line 139 def change(params) cur().change(params['ofs'], params['value'], params['disp'], params['type']) end |
#close(params) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/resedit/app/mz_command.rb', line 106 def close(params) mz = getfile(params['file']) raise "File not found: "+fn if nil == fl @files -= [mz] @cur = nil if @cur == mz mz.close() mz = nil @cur = @files[0] if !@cur && @files.length > 0 info() end |
#cur ⇒ Object
118 119 120 121 |
# File 'lib/resedit/app/mz_command.rb', line 118 def cur() raise "No MZ selected." if !@cur return @cur end |
#dasm(params) ⇒ Object
157 158 159 |
# File 'lib/resedit/app/mz_command.rb', line 157 def dasm(params) cur().dasm(params['ofs'], params['size'], params['how']) end |
#getfile(id) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/resedit/app/mz_command.rb', line 59 def getfile(id) return @cur if id == nil i,res=MZEnv.instance.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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/resedit/app/mz_command.rb', line 37 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
152 153 154 |
# File 'lib/resedit/app/mz_command.rb', line 152 def hex(params) cur().hex(params['ofs'], params['size'], params['how'], params['disp']) end |
#info(params = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/resedit/app/mz_command.rb', line 73 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
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 187 188 |
# File 'lib/resedit/app/mz_command.rb', line 162 def job(params) cmd = params['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
143 144 145 |
# File 'lib/resedit/app/mz_command.rb', line 143 def reloc(params) cur().reloc(params['value']) end |
#replace(params) ⇒ Object
134 135 136 |
# File 'lib/resedit/app/mz_command.rb', line 134 def replace(params) cur().replace(params['value'], params['type']) end |
#revert(params) ⇒ Object
147 148 149 |
# File 'lib/resedit/app/mz_command.rb', line 147 def revert(params) cur().revert(params['ofs']) end |
#save(params) ⇒ Object
124 125 126 |
# File 'lib/resedit/app/mz_command.rb', line 124 def save(params) cur().save(params['filename'], params['final']) end |