Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- cat <<END_PATCH | arm-linux-gnueabi-as -mcpu=cortex-a9 -march=armv7-a -o _patch
- MOV R0, #0
- MOV R1, #0x64000000
- ADD R2, R1, #0x2800
- memcpy:
- CMP R1, R2
- LDRNE R3, [R0],#4
- STRNE R3, [R1],#4
- BNE memcpy
- LDMFD SP!, {R0-R12,PC}
- END_PATCH
- arm-linux-gnueabi-objcopy -O binary _patch _patch.bin
- FN=$1
- OFFSET=$2
- SIZE=$(stat -c %s $FN)
- PATCHSIZE=$(stat -c %s _patch.bin)
- PATCHED=$FN".patched"
- JUMP=$(( (SIZE - OFFSET - PATCHSIZE - 8) / 4 ))
- JUMP=$(printf "%04X" $JUMP | sed 's/\(..\)\(..\)/\2\1/')
- dd if=$FN ibs=1 count=$OFFSET of=$PATCHED 2>&-
- echo $JUMP | xxd -r -p >> $PATCHED
- echo "00EA" | xxd -r -p >> $PATCHED
- dd if=$FN ibs=1 skip=$((OFFSET+4)) count=$((SIZE-PATCHSIZE-OFFSET-4)) of=$PATCHED oflag=append conv=notrunc 2>&-
- cat _patch.bin >> $PATCHED
- rm _patch _patch.bin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement