node/lib/metasm/metasm/parse_c.rb
# str is a reference to the underlying ruby String
# stroff is the offset from the start of this string (non-nul for nested structs)
# cp is a reference to the C::Parser
# struct to the C::Union/Struct/Array
# sizeof is the byte size of the C struct
str is a reference to the underlying ruby String
stroff is the offset from the start of this string (non-nul for nested structs)
cp is a reference to the C::Parser
struct to the C::Union/Struct/Array
sizeof is the byte size of the C struct
str is a reference to the underlying ruby String stroff is the offset from the start of this string ( non - nul for nested structs ) cp is a reference to the C :: Parser struct to the C :: Union / Struct / Array sizeof is the byte size of the C struct
def to_s(off=nil, maxdepth=500)
			return '{ /* ... */ }' if maxdepth <= 0
			str = ['']
			if @struct.kind_of?(C::Array)
				str.last << "#{@struct.type} x[#{@struct.length}] = " if not off
				mlist = (0...@struct.length)
				fldoff = mlist.inject({}) { |h, i| h.update i => i*@cp.sizeof(@struct.type) }
			elsif @struct.kind_of?(C::Struct)
				str.last << "struct #{@struct.name || '_'} x = " if not off
				@struct.update_member_cache(@cp) if not @struct.fldlist
				fldoff = @struct.fldoffset
				mlist = @struct.members.map { |m| m.name || m }
			else
				str.last << "union #{@struct.name || '_'} x = " if not off
				mlist = @struct.members.map { |m| m.name || m }
			end
			str.last << '{'
			mlist.each { |k|
				if k.kind_of? Variable	
					curoff = off.to_i + @struct.offsetof(@cp, k)
					val = self[k]
					k = '?'
				else
					curoff = off.to_i + (fldoff ? fldoff[k].to_i : 0)
					val = self[k]
				end
				if val.kind_of?(::Integer)
					if val >= 0x100
						val = '0x%X,   // +%x' % [val, curoff]
					elsif val <= -0x100
						val = '-0x%X,   // +%x' % [-val, curoff]
					else
						val = '%d,   // +%x' % [val, curoff]
					end
				elsif val.kind_of? AllocCStruct
					val = val.to_s(curoff, maxdepth-1)
				elsif not val
					val = 'NULL,   // +%x' % curoff 
				else
					val = val.to_s.sub(/$/, ',   // +%x' % curoff)
				end
				val = val.gsub("\n", "\n\t")
				str << "\t#{k.kind_of?(::Integer) ? "[#{k}]" : ".#{k}"} = #{val}"
			}
			str << '}'
			str.last << (off ? ',' : ';')
			str.join("\n")
		end
def to_s ( off = nil , maxdepth = 500 ) return '{ /* ... */ }' if maxdepth <= 0 str = [ '' ] if @struct . kind_of? ( C :: Array ) str . last << "#{@struct.type} x[#{@struct.length}] = " if not off mlist = ( 0 ... @struct . length ) fldoff = mlist . inject ( { } ) { | h , i | h . update i => i * @cp . sizeof ( @struct . type ) } elsif @struct . kind_of? ( C :: Struct ) str . last << "struct #{@struct.name || '_'} x = " if not off @struct . update_member_cache ( @cp ) if not @struct . fldlist fldoff = @struct . fldoffset mlist = @struct . members . map { | m | m . name || m } else str . last << "union #{@struct.name || '_'} x = " if not off mlist = @struct . members . map { | m | m . name || m } end str . last << '{' mlist . each { | k | if k . kind_of? Variable curoff = off . to_i + @struct . offsetof ( @cp , k ) val = self [ k ] k = '?' else curoff = off . to_i + ( fldoff ? fldoff [ k ] . to_i : 0 ) val = self [ k ] end if val . kind_of? ( :: Integer ) if val >= 0x100 val = '0x%X,   // +%x' % [ val , curoff ] elsif val <= - 0x100 val = '-0x%X,   // +%x' % [ - val , curoff ] else val = '%d,   // +%x' % [ val , curoff ] end elsif val . kind_of? AllocCStruct val = val . to_s ( curoff , maxdepth - 1 ) elsif not val val = 'NULL,   // +%x' % curoff else val = val . to_s . sub ( / $ / , ',   // +%x' % curoff ) end val = val . gsub ( "\n" , "\n\t" ) str << "\t#{k.kind_of?(::Integer) ? "[#{k}]" : ".#{k}"} = #{val}" } str << '}' str . last << ( off ? ',' : ';' ) str . join ( "\n" ) end
str is a reference to the underlying ruby String
stroff is the offset from the start of this string (non-nul for nested structs)
cp is a reference to the C::Parser
struct to the C::Union/Struct/Array
sizeof is the byte size of the C struct
str is a reference to the underlying ruby String stroff is the offset from the start of this string ( non - nul for nested structs ) cp is a reference to the C :: Parser struct to the C :: Union / Struct / Array sizeof is the byte size of the C struct
# anonymous member # pointer with NULL value
off
maxdepth