void FakeSMCSensor::encodeValue(float value, void *outBuffer) { if ((type[0] == 'u' || type[0] == 's') && type[1] == 'i') { bool minus = value < 0; if (type[0] == 'u' && minus) { value = -value; minus = false; } switch (type[2]) { case '8': if (type[3] == '\0' && size == 1) { UInt8 out = minus ? (UInt8)(-value) | 0x80 : (UInt8)value; bcopy(&out, outBuffer, 1); } break; case '1': if (type[3] == '6' && size == 2) { UInt16 out = OSSwapHostToBigInt16(minus ? (UInt16)(-value) | 0x8000 : (UInt16)value); bcopy(&out, outBuffer, 2); } break; case '3': if (type[3] == '2' && size == 4) { UInt32 out = OSSwapHostToBigInt32(minus ? (UInt32)(-value) | 0x80000000 : (UInt32)value); bcopy(&out, outBuffer, 4); } break; default: return; } } else if ((type[0] == 'f' || type[0] == 's') && type[1] == 'p') { bool minus = value < 0; UInt8 i = get_index(type[2]); UInt8 f = get_index(type[3]); if (i + f == (type[0] == 'f' ? 16 : 15)) { UInt64 mult = (minus ? -value : value) * 1000 ; UInt64 encoded = ((mult << f) / 1000) & 0xffff; UInt16 out = OSSwapHostToBigInt16(minus ? (UInt16)(encoded | 0x8000) : (UInt16)encoded); bcopy(&out, outBuffer, 2); } } }
static uint16_t _dispatch_transform_swap_from_host(uint16_t x, int32_t byteOrder) { if (byteOrder == OSLittleEndian) { return OSSwapHostToLittleInt16(x); } return OSSwapHostToBigInt16(x); }
// write the iPhone version check atom 'rmvc' static void write_iPhone_rmvc( FILE *outputFile ) { off_t headerOffset; uint32_t flags = 0; uint32_t gestaltTag = OSSwapHostToBigInt32( 'mobi' ); uint32_t val1 = OSSwapHostToBigInt32( 1 ); // bitflags is 1 uint32_t val2 = OSSwapHostToBigInt32( 1 ); // bitmask is 1 uint16_t checkType = OSSwapHostToBigInt16( 1 ); // type is mask writeHeader( outputFile, 'rmvc', &headerOffset ); fwrite( &flags, sizeof(flags), 1, outputFile ); fwrite( &gestaltTag, sizeof(gestaltTag), 1, outputFile ); fwrite( &val1, sizeof(val1), 1, outputFile ); fwrite( &val2, sizeof(val2), 1, outputFile ); fwrite( &checkType, sizeof(checkType), 1, outputFile ); patchHeader( outputFile, headerOffset ); }
__private_extern__ int ___chattr( const char * path, ___attr_t attr, ___attr_t noattr ) { /* * Change file flags. */ struct __chattrbuf { uint32_t size; uint8_t reserved0032[8]; ___attr_t attr; uint8_t reserved0112[22]; }; typedef struct __chattrbuf __chattrbuf; struct attrlist attributes; __chattrbuf buffer; int status; attributes.bitmapcount = ATTR_BIT_MAP_COUNT; attributes.commonattr = ATTR_CMN_FNDRINFO; attributes.dirattr = 0; attributes.fileattr = 0; attributes.forkattr = 0; attributes.volattr = 0; status = getattrlist( path, &attributes, &buffer, sizeof( buffer ), 0 ); if ( status == 0 ) { buffer.attr = OSSwapHostToBigInt16( ( OSSwapBigToHostInt16( buffer.attr ) & ~noattr ) | attr ); status = setattrlist( path, &attributes, ( ( uint8_t * ) &buffer ) + sizeof( buffer.size ), sizeof( buffer ) - sizeof( buffer.size ), 0 ); } return status; }
uint16_t tobe16(uint16_t x) { return OSSwapHostToBigInt16(x); }