Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 5th, 2013  |  syntax: None  |  size: 0.83 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data