Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Character Array Index help needed

Posted on 2013-05-17
6
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 opening and reading files in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

636 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