|
Packit Service |
e18529 |
/*
|
|
Packit Service |
e18529 |
* Compaq Ownership Tag
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* Copyright (C) 2003-2005 Jean Delvare <jdelvare@suse.de>
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
e18529 |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
e18529 |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
e18529 |
* (at your option) any later version.
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
e18529 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
e18529 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
e18529 |
* GNU General Public License for more details.
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
e18529 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
e18529 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* For the avoidance of doubt the "preferred form" of this code is one which
|
|
Packit Service |
e18529 |
* is in an open unpatent encumbered format. Where cryptographic key signing
|
|
Packit Service |
e18529 |
* forms part of the process of creating an executable the information
|
|
Packit Service |
e18529 |
* including keys needed to generate an equivalently functional executable
|
|
Packit Service |
e18529 |
* are deemed to be part of the source code.
|
|
Packit Service |
e18529 |
*
|
|
Packit Service |
e18529 |
* References:
|
|
Packit Service |
e18529 |
* - Compaq "Technical Reference Guide for Compaq Deskpro 4000 and 6000"
|
|
Packit Service |
e18529 |
* First Edition
|
|
Packit Service |
e18529 |
* http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html
|
|
Packit Service |
e18529 |
*/
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
#include <stdio.h>
|
|
Packit Service |
e18529 |
#include <stdlib.h>
|
|
Packit Service |
e18529 |
#include <string.h>
|
|
Packit Service |
e18529 |
#include <unistd.h>
|
|
Packit Service |
e18529 |
#include <getopt.h>
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
#include "version.h"
|
|
Packit Service |
e18529 |
#include "config.h"
|
|
Packit Service |
e18529 |
#include "types.h"
|
|
Packit Service |
e18529 |
#include "util.h"
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* Options are global */
|
|
Packit Service |
e18529 |
struct opt
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
const char *devmem;
|
|
Packit Service |
e18529 |
unsigned int flags;
|
|
Packit Service |
e18529 |
};
|
|
Packit Service |
e18529 |
static struct opt opt;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
#define FLAG_VERSION (1 << 0)
|
|
Packit Service |
e18529 |
#define FLAG_HELP (1 << 1)
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
static void ownership(u32 base, const char *pname, const char *devmem)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
u8 *buf;
|
|
Packit Service |
e18529 |
int i;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* read the ownership tag */
|
|
Packit Service |
e18529 |
if ((buf = mem_chunk(base, 0x51, devmem)) == NULL)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
perror(pname);
|
|
Packit Service |
e18529 |
return;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* chop the trailing garbage */
|
|
Packit Service |
e18529 |
i = 0x4f;
|
|
Packit Service |
e18529 |
while (i >= 0 && (buf[i] == 0x20 || buf[i] == 0x00))
|
|
Packit Service |
e18529 |
i--;
|
|
Packit Service |
e18529 |
buf[i + 1] = '\0';
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* filter and print */
|
|
Packit Service |
e18529 |
if (i >= 0)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
for (; i >= 0; i--)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
if (buf[i] < 32 || (buf[i] >= 127 && buf[i] < 160))
|
|
Packit Service |
e18529 |
buf[i] = '?';
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
printf("%s\n", (char *)buf);
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
free(buf);
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
static u32 decode(const u8 *p)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
int i;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* integrity checking (lack of checksum) */
|
|
Packit Service |
e18529 |
for (i = 0; i < p[4]; i++)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
if (p[5 + i * 10] != '$'
|
|
Packit Service |
e18529 |
|| !(p[6 + i * 10] >= 'A' && p[6 + i * 10] <= 'Z')
|
|
Packit Service |
e18529 |
|| !(p[7 + i * 10] >= 'A' && p[7 + i * 10] <= 'Z')
|
|
Packit Service |
e18529 |
|| !(p[8 + i * 10] >= 'A' && p[8 + i * 10] <= 'Z'))
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
printf("\t Abnormal Entry! Please report. [%02x %02x %02x %02x]\n",
|
|
Packit Service |
e18529 |
p[5 + i * 10], p[6 + i * 10],
|
|
Packit Service |
e18529 |
p[7 + i * 10], p[8 + i * 10]);
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* search for the right entry */
|
|
Packit Service |
e18529 |
for (i = 0; i < p[4]; i++)
|
|
Packit Service |
e18529 |
if (memcmp(p + 5 + i * 10, "$ERB", 4) == 0)
|
|
Packit Service |
e18529 |
return DWORD(p + 9 + i * 10);
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* Return -1 on error, 0 on success */
|
|
Packit Service |
e18529 |
static int parse_command_line(int argc, char * const argv[])
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
int option;
|
|
Packit Service |
e18529 |
const char *optstring = "d:hV";
|
|
Packit Service |
e18529 |
struct option longopts[] = {
|
|
Packit Service |
e18529 |
{ "dev-mem", required_argument, NULL, 'd' },
|
|
Packit Service |
e18529 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
e18529 |
{ "version", no_argument, NULL, 'V' },
|
|
Packit Service |
e18529 |
{ NULL, 0, NULL, 0 }
|
|
Packit Service |
e18529 |
};
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
while ((option = getopt_long(argc, argv, optstring, longopts, NULL)) != -1)
|
|
Packit Service |
e18529 |
switch (option)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
case 'd':
|
|
Packit Service |
e18529 |
opt.devmem = optarg;
|
|
Packit Service |
e18529 |
break;
|
|
Packit Service |
e18529 |
case 'h':
|
|
Packit Service |
e18529 |
opt.flags |= FLAG_HELP;
|
|
Packit Service |
e18529 |
break;
|
|
Packit Service |
e18529 |
case 'V':
|
|
Packit Service |
e18529 |
opt.flags |= FLAG_VERSION;
|
|
Packit Service |
e18529 |
break;
|
|
Packit Service |
e18529 |
case '?':
|
|
Packit Service |
e18529 |
return -1;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
static void print_help(void)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
static const char *help =
|
|
Packit Service |
e18529 |
"Usage: ownership [OPTIONS]\n"
|
|
Packit Service |
e18529 |
"Options are:\n"
|
|
Packit Service |
e18529 |
" -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
|
|
Packit Service |
e18529 |
" -h, --help Display this help text and exit\n"
|
|
Packit Service |
e18529 |
" -V, --version Display the version and exit\n";
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
printf("%s", help);
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
int main(int argc, char * const argv[])
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
u8 *buf;
|
|
Packit Service |
e18529 |
off_t fp;
|
|
Packit Service |
e18529 |
int ok = 0;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (sizeof(u8) != 1 || sizeof(u32) != 4)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
|
|
Packit Service |
e18529 |
exit(255);
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
/* Set default option values */
|
|
Packit Service |
e18529 |
opt.devmem = DEFAULT_MEM_DEV;
|
|
Packit Service |
e18529 |
opt.flags = 0;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (parse_command_line(argc, argv)<0)
|
|
Packit Service |
e18529 |
exit(2);
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (opt.flags & FLAG_HELP)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
print_help();
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (opt.flags & FLAG_VERSION)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
printf("%s\n", VERSION);
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if ((buf = mem_chunk(0xE0000, 0x20000, opt.devmem)) == NULL)
|
|
Packit Service |
e18529 |
exit(1);
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
for (fp = 0; !ok && fp <= 0x1FFF0; fp += 16)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
u8 *p = buf + fp;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (memcmp((char *)p, "32OS", 4) == 0)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
off_t len = p[4] * 10 + 5;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if (fp + len - 1 <= 0x1FFFF)
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
u32 base;
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
if ((base = decode(p)))
|
|
Packit Service |
e18529 |
{
|
|
Packit Service |
e18529 |
ok = 1;
|
|
Packit Service |
e18529 |
ownership(base, argv[0], opt.devmem);
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
}
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
free(buf);
|
|
Packit Service |
e18529 |
|
|
Packit Service |
e18529 |
return 0;
|
|
Packit Service |
e18529 |
}
|