Question

I am having trouble with my decoder and was wondering if anyone could help me out?

basically, i am trying to build a decoder for my steganography encoder, the encoder places a bit from a message on the LSB of every Byte from in the sound file

the Decoder job is to collect those bits up and create a new message out of them

the code is meant to do the following:

CODE: SELECT ALL

  • Go to message array location.

  • set bitindex to 0 an increment till 7 // (8 bits to a byte)

  • go to sound array location

  • if soundbit is equal add 0 to new byte otherwise add one to end of new byte

  • perform bitshift left once

  • increment bitindex

by using various printf's I can tell you it runs smoothly about 3/4 times before crashing.

Hope that makes sense the actual loops look like this:

 {


int mIndex, sIndex, bitIndex, mask;
char *message[9];

mask = 1;
mIndex = 0;


unsigned char *soundFile = LoadWavAudioFile("boomedit.wav");

int soundFileSize = GetSizeOfWavFile();



bitIndex = 0;

    for(mIndex = 0; mIndex < 8; mIndex++)//index for message
    {
        printf("1\n");
        for(sIndex = 0; sIndex < soundFileSize; sIndex++)//index for soundfile
        {
            printf("2\n");
            for(bitIndex = 0; bitIndex < 8;)
            {
                printf("3\n");
                int test;
                if((soundFile[sIndex] & mask) > 0)//is message bit > 0
                {                                   
                    printf("++++++++++++++++\n");
                    *message[mIndex] = (soundFile[sIndex] | 1);//adds a one to message byte
                    *message[mIndex] = *message[mIndex] <<1;    //shift bits 1 placce left
                    printf("*****************\n");

                }
                else
                { //no change the LSB to 0
                    printf("------------------\n");
                    *message[mIndex]= soundFile[sIndex] & 254; //adds a zero at end o
                    *message[mIndex] = *message[mIndex] <<1; //shifts bits 1 place to left
                    printf("******************\n");
                }

                bitIndex++;
            }   
        }
    }

printf("\n hiddden letters:%s\n", *message); //print message    
printf("\nalert 5\n");

}

Hope that helps anything will be helpfull.

Was it helpful?

Solution

The problem is here:

char *message[9];

You've made an array of 9 pointers to characters, you don't assign them any value or allocate them any memory. They're uninitialized.

The first thing you do now is deference one of those uninitialized pointers:

*message[mIndex] =

Thus you crash.


Edit:

You can initialize it to all NULLs via:

char *message[9] = {0};

But you still can't use that, not it will just seg fault on deferencing a NULL pointer. You have to assign some memory to these to be useful.. for example you could do:

message[0] = malloc(100); // I don't know how much you need for your strings
message[1] = malloc(100); // that's up to you, so I'm just arbitrally picking 100 bytes
message[2] = malloc(100); // here to illustrate the point.
message[3] = malloc(100);
message[4] = malloc(100);
message[5] = malloc(100);
message[6] = malloc(100);
message[7] = malloc(100);
message[8] = malloc(100); 

Then you'll have to free each of them when you're done. Is this want you wanted? An array of strings?

This line:

printf("\n hiddden letters:%s\n", *message); //print message 

implies to me that you were really after just a single string...

OTHER TIPS

In the code you post, sIndex will equal soundFileSize when you get to your first if statement. It looks from here like you are reading one past the end of your array, soundFile. (Assuming the size of the array is in fact soundFileSize)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top