/* * Compaq Ownership Tag * * (C) 2003 Jean Delvare * * 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; either version 2 of the License, or * (at your option) any later version. * * 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 * * For the avoidance of doubt the "preferred form" of this code is one which * is in an open unpatent encumbered format. Where cryptographic key signing * forms part of the process of creating an executable the information * including keys needed to generate an equivalently functional executable * are deemed to be part of the source code. * * References: * - Compaq "Technical Reference Guide for Compaq Deskpro 4000 and 6000" * First Edition * http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html */ #include #include #include #include #include #include #include #include "types.h" #include "util.h" static void ownership(int fd, u32 base, const char *pname, const char *devmem) { u8 *buf; int i; if((buf=malloc(0x51))==NULL) { perror(pname); return; } /* read the ownership tag */ if(lseek(fd, (off_t)base, SEEK_SET)==-1) { perror(devmem); return; } if(myread(fd, buf, 0x50, devmem)==-1) { free(buf); exit(1); } /* chop the trailing garbage */ i=0x4f; while(i>=0 && (buf[i]==0x20 || buf[i]==0x00)) i--; buf[i+1]='\0'; /* filter and print */ if(i>=0) { for(; i>=0; i--) { if(buf[i]<32 || (buf[i]>=127 && buf[i]<160)) buf[i]='?'; } printf("%s\n", (char *)buf); } free(buf); } static u32 decode(const u8 *p) { int i; /* integrity checking (lack of checksum) */ for(i=0; i='A' && p[6+i*10]<='Z') || !(p[7+i*10]>='A' && p[7+i*10]<='Z') || !(p[8+i*10]>='A' && p[8+i*10]<='Z')) { printf("\t Abnormal Entry! Please report. [%02x %02x %02x %02x]\n", p[5+i*10], p[6+i*10], p[7+i*10], p[8+i*10]); return 0; } } /* search for the right entry */ for(i=0; i=2) devmem=argv[1]; if((fd=open(devmem, O_RDONLY))==-1 || lseek(fd, fp, SEEK_SET)==-1) { perror(devmem); exit(1); } while(!ok && fp<0xFFFFF) { if(myread(fd, buf, 16, devmem)==-1) exit(1); if(memcmp((char *)buf, "32OS", 4)==0) { off_t len=buf[4]*10+5; u8 *p; if(fp+len-1<=0xFFFFF) { u32 base; if((p=malloc(len))==NULL) { perror("malloc"); exit(1); } memcpy(p, buf, 16); if(len>16) { /* buffer completion */ if(myread(fd, p+16, len-16, devmem)==-1) { free(p); exit(1); } } if((base=decode(p))) { ok=1; ownership(fd, base, argv[0], devmem); } else lseek(fd, fp+16, SEEK_SET); free(p); } } fp+=16; } if(close(fd)==-1) { perror(devmem); exit(1); } return 0; }