Class: Resedit::HexWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/resedit/classes/hexwriter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr, addressFormatter = nil) ⇒ HexWriter

Returns a new instance of HexWriter.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/resedit/classes/hexwriter.rb', line 9

def initialize(addr, addressFormatter=nil)
    @written = 0
    @charsInLine = 0x10
    @addr = addr
    @col = Colorizer.instance()
    @size = 0
    @line = nil
    @cline = ''
    @chr = ''
    @cchr = ''
    @pcol = nil
    @addressFormatter = addressFormatter
end

Instance Attribute Details

#addrObject

Returns the value of attribute addr.



7
8
9
# File 'lib/resedit/classes/hexwriter.rb', line 7

def addr
  @addr
end

#addressFormatterObject

Returns the value of attribute addressFormatter.



7
8
9
# File 'lib/resedit/classes/hexwriter.rb', line 7

def addressFormatter
  @addressFormatter
end

#writtenObject

Returns the value of attribute written.



7
8
9
# File 'lib/resedit/classes/hexwriter.rb', line 7

def written
  @written
end

Instance Method Details

#addBytes(bytes, color = nil) ⇒ Object



34
35
36
# File 'lib/resedit/classes/hexwriter.rb', line 34

def addBytes(bytes, color=nil)
    bytes.each_byte{|b| addChar(b, color)}
end

#addChar(c, color = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/resedit/classes/hexwriter.rb', line 53

def addChar(c, color = nil)
    c = c.ord
    @line = addrFormat if !@line
    procColored if color != @pcol && @pcol
    if !color
        @line += sprintf("%02X ",c)
        @chr += (c<0x20 || c>0x7E) ? '.' : c.chr
    else
        @cline += sprintf("%02X ",c)
        @cchr += (c<0x20 || c>0x7E) ? '.' : c.chr
    end
    @pcol = color
    @size += 1
    @written += 1
    if @size == @charsInLine
        buildLine()
    end
end

#addrFormatObject



23
24
25
26
27
28
29
30
31
# File 'lib/resedit/classes/hexwriter.rb', line 23

def addrFormat()
    if @addressFormatter
        res = @addressFormatter.formatAddress(@addr)+" | "
    else
        res = sprintf("%08X | ", @addr)
    end
    @addr += @charsInLine
    return res
end

#buildLineObject



45
46
47
48
49
50
51
# File 'lib/resedit/classes/hexwriter.rb', line 45

def buildLine()
    procColored() if @pcol
    puts @line+" | "+@chr
    @line = nil
    @chr=''
    @size = 0
end

#finishObject



72
73
74
75
76
77
# File 'lib/resedit/classes/hexwriter.rb', line 72

def finish()
    return if @size == 0
    procColored() if @pcol
    @line += "   " * (@charsInLine - @size)
    buildLine()
end

#procColoredObject



38
39
40
41
42
43
# File 'lib/resedit/classes/hexwriter.rb', line 38

def procColored()
    @line += @col.color(@pcol, @cline)
    @chr += @col.color(@pcol, @cchr)
    @cline = ''
    @cchr = ''
end