/** * Returns the checksum of all but the first 12 bytes of {@code dex}. */ public int computeChecksum() throws IOException { Adler32 adler32 = new Adler32(); byte[] buffer = new byte[8192]; ByteBuffer data = this.data.duplicate(); // positioned ByteBuffers aren't thread safe data.limit(data.capacity()); data.position(CHECKSUM_OFFSET + SizeOf.CHECKSUM); while (data.hasRemaining()) { int count = Math.min(buffer.length, data.remaining()); data.get(buffer, 0, count); adler32.update(buffer, 0, count); } return (int) adler32.getValue(); }
public static void updateChecksum(ByteBuffer buffer, int size) { byte[] data = buffer.array(); MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new AssertionError(); } digest.update(data, 32, size - 32); byte[] sha1 = digest.digest(); System.arraycopy(sha1, 0, data, 12, sha1.length); Adler32 adler32 = new Adler32(); adler32.update(data, 12, size - 12); int v = (int) adler32.getValue(); buffer.position(8); buffer.putInt(v); }
/** * Calculates the checksum for the <code>.dex</code> file in the * given array, and modify the array to contain it. * * @param bytes non-null; the bytes of the file */ public static void calcChecksum(byte[] bytes) { Adler32 a32 = new Adler32(); a32.update(bytes, 12, bytes.length - 12); int sum = (int) a32.getValue(); bytes[8] = (byte) sum; bytes[9] = (byte) (sum >> 8); bytes[10] = (byte) (sum >> 16); bytes[11] = (byte) (sum >> 24); }
private long computeClassPathHash(final URL... classpathEntry) { final Adler32 adler32 = new Adler32(); for (final URL url : classpathEntry) { try (CheckedInputStream inputStream = new CheckedInputStream(url.openStream(), adler32)) { // Just read it, the CheckedInputStream will update the checksum on it's own while (IOUtils.skip(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { // just loop } } catch (final FileNotFoundException ignored) { LOG.warning("Auxclasspath entry " + url.toString() + " doesn't exist, ignoring it"); } catch (final IOException e) { // Can this even happen? LOG.log(Level.SEVERE, "Incremental analysis can't check auxclasspath contents", e); throw new RuntimeException(e); } } return adler32.getValue(); }
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException { Adler32 a32 = new Adler32(); byte[] buffer = new byte[4 * 1024]; InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET); int bytesRead = input.read(buffer); while (bytesRead >= 0) { a32.update(buffer, 0, bytesRead); bytesRead = input.read(buffer); } // write checksum, utilizing logic in DexWriter to write the integer value properly OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET); DexDataWriter.writeInt(output, (int)a32.getValue()); output.close(); }
@Override public byte[] getCheckSum() { byte[] returnedCheckSum = new byte[ByteUtils.SIZE_OF_LONG]; ByteUtils.writeLong(returnedCheckSum, checkSumGenerator.getValue(), 0); checkSumGenerator.reset(); return returnedCheckSum; }
Adler32 adler32 = new Adler32(); adler32.update( byteArray ); retval = new Long( adler32.getValue() );
@Override public long hash(final byte[] value) { final Adler32 adler = new Adler32(); adler.update(value); return adler.getValue(); }
@Override public long hash(final byte[] value) { final Adler32 adler = new Adler32(); adler.update(value); return adler.getValue(); }
/** * A utility method to calculate Adler-32 checksum. * * @param data data * @return checksum */ public static int calcAdler32Checksum(byte[] data) { Adler32 adler32 = new Adler32(); adler32.update(data); return (int) adler32.getValue(); }
private String computeDefaultPrefix(ResourceContext context) { SortedSet<JClassType> gssResources = computeOperableTypes(context); Adler32 checksum = new Adler32(); for (JClassType type : gssResources) { checksum.update(Util.getBytes(type.getQualifiedSourceName())); } int seed = Math.abs((int) checksum.getValue()); return encode(seed) + "-"; }
final int seed = Math.abs((int) checksum.getValue()); classPrefix = "G" + computeObfuscatedClassName("", new Counter() { @Override
String newPrefix = makeIdent(hash.getValue()).substring(0, conflict.length()) + RESERVED_IDENT_CHAR;
private void readMeta(byte unencrypted[], int off) { Adler32 crc = new Adler32(); crc.update(unencrypted, off, META_SIZE - 4); long expected = crc.getValue(); long read = DataHelper.fromLong(unencrypted, off + META_SIZE - 4, 4); if (read != expected) { if (_log.shouldLog(Log.WARN)) _log.warn("I2NP metadata message had a bad CRC value"); _context.statManager().addRateData("ntcp.corruptMetaCRC", 1); close(); return; } long ts = DataHelper.fromLong(unencrypted, off + 2, 4); receiveTimestamp(ts); }
Adler32 crc = new Adler32(); crc.update(data, 0, META_SIZE - 4); DataHelper.toLong(data, META_SIZE - 4, 4, crc.getValue()); _context.aes().encrypt(data, 0, data, 0, _sessionKey, _prevWriteEnd, 0, META_SIZE); System.arraycopy(data, META_SIZE - 16, _prevWriteEnd, 0, _prevWriteEnd.length);
long val = buf.crc.getValue(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Outbound message " + _messagesWritten + " has crc " + val
public int checksum(final byte[] buf, int off, int sze) { assert buf != null; // reset before computing the checksum. chk.reset(); chk.update(buf, off, sze); /* * The Adler checksum is a 32-bit value. */ return (int) chk.getValue(); }
long val = _crc.getValue(); if (val == expectedCrc) { try {
public int checksum(final IByteArraySlice slice) { assert slice != null; // reset before computing the checksum. chk.reset(); chk.update(slice.array(), slice.off(), slice.len()); /* * The Adler checksum is a 32-bit value. */ return (int) chk.getValue(); }