Solved

Character Array Index help needed

Posted on 2013-05-17
6
297 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 for-loops in the C programming language.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now