void DisplayHex( ImageHdr * Hdr, unsigned char * image ) { int i,offs = 0; word imsize = swapword(Hdr->Size); # define NOPERLINE 16 printf("HEX DISPLAY OF IMAGE HEADER:\n"); printf("Magic = %lx\n", swapword(Hdr->Magic)); printf("Flags = %lx\n", swapword(Hdr->Flags)); printf("Size = %lx\n", imsize); printf("\nHEX DISPLAY OF IMAGE BODY:\n"); for(;;) { printf("%04x: ",offs); for (i=0; i < NOPERLINE ; i++) { if (imsize--) printf(" %02.2x", *image++); else { putchar('\n'); exit(0); } } putchar('\n'); offs += NOPERLINE; } }
void DisplayHdr( ImageHdr * Hdr ) { printf("IMAGE HEADER:\n"); printf("Magic = %lx\n", swapword(Hdr->Magic)); printf("Flags = %lx\n", swapword(Hdr->Flags)); printf("Size = %#lx (%ld)\n", swapword(Hdr->Size),swapword(Hdr->Size)); }
static int prcparse(UBYTE *prcfile,size_t_68k prcsize){ palmdb meep; meep.numrecords = prcfile[0x4C] << 8 | prcfile[0x4C + 1]; memcpy(meep.name,prcfile,32); memcpy(&meep.flags,prcfile + 0x20,2); swapword(meep.flags); memcpy(&meep.version,prcfile + 0x22,2); swapword(meep.version); memcpy(&meep.modnum,prcfile + 0x30,4); swaplong(meep.modnum); memcpy(&meep.appinfo,prcfile + 0x34,4); swaplong(meep.appinfo); memcpy(&meep.sortinfo,prcfile + 0x38,4); swaplong(meep.sortinfo); memcpy(meep.type.typec,prcfile + 0x3C,4); memcpy(meep.creator.typec,prcfile + 0x40,4); memcpy(&meep.uuidseed,prcfile + 0x44,4); swaplong(meep.uuidseed); memcpy(&meep.nextrecordlist,prcfile + 0x48,4); swaplong(meep.nextrecordlist); //get the needed 68k memory curmemloc = getnewlinearchunks(NUM_BANKS(prcsize + meep.numrecords * 4)) << 16; if(curmemloc != 0){ avbytes = NUM_BANKS(prcsize + meep.numrecords * 4) * SIZEOFBANK; currealaddr = (UBYTE*)get_real_address(curmemloc); } else return FAILEDMALLOC; meep.open = false; meep.resdb = true; apps.push_back(meep); unsigned int robin; for(robin = 0;robin < meep.numrecords;robin++){ unpackprcresource(robin,prcfile,prcsize,apps.size() - 1); } apps[apps.size() - 1].intmain = getresource(apps.size() - 1,1,'code'); if(apps[apps.size() - 1].intmain != 0){ apps[apps.size() - 1].exe = true; hasbootableapp = true; } return WORKED; }
// --------------------------------------------------------------------------- // // ----------- double popdouble(byte **c, char swap){ double d; memcpy(&d,*c,8); *c+=8; if(swap){ swapword(8,&d); } return(d); }
// --------------------------------------------------------------------------- // // ----------- UInt32 popint(byte **c, char swap){ UInt32 i; memcpy(&i,*c,4); *c+=4; if(swap){ swapword(4,&i); } return(i); }
// --------------------------------------------------------------------------- // // ------------ bString& bString::operator + (unsigned int* x){ char str[8]; UInt32 lx=*x; #ifdef __LITTLE_ENDIAN__ swapword(sizeof(UInt32),&lx); #endif sprintf(str,"%.4s",(char*)&lx); cat(str); return(*this); }
/* pSouce and PDest can be same */ static fz_error * decodeunicodeBMP(char* source, int sourcelen,char* dest, int destlen) { wchar_t tmp[1024*2]; int converted; memset(tmp,0,sizeof(tmp)); memcpy(tmp,source,sourcelen); swapword((char*)tmp,sourcelen); converted = WideCharToMultiByte(CP_ACP, 0, tmp, -1, dest, destlen, NULL, NULL); if(converted == 0) return fz_throw("fonterror"); return 0; }
void putmodules( void ) { word isize = swapword( hdr.Size ); word * v; Module * m; int rsize; word mtype; v = (word *)malloc( (int)isize ); if ( v == NULL ) return; fseek( fd, sizeof (ImageHdr), SEEK_SET ); rsize = fread( v, 1, (int)isize, fd ); if ( rsize != isize ) { fprintf(stderr, "Image file smaller than header size\n" ); exit(1); } m = (Module *)v; while ((mtype = swapword( m->Type )) != 0 ) { word msize = swapword( m->Size ); word mslot = swapword( m->Id ); word mdsize = swapword( m->MaxData ); word mversion = swapword( m->Version ); char * mname = m->Name; switch ( mtype ) { case T_Program: printf( "Program : %10s slot %3ld version %4ld size %5ld datasize %4ld\n", mname, mslot, mversion, msize, mdsize ); break; case T_Module: printf( "Module : %10s slot %3ld version %4ld size %5ld datasize %4ld\n", mname, mslot, mversion, msize, mdsize ); break; case T_ResRef: printf( "ResRef : %10s slot %3ld version %4ld\n", mname, mslot, mversion ); break; default: fprintf( stderr, "Unknown module type: %lx\n", mtype ); exit(1); } m = (Module *)((char *)m + msize); } free( v ); return; } /* putmodules */
int main( int argc, char **argv ) { long info = false; int size; long changed = false; long progtype; char * file = NULL; char * type = NULL; char * name = 0; long stacksize = -1; long heapsize = -1; long modules = false; argv++; while ( *argv != 0 ) { char *arg = *argv; if ( *arg++ == '-' ) { switch ( *arg++ ) { case 'n': _ARG_; name = arg; break; case 's': _ARG_; stacksize = (long)atol( arg ); break; case 'h': _ARG_; heapsize = (long)atol( arg ); break; case 'i': info = true; break; case 'm': modules = true; break; } } else { file = *argv; } argv++; } if (file == NULL) { fprintf( stderr, "objed: must have name of file to examine\n" ); exit(1); } if (name == 0 && stacksize == -1 && heapsize == -1) /* nowt to write */ { fd = fopen(file,"rb"); } else { #if defined(__TRAN) || defined(__ARM) || defined(R140) || defined(__C40) || defined (__HELIOS) fd = fopen( file, "r+b" ); #else fd = fopen( file, "rwb" ); #endif } if ( fd == 0 ) { fprintf(stderr, "Cannot open %s\n",file ); exit(1); } size = fread( &hdr, 1, sizeof (ImageHdr), fd ); if ( size != sizeof(ImageHdr) ) { fprintf( stderr, "Read failure: %d\n", size ); exit(1); } { static Image_Magics Values[] = { /* * XXX - the following have been extracted from /hsrc/include/module.h * make sure that they are kept up to date */ { 0x12345678L, "Transputer Helios Executable\n" }, { 0xc4045601L, "Helios-C40 Executable\n" }, { 0x0a245601L, "Helios-ARM Executable\n" }, { 0x86045601L, "Helios-I860 Executable\n" }, #ifdef HOSTISBIGENDIAN { 0x01560468L, "Helios-M68K Executable\n" }, #else { 0x68045601L, "Helios-M68K Executable\n" }, #endif { TaskForce_Magic, "Task Force Binary\n" }, { RmLib_Magic, "Resource Management Library Binary\n" } }; unsigned long value = swapword( hdr.Magic ); int i; for (i = sizeof (Values) / sizeof (Values[0]); i--;) { if (value == Values[ i ].Magic) { printf( Values[ i ].Type ); break; } } if (i < 0) { fprintf( stderr, "File not object image\n" ); exit(1); } if (Values[i].Magic == 0x01560468) { swapopt = FALSE; } } if ( info ) printf( "Image size = %ld bytes\n", swapword( hdr.Size ) ); size = fread( &prog, 1, sizeof (Program), fd ); if ( size != sizeof (Program) ) { fprintf(stderr, "Read failure: %d\n", size ); exit(1); } progtype = swapword( prog.Module.Type ); if ( progtype == T_Program ) type = "Program"; elif ( progtype == T_Module ) type = "Module"; elif ( progtype == T_ResRef ) type = "ResRef"; if ( type == NULL ) { fprintf(stderr, "Invalid Module type: %lx\n",progtype ); exit(1); } if ( info ) { printf( "Object type is %s\n",type ); printf( "Name is '%s' ",prog.Module.Name ); } if ( name != 0 ) { int i; changed = true; for (i = 0; i < 32; i++ ) prog.Module.Name[ i ] = 0; strncpy( prog.Module.Name, name, 31 ); if ( info ) printf( "New = '%s'", prog.Module.Name ); } if ( info ) putchar('\n'); if ( swapword( prog.Module.Type ) == T_Program ) { if ( info ) printf( "Stacksize = %ld ", swapword( prog.Stacksize ) ); if ( stacksize != -1 ) { changed = true; prog.Stacksize = swapword( stacksize ); if ( info ) printf( "New = %ld", stacksize ); } if ( info ) printf( "\nHeapsize = %ld ", swapword( prog.Heapsize ) ); if ( heapsize != -1 ) { changed = true; prog.Heapsize = swapword( heapsize ); if ( info ) printf( "New = %ld", heapsize ); } if ( info ) putchar('\n'); } else if (stacksize != -1 || heapsize != -1) { printf( "Cannot set stacksize/heapsize - image does not include a program stucture\n" ); } if ( modules ) putmodules(); if ( changed ) { fseek( fd, 0L, SEEK_SET ); size = fwrite( &hdr, 1, sizeof (ImageHdr), fd ); if ( size != sizeof (ImageHdr) ) { fprintf(stderr, "Write failure writing header: wrote %d bytes, errno = %d\n", size, errno); exit(1); } size = fwrite( &prog, 1, sizeof (Program), fd ); if ( size != sizeof (Program) ) { fprintf( stderr, "Write failure writing program: wrote %d bytes, errno = %d\n", size, errno); exit(1); } } fclose( fd ); return 0; } /* main */
unsigned char * LoadImage( ImageHdr * Hdr, char * name ) { unsigned char * image; FILE * fp; word imsize; #ifdef __STDC__ if( (fp = fopen(name, "rb")) == NULL) #else if( (fp = fopen(name, "r")) == NULL) #endif { fprintf(stderr,"imdump: file not found\n"); exit(1); } if (fread((char *)Hdr,1,sizeof(ImageHdr),fp) != sizeof(ImageHdr)) { fprintf(stderr,"imdump: Cannot read image file header\n"); exit(1); } { static Image_Magics Magics[] = { /* * XXX - the following have been extracted from /hsrc/include/module.h * make sure that they are kept up to date */ { 0x12345678L, FALSE, FALSE }, /* Transputer */ { 0xc4045601L, FALSE, TRUE }, /* TMS320C40 */ { 0x0a245601L, FALSE, TRUE }, /* ARM */ { 0x86045601L, FALSE, TRUE }, /* i860 */ #ifdef HOSTISBIGENDIAN { 0x01560468L, TRUE, FALSE }, /* 68K (on a big-endian host) */ #endif { 0x68045601L, FALSE, FALSE } /* 68K */ }; word Magic = swapword( Hdr->Magic ); int i; for (i = sizeof (Magics) / sizeof (Magics[ 0 ] ); i--;) { if (Magic == Magics[ i ].ImageMagic) { smtopt = Magics[ i ].smtopt; if (Magics[ i ].invert_swap) swapopt = !swapopt; break; } } if (i < 0) { if (Magic == 0xC3CBC6C5) { fprintf( stderr, "imdump: file is an ARM Object Format file!\n" ); } else if (Magic == 0xC5C6CBC3) { fprintf( stderr, "imdump: file is a byte swapped ARM Object Format file!\n" ); } else if ( (Magic & 0x00FFFFFF) == 0x00014120) { fprintf( stderr, "imdump: file is an Helios Object Format file!\n" ); } else { fprintf(stderr,"imdump: file is not an image file\n"); fprintf(stderr, "Magic %lx is not a Helios Magic number\n", Magic); } fclose(fp); exit(1); } } imsize = swapword(Hdr->Size); if((image = (unsigned char *)malloc((int)imsize)) == NULL ) { fprintf(stderr,"imdump: out of mem\n"); fclose(fp); exit(1); } if( fread(image,1,(int)imsize,fp) != imsize) { free(image); fprintf(stderr,"imdump: size of image file is wrong\n"); fclose(fp); exit(1); } fclose(fp); return image; }
void DisplayMods( ImageHdr * Hdr, unsigned char * image ) { Module *mod = (Module *)image; word swap, type, size, imsize; printf("\nIMAGE BODY:\n"); imsize = swapword(Hdr->Size); while ((unsigned char *)mod < image + imsize) { putchar('\n'); type = swapword(mod->Type); switch(type) { case T_Program: printf("Type = Program\n"); goto bypass; case T_Module: printf("Type = Code Module\n"); bypass: size = swapword(mod->Size); printf("Size = %#lx (%ld)\n",size,size); printf("Name = \"%s\"\n",mod->Name); swap = swapword(mod->Id); printf("Slot = %#lx (%ld)\n",swap,swap); swap = swapword(mod->Version); printf("Version = %#lx (%ld)\n",swap,swap); swap = swapword(mod->MaxData); printf("MaxData = %#lx (%ld)\n",swap,swap); swap = swapword(mod->Init); printf("Init RPTR = %#lx (%ld)\n",swap,swap); if (smtopt) { /* Cheat slightly, so we can have one version */ /* of imdump even if the Module struct has no */ /* MaxCodeP field. */ swap = swapword(*(((word *)(&mod->Init)) + 1)); printf("MaxCodeP = %#lx (%ld)\n",swap,swap); } if(type == T_Module) break; swap = swapword(((Program *)mod)->Stacksize); printf("Stacksize = %#lx (%ld)\n",swap,swap); swap = swapword(((Program *)mod)->Heapsize); printf("Heapsize = %#lx (%ld)\n",swap,swap); swap = swapword(((Program *)mod)->Main); printf("Main RPTR = %#lx (%ld)\n",swap,swap); break; case T_ResRef: printf("Type = ResRef\n"); size = swapword(((ResRef *)mod)->Size); printf("Size = %#lx (%ld)\n",size,size); printf("Require = \"%s\"\n",((ResRef *)mod)->Name); swap = swapword(((ResRef *)mod)->Id); printf("Slot = %#lx (%ld)\n",swap,swap); swap = swapword(((ResRef *)mod)->Version); printf("Version = %#lx (%ld)\n",swap,swap); break; case T_Device: /* This relies on the "Module" structure and * "Device" structure identity for the most part. * (Since <device.h> has too many Helios definitions * for a HOSTed version of this program) */ printf("Type = Device\n") ; size = swapword(mod->Size); printf("Size = %#lx (%ld)\n",size,size) ; printf("Name = \"%s\"\n",mod->Name) ; swap = swapword(mod->Version); printf("Version = %#lx (%ld)\n",swap,swap) ; swap = swapword(mod->MaxData); printf("DevOpen = %#lx (%ld)\n",swap,swap) ; break ; case 0L: /* module 0 = last module */ return; default: fprintf(stderr, "WARNING: Unknown module type %#lx - skipping\n",type); size = mod->Size; /* a definite maybe */ if (size <= 0) size = 4; break; } mod = (Module *)((char *)mod + size); } fprintf(stderr, "imdump exit - no last module indication\n"); }