Exemplo n.º 1
0
static VALUE
buffer_equal(VALUE self, VALUE other)
{
  VALUE str1, str2;
  str1 = buffer_digest(0, 0, self);
  str2 = buffer_digest(0, 0, other);

  StringValue(str1);
  StringValue(str2);

  if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
      rb_str_cmp(str1, str2) == 0) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}
Exemplo n.º 2
0
static VALUE
buffer_digest_length(VALUE self)
{
  /* subclasses really should redefine this method */
  VALUE digest = buffer_digest(0, 0, self);

  /* never blindly assume that #digest() returns a string */
  StringValue(digest);
  return UINT2NUM(RSTRING_LEN(digest));
}
Exemplo n.º 3
0
static VALUE
buffer_s_hexdigest(int argc, VALUE *argv, VALUE klass)
{
  VALUE str;
  volatile VALUE obj;

  if (argc < 1) {
    rb_raise(rb_eArgError, "no data given");
  }

  str = *argv++;
  argc--;

  StringValue(str);

  obj = rb_obj_alloc(klass);
  rb_obj_call_init(obj, argc, argv);

  return hexencode_str_new(buffer_digest(1, &str, obj));
}
Exemplo n.º 4
0
int main(int argc, char *argv[], char *envp[]) {
    struct ecc_state_s ecc;
    uint8_t buffer[0x1000], ecc_payload[0x40], regs[3], *jffs;
    int ret, len, eccbyte, count, partition;

    /* Check if we're called by "raw2flash.spitz" or similar */
    len = strlen(argv[0]);
    if (!strcasecmp(argv[0] + len - 5, "akita"))
        ecc.style = &akita;
    else if (!strcasecmp(argv[0] + len - 6, "borzoi"))
        ecc.style = &borzoi;
    else if (!strcasecmp(argv[0] + len - 7, "terrier"))
        ecc.style = &terrier;
    else
        ecc.style = &spitz;

# ifdef VERBOSE
    fprintf(stderr, "[");
# endif

    /* Skip first 10 bytes */
    TFR(read(0, buffer, 0x10));

    len = 0;
    jffs = (uint8_t *) malloc(PARTITION_START);
    while (len < PARTITION_START) {
        ret = TFR(read(0, jffs + len, PARTITION_START - len));
        if (ret <= 0)
            break;
        len += ret;
    }

    /* Convert data from stdin */
    partition = len = eccbyte = count = 0;
    memset(ecc_payload, 0xff, ecc.style->oob_size);
    jffs2_format(&ecc, ecc_payload);
    while (count < ecc.style->romsize) {
        buffer_fill(&ecc, buffer, &len, &partition, count, jffs);
        buffer_digest(&ecc, buffer, regs);

        ecc_payload[ecc.style->eccpos[eccbyte ++]] = regs[0];
        ecc_payload[ecc.style->eccpos[eccbyte ++]] = regs[1];
        ecc_payload[ecc.style->eccpos[eccbyte ++]] = regs[2];

        TFR(write(1, buffer, ecc.style->eccbytes));
        count += ecc.style->eccbytes;
        len -= ecc.style->eccbytes;
        memmove(buffer, buffer + ecc.style->eccbytes, len);

        if (eccbyte >= ecc.style->eccsize) {
            TFR(write(1, ecc_payload, ecc.style->oob_size));
            eccbyte = 0;
            memset(ecc_payload, 0xff, ecc.style->oob_size);
            if (partition < 2)
                jffs2_format(&ecc, ecc_payload);
        }

# ifdef VERBOSE
        if (count * PBAR_LEN / ecc.style->romsize >
                (count - ecc.style->eccbytes) *
                PBAR_LEN / ecc.style->romsize)
            fprintf(stderr, "#");
# endif
    }

# ifdef VERBOSE
    fprintf(stderr, "]\n");
# endif
    free(jffs);
    return 0;
}
Exemplo n.º 5
0
static VALUE
buffer_to_s(VALUE self)
{
  return hexencode_str_new(buffer_digest(0, 0, self));
}
Exemplo n.º 6
0
static VALUE
buffer_hexdigest(int argc, VALUE *argv, VALUE self)
{
  return hexencode_str_new(buffer_digest(argc, argv, self));
}