SHARE
TWEET

Untitled

a guest Mar 5th, 2013 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. cat <<END_PATCH | arm-linux-gnueabi-as -mcpu=cortex-a9 -march=armv7-a -o _patch
  4. MOV     R0, #0
  5. MOV     R1, #0x64000000
  6. ADD     R2, R1, #0x2800
  7.  
  8. memcpy:
  9. CMP     R1, R2
  10. LDRNE   R3, [R0],#4
  11. STRNE   R3, [R1],#4
  12. BNE     memcpy
  13.  
  14. LDMFD   SP!, {R0-R12,PC}
  15. END_PATCH
  16.  
  17. arm-linux-gnueabi-objcopy -O binary _patch _patch.bin
  18.  
  19. FN=$1
  20. OFFSET=$2
  21. SIZE=$(stat -c %s $FN)
  22. PATCHSIZE=$(stat -c %s _patch.bin)
  23. PATCHED=$FN".patched"
  24. JUMP=$(( (SIZE - OFFSET - PATCHSIZE - 8) / 4 ))
  25. JUMP=$(printf "%04X" $JUMP | sed 's/\(..\)\(..\)/\2\1/')
  26.  
  27. dd if=$FN ibs=1 count=$OFFSET of=$PATCHED 2>&-
  28. echo $JUMP | xxd -r -p >> $PATCHED
  29. echo "00EA" | xxd -r -p >> $PATCHED
  30.  
  31. dd if=$FN ibs=1 skip=$((OFFSET+4)) count=$((SIZE-PATCHSIZE-OFFSET-4)) of=$PATCHED oflag=append conv=notrunc 2>&-
  32. cat _patch.bin >> $PATCHED
  33.  
  34. rm _patch _patch.bin
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top