From: oohoseoo AT aol DOT com (OoHOSEoO) Newsgroups: comp.os.msdos.djgpp Subject: Re: SIGSEGV from reading an executable... (?) Lines: 183 Message-ID: <1998090501523400.VAA26069@ladder01.news.aol.com> NNTP-Posting-Host: ladder01.news.aol.com Date: 5 Sep 1998 01:52:34 GMT Organization: AOL http://www.aol.com References: <1998090501154700 DOT VAA20831 AT ladder01 DOT news DOT aol DOT com> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk ok, a little revision or two in the source; but still no difference: (new code below) #include #include #include long getsize(const char*); int readfile(const char*, long); void convert(int, char*, char*); int output(long, const char*); int main(int argc, char* argv[]) { long size = 0; if(argc == 2){ if((size = getsize(argv[1])) == 0){ puts("The file was zero bytes long.\n"); return 1; } printf("at reading\nsize = %l\n", size); if(readfile(argv[1], size)){ return 1; } } return 0; } int readfile(const char* argv, long size) { unsigned char buf[32768]; long amount = 32768; long left = size; long read = 0; FILE* fp; if((fp = fopen(argv, "rb")) == NULL){ puts("There was an error opening the file"); return 1; } while(left){ if(left < amount){ amount = left; } if((read = fread(buf, 1, amount, fp)) == 0){ puts("There was an error reading the file"); return 1; } output(read, buf); left -= amount; } fclose(fp); return 0; } int output(long size, const char* buf) { char HI[5]; char LO[5]; long count; for(count = 0; count < size; count++){ convert(buf[count], HI, LO); printf("%s%s ", HI, LO); } return 0; } long getsize(const char* argv) { FILE* fp; long curpos = 0; long length = 0; if((fp = fopen(argv, "rb")) == NULL){ return 0; } curpos = ftell(fp); printf("curpos = %l\n", curpos); fseek(fp, 0, SEEK_END); length = ftell(fp); printf("length = %l\n", length); fseek(fp, curpos, SEEK_SET); fclose(fp); return length; } void convert(int Byte, char* HI, char* LO) { char chr[3]; int status = 0; if(Byte == 0){ strcpy(chr, "00"); }else{ sprintf(chr, "%02X", Byte); } while(status < 2){ switch(chr[status]){ case '0': if(!status) strcpy(HI, "0000"); if(status) strcpy(LO, "0000"); case '1': if(!status) strcpy(HI, "0001"); if(status) strcpy(LO, "0001"); break; case '2': if(!status) strcpy(HI, "0010"); if(status) strcpy(LO, "0010"); break; case '3': if(!status) strcpy(HI, "0011"); if(status) strcpy(LO, "0011"); break; case '4': if(!status) strcpy(HI, "0100"); if(status) strcpy(LO, "0100"); break; case '5': if(!status) strcpy(HI, "0101"); if(status) strcpy(LO, "0101"); break; case '6': if(!status) strcpy(HI, "0110"); if(status) strcpy(LO, "0110"); break; case '7': if(!status) strcpy(HI, "0111"); if(status) strcpy(LO, "0111"); break; case '8': if(!status) strcpy(HI, "1000"); if(status) strcpy(LO, "1000"); break; case '9': if(!status) strcpy(HI, "1001"); if(status) strcpy(LO, "1001"); break; case 'A': if(!status) strcpy(HI, "1010"); if(status) strcpy(LO, "1010"); break; case 'B': if(!status) strcpy(HI, "1011"); if(status) strcpy(LO, "1011"); break; case 'C': if(!status) strcpy(HI, "1100"); if(status) strcpy(LO, "1100"); break; case 'D': if(!status) strcpy(HI, "1101"); if(status) strcpy(LO, "1101"); break; case 'E': if(!status) strcpy(HI, "1110"); if(status) strcpy(LO, "1110"); break; case 'F': if(!status) strcpy(HI, "1111"); if(status) strcpy(LO, "1111"); break; } status++; } return; } James B. (OoHOSEoO AT aol DOT com) *please enable "Email author" or "CC Author" before you post, thank you :)