Solved

Character Array Index help needed

Posted on 2013-05-17
6
299 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Line meaning 9 87
White board coding practice 3 88
Path to  STL Map header file 1 58
Resolve Dependency Issues 4 68
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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

831 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