Difference between revisions of "Patchloader"

From Exploitee.rs
Jump to navigationJump to search
(Patchloader script for packaging solutions for end-user install on GTV.)
 
m (bash -> sh)
Line 1: Line 1:
Patchloader framework for packaging solutions for end-user install on GTV.  Intended to make solutions approachable and installs automatic.
Patchloader framework for packaging solutions for end-user install on GTV.  Intended to make solutions approachable and installs automatic.


<pre>#!/bin/bash
<pre>#!/bin/sh


# patchloader, by Catrane
# patchloader, by Catrane

Revision as of 02:45, 15 March 2012

Patchloader framework for packaging solutions for end-user install on GTV. Intended to make solutions approachable and installs automatic.

#!/bin/sh

# patchloader, by Catrane
#
# DEVELOPER INSTRUCTIONS
# -----------------
# Search for these sections below:
#  PRE PATCH, PATCH PAYLOAD, PATCH MD5, POST PATCH, and USER INSTRUCTIONS.
# Follow directions in each section.
# Do not modify any other sections.

# PATCHLOADER TRUNCATION CHECK
# -----------------
busybox tail $0 | grep -q "[P]ATCHLOADER END FILE SIGNATURE"
if [ "$?" != "0" ]
then
	echo "FATAL: Patchloader truncated.  Please redownload and try again."
	exit
fi

# PRE PATCH
# -----------------
# Add any commands below which should be run prior to applying the patch.

# END PRE PATCH
# -----------------

# PATCH PAYLOAD
# -----------------
# Add patch content after the "echo" line here.  Be sure to escape any
# characters as necessary and adjust dos2unix/unix2dos settings as appropriate.
echo '
<delete this line and insert payload here>
' | busybox dos2unix -u > patchloader.patch

# PATCH MD5
# -----------------
# Calculate the MD5 hash of the patch file and set here for validation.
# Note that the script above starts and ends with a linefeed, so the best way to
# get the right value is to run the script with "GARBAGE" as the MD5 below and
# let it tell you the right value.
PATCH_MD5="GARBAGE" # PATCH_MD5="f7be3e1337c0d37b2850fabed5469d34  patchloader.patch"

# MD5 VALIDATION
# -----------------
MD5_CALC="`busybox md5sum patchloader.patch`"
if [ "$PATCH_MD5" != "$MD5_CALC" ]
then
	if [ "GARBAGE" != "$PATCH_MD5" ]
	then
		echo "FATAL: Failure to validate patch integrity.  Please redownload and try again."
	else
		echo "patchloader MD5 hash is as follows.  Users should not see this message."
		echo $MD5_CALC
	fi
	rm patchloader.patch
	exit
fi

# PATCH APPLICATION
# -----------------
busybox patch -p1 < patchloader.patch
if [ "$?" != "0" ]
then
	echo "FATAL: Error patching.  Please redownload and try again."
	rm patchloader.patch
	exit
fi
rm patchloader.patch

# POST PATCH
# -----------------
# Add any commands below which should be run prior to applying the patch.
# Include here any instructions for user to reboot if necessary.

# END POST PATCH
# -----------------

# USER INSTRUCTIONS
# -----------------
# The patch developer should move these instructions to directly above the
# "DEVELOPER INSTRUCTIONS" line atop this file, deleting these three
# developer instructions lines.
# 1) Save the full contents of this patchloader file to your computer.  This may
#    involve copying and pasting, or just downloading.
# 2) Connect to your device using adb.  adb usage is outside the scope of this
#    document.
# 3) Transfer this patchloader file to your device via adb so that it exists as
#    /patchloader.sh on your device.
#    e.g. adb push patchloader.sh /patchloader.sh
# 4) Execute the patchloader by running the following command via adb.
#    adb shell /bin/sh /patchloader.sh
# 5) Follow any instructions printed out by the patchloader.

# PATCHLOADER END FILE SIGNATURE
# -----------------
# Do not remove this PATCHLOADER END FILE SIGNATURE from the end of the file or
# place anything after it.  Pretty much, the text "PATCHLOADER END FILE SIGNATURE"
# needs to be in the last ten lines so we can make sure nothing is missing.