Ejemplo n.º 1
0
int main ( int argc, char** argv )
{
   FILE* f;
   int   r;
   int   bit;
   int   i;

   if (argc != 2) {
      fprintf ( stderr, "usage: unzcrash filename\n" );
      return 1;
   }

   f = fopen ( argv[1], "r" );
   if (!f) {
      fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
      return 1;
   }

   nIn = fread ( inbuf, 1, M_BLOCK, f );
   fprintf ( stderr, "%d bytes read\n", nIn );

   nZ = M_BLOCK;
   r = BZ2_bzBuffToBuffCompress (
         zbuf, &nZ, inbuf, nIn, 9, 0, 30 );

   assert (r == BZ_OK);
   fprintf ( stderr, "%d after compression\n", nZ );

   for (bit = 0; bit < nZ*8; bit++) {
      fprintf ( stderr, "bit %d  ", bit );
      flip_bit ( bit );
      nOut = M_BLOCK_OUT;
      r = BZ2_bzBuffToBuffDecompress (
            outbuf, &nOut, zbuf, nZ, 0, 0 );
      fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );

      if (r != BZ_OK) {
         fprintf ( stderr, "\n" );
      } else {
         if (nOut != nIn) {
           fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
           return 1;
         } else {
           for (i = 0; i < nOut; i++)
             if (inbuf[i] != outbuf[i]) { 
                fprintf(stderr, "mismatch at %d\n", i ); 
                return 1; 
           }
           if (i == nOut) fprintf(stderr, "really ok!\n" );
         }
      }

      flip_bit ( bit );
   }

   fprintf ( stderr, "all ok\n" );
   return 0;
}
Ejemplo n.º 2
0
Archivo: am.c Proyecto: flyhorsegit/am
char * hm_decode(char *data, size_t len) {
    char *rez = calloc(sizeof(char), len * 4 / 7);
    unsigned char bl;
    char hb;
    char sind;
    int i, j;
    for (i = 0; i < len * 8 / 7; i++) {
        bl = 0;
        for (j = 0; j < 7; j++)
            bl += get_bit(data[(i * 7 + j) / 8], ((i * 7 + j) % 8) + 1)
                  << (7 - j);
        bl >>= 1;
        sind = (get_bit(bl, 2) ^ get_bit(bl, 6) ^ get_bit(bl, 7)
                ^ get_bit(bl, 8)) << 2;
        sind += (get_bit(bl, 3) ^ get_bit(bl, 5) ^ get_bit(bl, 7)
                 ^ get_bit(bl, 8)) << 1;
        sind += (get_bit(bl, 4) ^ get_bit(bl, 5) ^ get_bit(bl, 6)
                 ^ get_bit(bl, 8)) << 0;
        if (sind != 0) {
            //	printf("corecting error %s %d %d\n", byte_to_binary(bl), i, sind);
            bl = flip_bit(bl, sind + 1);
        }
        hb = (get_bit(bl, 5) << 3) + (get_bit(bl, 6) << 2)
             + (get_bit(bl, 7) << 1) + (get_bit(bl, 8) << 0);
        rez[i / 2] += hb << (i % 2 ? 0 : 4);

    }
    return rez;
}
Ejemplo n.º 3
0
Archivo: am.c Proyecto: flyhorsegit/am
frame *get_msg_fm(int *sbf) {
    char *msg = (char *) calloc(sizeof(char), EF_SIZE);
    int i, j, k, index;
    double freq;
    int highcount;
    char byte;
    for (i = 0; i < EF_SIZE; i++) {
        byte = 0;
        for (j = 0; j < BITS_BYTE; j++) {
            highcount = 0;
            for (k = 0; k < (BIT_SIZE - 2); k++) {
                index = i * BITS_BYTE * BIT_SIZE + j * BIT_SIZE + k;
                if (( sbf[index]  < sbf[index + 1] ) && (sbf[index + 1] > sbf[index + 2]))
                    highcount++;
                //	if (( sbf[index]  > sbf[index + 1] ) && (sbf[index + 1] < sbf[index + 2]))
                //		highcount++;
            }
            //freq = ((double) highcount) * SAMPLE_RATE / (BIT_SIZE * 2);
            freq = ((double) highcount) * SAMPLE_RATE / BIT_SIZE;
            if (freq > (FREQUENCY /*+ FREQUENCY_DELTA / 8*/) ) {
                byte = flip_bit(byte, (j + 1)); /*printf("%d ", (int) freq);*/
            }
        }
        msg[i] = byte;
    }
    return (frame *) hm_decode(msg, EF_SIZE);
}
Ejemplo n.º 4
0
void test_flip_bit(unsigned x,
                   unsigned n,
                   unsigned expected) {
    unsigned o = x;
    flip_bit(&x, n);
    if(x!=expected) {
        printf("flip_bit(0x%08x,%u): 0x%08x, expected 0x%08x\n",o,n,x,expected);
    } else {
        printf("flip_bit(0x%08x,%u): 0x%08x, correct\n",o,n,x);
    }
}
// Floating Negate
static void
fneg(ThreadState *state, Instruction instr)
{
   uint64_t b, d;

   b = state->fpr[instr.frB].value0;
   d = flip_bit(b, 63);
   state->fpr[instr.frD].value0 = d;

   if (instr.rc) {
      updateFloatConditionRegister(state);
   }
}
Ejemplo n.º 6
0
// Reverse and flip the bits from i = 0 to i = end
void reverse_and_flip_bits(int A[], int end) {
    for (int i = 0; i < (end / 2); i++) {
        int temp = check_bit(A, i);
        if (check_bit(A, end - i - 1)) {
            set_bit(A, i);
        } else {
            clear_bit(A, i);
        }
        if (temp) {
            set_bit(A, end - i - 1);
        } else {
            clear_bit(A, end - i - 1);
        }
    }
    for (int i = 0; i < end; i++) {
        flip_bit(A, i);
    }
}
Ejemplo n.º 7
0
T flip_head_bit(T x) {
  return flip_bit(x, head_bit_idx<T>());
}