ruby: handle ptr-strings in df-structures

develop
jj 2012-09-19 14:25:14 +02:00
parent b470abed90
commit 45c057b3d2
2 changed files with 12 additions and 3 deletions

@ -965,7 +965,7 @@ sub render_item_bytes {
my $subtype = $item->getAttribute('ld:subtype'); my $subtype = $item->getAttribute('ld:subtype');
if ($subtype eq 'padding') { if ($subtype eq 'padding') {
} elsif ($subtype eq 'static-string') { } elsif ($subtype eq 'static-string') {
my $size = $item->getAttribute('size'); my $size = $item->getAttribute('size') || -1;
push @lines_rb, "static_string($size)"; push @lines_rb, "static_string($size)";
} else { } else {
print "no render bytes $subtype\n"; print "no render bytes $subtype\n";

@ -423,11 +423,20 @@ module DFHack
def initialize(length) def initialize(length)
@_length = length @_length = length
end end
def length
if @_length == -1
maxlen = 4096 - (@_memaddr & 0xfff)
maxlen += 4096 until len = DFHack.memory_read(@_memaddr, maxlen).index(?\0)
len
else
@_length
end
end
def _get def _get
DFHack.memory_read(@_memaddr, @_length) DFHack.memory_read(@_memaddr, length)
end end
def _set(v) def _set(v)
DFHack.memory_write(@_memaddr, v[0, @_length]) DFHack.memory_write(@_memaddr, v[0, length])
end end
end end