ÜberWall

UWfirmforce

/* $Id: android.c,v 1.1 2011/02/26 18:03:52 khorben Exp $ */
/* Copyright (c) 2011 Joachim Steiger <roh@hyte.de> (original version) */
/* Copyright (c) 2011 khorben of Uberwall */
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <stdint.h>
#include <time.h>
#include "plugin.h"
/* android */
/* public */
/* types */
/* from http://android.git.kernel.org/?p=platform/bootloader/legacy.git;a=blob;f=include/boot/bootimg.h;h=44fde9277d65c82eecb8ffeaab7b078e61c6ff3f;hb=HEAD */
#define BOOT_MAGIC "ANDROID!"
#define BOOT_MAGIC_SIZE 8
#define BOOT_NAME_SIZE 16
#define BOOT_ARGS_SIZE 512
#pragma pack(1)
struct android
{
unsigned char magic[BOOT_MAGIC_SIZE];
unsigned kernel_size; /* size in bytes */
unsigned kernel_addr; /* physical load addr */
unsigned ramdisk_size; /* size in bytes */
unsigned ramdisk_addr; /* physical load addr */
unsigned second_size; /* size in bytes */
unsigned second_addr; /* physical load addr */
unsigned tags_addr; /* physical addr for kernel tags */
unsigned page_size; /* flash page size we assume */
unsigned unused[2]; /* future expansion: should be 0 */
unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
unsigned char cmdline[BOOT_ARGS_SIZE];
unsigned id[8]; /* timestamp / checksum / sha1 / etc */
};
#pragma pack()
/* constants */
/* variables */
/* magic */
static unsigned char sig1[BOOT_MAGIC_SIZE] = BOOT_MAGIC;
static PluginMagic android_magic[] =
{
{ sizeof(struct android), 0, sig1, sizeof(sig1)-1 },
{ 0, 0, NULL, 0 }
};
/* functions */
static int android_callback(PluginHelper * ph, int signature, FILE * fp);
/* plugin */
Plugin plugin =
{
PT_EXECUTABLE,
"ANDROID",
android_magic,
android_callback
};
/* private */
/* functions */
/* android_callback */
static int _callback_size(PluginHelper * ph, struct android * buf);
static int _callback_addr(PluginHelper * ph, struct android * buf);
static int _callback_cmdline(PluginHelper * ph, struct android * buf);
static int _callback_name(PluginHelper * ph, struct android * buf);
static int android_callback(PluginHelper * ph, int signature, FILE * fp)
{
int score = 0;
struct android buf;
if(fread(&buf, sizeof(buf), 1, fp) != 1)
return 0;
score += _callback_size(ph, &buf);
_callback_addr(ph, &buf);
_callback_cmdline(ph, &buf);
_callback_name(ph, &buf);
ph->printf(ph, "\n");
return score;
}
static int _callback_size(PluginHelper * ph, struct android * buf)
{
ph->printf(ph, ", kernel size 0x%08x", buf->kernel_size);
ph->printf(ph, ", ramdisk size 0x%08x", buf->ramdisk_size);
ph->printf(ph, ", second size 0x%08x", buf->second_size);
ph->printf(ph, ", page size 0x%08x", buf->page_size);
return buf->kernel_size > 0 && buf->kernel_size < (2 << 30) ? 100 : 0;
}
static int _callback_addr(PluginHelper * ph, struct android * buf)
{
ph->printf(ph, ", kernel at 0x%08x", buf->kernel_addr);
ph->printf(ph, ", ramdisk at 0x%08x", buf->ramdisk_addr);
ph->printf(ph, ", second at 0x%08x", buf->second_addr);
ph->printf(ph, ", tags at 0x%08x", buf->tags_addr);
return 100;
}
static int _callback_cmdline(PluginHelper * ph, struct android * buf)
{
ph->printf(ph, ", cmdline=\"%512s\"", buf->cmdline);
return 100;
}
static int _callback_name(PluginHelper * ph, struct android * buf)
{
ph->printf(ph, ", name \"%32s\"", buf->name);
return 0;
}