ÜberWall

UWfirmforce

/* $Id: java.c,v 1.2 2010/07/04 17:49:02 khorben Exp $ */
/* Copyright (c) 2010 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 <stdio.h>
#include <string.h>
#include <stdint.h>
#include "plugin.h"
/* java */
/* types */
#pragma pack(1)
struct header
{
uint32_t magic;
uint16_t minor_version;
uint16_t major_version;
uint16_t constant_pool;
};
#pragma pack()
/* variables */
/* magic */
static unsigned char sig1[] = "\xca\xfe\xba\xbe";
static unsigned char sig2[] = "<init>";
static PluginMagic java_magic[] =
{
{ 0, 0, sig1, sizeof(sig1)-1 },
{ 0, 0, sig2, sizeof(sig2)-1 },
{ 0, 0, NULL, 0 }
};
/* functions */
static int java_callback(PluginHelper * ph, int signature, FILE * fp);
/* plugin */
Plugin plugin =
{
PT_EXECUTABLE,
"JAVA",
java_magic,
java_callback
};
/* private */
static int _callback_header(PluginHelper * ph, struct header * hdr);
static int java_callback(PluginHelper * ph, int signature, FILE * fp)
{
int score = 0;
struct header buf;
if(signature != 0)
return 50;
if(fread(&buf, sizeof(buf), 1, fp) != 1)
return -1;
buf.major_version = htob16(buf.major_version);
buf.minor_version = htob16(buf.minor_version);
buf.constant_pool = htob16(buf.constant_pool);
score += _callback_header(ph, &buf);
return score;
}
static int _callback_header(PluginHelper * ph, struct header * hdr)
{
ph->printf(ph, "version %u.%u, %u constants in pool\n",
hdr->major_version, hdr->minor_version,
hdr->constant_pool);
return 100;
}