ant-thomas / zsgx1hacks

Hacks for ZS-GX1 IP Camera and various Goke GK7102 based IP Cameras
364 stars 102 forks source link

Permanent Hack - without SD #12

Open ant-thomas opened 6 years ago

ant-thomas commented 6 years ago

Working on trying to figure out a permanent hack without using an SD card.

Currently got one working where you only need to use an SD card once. The hack is copied across and the SD card can be removed once the hack is applied.

This is possible because everything in /home is persistent across reboots. Meaning you can use debug_cmd.sh to copy a new start.sh file to /home and copy all the required files (dropbear, busybox, hosts etc) to a folder on /home.

Within a new start.sh the commands are added to apply the hack on each boot. No SD required.

deorder commented 6 years ago

I already modified my ipcams to work without the use of an sdcard. Unpack the following and replace /home/start.sh with the unpacked start.sh: start.tar.gz

It boots normally when there is a sdcard inside the slot and runs the debug_cmd.sh if available. If there is no sdcard in the slot it will continue from /home/boot.sh.

From inside the /home/boot.sh I do the following (among many other things):

#!/bin/sh

LOG_FILE=/dev/null

:> ${LOG_FILE}

export LD_LIBRARY_PATH="/home"

# ...snip...

echo "Installing busybox" >> ${LOG_FILE} 2>&1
cp -f /home/busybox /bin/busybox >> ${LOG_FILE} 2>&1
/bin/busybox --install -s >> ${LOG_FILE} 2>&1

echo "Loading sensor drivers" >> ${LOG_FILE} 2>&1
/home/sensor.sh

echo "Loading kernel modules" >> ${LOG_FILE} 2>&1
insmod /home/gio.ko >> ${LOG_FILE} 2>&1 
insmod /home/8188fu.ko >> ${LOG_FILE} 2>&1
insmod /home/gkptz.ko cfg_file=/home/ptz.cfg psp_file=/home/psp.dat no_selfck=0 >> ${LOG_FILE} 2>&1

echo "Installing device nodes" >> ${LOG_FILE} 2>&1
mdev -s >> ${LOG_FILE} 2>&1

echo "Configuring network" >> ${LOG_FILE} 2>&1
ifconfig eth0 up >> ${LOG_FILE} 2>&1
ifconfig wlan0 up >> ${LOG_FILE} 2>&1
ifconfig lo 127.0.0.1 >> ${LOG_FILE} 2>&1

sleep 1

# Check if ethernet is plugged in
if [ "$(cat /sys/class/net/eth0/carrier)" == "1" ]; then
        echo "Configuring wired network" >> ${LOG_FILE} 2>&1
        ifconfig eth0 hw ether $(cat /sys/class/net/wlan0/address) >> ${LOG_FILE} 2>&1
        udhcpc -i eth0 -F "${NAME}" -n >> ${LOG_FILE} 2>&1 
else
        echo "Configuring wireless network" >> ${LOG_FILE} 2>&1
        wpa_supplicant -Dwext -iwlan0 -c/home/wpa_supplicant.conf -B >> ${LOG_FILE} 2>&1
        udhcpc -i wlan0 -F "${NAME}" -n >> ${LOG_FILE} 2>&1
fi

# ...snip...

# The usual stuff needed to run p2pcam

Make sure /home/boot.sh is executable by running chmod 777 /home/boot.sh. The /home/boot.sh I am using is a bit more advanced, but you get the idea.

ant-thomas commented 6 years ago

Thanks for that.

Does wpa_supplicant actually work on an unconfigured camera?

deorder commented 6 years ago

It works but as soon as p2pcam starts running it will connect to WiFi as specified in devParams.dat. Still have to figure out what checksum algorithm is being used so p2pcam will accept it. While testing I remove p2pcam from the boot.sh and add a endless while loop containing a sleep at the end of the script.

int2018 commented 6 years ago

So far it is working when things are available on the SD card. But things do not survive the reboot, even when I put everything in /home. Anyway, now the device seems messed up, it does not finish the boot sequence. It sounds as if it tries to connect again and again. Any hints? Downgrade firmware?