UInt8* CC_SHA1(const void *data, CC_LONG len, UInt8 *md) { CC_LONG bytes_hashed = 0; const UInt8 *data_buff = (const UInt8 *)data; if(md == NULL) return NULL; CC_SHA1_CTX ctx; CC_SHA1_Init(&ctx); if (len > CC_SHA1_USE_HARDWARE_THRESHOLD && !((intptr_t)data_buff & 3) && !pthread_once(&cc_sha1_connect_once, cc_sha1_connect) && cc_sha1_device >= 0) { bytes_hashed = sha1_hash_in_hardware(&ctx, data_buff, len, true); if (bytes_hashed == len) { OSWriteBigInt32(md, 0, ctx.h0); OSWriteBigInt32(md, 4, ctx.h1); OSWriteBigInt32(md, 8, ctx.h2); OSWriteBigInt32(md, 12, ctx.h3); OSWriteBigInt32(md, 16, ctx.h4); return md; } //Either we have failed partially or completely. //Fall through to the software. data_buff += bytes_hashed; len -= bytes_hashed; } //Fall back to Software SHA1. CC_SHA1_Update(&ctx, data_buff, len); CC_SHA1_Final(md, &ctx); return md; }
virtual void copyRawContent(uint8_t buffer[]) const { OSWriteBigInt32(&buffer[ 0], 0, 0x3d600000); // lis r11,ha16(L_foo$lazy_ptr) if ( _for64 ) OSWriteBigInt32(&buffer[ 4], 0, 0xe98b0001);// ldu r12,lo16(L_foo$lazy_ptr)(r11) else OSWriteBigInt32(&buffer[ 4], 0, 0x858b0000);// lwzu r12,lo16(L_foo$lazy_ptr)(r11) OSWriteBigInt32(&buffer[ 8], 0, 0x7d8903a6); // mtctr r12 OSWriteBigInt32(&buffer[12], 0, 0x4e800420); // bctr }
virtual void copyRawContent(uint8_t buffer[]) const { OSWriteBigInt32(&buffer[ 0], 0, 0x7c0802a6); // mflr r0 OSWriteBigInt32(&buffer[ 4], 0, 0x429f0005); // bcl 20,31,Lpicbase OSWriteBigInt32(&buffer[ 8], 0, 0x7d6802a6); // Lpicbase: mflr r11 OSWriteBigInt32(&buffer[12], 0, 0x3d6b0000); // addis r11,r11,ha16(L_fwrite$lazy_ptr-Lpicbase) OSWriteBigInt32(&buffer[16], 0, 0x7c0803a6); // mtlr r0 if ( _for64 ) OSWriteBigInt32(&buffer[20], 0, 0xe98b0001);// ldu r12,lo16(L_fwrite$lazy_ptr-Lpicbase)(r11) else OSWriteBigInt32(&buffer[20], 0, 0x858b0000);// lwzu r12,lo16(L_fwrite$lazy_ptr-Lpicbase)(r11) OSWriteBigInt32(&buffer[24], 0, 0x7d8903a6); // mtctr r12 OSWriteBigInt32(&buffer[28], 0, 0x4e800420); // bctr }
void FakeSMCSensor::encodeNumericValue(float value, void *outBuffer) { if ((type[0] == 'u' || type[0] == 's') && type[1] == 'i') { bool minus = value < 0; bool signd = type[0] == 's'; if (minus) value = -value; switch (type[2]) { case '8': if (type[3] == '\0' && size == 1) { UInt8 encoded = (UInt8)value; if (signd) bit_write(signd && minus, encoded, BIT(7)); bcopy(&encoded, outBuffer, 1); } break; case '1': if (type[3] == '6' && size == 2) { UInt16 encoded = (UInt16)value; if (signd) bit_write(signd && minus, encoded, BIT(15)); OSWriteBigInt16(outBuffer, 0, encoded); } break; case '3': if (type[3] == '2' && size == 4) { UInt32 encoded = (UInt32)value; if (signd) bit_write(signd && minus, encoded, BIT(31)); OSWriteBigInt32(outBuffer, 0, encoded); } break; default: return; } } else if ((type[0] == 'f' || type[0] == 's') && type[1] == 'p') { bool minus = value < 0; bool signd = type[0] == 's'; UInt8 i = get_index(type[2]); UInt8 f = get_index(type[3]); if (i + f == (signd ? 15 : 16)) { if (minus) value = -value; UInt16 encoded = value * (float)BIT(f); if (signd) bit_write(minus, encoded, BIT(15)); OSWriteBigInt16(outBuffer, 0, encoded); } } }
/** * Encode integer value to SMC integer format * * @param value Integer value to be encoded * @param type Integer SMC type ("ui8 ", "ui16", "ui32", "si8 ") * @param size Buffer size for encoded bytes, one byte for ui8, 2 bytes for ui16 etc. * @param outBuffer Buffer where encoded bytes will be copied to, should be already allocated with correct size * * @return True on success False otherwise */ bool fakeSMCPluginEncodeIntValue(int value, const char *type, const UInt8 size, void *outBuffer) { if (type && outBuffer) { size_t typeLength = strnlen(type, 4); if (typeLength >= 3 && (type[0] == 'u' || type[0] == 's') && type[1] == 'i') { bool minus = value < 0; bool signd = type[0] == 's'; if (minus) value = -value; switch (type[2]) { case '8': if (type[3] == '\0' && size == 1) { UInt8 encoded = (UInt8)value; if (signd) bit_write(signd && minus, encoded, BIT(7)); bcopy(&encoded, outBuffer, 1); return true; } break; case '1': if (type[3] == '6' && size == 2) { UInt16 encoded = (UInt16)value; if (signd) bit_write(signd && minus, encoded, BIT(15)); OSWriteBigInt16(outBuffer, 0, encoded); return true; } break; case '3': if (type[3] == '2' && size == 4) { UInt32 encoded = (UInt32)value; if (signd) bit_write(signd && minus, encoded, BIT(31)); OSWriteBigInt32(outBuffer, 0, encoded); return true; } break; } } } return false; }
static int FuseHFS_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t position) { //dprintf("getxattr %s %s %p %lu %u\n", path, name, value, size, position); // convert to hfs path char *hfspath = mkhfspath(path); if (hfspath == NULL) return -ENOENT; // find file hfsdirent ent; if (hfs_stat(NULL, hfspath, &ent) == -1) { free(hfspath); return -ENOENT; } if (strcmp(name, XATTR_FINDERINFO_NAME) == 0) { if (value == NULL) { free(hfspath); return 32; } if (size < 32) { free(hfspath); return -ERANGE; } // return finder info if (ent.flags & HFS_ISDIR) { // directory info OSWriteBigInt16(value, 0, ent.u.dir.rect.top); OSWriteBigInt16(value, 2, ent.u.dir.rect.left); OSWriteBigInt16(value, 4, ent.u.dir.rect.bottom); OSWriteBigInt16(value, 6, ent.u.dir.rect.right); OSWriteBigInt16(value, 8, ent.fdflags); OSWriteBigInt16(value, 10, ent.fdlocation.v); OSWriteBigInt16(value, 12, ent.fdlocation.h); OSWriteBigInt16(value, 14, ent.u.dir.view); // DXInfo OSWriteBigInt16(value, 16, ((DXInfo*)(ent.u.dir.xinfo))->frScroll.v); OSWriteBigInt16(value, 18, ((DXInfo*)(ent.u.dir.xinfo))->frScroll.h); OSWriteBigInt32(value, 20, ((DXInfo*)(ent.u.dir.xinfo))->frOpenChain); OSWriteBigInt16(value, 24, ((DXInfo*)(ent.u.dir.xinfo))->frUnused); OSWriteBigInt16(value, 26, ((DXInfo*)(ent.u.dir.xinfo))->frComment); OSWriteBigInt32(value, 28, ((DXInfo*)(ent.u.dir.xinfo))->frPutAway); } else { // file info memcpy(value, ent.u.file.type, 4); memcpy(value+4, ent.u.file.creator, 4); OSWriteBigInt16(value, 8, ent.fdflags); OSWriteBigInt16(value, 10, ent.fdlocation.v); OSWriteBigInt16(value, 12, ent.fdlocation.h); OSWriteBigInt16(value, 14, ent.u.file.window); // FXInfo OSWriteBigInt16(value, 16, ((FXInfo*)(ent.u.file.xinfo))->fdIconID); OSWriteBigInt16(value, 18, ((FXInfo*)(ent.u.file.xinfo))->fdUnused[0]); OSWriteBigInt16(value, 20, ((FXInfo*)(ent.u.file.xinfo))->fdUnused[1]); OSWriteBigInt16(value, 22, ((FXInfo*)(ent.u.file.xinfo))->fdUnused[2]); OSWriteBigInt16(value, 24, ((FXInfo*)(ent.u.file.xinfo))->fdUnused[3]); OSWriteBigInt16(value, 26, ((FXInfo*)(ent.u.file.xinfo))->fdComment); OSWriteBigInt32(value, 28, ((FXInfo*)(ent.u.file.xinfo))->fdPutAway); } free(hfspath); return 32; } else if (strcmp(name, XATTR_RESOURCEFORK_NAME) == 0 && (!(ent.flags & HFS_ISDIR)) && ent.u.file.rsize) { // resource fork if (value == NULL) { free(hfspath); return ent.u.file.rsize-position; } int bw = ent.u.file.rsize-position; if (bw > size) bw = size; // copy resource fork hfsfile *fp = hfs_open(NULL, hfspath); hfs_setfork(fp, 1); hfs_seek(fp, position, SEEK_SET); hfs_read(fp, value, bw); hfs_close(fp); // the end free(hfspath); return bw; } free(hfspath); dprintf("getxattr: ENOATTR\n"); return -ENOATTR; }