Thursday, 3 July 2014

Howto install OpenWRT on Netgear DG834 or DG834G (v1 or v2)

Got a spare Netgear DG834 or DG834G? Want to try OpenWRT? Want an easy process?

This assume you are running Ubuntu.

Try this:


0. Before you start...

0.1 Ensure router power plug is secure.
0.2 Ensure LAN cable is clicked into both router and computer.
0.3 Ensure your router is working by opening http://192.168.0.1 (or whatever IP address you have changed it to)

1. Backup router config in case you want to restore factory firmware.

2. Factory default router to ensure it's IP address is 192.168.0.1

2.1 Power on router.
2.2 Hold in reset button until test light (tick) flashes.
2.3 Wait for router to reboot (I think - might have to power cycle it).

3. Run my script to turn on telnet, backup partitions, extract environment file, patch ADAM2 to turn off checksum test, download OpenWRT, split into 2 parts, install patched ADAM2 and OpenWRT parts...

Note: This is not conventional and may not work. But unless you have some hardware fault or power failure, you can fairly easily recover your Netgear using a Netgear image and a small C program called nftp. I'll add instructions below.

3.1 mkdir
3.2 cd
3.3 save my script here
3.4 Run my script like this: 

bash ./pc-setup-wrt-v2.bash

... and follow my instructions.

4. Boot into OpenWRT

4.1 Power cycle router.
4.2 Connect ethernet port - may take 1-2 minutes first time.
4.3 Browse to http://192.168.1.1
4.4 Follow instructions to set password.

Done.

My Script

Save as pc-setup-wrt-v2.bash

#!/bin/bash
# Factory default router#   Power on. Hold in reset button until test light (tick) turns on.# Setup PC ethernet interface use DHCP. Disconnect. Connect - should get 192.168.0.2?#   router should be 192.168.0.1# test by pointing browser to 192.168.0.1 - should get Netgear Setup Wizard screen# route del default
# info stuff here
# MTDx partitions using 3.??.32? - seems to have 5 mtdx# mtd0  0x900d0000,0x903e0000  ROOTFS# mtd1  0x90020000,0x900d0000  Kernel# mtd2  0x90000000,0x90020000  ADAM2# mtd3  0x903e0000,0x903f0000  Probably Netgear firmware config# mtd4  0x903f0000,0x90400000  Probably ADAM2 config
# Ordered# mtd2  0x90000000,0x90020000  ADAM2# mtd1  0x90020000,0x900d0000  Kernel# mtd0  0x900d0000,0x903e0000  ROOTFS# mtd3  0x903e0000,0x903f0000  Probably Netgear firmware config# mtd4  0x903f0000,0x90400000  Prob. ADAM2 config
echo "Install needed packages..."
sudo apt-get install wgetsudo apt-get install expectsudo apt-get install mini-httpd
echo "Get openwrt image - this is for mtd0 and mtd1 so it needs to be split..."
which wget || { echo "ERROR: wget not installed"; exit 1; }OPENWRT="openwrt-ar7-squashfs.bin"[[ -f ${OPENWRT} ]] \  || wget "http://downloads.openwrt.org/backfire/10.03.1/ar7/${OPENWRT}"
echo "Configure this script..."
# ip address of router - should be 192.168.0.1 after factory reboot
ROUTER="192.168.0.1"
# ip address on this host - should not need to change
HOST="192.168.0.10"
# port on this host that has ethernet cable to router plugged in - should be same
ETH="eth0"
echo "Configure this script (ROUTER, HOST, and ETH) variables."echo "Disconnect from all other networks."echo "Next time you run this it will reconfigure your ETH port and "echo "connect to your router."echoecho "If you have configured variables correctly, comment out next line."
exit 0
echo "Split OpenWRT image file..."
OPEN0="ow-mtd0.bin"OPEN1="ow-mtd1.bin"which dd || { echo "ERROR: dd not installed"; exit 1; }dd if=${OPENWRT} of=${OPEN1} count=720896 bs=1dd if=${OPENWRT} of=${OPEN0}  skip=720896 bs=1
echo "Reconfigure ETH port..."
which ifconfig || { echo "ERROR: ifconfig not installed"; exit 1; }sudo ifconfig ${ETH} ${HOST} netmask 255.255.255.0
echo "Turn on telnet - assumes your reouter has been factory defaulted..."
LOGIN="--user=admin --password=password"wget -v -O debug.log ${LOGIN} "http://${ROUTER}/setup.cgi?todo=debug"
echo "Telnet to router, and do some heavy stuff - but nothing dangerous...yet..."
# Assign an IP address to ADAM2 (patch)# Backup each MTD Block to RAM# Spawn a HTTP Daemon to download MTD Backups
which expect || { echo "ERROR: expect not installed"; exit 1; }which telnet || { echo "ERROR: telnet not installed"; exit 1; }
expect >telnet.log <set timeout 30set send_human {.1 .3 1 .05 2}
spawn telnet ${ROUTER};                             expect "# "; sleep 1;
send_error "Telnet script\n";send -h "cat /proc/sys/dev/adam2/environment | grep -v \"^my\" > /proc/sys/dev/adam2/environment\r";                                                     expect "# "; sleep 1;send -h "echo \"my_ipaddress ${ROUTER}\" > /proc/sys/dev/adam2/environment\r";                                                     expect "# "; sleep 1;send_error "Cat environment file...\n";send -h "cat /proc/sys/dev/adam2/environment\r";    expect "# "; sleep 1;
send_error "Copy partitions to tmp...\n";send -h "dd if=/dev/mtdblock/0 of=/tmp/mtd0.bin\r"; expect "# "; sleep 1;send -h "dd if=/dev/mtdblock/1 of=/tmp/mtd1.bin\r"; expect "# "; sleep 1;send -h "dd if=/dev/mtdblock/2 of=/tmp/mtd2.bin\r"; expect "# "; sleep 1;send -h "dd if=/dev/mtdblock/3 of=/tmp/mtd3.bin\r"; expect "# "; sleep 1;send -h "dd if=/dev/mtdblock/4 of=/tmp/mtd4.bin\r"; expect "# "; sleep 1;
send_error "Copy environment file...\n";send -h "cat /proc/sys/dev/adam2/environment > /tmp/environment.bak\r";                                                     expect "# "; sleep 1;send -h "cd /tmp\r";                                expect "# "; sleep 1;
send_error "Start web server...\n";send -h "mini_httpd -p 1080\r";                     expect "# "; sleep 1;
send -h "exit\r";EOF

echo "Pull files from router..."
wget ${LOGIN} -O mtd0.bin        "http://${ROUTER}:1080/mtd0.bin"wget ${LOGIN} -O mtd1.bin        "http://${ROUTER}:1080/mtd1.bin"wget ${LOGIN} -O mtd2.bin        "http://${ROUTER}:1080/mtd2.bin"wget ${LOGIN} -O mtd3.bin        "http://${ROUTER}:1080/mtd3.bin"wget ${LOGIN} -O mtd4.bin        "http://${ROUTER}:1080/mtd4.bin"wget ${LOGIN} -O environment.bak "http://${ROUTER}:1080/environment.bak"
echo "See if correct ADAM2 versio is installed..."
which grep || { echo "ERROR: grep not installed"; exit 1; }grep "bootloaderVersion.*0.18.01" environment.bak \  || { echo "HALT: Boot loader version is not 0.18.01"; exit 1; }
echo "See if ADAM2 is already patched..."
ADAM2NEW="mtd2.bin.new"
which md5sum || { echo "ERROR: md5sum not installed"; exit 1; }MDS2=$( md5sum mtd2.bin | cut -d' ' -f1 )if [[ "$MDS2" == "d8a2f4623bf6f64b7427812f0e849aa7" ]]; then  echo "mtd2.bin already patched"  cp mtd2.bin ${ADAM2NEW}else  echo "mtd2.bin not patched"  echo "Verify ADAM2 file..."  MDS=$( md5sum mtd2.bin | cut -d' ' -f1 )  if [[ "$MDS" != "0530bfdf00ec155f4182afd70da028c1" ]]; then    echo "HALT: ADAM2 (mtd2.bin) MD5 sum does not match"    exit 1  fi
  echo "Patch ADAM2..."
  cp mtd2.bin ${ADAM2NEW}  printf '\x00\x00\x00\x00' | dd of=${ADAM2NEW} bs=1 seek=14660 count=4 conv=notrunc 
  echo "Verify patched ADAM2..."
  MDS2=$( md5sum ${ADAM2NEW} | cut -d' ' -f1 )  if [[ "$MDS2" != "d8a2f4623bf6f64b7427812f0e849aa7" ]]; then    echo "HALT: Modified ADAM2 (${ADAM2NEW}) MD5 sum does not match"    exit 1  fifi
echo "Kill off any legacy http servers (if we have somehow left them running)..."
killall mini-httpd
echo "Start local web server..."
sudo mini-httpd -p 8000 || { echo "ERROR: mini-httpd did not start"; exit 1; }
echo "Download modified ADAM2 and OpenWRT files to router and install them..."
expect >flash.log <set timeout 30set send_human {.1 .3 1 .05 2}
spawn telnet ${ROUTER};                           expect "# "; sleep 1;send_error "Telnet script to install modified ${ADAM2NEW}\n";send -h "cd /tmp\r";                              expect "# "; sleep 1;
send -h "rm mtd0.bin\r";                          expect "# "; sleep 1;send -h "rm mtd1.bin\r";                          expect "# "; sleep 1;send -h "rm mtd2.bin\r";                          expect "# "; sleep 1;send -h "rm mtd3.bin\r";                          expect "# "; sleep 1;send -h "rm mtd4.bin\r";                          expect "# "; sleep 1;
send -h "rm ${ADAM2NEW}\r";                       expect "# "; sleep 1;send_error "Download modified ${ADAM2NEW} from ${HOST}...\n";send -h "wget http://${HOST}:8000/${ADAM2NEW}\r"; expect "# "; sleep 10;send -h "dd if=${ADAM2NEW} bs=1 skip=110747 count=5\r";expect {  "DG834" { send_error "GOOD: ${ADAM2NEW} contains DG834 string\n"; };  timeout { send_error "ERROR: TIMEOUT: Did not get DG834\n"; exit;  };  "# "    { send_error "ERROR: Got prompt instead of DG834\n"; exit; };}sleep 1;send_error "Install modified ${ADAM2NEW}...\n";send -h "dd if=${ADAM2NEW} of=/dev/mtdblock/2\r"; expect "# "; sleep 20;send -h "rm ${ADAM2NEW}\r";                       expect "# "; sleep 1;
send -h "rm ${OPEN0}\r";                          expect "# "; sleep 1;send_error "Download ${OPEN0} from ${HOST}...\n";send -h "wget http://${HOST}:8000/${OPEN0}\r";    expect "# "; sleep 10;send_error "Install ${OPEN0}...\n";send -h "dd if=${OPEN0} of=/dev/mtdblock/0\r";    expect "# "; sleep 20;send -h "rm ${OPEN0}\r";                          expect "# "; sleep 1;
send -h "rm ${OPEN1}\r";                          expect "# "; sleep 1;send_error "Download ${OPEN1} from ${HOST}...\n";send -h "wget http://${HOST}:8000/${OPEN1}\r";    expect "# "; sleep 10;send_error "Install ${OPEN1}...\n";send -h "dd if=${OPEN1} of=/dev/mtdblock/1\r";    expect "# "; sleep 20;send -h "rm ${OPEN1}\r";                          expect "# "; sleep 1;
send -h "reboot\r";EOF
echo "Shutdown local web server..."
killall mini-httpd
echo "All done."echoecho "Power cycle router."echo "Reconnect ethernet interface - may take 1-2 minutes"echo "Browse to http://192.168.1.1"
exit 0

Basic Configuration Steps


Save and Apply after each change.

If unsure, power cycle router.

Set password
Set timezone
Set dropbear (ssh) interface to lan

Edit LAN interface
  IP address (WARNING: This gives me most headaches - perhaps leave it alone for a while)
  (When you save and apply, you may need to disconnect/reconnect ethernet interface on pc)
  I set MTU to 1474

Add new (PPPoATM) interface
Set username and password
Set custom DNS servers to OpenDNS 208.67.222.222 and 208.67.220.220
Assign ADSL interface to WAN

Edit Wifi
  Enable
  Set SSID etc.
  Set to WEP and generate WEP hex key somehow.

No WPA???


Sunday, 12 January 2014

Virtualize an old Windows XP disk partition (howto convert disk partition to virtual disk for VirtualBox)

I dug out an old hard disk. I was curious: what gems are stored here?

Turns out there was nothing, but it was in interesting exercise in converting a single disk partition into a VM - something that is not trivial.

I plugged my old drive into a USB hard disk docking station and had a look. It contained Windows XP and Linux from an old PC dating from 2004-2007 I believe.

"Hey!" I thought. I could virtualize this for no good reason and show how easy it is using free and open source software.

Ubuntu Packages

I installed VirtualBox and mbr.

Create VirtualBox VM

  • Select New
  • Name your VM (say TEST)
  • Select Windows and Windows XP
  • Set memory size (default is ok)
  • Select 'do not add a virtual hard drive' - we will create this later in tis VM's directory.

Create Virtual Disk Drive

Open a terminal and change to your ~/VirtualBox\ VM/TEST directory for this example.

Copy and paste my script into your editor.

#!/bin/bash

DISK=/dev/sdd
PART=1

printf "Copy boot sector image...\n"
sudo dd if=$DISK of=mbr.img bs=512 count=1 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

# put 'normal' mbr incase grub or something was used
printf "Replace MBR code..."
sudo install-mbr mbr.img -t 36 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

printf "Copy disk (%s) partition %d...(at 10MB/s 1GB will take 100s)...\n" "$DISK" $PART
PARTIMG=part${PART}.img
sudo dd if=${DISK}${PART} of=$PARTIMG bs=512 || { printf "FAILED\n"; exit 1; }
sudo chown $USER:$USER $PARTIMG
printf "Done\n"

printf "Make VirtualBox VMDK image with MBR...\n"
sudo VBoxManage internalcommands createrawvmdk -filename ./disk.vmdk -rawdisk $DISK -partitions $PART -mbr ./mbr.img || { printf "FAILED\n"; exit 1; }
# VB needs this owned by user
sudo chown $USER:$USER disk-pt.vmdk
printf "Done\n"

# switch to partition image and zero starting offset
# eg.
# from this: RW 8514387 FLAT "/dev/sdd" 63
# to this: RW 8514387 FLAT "/home/phil/Development/pc-part2disk/part1.img" 0
 
printf "Modify VMDK files to use disk partition image...\n"
sudo cat disk.vmdk | sed "s@\"$DISK.*@\"./$PARTIMG\" 0@" > diskimage.vmdk
sudo chown $USER:$USER diskimage.vmdk
printf "Done\n"

# remove VB vmdk that points to physical drive - no longer required
sudo rm disk.vmdk

exit 0
 Change DISK and PART to suit your case. This example uses disk /dev/sdd and partition 1.

Also, run chmod +x

Saturday, 15 June 2013

Howto enable AHCI Mode MacBookPro1,2 and MacBookPro4,1

I added this after insmod ext2 in grub:

setpci -s 0:1f.2 90.b=40

This sets Intel ICH7 (page 509) or ICH8 (page 486) controller into AHCI mode.

A similar command will probably work for other ICHx devices.

I got my bus:slot.function from running lspci - take value from line that states SATA IDE mode

eg.

00:1f.2 SATA controller: Intel Corporation 82801GBM/GHM (ICH7-M Family) SATA Controller [IDE mode] (rev 02)

Both MBP1,2 and MBP4,1 have same bus:slot.function and use same value (40h) to put controller into AHCI mode.

UPDATE: Should be MacBookPro1,2 not MacBookPro2,1





Monday, 3 June 2013

Root Huawei X3 8150 Without Windows or a Working Touchscreen

I got some of this from here

Some phone modes

Enter FASTBOOT Mode

Disconnect USB.
Power-off phone.
RED+VOL-DN+POWER - hold for about 5 seconds. Phone will vibrate and show a white screen with IDEOS displayed.
Connect USB.

Enter RECOVERY Mode

Disconnect USB.
Power-off phone.
GREEN+VOL-UP+POWER - hold for about 5 seconds. Phone will vibrate, show a white screen with IDEOS displayed and then show Recovery menu.
Connect USB.

Enter DOWNLOAD mode

Disconnect USB.
Power-off phone.
RED+GREEN+POWER - hold for a few seconds until screen turns pink/magenta.
Connect USB.
(This does not work for me under Linux)

Replace Stock Recovery with ClockWork Recovery

Install Android SDK
From ubuntu this is very easy now:
apt-get install android-tools-adb
apt-get install android-tools-fastboot
Open root terminal or open terminal and sudo su.

Check that all is well, that USB connection is working and that ADB is correctly installed

Enter RECOVERY mode
Phone should boot into 'Android system recovery'

# adb devices
List of devices attached 
308730C82377 recovery

Enter FASTBOOT mode

# fastboot erase recovery
erasing 'recovery'...
OKAY [  0.033s]
finished. total time: 0.033s

Get ClockWorkMod Recovery
All available Recovery's are here: http://clockworkmod.com/rommanager

Get ClockWork Recovery fro IDEOS
I used http://download2.clockworkmod.com/recoveries/recovery-clockwork-3.0.2.4-ideos.img

# fastboot flash recovery /home/phil/Downloads/recovery-clockwork-3.0.2.4-ideos.img 
sending 'recovery' (3796 KB)...
OKAY [  0.255s]
writing 'recovery'...
OKAY [  0.806s]
finished. total time: 1.061s

Reboot
# fastboot reboot
Phone should reboot.

Get Root
Get files from http://forum.xda-developers.com/attachment.php?attachmentid=416413&d=1286678225

# adb push ../../rootme/rageagainstthecage-arm5.bin  /data/local/tmp
127 KB/s (5392 bytes in 0.041s)

# adb ls /data/local/tmp
000041fd 00000000 51208853 .
000041fd 00000000 51208845 ..
000081b6 00001510 4c77ab24 rageagainstthecage-arm5.bin

# adb shell
~ # cd /data/local/tmp
/data/local/tmp # chmod 0755 rageagainstthecage-arm5.bin 
/data/local/tmp # ./rageagainstthecage-arm5.bin 
/sbin/sh: ./rageagainstthecage-arm5.bin: not found

I give up. I'll exit shell and try again.

/data/local/tmp # exit

# adb shell
~ # whoami
root

Hmm. It seem I was already root! I suspect that SuperuserOneClick that I experimented with - but did not log - using mono under linux may have worked - although I had no indication that it did.

I'll carry on.

Next I remount mdtblock4 to be able to write to it.

~ # mount -o rw,remount /dev/block/mdtblock4 /system
mount: mounting /dev/block/mdtblock4 on /system failed: Invalid argument

But it seems it is not mounted.

~ # mount          
rootfs on / type rootfs (rw)
tmpfs on /dev type tmpfs (rw,relatime,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/block/mtdblock5 on /cache type yaffs2 (rw,nodev,noatime,nodiratime)

~ # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache

In my case, mtdblock4 is not mounted so I mounted it.

~ # mount /dev/block/mtdblock4 /system

~ # ls /system/
app         etc         lib         tts         xbin
bin         fonts       lost+found  usr
build.prop  framework   media       wifi

Now I realise that I made a typo: I entered mdtblock4 instead of mtdblock4.

~ # mount -o rw,remount /dev/block/mtdblock4 /system 
~ # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache
/dev/block/mtdblock4    174080    131780     42300  76% /system

Ok. mtdblock4 is now writeable.

Copy su, busybox, sqlite3, Superuser.apk to device.

# adb push rootme/su  /system/bin/su
837 KB/s (26264 bytes in 0.030s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Dependencies/busybox  /system/bin/busybox
1978 KB/s (1075144 bytes in 0.530s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Dependencies/sqlite3  /system/bin/sqlite3
333 KB/s (24120 bytes in 0.070s)

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Root/  /system/bin/sqlite3
Superuser.apk  su-v1          su-v2          

# adb push SuperOneClickv2.3.3-ShortFuse\ \(1\)/Root/Superuser.apk  /system/app/Superuser.apk
2095 KB/s (843503 bytes in 0.393s)

Now to change permissions.

# adb shell
~ # cd /system/bin
/system/bin # chmod 4755 su
/system/bin # chmod 4755 busybox 
/system/bin # chmod 4755 sqlite3 

/system/bin # cat /proc/cpu
/proc/cpu/     /proc/cpuinfo

What CPU do we have?

/system/bin # cat /proc/cpuinfo 
Processor : ARMv6-compatible processor rev 2 (v6l)
BogoMIPS : 594.73
Features : swp half thumb fastmult edsp java 
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 2

Hardware : HUAWEI U8150 BOARD 
Revision : 0000
Serial : 0000000000000000

Mount /data using ClockWorkMod Recovery
(could have done this using adb)

/system/bin # df
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                    91624        32     91592   0% /dev
/dev/block/mtdblock5     95232      1688     93544   2% /cache
/dev/block/mtdblock4    174080    133716     40364  77% /system
/dev/block/mtdblock6    170624     12340    158284   7% /data

/data is mounted and this seems to be where settings are stored.
 Open settings using sqlite3

/system/bin # ./sqlite3 /data/data/com.android.providers.settings/databases/settings.db 
SQLite version 3.6.22
Enter ".help" for instructions
sqlite>
sqlite> .dump
BEGIN TRANSACTION;
CREATE TABLE android_metadata (locale TEXT);
INSERT INTO "android_metadata" VALUES('en_AU');
CREATE TABLE system (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
INSERT INTO "system" VALUES(4,'volume_voice','4');
INSERT INTO "system" VALUES(5,'volume_alarm','6');
INSERT INTO "system" VALUES(6,'volume_notification','5');
INSERT INTO "system" VALUES(7,'volume_bluetooth_sco','7');
INSERT INTO "system" VALUES(9,'vibrate_on','6');
INSERT INTO "system" VALUES(10,'mode_ringer_streams_affected','166');
INSERT INTO "system" VALUES(11,'mute_streams_affected','46');
INSERT INTO "system" VALUES(12,'dim_screen','1');
INSERT INTO "system" VALUES(13,'stay_on_while_plugged_in','0');
INSERT INTO "system" VALUES(14,'screen_off_timeout','60000');
INSERT INTO "system" VALUES(15,'emergency_tone','0');
INSERT INTO "system" VALUES(16,'call_auto_retry','0');
INSERT INTO "system" VALUES(17,'dtmf_tone_type','0');
INSERT INTO "system" VALUES(18,'hearing_aid','0');
INSERT INTO "system" VALUES(19,'tty_mode','0');
INSERT INTO "system" VALUES(20,'airplane_mode_on','0');
INSERT INTO "system" VALUES(21,'airplane_mode_radios','cell,bluetooth,wifi');
INSERT INTO "system" VALUES(22,'airplane_mode_toggleable_radios','wifi');
INSERT INTO "system" VALUES(23,'auto_time','1');
INSERT INTO "system" VALUES(24,'screen_brightness','77');
INSERT INTO "system" VALUES(25,'screen_brightness_mode','0');
INSERT INTO "system" VALUES(26,'window_animation_scale','0.0');
INSERT INTO "system" VALUES(27,'transition_animation_scale','0.0');
INSERT INTO "system" VALUES(28,'accelerometer_rotation','1');
INSERT INTO "system" VALUES(29,'haptic_feedback_enabled','1');
INSERT INTO "system" VALUES(30,'end_button_behavior','1');
INSERT INTO "system" VALUES(31,'notification_light_pulse','1');
INSERT INTO "system" VALUES(32,'set_install_location','0');
INSERT INTO "system" VALUES(33,'default_install_location','0');
INSERT INTO "system" VALUES(34,'power_sounds_enabled','1');
INSERT INTO "system" VALUES(35,'low_battery_sound','/system/media/audio/ui/LowBattery.ogg');
INSERT INTO "system" VALUES(36,'dock_sounds_enabled','0');
INSERT INTO "system" VALUES(37,'desk_dock_sound','/system/media/audio/ui/Dock.ogg');
INSERT INTO "system" VALUES(38,'desk_undock_sound','/system/media/audio/ui/Undock.ogg');
INSERT INTO "system" VALUES(39,'car_dock_sound','/system/media/audio/ui/Dock.ogg');
INSERT INTO "system" VALUES(40,'car_undock_sound','/system/media/audio/ui/Undock.ogg');
INSERT INTO "system" VALUES(41,'lockscreen_sounds_enabled','0');
INSERT INTO "system" VALUES(42,'lock_sound','/system/media/audio/ui/Lock.ogg');
INSERT INTO "system" VALUES(43,'unlock_sound','/system/media/audio/ui/Unlock.ogg');
INSERT INTO "system" VALUES(44,'vibrate_in_silent','1');
INSERT INTO "system" VALUES(47,'alarm_alert','content://media/internal/audio/media/5');
INSERT INTO "system" VALUES(48,'notification_sound','content://media/internal/audio/media/28');
INSERT INTO "system" VALUES(49,'ringtone','content://media/internal/audio/media/55');
INSERT INTO "system" VALUES(57,'volume_system','0');
INSERT INTO "system" VALUES(58,'volume_system_last_audible','7');
INSERT INTO "system" VALUES(59,'volume_ring','0');
INSERT INTO "system" VALUES(60,'volume_ring_last_audible','1');
INSERT INTO "system" VALUES(61,'mode_ringer','1');
INSERT INTO "system" VALUES(62,'volume_music','10');
INSERT INTO "system" VALUES(63,'volume_music_last_audible','10');
INSERT INTO "system" VALUES(75,'next_alarm_formatted','');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('system',75);
INSERT INTO "sqlite_sequence" VALUES('secure',25);
INSERT INTO "sqlite_sequence" VALUES('systemex',1);
CREATE TABLE secure (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
INSERT INTO "secure" VALUES(1,'bluetooth_on','0');
INSERT INTO "secure" VALUES(2,'data_roaming','0');
INSERT INTO "secure" VALUES(3,'default_input_method','com.android.inputmethod.latin/.LatinIME');
INSERT INTO "secure" VALUES(4,'enabled_input_methods','com.huawei.inputmethod.hwpal/.PinyinIME:com.android.inputmethod.latin/.LatinIME:com.android.inputmethod.pinyin/.PinyinIME:jp.co.omronsoft.openwnn/.OpenWnnJAJP');
INSERT INTO "secure" VALUES(5,'install_non_market_apps','0');
INSERT INTO "secure" VALUES(6,'location_providers_allowed','gps');
INSERT INTO "secure" VALUES(7,'assisted_gps_enabled','1');
INSERT INTO "secure" VALUES(8,'network_preference','1');
INSERT INTO "secure" VALUES(9,'usb_mass_storage_enabled','1');
INSERT INTO "secure" VALUES(10,'wifi_on','0');
INSERT INTO "secure" VALUES(11,'wifi_networks_available_notification_on','1');
INSERT INTO "secure" VALUES(12,'preferred_network_mode','0');
INSERT INTO "secure" VALUES(13,'cdma_cell_broadcast_sms','1');
INSERT INTO "secure" VALUES(14,'preferred_cdma_subscription','0');
INSERT INTO "secure" VALUES(15,'mock_location','0');
INSERT INTO "secure" VALUES(16,'backup_enabled','1');
INSERT INTO "secure" VALUES(17,'backup_transport','com.google.android.backup/.BackupTransportService');
INSERT INTO "secure" VALUES(18,'mount_play_not_snd','1');
INSERT INTO "secure" VALUES(19,'mount_ums_autostart','0');
INSERT INTO "secure" VALUES(20,'mount_ums_prompt','1');
INSERT INTO "secure" VALUES(21,'mount_ums_notify_enabled','1');
INSERT INTO "secure" VALUES(22,'android_id','9774d56d682e549c');
INSERT INTO "secure" VALUES(23,'adb_enabled','0');
INSERT INTO "secure" VALUES(24,'voice_recognition_service','com.google.android.voicesearch/.GoogleRecognitionService');
INSERT INTO "secure" VALUES(25,'throttle_reset_day','3');
CREATE TABLE bluetooth_devices (_id INTEGER PRIMARY KEY,name TEXT,addr TEXT,channel INTEGER,type INTEGER);
CREATE TABLE bookmarks (_id INTEGER PRIMARY KEY,title TEXT,folder TEXT,intent TEXT,shortcut INTEGER,ordering INTEGER);
INSERT INTO "bookmarks" VALUES(1,'Browser',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.browser/.BrowserActivity;end',98,NULL);
INSERT INTO "bookmarks" VALUES(2,'Contacts',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.contacts/.DialtactsContactsEntryActivity;end',99,NULL);
INSERT INTO "bookmarks" VALUES(3,'Email',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.email/.activity.Welcome;end',101,NULL);
INSERT INTO "bookmarks" VALUES(4,'Gmail',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.google.android.gm/.ConversationListActivityGmail;end',103,NULL);
INSERT INTO "bookmarks" VALUES(5,'Calendar',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.calendar/.LaunchActivity;end',108,NULL);
INSERT INTO "bookmarks" VALUES(6,'Music',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.music/.MusicBrowserActivity;end',112,NULL);
INSERT INTO "bookmarks" VALUES(7,'Messaging',NULL,'#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.mms/.ui.ConversationList;end',115,NULL);
CREATE TABLE systemex (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
INSERT INTO "systemex" VALUES(1,'white_languages','en_PK,en_AU,en_US,es_ES');
CREATE INDEX systemIndex1 ON system (name);
CREATE INDEX secureIndex1 ON secure (name);
CREATE INDEX bookmarksIndex1 ON bookmarks (folder);
CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);
CREATE INDEX systemexIndex1 ON systemex (name);
COMMIT;

I wonder what INSERT INTO "secure" VALUES(23,'adb_enabled','0'); is?

I think I want to try this to turn USB Debugging on (based on http://stackoverflow.com/questions/10282484/android-adb-turn-on-wifi-via-adb)

update secure set value=1 where name='adb_enabled';


So here goes...

/system/bin # ./sqlite3 /data/data/com.android.providers.settings/databases/sett
ings.db

sqlite> select * from secure;
1|bluetooth_on|0
2|data_roaming|0
3|default_input_method|com.android.inputmethod.latin/.LatinIME
4|enabled_input_methods|com.huawei.inputmethod.hwpal/.PinyinIME:com.android.inputmethod.latin/.LatinIME:com.android.inputmethod.pinyin/.PinyinIME:jp.co.omronsoft.openwnn/.OpenWnnJAJP
5|install_non_market_apps|0
6|location_providers_allowed|gps
7|assisted_gps_enabled|1
8|network_preference|1
9|usb_mass_storage_enabled|1
10|wifi_on|0
11|wifi_networks_available_notification_on|1
12|preferred_network_mode|0
13|cdma_cell_broadcast_sms|1
14|preferred_cdma_subscription|0
15|mock_location|0
16|backup_enabled|1
17|backup_transport|com.google.android.backup/.BackupTransportService
18|mount_play_not_snd|1
19|mount_ums_autostart|0
20|mount_ums_prompt|1
21|mount_ums_notify_enabled|1
22|android_id|9774d56d682e549c
23|adb_enabled|1
24|voice_recognition_service|com.google.android.voicesearch/.GoogleRecognitionService
25|throttle_reset_day|3
sqlite> 

Reboot phone.

No good.

I then installed CyanogenMod 7 for Huewei IDEOS 8150.

It supports adb so I should have done this ages ago.

I wrote this bash script to begin phone setup without a touchscreen.

#!/bin/bash

adb_sendevent(){
    local -i _a=$1 _k=$2 _v=$3
    printf "$FUNCNAME: _a=%d  _k=%d  _v=%d\n" $_a $_k $_v
    adb shell sendevent "/dev/input/event2" $_a $_k $_v
}

adb_touch1(){
    local -i _a=$1 _x=$2 _y=$3 _w=$4
    #printf "$FUNCNAME: _a=%d  _x=%d  _y=%d  _w=%d\n" $_a $_x $_y $_w
    # send touch event x y
    adb_sendevent 3 0x39 $_a  # start event?
    adb_sendevent 3 0x35 $_x
    adb_sendevent 3 0x36 $_y
    adb_sendevent 3 0x30 $_w  # finger width?
    adb_sendevent 3 0x31 0  # x moved?
    adb_sendevent 3 0x34 0
    adb_sendevent 3 0x32 0  # y moved?
    adb_sendevent 0 0x02 0  # end event?
}

adb_touch(){
    local -i _x=$1 _y=$2 _w=$3
    #adb_sendevent 0 0 0
    adb_touch1 0 $_x $_y   $_w
    adb_touch1 1 0   0x15b 0
    adb_sendevent 0 0 0
}

adb_tap(){
    local -i _x=$1 _y=$2
    adb_touch $_x $_y 0x20
    # android icon selected
    adb_touch $_x $_y 0
}

#0 -->  "KEYCODE_UNKNOWN" 
#1 -->  "KEYCODE_MENU" 
#2 -->  "KEYCODE_SOFT_RIGHT" 
#3 -->  "KEYCODE_HOME" 
#4 -->  "KEYCODE_BACK" 
#5 -->  "KEYCODE_CALL" 
#6 -->  "KEYCODE_ENDCALL" 
#7 -->  "KEYCODE_0" 
#8 -->  "KEYCODE_1" 
#9 -->  "KEYCODE_2" 
#10 -->  "KEYCODE_3" 
#11 -->  "KEYCODE_4" 
#12 -->  "KEYCODE_5" 
#13 -->  "KEYCODE_6" 
#14 -->  "KEYCODE_7" 
#15 -->  "KEYCODE_8" 
#16 -->  "KEYCODE_9" 
#17 -->  "KEYCODE_STAR" 
#18 -->  "KEYCODE_POUND" 
#19 -->  "KEYCODE_DPAD_UP" 
#20 -->  "KEYCODE_DPAD_DOWN" 
#21 -->  "KEYCODE_DPAD_LEFT" 
#22 -->  "KEYCODE_DPAD_RIGHT" 
#23 -->  "KEYCODE_DPAD_CENTER" 
#24 -->  "KEYCODE_VOLUME_UP" 
#25 -->  "KEYCODE_VOLUME_DOWN" 
#26 -->  "KEYCODE_POWER" 
#27 -->  "KEYCODE_CAMERA" 
#28 -->  "KEYCODE_CLEAR" 
#29 -->  "KEYCODE_A" 
#30 -->  "KEYCODE_B" 
#31 -->  "KEYCODE_C" 
#32 -->  "KEYCODE_D" 
#33 -->  "KEYCODE_E" 
#34 -->  "KEYCODE_F" 
#35 -->  "KEYCODE_G" 
#36 -->  "KEYCODE_H" 
#37 -->  "KEYCODE_I" 
#38 -->  "KEYCODE_J" 
#39 -->  "KEYCODE_K" 
#40 -->  "KEYCODE_L" 
#41 -->  "KEYCODE_M" 
#42 -->  "KEYCODE_N" 
#43 -->  "KEYCODE_O" 
#44 -->  "KEYCODE_P" 
#45 -->  "KEYCODE_Q" 
#46 -->  "KEYCODE_R" 
#47 -->  "KEYCODE_S" 
#48 -->  "KEYCODE_T" 
#49 -->  "KEYCODE_U" 
#50 -->  "KEYCODE_V" 
#51 -->  "KEYCODE_W" 
#52 -->  "KEYCODE_X" 
#53 -->  "KEYCODE_Y" 
#54 -->  "KEYCODE_Z" 
#55 -->  "KEYCODE_COMMA" 
#56 -->  "KEYCODE_PERIOD" 
#57 -->  "KEYCODE_ALT_LEFT" 
#58 -->  "KEYCODE_ALT_RIGHT" 
#59 -->  "KEYCODE_SHIFT_LEFT" 
#60 -->  "KEYCODE_SHIFT_RIGHT" 
#61 -->  "KEYCODE_TAB" 
#62 -->  "KEYCODE_SPACE" 
#63 -->  "KEYCODE_SYM" 
#64 -->  "KEYCODE_EXPLORER" 
#65 -->  "KEYCODE_ENVELOPE" 
#66 -->  "KEYCODE_ENTER" 
#67 -->  "KEYCODE_DEL" 
#68 -->  "KEYCODE_GRAVE" 
#69 -->  "KEYCODE_MINUS" 
#70 -->  "KEYCODE_EQUALS" 
#71 -->  "KEYCODE_LEFT_BRACKET" 
#72 -->  "KEYCODE_RIGHT_BRACKET" 
#73 -->  "KEYCODE_BACKSLASH" 
#74 -->  "KEYCODE_SEMICOLON" 
#75 -->  "KEYCODE_APOSTROPHE" 
#76 -->  "KEYCODE_SLASH" 
#77 -->  "KEYCODE_AT" 
#78 -->  "KEYCODE_NUM" 
#79 -->  "KEYCODE_HEADSETHOOK" 
#80 -->  "KEYCODE_FOCUS" 
#81 -->  "KEYCODE_PLUS" 
#82 -->  "KEYCODE_MENU" 
#83 -->  "KEYCODE_NOTIFICATION" 
#84 -->  "KEYCODE_SEARCH" 
#85 -->  "TAG_LAST_KEYCODE"

adb_tap 0x70 0x80  # tap on android icon
adb shell input keyevent 20  # down to 'Create'
adb shell input keyevent 20  # down to 'Sign in'
adb shell input keyevent 23  # enter
adb shell input text 'username@gmail.com'
adb shell input keyevent 20  # down to 'password'
adb shell input text 'password or 2-factor code'  # 2-factor pw
adb shell input keyevent 23  # enter
adb shell input keyevent 20  # down to 'Sign in'
adb shell input keyevent 23  # enter
My phone is now setup and working.

Now to setup WiFi.


Friday, 31 May 2013

Install Lubuntu 13.04 on PowerBook G4 17" (REV D? 2005)

Get ISO from here

http://cdimage.ubuntu.com/lubuntu/releases/raring/release/lubuntu-13.04-desktop-powerpc.iso

Boot ISO (Option-C) when power on or 'c' if yaboot is already installed.

At the boot: prompt type:
live video=radeonfb:1024x768-32@60 

https://help.ubuntu.com/community/Lubuntu/Documentation/FAQ/PPC

Install!

Saturday, 23 February 2013

Howto Telnet into Netgear DG834GVv1

This probably works for any Netgear DG834*

Your default router IP address is 192.168.0.1 unless you have changed it.

Start Telnet Daemon

http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26/usr/sbin/utelnetd+-d

You may now telnet to your router's IP address.

eg. telnet 192.168.0.1

NB: This may enable telnet access from any Internet host.
In my case on a DG834GV v1, I could not connect to my router over Internet.

To run any installed program, use this general form.
It will launch program and redirect output to ppp_log.

General Form

http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26
+

View ppp_log

http://192.168.0.1/ppp_log

Read a File

eg. to read /etc/hosts


http://192.168.0.1/setup.cgi?todo=ping_test&c4_IPAddr=%26/bin/cat+/etc/hosts+%3E+/www/ppp_log

Ignore Ping error message and read ppp_log:

Stop Telnet Daemon

From telnet session

/bin/ps

Find PID (first number) for utelnetd daemon

/bin/kill

You should see a message on your console like "Connection closed by foreign host.

Via browser


Ensure you can no longer login into your router.

Monday, 28 January 2013

Spell checker and corrector in BASH

Why? Because it can be done.


I have used nothing but BASH.

Sample run:




I tried to make it very feature rich while keeping code to about 100 lines - this version is about 80.

Can you make it smaller?

Features:
* Auto-corrects if it can only find 1 suggested correction.
* Lists all words in dictionary that could be corrections and lets user choose or replace word.
* Suggestions only consider words with single letter deletions, additions or changes.
* Spelling errors are highlighted in yellow.
* Corrections are highlighted in green.

Todo:
* Save result to a file (Currently just displays result on terminal).

I did go a little overboard with processing word case.


#!/bin/bash

[[ -z "$1" ]] && echo "Usage: $0 " && exit 1
ERR=33; COR=32                                   # error and corrected colours
PS3="Select or manually enter a correction: "
L="a-zA-Z'"                                      # these letters are deemed part of words
FINAL=
shopt -s extglob
shopt -u nocasematch
declare -A WORD
while read W; do WORD[${W,,}]=${W,,}; done < /usr/share/dict/words

function checkSuggestion() {
    local p=$1 S=$1 C                            # uses CASE and SUGGEST from caller
    [ -z "${WORD[$p]}" ] && return 1             # matches word in dict!
    [ $CASE = PROP  ] && S=${p^}                 # change case to original word
    [ $CASE = CAP   ] && S=${p^^}   
    [ $CASE = CAPs  ] && { S=${p%%\'*};             S="${S^^}'${p#*\'}"; }   
    [ $CASE = LAT   ] && { S=${p##*\'};             S="${p%\'*}'${S^^}"; }   
    [ $CASE = OPROP ] && { S=${p%%\'*}; C=${p#*\'}; S="${S^^}'${C^}";    }   
    SUGGEST="${SUGGEST/ $S /} $S "               # add to suggestion list
}

function getSuggestions() {
    local W=$1 t l # p
    SUGGEST=; CASE=LOWER
    [[ $W =~ ^[A-Z][a-z]        ]] && CASE=PROP   # Prop
    [[ $W =~ ^[A-Z][A-Z]        ]] && CASE=CAP    # CAP
    [[ $W =~ ^[A-Z]\'[a-z]      ]] && CASE=PROP   # P'rop
    [[ $W =~  [A-Z]\'[a-z]$     ]] && CASE=CAPs   # CAP's
    [[ $W =~ ^[a-z]\'[A-Z]      ]] && CASE=LAT    # l'At
    [[ $W =~ ^[A-Z]\'[A-Z][A-Z] ]] && CASE=CAP    # C'AP
    [[ $W =~ ^[A-Z]\'[A-Z][a-z] ]] && CASE=OPROP  # O'Prop
    W=${W,,}                                     # lowercase word
    for (( t=0 ; t<=${#W} ; t++ )); do           # for each letter position of word, delete|change|insert a letter
        checkSuggestion ${W:0:t}${W:t+1}         # try deleting letter at position t
        for l in {a..z} "'"; do                  # try changing and inserting letters
            checkSuggestion ${W:0:t}$l${W:t+1}   # try changing letter
            checkSuggestion ${W:0:t}$l${W:t}     # try inserting letter
        done
    done
}

function correctWord() {                         # correct word and return in RET as well as pattern in PAT
    local W=$1 D1 D2 SUGGEST                     # uses L RESULT
        getSuggestions "$W"
        [[ ! "$RESULT" =~ ([^$L]|^)$W([^$L]|$) ]] && { printf "ERROR: Could not find [%s] in %s\n" "$W" "$LINE"; exit 1; }
        D1="${BASH_REMATCH[1]}"; D2="${BASH_REMATCH[2]}"  # get delimiters around word
        PAT="${D1:-#}$W${D2:-%}"                 # match pattern
        case $SUGGEST in
             '') echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 read -p "Enter correction [$W]: " RET < /dev/fd/3  # no suggestions - let user correct
                 RET=${RET:-$W};;
            +([$L ])\ +([$L ]))                                     # multiple suggestions
                 echo -e "${RESULT/$PAT/$D1\e[${ERR}m$W\e[0m$D2}"   # display line with spelling mistake highlighted
                 select RET in "(IGNORE)" $SUGGEST; do              # get correction
                     RET=${RET:-$REPLY}                             # user entered a word instead
                     [ "$REPLY" = "1" ] && RET=$W                   # no change
                     break
                 done < /dev/fd/3;;
              *) RET=${SUGGEST// /}                                 # get single suggestion
                 printf "%b\n" "\e[31mAuto:\e[0m ${RESULT/$PAT/$D1\e[9;${ERR}m$W\e[0;${COR}m $RET\e[0m$D2}"
        esac
        COL=$COR; [ "$RET" = "$W" ] && COL=$ERR   # if unchanged, highlight in error colour
        RESULT="${RESULT/$PAT/$D1\e[${COL}m${RET}\e[0m$D2}"       # correct word
}

function correctLine(){
    local LINE="$1" W                            # uses RESULT
    while read -d' ' W; do                       # for each word in line
        [[ -z "$W" || -n ${WORD[${W,,}]} ]] 2> /dev/null && continue  # null or word in dict so ignore it
        correctWord $W
        printf ">> %b\n\n" "$RESULT" 
    done <<< "$LINE"
}

while read LINE; do  # for each line
    RESULT="$LINE"
    correctLine " ${LINE//[^$L ]/ } "            # replace punctuation with spaces
    FINAL+="$RESULT\n"                           # append corrected line to result
done 3<&0 < $1                                   # redirect stdin to /dev/fd/3 for select and read

printf "\nCORRECTED TEXT\n\n%b\n" "$FINAL"