Solved

Character Array Index help needed

Posted on 2013-05-17
6
300 Views
Last Modified: 2013-05-21
I am practicing anti-debugging programming.

In my simple example, I have 3 EDIT boxes ( a sort of serial number ).

Rather than do a simple compare, which the correct serial number would show up if decompiled, I want to use a keyphrase:

char keyPhrase[] = "The quick brown fox";

Open in new window


The correct serial number is: 0 , 1, 6  which would map to the word "tin" in the keyphrase

My question is, how do I compare my 3 edit boxes to see if they entered the right serial number, without comparing their number to 0, 1, 6, and only using the key.

If we compare "tin" to their entered mapped word, that would be PERFECT!

Thanks.
0
Comment
Question by:edvinson
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39176589
Your approach using the indices into that array seems to be bang-on. So why not just doing that like

char keyPhrase[] = "The quick brown fox";
char acSubItem[255];

GetDlgItemText(hDlg,IDD_SUB_ITEM1,aacSubItem1,sizeof(acSubItem1));

if (0 == (ptrdiff_t) acSubItem1 - strchr('T')) {

  // found
}

Open in new window


Yet, sorry, can't find 'in' at their respective positions, misconception on my side?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39176598
how does  0 , 1, 6 map to "tin" in "The quick brown fox"?
0
 
LVL 1

Author Comment

by:edvinson
ID: 39176600
hmmmm...

Apparently I made a mistake in my post.

Correct serial should be 0, 6, 14 , is that correct?

If so, could you elaborate on your proposed solution:

Could you walk me through this block?

if (0 == (ptrdiff_t) acSubItem1 - strchr('T')) {

  // found
}

Open in new window

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:edvinson
ID: 39176603
PLEASE NOTE I CHANGED THE CORRECT SERIAL KEY....
This is my actual program, in my question I was trying to be brief.

I think I am close, but getting error:

#include <windows.h>
#include "resource.h"

//---------------------------------------------------------------------------
HWND hWnd;

char Phrase1[] = "The quick brown fox jumps over the lazy dog";
char Phrase2[] = "crackmes";
char UserAnswer[10];
bool CombinationCorrect;
int CorrectIndex [8] = { 8, 12, 37, 8, 9, 23, 29, 25 }; 
char acSubItem[255];



LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_INITDIALOG:
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
		case IDOK:
        
             /* Assume Combination is FALSE */
            CombinationCorrect = 0;
            
            /* Check 1st Number */
            GetDlgItemText(hWndDlg,IDC_EDIT1,UserAnswer,sizeof(acSubItem1));

            if (0 == (ptrdiff_t) acSubItem1 - strchr('T')) {

               MessageBox(hWndDlg, UserAnswer, "Correct So Far", MB_OK);
            }
    
			EndDialog(hWndDlg, 0);

			return TRUE;
		}
		break;
	}

	return FALSE;
}
//---------------------------------------------------------------------------
                                  

Open in new window

0
 
LVL 86

Expert Comment

by:jkr
ID: 39176612
What error are you getting at which line?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39176657
char Phrase1[] = "The quick brown fox jumps over the lazy dog";
char Phrase2[] = "crackmes";
char UserAnswer[10];
bool CombinationCorrect;
int CorrectIndex [8] = { 8, 12, 37, 8, 9, 23, 29, 25 };
for( int i=0; i < sizeof( CorrectIndex)/sizeof(CorrectIndex[0]); ++i ){
   if( UserAnswer[ i ] !=  Phrase1[CorrectIndex[ i ]] ){ return false; }
}
return true;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question