Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   read access violation (http://www.programmingforums.org/showthread.php?t=11528)

backstabber Oct 9th, 2006 1:31 AM

read access violation
 
this program is compiled using mingw and borland c++ and it gives a read access violation error (olly debug) when it starts the search for "the"

:

#include <cstdlib>
#include <iostream>
#include "file.h"
#include "alpha.h"

using namespace std;

int main(int argc, char *argv[])
{
    char fileout[302];
    char key;
    int iter =0;
    for (int w = 0; w < 102; w++)
    {
        key = alpha[w];
    for (int i = 0; i < 302; i++)
    {
        fileout[i] = key ^ file[i];
        }
    for (int f = 0; f < 302; f++)
        {
            iter++;
            if (fileout[iter] == 0x74 && fileout[iter+1] == 0x68 && fileout[iter+2] == 0x65)
            {
                            for (int d = 0; d < 302; d++)
                            {
                                cout << fileout[d];
                            }
            }
        }
}
}

it a little messy but this app pulls a single char from the alpha[] array and xors it with ever char in the file array this is a challenge please only fix the access violation not any thing else and a few hints as to good code production would help
this is an xor brute forcer

DaWei Oct 9th, 2006 1:50 AM

Too little information. There's no indication as to what "alpha" or "file" is. If you're looking for psychic phenomena, I suggest you check the midway at your nearest state fair. Violations of this type are often caused by attempting to access memory which isn't yours to access, or by attempting to write to memory which is only readable. A very common cause is presuming that some pointer can contain the information which you seek, when it can only contain information directing you to the information which you seek. If that information is not separately provided, or if you have not informed the pointer of the proper location of said information, you are up the proverbial creek. Paddling upstream in wave-ridden dung with a needle is not recommended.

backstabber Oct 9th, 2006 2:44 AM

sorry heres the extra info
 
alpha.h
:

const char alpha[102] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,0x57, 0x58, 0x59, 0x5A, 0xFC, 0xF6, 0xE4, 0xDC, 0xD6, 0xC4, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,0x36, 0x37, 0x38, 0x39, 0x3D, 0x21, 0x22, 0xA7, 0x24, 0x25, 0x26, 0x2F, 0x28, 0x29, 0x7B, 0x5B,0x5D, 0x7D, 0x3F, 0x5C, 0x2D, 0x2B, 0x2A, 0x5F, 0x2C, 0x2E, 0x3B, 0x3A, 0x23, 0x27, 0x7E, 0x3C,0x3E, 0x7C, 0x40, 0x5E, 0xB0, 0x20};

file.h

:

const char file[302] = {0x2F, 0x0A, 0x1E, 0x07, 0x45, 0x1D, 0x17, 0x01, 0x17, 0x47, 0x45, 0x00, 0x17, 0x1A, 0x55, 0x1D, 0x00, 0x59, 0x1B, 0x1D, 0x13, 0x08, 0x0E, 0x1C, 0x1C, 0x4F, 0x13, 0x05, 0x0A, 0x0D, 0x10, 0x0A, 0x00, 0x4B, 0x00, 0x17, 0x1B, 0x1D, 0x0B, 0x1B, 0x11, 0x10, 0x17, 0x01, 0x52, 0x08, 0x0A, 0x1D, 0x1D, 0x41, 0x7F, 0x61, 0x2C, 0x1F, 0x58, 0x16, 0x1D, 0x1E, 0x45, 0x11, 0x19, 0x19, 0x17, 0x05, 0x42, 0x0D, 0x58, 0x0E, 0x1E, 0x19, 0x00, 0x18, 0x1C, 0x16, 0x52, 0x05, 0x0A, 0x0D, 0x11, 0x0C, 0x17, 0x0F, 0x45, 0x0D, 0x10, 0x06, 0x01, 0x4B, 0x0A, 0x17, 0x1D, 0x4F, 0x05, 0x0A, 0x16, 0x59, 0x00, 0x00, 0x00, 0x4B, 0x00, 0x17, 0x1B, 0x1D, 0x0B, 0x1B, 0x11, 0x10, 0x17, 0x01, 0x5E, 0x4B, 0x04, 0x17, 0x1C, 0x4F, 0x06, 0x03, 0x00, 0x59, 0x1B, 0x07, 0x13, 0x05, 0x06, 0x1C, 0x0B, 0x4F, 0x13, 0x19, 0x00, 0x59, 0x01, 0x00, 0x07, 0x4B, 0x10, 0x0A, 0x1D, 0x4F, 0x01, 0x04, 0x08, 0x1C, 0x58, 0x0C, 0x1A, 0x0E, 0x04, 0x09, 0x58, 0x0E, 0x00, 0x18, 0x00, 0x59, 0x10, 0x0E, 0x0A, 0x04, 0x17, 0x59, 0x0C, 0x00, 0x1D, 0x07, 0x45, 0x0D, 0x17, 0x4F, 0x10, 0x19, 0x00, 0x18, 0x13, 0x4F, 0x1B, 0x1F, 0x49, 0x59, 0x0C, 0x07, 0x17, 0x4B, 0x0B, 0x1C, 0x00, 0x1B, 0x52, 0x04, 0x0B, 0x1C, 0x58, 0x18, 0x1D, 0x05, 0x11, 0x59, 0x1A, 0x0A, 0x52, 0x18, 0x0A, 0x59, 0x1D, 0x0E, 0x01, 0x12, 0x4B, 0x74, 0x72, 0x3B, 0x1A, 0x0E, 0x45, 0x1A, 0x17, 0x0B, 0x17, 0x4B, 0x1C, 0x16, 0x0D, 0x4F, 0x1C, 0x0E, 0x00, 0x1D, 0x58, 0x09, 0x1D, 0x19, 0x45, 0x00, 0x17, 0x1A, 0x00, 0x4B, 0x0B, 0x1C, 0x00, 0x1B, 0x52, 0x18, 0x11, 0x18, 0x0A, 0x4F, 0x1B, 0x18, 0x45, 0x5E, 0x0A, 0x00, 0x0A, 0x0E, 0x09, 0x09, 0x15, 0x06, 0x01, 0x4C, 0x45, 0x0A, 0x17, 0x4F, 0x17, 0x05, 0x11, 0x1C, 0x0A, 0x4F, 0x06, 0x03, 0x0C, 0x0A, 0x58, 0x06, 0x1C, 0x4B, 0x11, 0x11, 0x1D, 0x4F, 0x13, 0x1B, 0x15, 0x0B, 0x17, 0x1F, 0x00, 0x02, 0x04, 0x0D, 0x1D, 0x4F, 0x02, 0x07, 0x04, 0x1A, 0x1D, 0x41};

backstabber Oct 9th, 2006 2:49 AM

the file.h is making the page slow it has about half a meg of info in it

Polyphemus_ Oct 9th, 2006 3:06 AM

Next time, make sure your tabs are right.

Here's your problem:
:

for (int f = 0; f < 302; f++)
        {
            iter++;
            if (fileout[iter] == 0x74 && fileout[iter+1] == 0x68 && fileout[iter+2] == 0x65)
            {


Firstly, what is the goal of iter++, while you already have f?
Now, your actual error: When f equal 301, iter will contain the same value. You can figure out yourself what the answer of 301 + 2 is.

The Dark Oct 9th, 2006 3:13 AM

Not to mention that iter is incremented inside the inner loop, but is never reset in the outer loop, so it could get up to about 30,000 if the program didn't crash.

backstabber Oct 11th, 2006 4:29 AM

nope that did not fix the "READ ACCESS VIOLATION"

The Dark Oct 11th, 2006 4:35 AM

You need to show your changed code. I made the changes suggested by Polyphemus_ and I didn't get an access violation. I didn't get any output either, but maybe thats what you were expecting.

backstabber Oct 12th, 2006 12:47 AM

there is a read access violation at the point of entry of the first iteration when it starts the check for the word "the" when it tries to pull up the array it crashes would you like the complete dissasembly to help you understand what i am trying to get help with, now that i know its not my source code thats the problem maybe some other program is moving the array.

this is the error i get from olly when i put it through

read access violation at address ???????? and when i go to the point where the program crashes it is the FIRST iteration the FIRST occurence of the loop

DaWei Oct 12th, 2006 12:55 AM

I would be wary about thinking it isn't your souce code....


All times are GMT -5. The time now is 1:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC