Solved

Character Array Index help needed

Posted on 2013-05-17
6
291 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
Comment Utility
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
Comment Utility
how does  0 , 1, 6 map to "tin" in "The quick brown fox"?
0
 
LVL 1

Author Comment

by:edvinson
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:edvinson
Comment Utility
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
Comment Utility
What error are you getting at which line?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 opening and writing to files 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.

763 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

7 Experts available now in Live!

Get 1:1 Help Now