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) ⇒ 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)
    @written = 0
    @charsInLine = 0x10
    @addr = addr
    @col = Colorizer.instance()
    @size = 0
    @line = nil
    @cline = ''
    @chr = ''
    @cchr = ''
    @pcol = nil
    @segments = nil
end

Instance Attribute Details

#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



42
43
44
# File 'lib/resedit/classes/hexwriter.rb', line 42

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

#addChar(c, color = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/resedit/classes/hexwriter.rb', line 61

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



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/resedit/classes/hexwriter.rb', line 28

def addrFormat()
    add = ''
    if @segments
        seg = (@addr-@sfix) >> 4
        min = @segments.find{|e| e <= seg}
        min = 0 if !min
        add = sprintf(" %04X:%04X", min, @addr - @sfix - (min << 4))
    end
    res = sprintf("%08X%s | ", @addr, add)
    @addr += @charsInLine
    return res
end

#buildLineObject



53
54
55
56
57
58
59
# File 'lib/resedit/classes/hexwriter.rb', line 53

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

#finishObject



80
81
82
83
84
85
# File 'lib/resedit/classes/hexwriter.rb', line 80

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

#procColoredObject



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

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

#setSegments(segments, sfix) ⇒ Object



23
24
25
26
# File 'lib/resedit/classes/hexwriter.rb', line 23

def setSegments(segments, sfix)
    @segments = segments.sort.reverse
    @sfix = sfix
end