int main ()

{
    int a = TestByteOrder(); 
    printf("%d.\n",a);
    return 0;
}
Example #2
0
main()
{
  unsigned int n = 1;
  char *p;
  
  p = (char *)&n;
  
  if(*p == 1)
    printf("Little Endian\n");
  else if(*(p + sizeof(int) - 1) == 1)
    printf("Big Endian\n");
  else
    printf("????\n");
    
  isLittleEndian();

  int i = 0x01234567;
  char *ptr = (char *)&i;

  printf("%x\t %x\n", *ptr, *(ptr+1));

  
  show_mem_rep((char *)&i, sizeof(i));

  printf("TestByteOrder = [%d]\n", TestByteOrder());
  
}
Example #3
0
/*----------------------------------------------------------------------
 * convert2ulong
 * Convert four adjacent bytes to a unsigned long.
 *
 * parameters:  buffer : pointer to a 4 byte buffer.
 * returns:     the converted value as a unsigned long.
 *--------------------------------------------------------------------*/
unsigned long convert2ulong(unsigned char* plbyte) {
	unsigned long ul = 0;
	if(TestByteOrder() != BIG_ENDIAN) {
	   ul = (plbyte[0] <<24) + (plbyte[1] <<16) + (plbyte[2] <<8) + (plbyte[3] & 0xFF);    
	}else{
		ul = (unsigned long)plbyte;
	}
  	return ul;
}
Example #4
0
/*----------------------------------------------------------------------
 * convert2ushort
 * Convert two adjacent bytes to a short.
 *
 * parameters:  buffer : pointer to first of two buffer bytes.
 * returns:     the converted value as a unsigned short 0-64k.
 *--------------------------------------------------------------------*/
unsigned short convert2ushort(unsigned char* buffer) {
	unsigned short x;
	if(TestByteOrder() != BIG_ENDIAN) {
	   x = (buffer[0] <<8) + (buffer[1] & 0xFF);
	}else{
		x = (unsigned short)buffer;
	}
	return x;
}
Example #5
0
unsigned long Bytes2Ulong(unsigned char* plByte)
{
	unsigned long ul = 0;
	if(TestByteOrder() != FALSE) {
	   ul = (plByte[0] <<24) + (plByte[1] <<16) + (plByte[2] <<8) + (plByte[3] & 0xFF);
	}else{
		ul = (unsigned long)plByte;
	}
  	return ul;
}
Example #6
0
void init_libxpwn(int *argc, char *argv[]) {
	int i, j, n = *argc;
	for (i = 0; i < n; i++) {
		if (!strcmp(argv[i], "--old-img3-decrypt")) {
			n--;
			memmove(&argv[i], &argv[i + 1], (n - i) * sizeof(char *));
			Img3DecryptLast = FALSE;
		}
	}
	argv[*argc = n] = NULL;

	TestByteOrder();
	GlobalLogLevel = 0xFF;
	logCallback = defaultCallback;
}
Example #7
0
/* ----------------------------------Utility Functions---------------------------------- */
float Bytes2Float(const unsigned char* pBytes)
{
	float f = 0;
	if(TestByteOrder() != FALSE) {
	   ((Byte*)(&f))[0] = pBytes[3];
	   ((Byte*)(&f))[1] = pBytes[2];
	   ((Byte*)(&f))[2] = pBytes[1];
	   ((Byte*)(&f))[3] = pBytes[0];
	}else{
	   ((Byte*)(&f))[0] = pBytes[0];
	   ((Byte*)(&f))[1] = pBytes[1];
	   ((Byte*)(&f))[2] = pBytes[2];
	   ((Byte*)(&f))[3] = pBytes[3];
	}

	return f;
}
Example #8
0
/*----------------------------------------------------------------------
 * FloatFromBytes
 * Converts bytes to Float.
 *
 * parameters:  pBytes : received buffer containing pointer to 4 bytes
 *
 * returns:     a float value.
 *--------------------------------------------------------------------*/
float FloatFromBytes(const unsigned char* pBytes)
{
	float f = 0;
	if(TestByteOrder() != BIG_ENDIAN) {
	   ((BYTE*)(&f))[0] = pBytes[3];
	   ((BYTE*)(&f))[1] = pBytes[2];
	   ((BYTE*)(&f))[2] = pBytes[1];
	   ((BYTE*)(&f))[3] = pBytes[0];
	}else{
	   ((BYTE*)(&f))[0] = pBytes[0];
	   ((BYTE*)(&f))[1] = pBytes[1];
	   ((BYTE*)(&f))[2] = pBytes[2];
	   ((BYTE*)(&f))[3] = pBytes[3];
	}
	
	return f; 
}
Example #9
0
File: hfs.c Project: arkanoid1/xpwn
int main(int argc, const char *argv[]) {
	io_func* io;
	Volume* volume;
	
	TestByteOrder();
	
	if(argc < 3) {
		printf("usage: %s <image-file> <ls|cat|mv|symlink|mkdir|add|rm|chmod|extract|extractall|rmall|addall|grow|getattr|debug> <arguments>\n", argv[0]);
		return 0;
	}
	
	io = openFlatFile(argv[1]);
	if(io == NULL) {
		fprintf(stderr, "error: Cannot open image-file.\n");
		return 1;
	}
	
	volume = openVolume(io); 
	if(volume == NULL) {
		fprintf(stderr, "error: Cannot open volume.\n");
		CLOSE(io);
		return 1;
	}
	
	if(argc > 1) {
		if(strcmp(argv[2], "ls") == 0) {
			cmd_ls(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "cat") == 0) {
			cmd_cat(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "mv") == 0) {
			cmd_mv(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "symlink") == 0) {
			cmd_symlink(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "mkdir") == 0) {
			cmd_mkdir(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "add") == 0) {
			cmd_add(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "rm") == 0) {
			cmd_rm(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "chmod") == 0) {
			cmd_chmod(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "extract") == 0) {
			cmd_extract(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "extractall") == 0) {
			cmd_extractall(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "rmall") == 0) {
			cmd_rmall(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "addall") == 0) {
			cmd_addall(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "grow") == 0) {
			cmd_grow(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "getattr") == 0) {
			cmd_getattr(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[2], "debug") == 0) {
			if(argc > 3 && strcmp(argv[3], "verbose") == 0) {
				debugBTree(volume->catalogTree, TRUE);
			} else {
				debugBTree(volume->catalogTree, FALSE);
			}
		}
	}
	
	closeVolume(volume);
	CLOSE(io);
	
	return 0;
}
Example #10
0
File: libxpwn.c Project: OPK/xpwn
void init_libxpwn() {
	TestByteOrder();
	GlobalLogLevel = 0xFF;
	logCallback = defaultCallback;
}
Example #11
0
File: libxpwn.c Project: Sayen/xpwn
void init_libxpwn() {
	TestByteOrder();
}
Example #12
0
/*--------------------------------------------------------------------*/
int main(int argc, char **argv) {

        s32 zvert=0;
        BOOL endloopy = FALSE;

	s16 portNum;
	s16 deviceNum = 0;
	s16 i;
        s16 Ccount=0;
	u16 value=0;
	s16 id_flag = 0;
	s16 errorCode;
	s16 tryPortNum = 1;
	unsigned char Record[79];				//record returned from device read where max size is 79
	C2Accel_AngRecord	Accel_AngRecord;

	printf("\n   3DM-GX3 Read Acceleration and Angular Rate\n");

	/*-------- If user specifies a port, then use it */
	if (argc > 1) {
		tryPortNum = atoi(argv[1]);
		if (tryPortNum < 2 || tryPortNum > 256) {
			printf("   usage:  i3dmgx3 <portNumber>\n");
			printf("        valid ports are 2..256\n");
			exit(1);
		}

	        /*-------- open a port, map a device */
	        portNum = i3dmgx3_openPort(tryPortNum, 115200, 8, 0, 1, 1024, 1024);
	        if (portNum<0) {
		    printf("   port open failed.\n");
		    printf("   Comm error %d, %s: ", portNum, explainError(portNum));
		   goto Exit;
	        }

        }else{
          portNum=OnGetSerialPorts();
          if(portNum<0)
             goto Exit;

        }
	printf("\n   Using COM Port #%d \n", portNum);

	/*-------- Set Comm Timeout values */
	errorCode = setCommTimeouts(portNum, 50, 50); /* Read & Write timeout values */
	if (errorCode!=I3DMGX3_COMM_OK) {
		printf("   setCommTimeouts failed on port:%d with errorcode:%d\n",portNum,errorCode);
		goto Exit;
	} 

	/*-------- Disclose the byte order of host */
	if( TestByteOrder() !=BIG_ENDIAN)
		printf("   (Local Host is in Little Endian format)\n");
	else
		printf("   (Local Host is in Big Endian format)\n");
	printf("\n");  

	/*-------- 0xC2 Accel and Ang rate Output --- Accel x y z and Ang x y z */
	printf("\n   0xC2  Accel and Ang Output  \n");


	errorCode = i3dmgx3_AccelAndAngRate(portNum, &Record[0]);
	if (errorCode < 0){
		printf("   Error Accel and AngRate - : %s\n", explainError(errorCode));
                endloopy =TRUE;
	}else{
		for (i=0; i<3; i++) {
			Accel_AngRecord.Accel[i] = FloatFromBytes(&Record[1 + i*4]);	// extract float from byte array
			Accel_AngRecord.AngRt[i] = FloatFromBytes(&Record[13 + i*4]);	// extract float from byte array
		}
		printf("\n\tAccel X\t\tAccel Y\t\tAccel Z\n");
		printf("  \t%f\t%f\t%f\n", Accel_AngRecord.Accel[0], Accel_AngRecord.Accel[1], Accel_AngRecord.Accel[2]);
		printf("\n\t  Ang X\t\t Ang Y\t\t Ang Z\n");
		printf("  \t%f\t%f\t%f\n", Accel_AngRecord.AngRt[0], Accel_AngRecord.AngRt[1], Accel_AngRecord.AngRt[2]);

		Accel_AngRecord.timer = convert2ulong(&Record[25]);
		printf("\n   Time Stamp: %u\n", Accel_AngRecord.timer);
        }

Exit:
	/*-------- close device */
	if (portNum >= 0)
		i3dmgx3_closeDevice(portNum);

	/*-------- wait for user to respond before exiting */
	printf("\nHit return to exit...\n");
	while (getchar() == EOF);
	return(0);
}
Example #13
0
int main(int argc, const char *argv[]) {
	io_func* io;
	Volume* volume;
	AbstractFile* image;
	int argOff;
	
	TestByteOrder();
	
	if(argc < 3) {
		printf("usage: %s <image-file> (-k <key>) <ls|cat|mv|mkdir|add|rm|chmod|extract|extractall|rmall|addall|grow|untar> <arguments>\n", argv[0]);
		return 0;
	}

	argOff = 2;
	
	if(strstr(argv[1], ".dmg")) {
		image = createAbstractFileFromFile(fopen(argv[1], "rb"));
		if(argc > 3) {
			if(strcmp(argv[2], "-k") == 0) {
				image = createAbstractFileFromFileVault(image, argv[3]);
				argOff = 4;
			}
		}
		io = openDmgFilePartition(image, -1);
	} else {
		io = openFlatFile(argv[1]);
	}

	if(io == NULL) {
		fprintf(stderr, "error: Cannot open image-file.\n");
		return 1;
	}
	
	volume = openVolume(io); 
	if(volume == NULL) {
		fprintf(stderr, "error: Cannot open volume.\n");
		CLOSE(io);
		return 1;
	}
	
	if(argc > argOff) {
		if(strcmp(argv[argOff], "ls") == 0) {
			cmd_ls(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "cat") == 0) {
			cmd_cat(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "mv") == 0) {
			cmd_mv(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[2], "symlink") == 0) {
			cmd_symlink(volume, argc - 2, argv + 2);
		} else if(strcmp(argv[argOff], "mkdir") == 0) {
			cmd_mkdir(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "add") == 0) {
			cmd_add(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "rm") == 0) {
			cmd_rm(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "chmod") == 0) {
			cmd_chmod(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "extract") == 0) {
			cmd_extract(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "extractall") == 0) {
			cmd_extractall(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "rmall") == 0) {
			cmd_rmall(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "addall") == 0) {
			cmd_addall(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "grow") == 0) {
			cmd_grow(volume, argc - argOff, argv + argOff);
		} else if(strcmp(argv[argOff], "untar") == 0) {
			cmd_untar(volume, argc - argOff, argv + argOff);
		}
	}
	
	closeVolume(volume);
	CLOSE(io);
	
	return 0;
}