add update_checksum, size, and length methods

git-svn-id: file:///home/svn/framework3/trunk@10036 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2010-08-18 04:39:38 +00:00
parent c551f8d2ee
commit 24d10866b6
2 changed files with 32 additions and 1 deletions

View File

@ -202,5 +202,11 @@ class Pe < PeBase
_isource.read(offset, len)
end
def size
_isource.size
end
def length
_isource.size
end
end end end

View File

@ -1650,6 +1650,31 @@ class PeBase
rname.to_s
end
def update_checksum
off = _dos_header.e_lfanew + IMAGE_FILE_HEADER_SIZE + 0x40
_isource.rawdata[off, 4] = [0].pack('V')
rem = _isource.size % 4
sum_me = ''
sum_me << _isource.rawdata
sum_me << "\x00" * (4 - rem) if rem > 0
cksum = 0
sum_me.unpack('V*').each { |el|
cksum = (cksum & 0xffffffff) + (cksum >> 32) + el
if cksum > 2**32
cksum = (cksum & 0xffffffff) + (cksum >> 32)
end
}
cksum = (cksum & 0xffff) + (cksum >> 16)
cksum += (cksum >> 16)
cksum &= 0xffff
cksum += _isource.size
_isource.rawdata[off, 4] = [cksum].pack('V')
end
end end end