Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created September 27, 2011 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjameshuff/1246142 to your computer and use it in GitHub Desktop.
Save cjameshuff/1246142 to your computer and use it in GitHub Desktop.
def lpcrc(fw)
# fix CRC (thanks to Roel Verdult for the lpcrc utility this is based on)
blocks = fw.unpack('V7') # read 7 little endian 32-bit integers
crc = (~(blocks.inject(0) {|crc, block| (crc + block) & 0xFFFFFFFF}) + 1) & 0xFFFFFFFF
fw[7*4, 4] = [crc].pack('V')
fw
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment