add update_checksum, size, and length methods
git-svn-id: file:///home/svn/framework3/trunk@10036 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
c551f8d2ee
commit
24d10866b6
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue