This is cryptsums.c in view mode; [Download] [Up]
/* cryptsums.c -- copyright 1992 by C.D.Lane */ #include <c.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <strings.h> #include <sys/loader.h> #include "cryptsum.h" typedef enum {PROGRAM, FILENAME, PASSWORD, ARGC} ARGUMENTS; void error_puts(char *string) { perror(string); exit(EXIT_FAILURE); } void error_printf(const char *format, ...) { va_list ap; va_start(ap, format); { (void) vfprintf(stderr, format, ap); } va_end(ap); exit(EXIT_FAILURE); } void main(int argc, char *argv[]) { FILE *stream; char *password; unsigned short halfword; long l_offset, s_offset; unsigned long ncmds, nsects, size; struct section s_section; struct mach_header m_header; struct load_command l_command; struct segment_command s_command; if (argc != ARGC) error_printf("Usage: %s Application Password\n", argv[PROGRAM]); if ((stream = fopen(argv[FILENAME], "r")) == NULL) error_puts("fopen"); if (fread(&m_header, sizeof(m_header), 1, stream) == 0) error_puts("fread"); if (m_header.magic != MH_MAGIC) error_printf("Incorrect Mach magic number %x!\n", m_header.magic); for (ncmds = m_header.ncmds; ncmds > 0; ncmds--) { l_offset = ftell(stream); if (fread(&l_command, sizeof(l_command), 1, stream) == 0) error_puts("fread"); if (l_command.cmd == LC_SEGMENT) { if (fseek(stream, l_offset, SEEK_SET) == CERROR) error_puts("fseek"); if (fread(&s_command, sizeof(s_command), 1, stream) == 0) error_puts("fread"); if (strcmp(s_command.segname, CS_SEGMENT) != 0) { for (nsects = s_command.nsects; nsects > 0; nsects--) { if (fread(&s_section, sizeof(s_section), 1, stream) == 0) error_puts("fread"); s_offset = ftell(stream); if (fseek(stream, s_section.offset, SEEK_SET) == CERROR) error_puts("fseek"); for (size = 0L, halfword = 0; size < s_section.size; size++) halfword = cs_checksum(halfword, getc(stream)); password = cs_cryptkey(argv[PASSWORD], halfword); (void) printf("%s %s %s\n", s_command.segname, s_section.sectname, password); if (fseek(stream, s_offset, SEEK_SET) == CERROR) error_puts("fseek"); } } } if(fseek(stream, l_command.cmdsize + l_offset, SEEK_SET) == CERROR) error_puts("fseek"); } exit(EXIT_SUCCESS); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.