bool DIVMDKBlockStorage::writeBlocks(DIInt index, const DIChar *buf, DIInt num) { for (; num; index++, buf += DI_BLOCKSIZE, num--) { if (index >= blockNum) return false; DIInt directoryIndex = index / directoryEntrySize; DIInt directoryEntry = metadata[directory1Block * DI_BLOCKSIZE / sizeof(DIInt) + directoryIndex]; DIInt grainTableIndex = (index % directoryEntrySize) / grainSize; DIInt grainTableEntry = metadata[directoryEntry * DI_BLOCKSIZE / sizeof(DIInt) + grainTableIndex]; if (grainTableEntry <= 1) { if (isBlockEmpty(buf)) continue; grainTableEntry = allocateGrain(directoryIndex, grainTableIndex); if (!grainTableEntry) return false; } DIInt blockIndex = grainTableEntry + index % grainSize; if (!backingStore->write(blockIndex * DI_BLOCKSIZE, buf, DI_BLOCKSIZE)) return false; } return true; }
void BlockRedstone::onNeighbourBroken(User* user, int16_t oldblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { uint8_t block; uint8_t meta; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { return; } if (isBlockEmpty(x, y - 1, z, map)) { // Break torch and spawn torch item ServerInstance->map(map)->sendBlockChange(x, y, z, BLOCK_AIR, 0); ServerInstance->map(map)->setBlock(x, y, z, BLOCK_AIR, 0); spawnBlockItem(x, y, z, map, block); } }
bool BufferIODevice::seek( qint64 pos ) { Q_D( BufferIODevice ); qDebug() << Q_FUNC_INFO << pos << d->size; if ( pos >= d->size ) return false; int block = blockForPos( pos ); if ( isBlockEmpty( block ) ) emit blockRequest( block ); d->pos = pos; qDebug() << "Finished seeking"; return true; }
bool BlockRedstone::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction, int8_t posx, int8_t posy, int8_t posz) { uint8_t block; uint8_t meta; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { revertBlock(user, x, y, z, map); return true; } /* Check block below allows blocks placed on top */ if (!isBlockStackable(block)) { revertBlock(user, x, y, z, map); return true; } /* move the x,y,z coords dependent upon placement direction */ if (!translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } newblock = 55; meta = 0; ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta); ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta); ServerInstance->redstone(map)->addSimulation(vec(x,y,z)); return false; }
QByteArray BufferIODevice::getData( qint64 pos, qint64 size ) { Q_D( BufferIODevice ); // qDebug() << Q_FUNC_INFO << pos << size << 1; QByteArray ba; int block = blockForPos( pos ); int offset = offsetForPos( pos ); QMutexLocker lock( &d->mut ); while( ba.count() < size ) { if ( block > maxBlocks() ) break; if ( isBlockEmpty( block ) ) break; ba.append( d->buffer.at( block++ ).mid( offset ) ); } // qDebug() << Q_FUNC_INFO << pos << size << 2; return ba.left( size ); }
int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { uint8_t data[64]; if (traceState == TRACE_ERROR) return 1; if (len > 64) { traceState = TRACE_ERROR; return 1; } memcpy(data, data_src, len); if ((traceCrypto1) && ((traceState == TRACE_IDLE) || (traceState > TRACE_AUTH_OK))) { mf_crypto1_decrypt(traceCrypto1, data, len, 0); PrintAndLog("dec> %s", sprint_hex(data, len)); AddLogHex(logHexFileName, "dec> ", data, len); } switch (traceState) { case TRACE_IDLE: // check packet crc16! if ((len >= 4) && (!CheckCrc14443(CRC_14443_A, data, len))) { PrintAndLog("dec> CRC ERROR!!!"); AddLogLine(logHexFileName, "dec> ", "CRC ERROR!!!"); traceState = TRACE_ERROR; // do not decrypt the next commands return 1; } // AUTHENTICATION if ((len == 4) && ((data[0] == 0x60) || (data[0] == 0x61))) { traceState = TRACE_AUTH1; traceCurBlock = data[1]; traceCurKey = data[0] == 60 ? 1:0; return 0; } // READ if ((len ==4) && ((data[0] == 0x30))) { traceState = TRACE_READ_DATA; traceCurBlock = data[1]; return 0; } // WRITE if ((len ==4) && ((data[0] == 0xA0))) { traceState = TRACE_WRITE_OK; traceCurBlock = data[1]; return 0; } // HALT if ((len ==4) && ((data[0] == 0x50) && (data[1] == 0x00))) { traceState = TRACE_ERROR; // do not decrypt the next commands return 0; } return 0; break; case TRACE_READ_DATA: if (len == 18) { traceState = TRACE_IDLE; if (isBlockTrailer(traceCurBlock)) { memcpy(traceCard + traceCurBlock * 16 + 6, data + 6, 4); } else { memcpy(traceCard + traceCurBlock * 16, data, 16); } if (wantSaveToEmlFile) saveTraceCard(); return 0; } else { traceState = TRACE_ERROR; return 1; } break; case TRACE_WRITE_OK: if ((len == 1) && (data[0] == 0x0a)) { traceState = TRACE_WRITE_DATA; return 0; } else { traceState = TRACE_ERROR; return 1; } break; case TRACE_WRITE_DATA: if (len == 18) { traceState = TRACE_IDLE; memcpy(traceCard + traceCurBlock * 16, data, 16); if (wantSaveToEmlFile) saveTraceCard(); return 0; } else { traceState = TRACE_ERROR; return 1; } break; case TRACE_AUTH1: if (len == 4) { traceState = TRACE_AUTH2; nt = bytes_to_num(data, 4); return 0; } else { traceState = TRACE_ERROR; return 1; } break; case TRACE_AUTH2: if (len == 8) { traceState = TRACE_AUTH_OK; nr_enc = bytes_to_num(data, 4); ar_enc = bytes_to_num(data + 4, 4); return 0; } else { traceState = TRACE_ERROR; return 1; } break; case TRACE_AUTH_OK: if (len ==4) { traceState = TRACE_IDLE; at_enc = bytes_to_num(data, 4); // decode key here) ks2 = ar_enc ^ prng_successor(nt, 64); ks3 = at_enc ^ prng_successor(nt, 96); revstate = lfsr_recovery64(ks2, ks3); lfsr_rollback_word(revstate, 0, 0); lfsr_rollback_word(revstate, 0, 0); lfsr_rollback_word(revstate, nr_enc, 1); lfsr_rollback_word(revstate, uid ^ nt, 0); crypto1_get_lfsr(revstate, &key); printf("Key: %012"llx"\n",key); AddLogUint64(logHexFileName, "key: ", key); int blockShift = ((traceCurBlock & 0xFC) + 3) * 16; if (isBlockEmpty((traceCurBlock & 0xFC) + 3)) memcpy(traceCard + blockShift + 6, trailerAccessBytes, 4); if (traceCurKey) { num_to_bytes(key, 6, traceCard + blockShift + 10); } else { num_to_bytes(key, 6, traceCard + blockShift); } if (wantSaveToEmlFile) saveTraceCard(); if (traceCrypto1) { crypto1_destroy(traceCrypto1); } // set cryptosystem state traceCrypto1 = lfsr_recovery64(ks2, ks3); // nt = crypto1_word(traceCrypto1, nt ^ uid, 1) ^ nt; /* traceCrypto1 = crypto1_create(key); // key in lfsr crypto1_word(traceCrypto1, nt ^ uid, 0); crypto1_word(traceCrypto1, ar, 1); crypto1_word(traceCrypto1, 0, 0); crypto1_word(traceCrypto1, 0, 0);*/ return 0; } else { traceState = TRACE_ERROR; return 1; } break; default: traceState = TRACE_ERROR; return 1; } return 0; }
bool BlockRedstoneUtil::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { uint8_t block; uint8_t meta = 0; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { revertBlock(user, x, y, z, map); return true; } /* Check block below allows blocks placed on top */ if (!isBlockStackable(block)) { revertBlock(user, x, y, z, map); return true; } /* move the x,y,z coords dependent upon placement direction */ if (!translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } // Check that switch is placed on legal direction if ((newblock == BLOCK_STONE_BUTTON && (direction == BLOCK_TOP || direction == BLOCK_BOTTOM)) || ((newblock == BLOCK_STONE_PRESSURE_PLATE || newblock == BLOCK_WOODEN_PRESSURE_PLATE) && direction != BLOCK_TOP)) { revertBlock(user, x, y, z, map); return true; } // Set metadata for the position if (newblock == BLOCK_STONE_BUTTON || newblock == BLOCK_LEVER) { // Wall switch if (direction != BLOCK_TOP && direction != BLOCK_BOTTOM) { meta = direction; } // Ceiling lever else if (direction == BLOCK_BOTTOM) { int yaw = abs(int(user->pos.yaw)) % 360; if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) { meta = 0x00; } else { meta = 0x07; } } // Floor lever else { int yaw = abs(int(user->pos.yaw)) % 360; if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) { meta = 0x06; } else { meta = 0x05; } } } ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta); ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta); return false; }