1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <unistd.h> 32 #include <fcntl.h> 33 #include <strings.h> 34 #include <sys/types.h> 35 #include <sys/mman.h> 36 37 #define ISTRLEN 16 38 char istr[ISTRLEN + 1] = "/usr/lib/ld.so.1"; 39 char istretc[ISTRLEN + 1] = "/etc/lib/ld.so.1"; 40 char bstr[ISTRLEN + 1] = "/tmp/bfulib/bf.1"; 41 42 #define ISTRLEN2 12 43 char istr2[ISTRLEN2 + 1] = "/lib/ld.so.1"; 44 char bstr2[ISTRLEN2 + 1] = "/tmp/bl/bf.1"; 45 46 #ifdef __sparc 47 48 #define LD64 49 50 #define I64STRLEN 24 51 char i64str[I64STRLEN + 1] = "/usr/lib/sparcv9/ld.so.1"; 52 char b64str[I64STRLEN + 1] = "/tmp/bfulib/sparcv9/bf.1"; 53 54 #define I64STRLEN2 20 55 char i64str2[I64STRLEN2 + 1] = "/lib/sparcv9/ld.so.1"; 56 char b64str2[I64STRLEN2 + 1] = "/tmp/bl/sparcv9/bf.1"; 57 58 #endif /* __sparc */ 59 60 #ifdef __i386 61 62 #define LD64 63 64 #define I64STRLEN 22 65 char i64str[I64STRLEN + 1] = "/usr/lib/amd64/ld.so.1"; 66 char b64str[I64STRLEN + 1] = "/tmp/bfulib/amd64/bf.1"; 67 68 #define I64STRLEN2 18 69 char i64str2[I64STRLEN2 + 1] = "/lib/amd64/ld.so.1"; 70 char b64str2[I64STRLEN2 + 1] = "/tmp/bl/amd64/bf.1"; 71 72 #endif /* __sparc */ 73 74 #define MINSIZE 12 /* MIN of ISTRLEN ISTRLEN2 I64STRLEN I64STRLEN2 */ 75 76 int 77 main(int argc, char **argv) 78 { 79 int i, f, fd; 80 size_t size; 81 char *map; 82 83 for (f = 1; f < argc; f++) { 84 boolean_t found = B_FALSE; 85 86 fd = open(argv[f], O_RDWR); 87 size = lseek(fd, 0, SEEK_END); 88 map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 89 for (i = 0; i < size - MINSIZE - 1; i++) { 90 if (i < size - ISTRLEN - 1 && 91 (bcmp(&map[i], istr, ISTRLEN) == 0 || 92 bcmp(&map[i], istretc, ISTRLEN) == 0)) { 93 bcopy(bstr, &map[i], ISTRLEN); 94 found = B_TRUE; 95 } 96 if (i < size - ISTRLEN2 - 1 && 97 bcmp(&map[i], istr2, ISTRLEN2) == 0) { 98 bcopy(bstr2, &map[i], ISTRLEN2); 99 found = B_TRUE; 100 } 101 #ifdef LD64 102 if (i < size - I64STRLEN - 1 && 103 bcmp(&map[i], i64str, I64STRLEN) == 0) { 104 bcopy(b64str, &map[i], I64STRLEN); 105 found = B_TRUE; 106 } 107 if (i < size - I64STRLEN2 - 1 && 108 bcmp(&map[i], i64str2, I64STRLEN2) == 0) { 109 bcopy(b64str2, &map[i], I64STRLEN2); 110 found = B_TRUE; 111 } 112 #endif 113 } 114 msync(map, size, MS_SYNC); 115 munmap(map, size); 116 close(fd); 117 if (!found) 118 fprintf(stderr, "bfuld: %s: no ld.so.1 found\n", 119 argv[f]); 120 } 121 return (0); 122 } 123