Commit Diff


commit - e1716e31fec0683e492d71167afd826075bf69f2
commit + a2a93b840dde3c1b4bfea464f6d6488f113f4456
blob - addd1f7834039dd2ec4c03cdfc3081f4c694dd82
blob + 3fc400dd00f83a973e016e2f7881d71b73c7060c
--- dermob-cli.c
+++ dermob-cli.c
@@ -24,7 +24,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $Id: dermob-cli.c,v 1.7 2006/08/12 13:37:06 matthias Exp $ */
+/* $Id: dermob-cli.c,v 1.8 2006/08/12 14:15:25 matthias Exp $ */
 
 #include "dermob.h"
 #include "mach.h"
@@ -84,7 +84,8 @@ main (int argc, char **argv)
 	if ((buffer = malloc(sb.st_size)) == NULL)
 		errx(1, "Cannot allocate memory");
 	
-	len = read(fd, buffer, sb.st_size);
+	size = sb.st_size;
+	len = read(fd, buffer, size);
 	
 	cpu = get_cpu_information();
 	bo_a = get_bo_information();
blob - 535c94e400c7efbce3e168be21630fff3f5d022d
blob + d6bcac0788b9de1b13a0cb70e22c7f9ecb9bdd03
--- dermob.c
+++ dermob.c
@@ -24,7 +24,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $Id: dermob.c,v 1.26 2006/08/12 13:52:39 matthias Exp $ */
+/* $Id: dermob.c,v 1.27 2006/08/12 14:15:25 matthias Exp $ */
 
 #include "dermob.h"
 #include "mach.h"
@@ -172,16 +172,16 @@ examine_segmet(char *buffer, int *offset, int cmd, int
 		case LC_SEGMENT:
 			sc = malloc(sizeof(*sc));
 			memcpy(sc, ptr, sizeof(*sc));
-			mprintf("  Name:		%s\n", sc->segname);
-			mprintf("  VM addr:	0x%.08x\n", swapi(sc->vmaddr));
-			mprintf("  VM size:	0x%.08x\n", swapi(sc->vmsize));
-			mprintf("  VM size:	0x%.08x\n", swapi(sc->vmsize));
-			mprintf("  File offset:	0x%.08x\n", swapi(sc->fileoff));
-			mprintf("  File size:	%d bytes\n", swapi(sc->filesize));
-			mprintf("  Max prot:	0x%.08x\n", swapi(sc->maxprot));
-			mprintf("  Init prot:	0x%.08x\n", swapi(sc->initprot));
-			mprintf("  No of sects:	%d\n", swapi(sc->nsects));
-			mprintf("  Flags:	0x%.08x\n", swapi(sc->flags));
+			mprintf("    Name:		%s\n", sc->segname);
+			mprintf("    VM addr:		0x%.08x\n", swapi(sc->vmaddr));
+			mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
+			mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
+			mprintf("    File offset:	0x%.08x\n", swapi(sc->fileoff));
+			mprintf("    File size:		%d bytes\n", swapi(sc->filesize));
+			mprintf("    Max prot:		0x%.08x\n", swapi(sc->maxprot));
+			mprintf("    Init prot:		0x%.08x\n", swapi(sc->initprot));
+			mprintf("    No of sects:	%d\n", swapi(sc->nsects));
+			mprintf("    Flags:		0x%.08x\n", swapi(sc->flags));
 			*nofx = swapi(sc->nsects);
 			//*offset += sizeof(*sc);
 			ret = sizeof(*sc);
@@ -190,10 +190,10 @@ examine_segmet(char *buffer, int *offset, int cmd, int
 		case LC_SYMTAB:
 			symc = malloc(sizeof(*symc));
 			memcpy(symc, ptr, sizeof(*symc));
-			mprintf("  Symbol table offset:	%d bytes\n", swapi(symc->symoff));
-			mprintf("  Symbol table entries:	%d\n", swapi(symc->nsyms));
-			mprintf("  String table offset:	%d bytes\n", swapi(symc->stroff));
-			mprintf("  String table size:	%d bytes\n", swapi(symc->strsize));
+			mprintf("    Symbol table offset:	%d bytes\n", swapi(symc->symoff));
+			mprintf("    Symbol table entries:	%d\n", swapi(symc->nsyms));
+			mprintf("    String table offset:	%d bytes\n", swapi(symc->stroff));
+			mprintf("    String table size:		%d bytes\n", swapi(symc->strsize));
 			//*offset += sizeof(*symc);
 			ret = sizeof(*symc);
 			free(symc);
@@ -203,11 +203,11 @@ examine_segmet(char *buffer, int *offset, int cmd, int
 			dly = malloc(sizeof(*dly));
 			memcpy(dly, ptr, sizeof(*dly));
 			if (dyn_display < 1) {
-				mprintf("  Name:			%s\n", ptr+swapi(dly->dylib.name.offset));
+				mprintf("    Name:		%s\n", ptr+swapi(dly->dylib.name.offset));
 				timev = swapi(dly->dylib.timestamp);
-				mprintf("  Timestamp:		%s", ctime(&timev));
-				mprintf("  Current version:	0x%x\n", swapi(dly->dylib.current_version));
-				mprintf("  Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
+				mprintf("    Timestamp:		%s", ctime(&timev));
+				mprintf("    Current version:	0x%x\n", swapi(dly->dylib.current_version));
+				mprintf("    Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
 			} else {
 				trigger = 0;
 				mprintf("   + %s\n", ptr+swapi(dly->dylib.name.offset));
@@ -220,7 +220,7 @@ examine_segmet(char *buffer, int *offset, int cmd, int
 		case LC_LOAD_DYLINKER:
 			dlnk = malloc(sizeof(*dlnk));
 			memcpy(dlnk, ptr, sizeof(*dlnk));
-			mprintf("  Name:		%s\n", ptr+swapi(dlnk->name.offset));
+			mprintf("    Name:		%s\n", ptr+swapi(dlnk->name.offset));
 			//*offset += sizeof(*dlnk);
 			ret = sizeof(*dlnk);
 			free(dlnk);
@@ -228,24 +228,24 @@ examine_segmet(char *buffer, int *offset, int cmd, int
 		case LC_DYSYMTAB:
 			dsym = malloc(sizeof(*dsym));
 			memcpy(dsym, ptr, sizeof(*dsym));
-			mprintf("  ilocalsym:		%d\n", swapi(dsym->ilocalsym));
-			mprintf("  nlocalsym:		%d\n", swapi(dsym->nlocalsym));
-			mprintf("  iextdefsym:		%d\n", swapi(dsym->iextdefsym));
-			mprintf("  nextdefsym:		%d\n", swapi(dsym->nextdefsym));
-			mprintf("  iundefsym:		%d\n", swapi(dsym->iundefsym));
-			mprintf("  nundefsym:		%d\n", swapi(dsym->nundefsym));
-			mprintf("  tocoff:		%d\n", swapi(dsym->tocoff));
-			mprintf("  ntoc:			%d\n", swapi(dsym->ntoc));
-			mprintf("  modtaboff:		%d\n", swapi(dsym->modtaboff));
-			mprintf("  nmodtab:		%d\n", swapi(dsym->nmodtab));
-			mprintf("  extrefsymoff:		%d\n", swapi(dsym->extrefsymoff));
-			mprintf("  nextrefsyms:		%d\n", swapi(dsym->nextrefsyms));
-			mprintf("  indirectsymoff:	%d\n", swapi(dsym->indirectsymoff));
-			mprintf("  nindirectsyms:	%d\n", swapi(dsym->nindirectsyms));
-			mprintf("  extreloff:		%d\n", swapi(dsym->extreloff));
-			mprintf("  nextrel:		%d\n", swapi(dsym->nextrel));
-			mprintf("  locreloff:		%d\n", swapi(dsym->locreloff));
-			mprintf("  nlocrel:		%d\n", swapi(dsym->nlocrel));
+			mprintf("    ilocalsym:		%d\n", swapi(dsym->ilocalsym));
+			mprintf("    nlocalsym:		%d\n", swapi(dsym->nlocalsym));
+			mprintf("    iextdefsym:	%d\n", swapi(dsym->iextdefsym));
+			mprintf("    nextdefsym:	%d\n", swapi(dsym->nextdefsym));
+			mprintf("    iundefsym:		%d\n", swapi(dsym->iundefsym));
+			mprintf("    nundefsym:		%d\n", swapi(dsym->nundefsym));
+			mprintf("    tocoff:		%d\n", swapi(dsym->tocoff));
+			mprintf("    ntoc:		%d\n", swapi(dsym->ntoc));
+			mprintf("    modtaboff:		%d\n", swapi(dsym->modtaboff));
+			mprintf("    nmodtab:		%d\n", swapi(dsym->nmodtab));
+			mprintf("    extrefsymoff:	%d\n", swapi(dsym->extrefsymoff));
+			mprintf("    nextrefsyms:	%d\n", swapi(dsym->nextrefsyms));
+			mprintf("    indirectsymoff:	%d\n", swapi(dsym->indirectsymoff));
+			mprintf("    nindirectsyms:	%d\n", swapi(dsym->nindirectsyms));
+			mprintf("    extreloff:		%d\n", swapi(dsym->extreloff));
+			mprintf("    nextrel:		%d\n", swapi(dsym->nextrel));
+			mprintf("    locreloff:		%d\n", swapi(dsym->locreloff));
+			mprintf("    nlocrel:		%d\n", swapi(dsym->nlocrel));
 			//*offset += sizeof(*dsym);
 			ret = sizeof(*dsym);
 			free(dsym);
blob - 5f101236ff224accdedb3d8790a37334615230bb
blob + 43530b76e43cd58d6f0db158cc2bacbf6de21667
--- dermob.h
+++ dermob.h
@@ -47,5 +47,7 @@ int cpu;
 int bo_a;
 // Binary byte order
 int bo_b;
+// Size in bytes of the binary
+size_t size;
 
 #endif
blob - 28c581ed092006c1b800d2d38e081ffb4db7b843
blob + 79999577cb4c4bc900dc59f0a50ae83110e9740a
--- util.c
+++ util.c
@@ -24,7 +24,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $Id: util.c,v 1.14 2006/08/12 14:01:14 matthias Exp $ */
+/* $Id: util.c,v 1.15 2006/08/12 14:15:25 matthias Exp $ */
 
 #include "dermob.h"
 #include "mach.h"
@@ -55,9 +55,15 @@ display_fat_header(char *buffer, int *roffset)
 
 	narch = swapi(fh->nfat_arch);
 	for (i = 0; i < narch; i++) {
-		mprintf(" Architecture %d\n", i);
 		analyse_fat_arch(buffer, &offset, fa);
 
+		if (swapi(fa->size) > size) {
+			printf("Malformed universal binary.  Size for one " \
+			"Architecture is larger than the complete binary.\n");
+			exit(1);
+		}
+		mprintf(" Architecture %d\n", i+1);
+		
 		if (cpu == swapi(fa->cputype))
 			*roffset = swapi(fa->offset);
 
@@ -100,7 +106,7 @@ display_load_commands(char *buffer, int *offset, int n
 	sec = malloc(sizeof(*sec));
 	
 	for (i = 0; i < ncmds; i++) {
-		mprintf("Load command:	%d\n", i);
+		mprintf(" - Load command:	%d\n", i+1);
 		analyse_load_command(buffer, offset, ld);
 		print_load_command(ld);
 		offset_old = *offset;
@@ -109,7 +115,7 @@ display_load_commands(char *buffer, int *offset, int n
 			for (j = 0; j < nofx; j++) {
 				// Skip the segment header
 				if (j == 0) *offset += val;
-				mprintf("Section %d\n", j);
+				mprintf("   + Section %d\n", j+1);
 				examine_section(buffer, offset, sec);
 				if ((strcmp(sec->segname, "__TEXT") == 0) &&
 				    (strcmp(sec->sectname, "__text") == 0)) {
@@ -152,25 +158,25 @@ display_load_commands(char *buffer, int *offset, int n
 void
 print_section(struct section *sec)
 {
-	mprintf("    Sectname:	%s\n", sec->sectname);
-	mprintf("    VM addr:	0x%.08x\n", swapi(sec->addr));
-	mprintf("    VM size:	%d bytes\n", swapi(sec->size));
-	mprintf("    Offset:	%d\n", swapi(sec->offset));
+	mprintf("     Sectname:	%s\n", sec->sectname);
+	mprintf("     VM addr:	0x%.08x\n", swapi(sec->addr));
+	mprintf("     VM size:	%d bytes\n", swapi(sec->size));
+	mprintf("     Offset:	%d\n", swapi(sec->offset));
 	mprintf("\n");
 }
 
 void
 print_load_command(struct load_command *ld)
 {
-	mprintf("  Command:	");
+	mprintf("    Command:	");
 	display_cmd_name(swapi(ld->cmd));
-	mprintf("  Command size:	%d bytes\n", swapi(ld->cmdsize));
+	mprintf("    Command size:	%d bytes\n", swapi(ld->cmdsize));
 }
 
 void
 print_mo_header(struct mach_header *mh)
 {
-	mprintf(" Magic:		0x%x\n", swapi(mh->magic));
+	mprintf("Magic:		0x%x\n", swapi(mh->magic));
 	mprintf(" CPU Type:	");
 	display_cpu_arch(swapi(mh->cputype));
 	mprintf("\n");	
@@ -185,7 +191,7 @@ print_mo_header(struct mach_header *mh)
 void
 print_fat_header(struct fat_header *fh)
 {
-	mprintf(" Magic:		0x%x\n", swapi(fh->magic));
+	mprintf("Magic:		0x%x\n", swapi(fh->magic));
 }
 
 void