Class: Resedit::Changeable
- Inherits:
-
Object
- Object
- Resedit::Changeable
- Defined in:
- lib/resedit/classes/changeable.rb
Defined Under Namespace
Classes: Change
Constant Summary collapse
- HOW_CHANGED =
0- HOW_ORIGINAL =
1- COL_CHANGED =
Colorizer::YELLOW
- COL_ORIGINAL =
Colorizer::PURPLE
- LOG =
Logger.new(STDOUT)
Instance Method Summary collapse
- #addData(fileOrBytes, size = nil) ⇒ Object
- #bytes ⇒ Object
- #change(ofs, bytes) ⇒ Object
- #changed?(ofs, size = 1) ⇒ Boolean
- #colStr(str, cond = true) ⇒ Object
- #colVal(ofs, size) ⇒ Object
- #curcol ⇒ Object
- #dbgdump ⇒ Object
- #debug ⇒ Object
- #getChanges ⇒ Object
- #getData(ofs, size) ⇒ Object
- #hex(writer, ofs, size, how) ⇒ Object
-
#initialize(fileOrBytes, fileSize = nil) ⇒ Changeable
constructor
Changeable.
- #insert(offset, data) ⇒ Object
- #loadChanges(file) ⇒ Object
- #mode(how) ⇒ Object
- #parseHow(how) ⇒ Object
- #revert(what) ⇒ Object
- #saveChanges(file) ⇒ Object
- #saveData(file) ⇒ Object
- #undo(offset) ⇒ Object
Constructor Details
#initialize(fileOrBytes, fileSize = nil) ⇒ Changeable
Changeable
171 172 173 174 175 176 177 |
# File 'lib/resedit/classes/changeable.rb', line 171 def initialize(fileOrBytes, fileSize=nil) LOG.level = Logger::INFO @col = Colorizer.instance() @mode = HOW_CHANGED @root = nil addData(fileOrBytes, fileSize) end |
Instance Method Details
#addData(fileOrBytes, size = nil) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/resedit/classes/changeable.rb', line 179 def addData(fileOrBytes, size=nil) if fileOrBytes.is_a?(IO) data = fileOrBytes.read(size) else data = fileOrBytes end data = @root.buf + data if @root @root = Change.new(data) end |
#bytes ⇒ Object
223 |
# File 'lib/resedit/classes/changeable.rb', line 223 def bytes; return @root.all() end |
#change(ofs, bytes) ⇒ Object
206 207 208 209 210 |
# File 'lib/resedit/classes/changeable.rb', line 206 def change(ofs, bytes) @root.change(ofs, bytes) @root.normalize() return ofs end |
#changed?(ofs, size = 1) ⇒ Boolean
212 |
# File 'lib/resedit/classes/changeable.rb', line 212 def changed?(ofs, size=1); return @root.changed?(ofs, size) end |
#colStr(str, cond = true) ⇒ Object
246 247 248 249 250 |
# File 'lib/resedit/classes/changeable.rb', line 246 def colStr(str, cond=true) str = sprintf("%04X", str) if !str.is_a?(String) return str if !cond return @col.color(curcol(), str) end |
#colVal(ofs, size) ⇒ Object
240 241 242 243 244 |
# File 'lib/resedit/classes/changeable.rb', line 240 def colVal(ofs, size) fmt = "%#{size*2}.#{size*2}X" u = size == 2 ? "v" : V return colStr( sprintf(fmt, getData(ofs, size).unpack(u)[0]) , changed?(ofs,size)) end |
#curcol ⇒ Object
238 |
# File 'lib/resedit/classes/changeable.rb', line 238 def curcol; @mode == HOW_ORIGINAL ? COL_ORIGINAL : COL_CHANGED end |
#dbgdump ⇒ Object
216 217 218 219 |
# File 'lib/resedit/classes/changeable.rb', line 216 def dbgdump LOG.debug("---#{@root.size()}---\n") @root.dump() end |
#debug ⇒ Object
214 |
# File 'lib/resedit/classes/changeable.rb', line 214 def debug(); LOG.level = Logger::DEBUG end |
#getChanges ⇒ Object
225 |
# File 'lib/resedit/classes/changeable.rb', line 225 def getChanges; @root.getChanges(); end |
#getData(ofs, size) ⇒ Object
221 |
# File 'lib/resedit/classes/changeable.rb', line 221 def getData(ofs, size); return @root.data(ofs, size) end |
#hex(writer, ofs, size, how) ⇒ Object
261 262 263 264 265 |
# File 'lib/resedit/classes/changeable.rb', line 261 def hex(writer, ofs, size, how) mode(parseHow(how)) col = curcol() return @root.hex(writer, ofs, size, col) end |
#insert(offset, data) ⇒ Object
195 196 197 198 199 |
# File 'lib/resedit/classes/changeable.rb', line 195 def insert(offset, data) return if !data || !data.length @root.insert(offset, data) @root.normalize() end |
#loadChanges(file) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/resedit/classes/changeable.rb', line 284 def loadChanges(file) mode(HOW_CHANGED) @root.revert clen = file.read(4).unpack('V')[0] for _ in 0..clen-1 ofs, len = file.read(8).unpack('VV') isNu = len & 0x80000000 !=0 len &= 0x7FFFFFFF @root.cload(ofs, isNu ? "" : file.read(len), len) end mode(HOW_CHANGED) end |
#mode(how) ⇒ Object
190 191 192 193 |
# File 'lib/resedit/classes/changeable.rb', line 190 def mode(how) @root.mode(how) @mode = how end |
#parseHow(how) ⇒ Object
253 254 255 256 257 258 |
# File 'lib/resedit/classes/changeable.rb', line 253 def parseHow(how) return HOW_CHANGED if !how || how == HOW_CHANGED return HOW_ORIGINAL if how == HOW_ORIGINAL return HOW_ORIGINAL if how[0] == 'o' || how[0] == 'O' return HOW_CHANGED end |
#revert(what) ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'lib/resedit/classes/changeable.rb', line 227 def revert(what) if what=='all' @root.revert() @root.normalize() return true end undo(what) return true end |
#saveChanges(file) ⇒ Object
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/resedit/classes/changeable.rb', line 273 def saveChanges(file) mode(HOW_CHANGED) chs = getChanges() file.write([chs.length].pack('V')) chs.each{|o,bts| flg = bts[0].length==0 ? 0x80000000 : 0 file.write([o, bts[1].length | flg ].pack('VV')) file.write(bts[0]) if flg==0 } end |
#saveData(file) ⇒ Object
268 269 270 271 |
# File 'lib/resedit/classes/changeable.rb', line 268 def saveData(file) mode(HOW_CHANGED) file.write(bytes()) end |
#undo(offset) ⇒ Object
201 202 203 204 |
# File 'lib/resedit/classes/changeable.rb', line 201 def undo(offset) @root.undo(offset) @root.normalize() end |