Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhy does the program crash when it enters a function? Pin
KaKa'18-Sep-06 6:35
KaKa'18-Sep-06 6:35 
QuestionRe: Why does the program crash when it enters a function? Pin
David Crow18-Sep-06 6:56
David Crow18-Sep-06 6:56 
AnswerRe: Why does the program crash when it enters a function? Pin
Nynaeve18-Sep-06 7:54
Nynaeve18-Sep-06 7:54 
AnswerRe: Why does the program crash when it enters a function? Pin
BlitzPackage18-Sep-06 9:14
BlitzPackage18-Sep-06 9:14 
AnswerRe: Why does the program crash when it enters a function? Pin
ThatsAlok18-Sep-06 18:53
ThatsAlok18-Sep-06 18:53 
AnswerRe: Why does the program crash when it enters a function? Pin
Hamid_RT18-Sep-06 19:43
Hamid_RT18-Sep-06 19:43 
AnswerRe: Why does the program crash when it enters a function? Pin
KaKa'20-Sep-06 6:43
KaKa'20-Sep-06 6:43 
QuestionHelp in conversion from C++ to VB6 Pin
Tomazas7718-Sep-06 6:33
Tomazas7718-Sep-06 6:33 
Hi,
I have a small bit of C++ program, but I am not programmer in C++. Could anyone help me to explain or rewrite similar program in VB6??
This code is looking for this line in file:
DPB="FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86"

And then it is processing it. This line contains password (in this case is '000000000'), I think this line is a bit changed so it is incorrectly giving and answer. That's why I need to understand this C++ code to make a correction to a code and get correct password.

C++ program looks like this:
<br />
#include <stdio.h><br />
#include <windows.h><br />
#include <conio.h><br />
#pragma hdrstop<br />
#include <condefs.h><br />
<br />
#define BLOCK_SIZE 32768<br />
<br />
//---------------------------------------------------------------------------<br />
<br />
int memstr(const char *buf, const char *s, size_t size)<br />
{<br />
   int        off;<br />
   const char *s_temp;<br />
<br />
   //return -1;<br />
   if(!buf || !s || !(*s)) return -1;<br />
<br />
   for(off = 0; off < size; off++)<br />
   {<br />
      for(s_temp = s; *s_temp != 0 && *buf == *s_temp; buf++, s_temp++)<br />
      {<br />
         off++;<br />
         if(off >= size) return -1;<br />
      }<br />
      if((*(buf - 1) == *(s_temp - 1)) && *s_temp == 0) return off;<br />
      buf++;<br />
   }<br />
   return -1;<br />
}<br />
<br />
LPSTR findEncryptPass(const char *filename)<br />
{<br />
   FILE   *prot_file;<br />
   char   *buff = 0, *s;<br />
   size_t rc;<br />
   int    off;<br />
<br />
   prot_file = fopen(filename, "rb");<br />
   if(!prot_file) return 0;<br />
   buff = (char *)malloc(BLOCK_SIZE);<br />
   if(!buff) return 0;<br />
   do<br />
   {<br />
      rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
      if(!rc) break;<br />
      off = memstr(buff, "DPB=\"", BLOCK_SIZE);<br />
      if(off < 0)<br />
      {<br />
         if(rc < BLOCK_SIZE) break;<br />
         fseek(prot_file, -32, SEEK_CUR);<br />
         continue;<br />
      }<br />
      fseek(prot_file, off - rc, SEEK_CUR);<br />
      rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
      if(!rc) break;<br />
      s = strchr(buff, '\"');<br />
      *s = 0;<br />
      return buff;<br />
   } while(!feof(prot_file));<br />
   free(buff);<br />
   return 0;<br />
}<br />
<br />
void decryptPassword(const char *encrypt_pass, char *s)<br />
{<br />
   char str[128], ch;<br />
   char hs[] = { 0, 0, 0 };<br />
   int  v1, v2, i, l;<br />
   int  begin_found = 0;<br />
<br />
   *s = 0;<br />
<br />
   for(i = 0; encrypt_pass[i*2]; i++)<br />
   {<br />
      hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
      v1 = strtol(hs, 0, 16);<br />
      hs[0] = encrypt_pass[i*2+4]; hs[1] = encrypt_pass[i*2+5];<br />
      v2 = strtol(hs, 0, 16);<br />
      if(!begin_found)<br />
      {<br />
         if(v1 == v2) begin_found = 1;<br />
      }<br />
      else<br />
      {<br />
         if(v1 != v2)<br />
            begin_found = 0;<br />
         else<br />
         {<br />
            i += 3;<br />
            break;<br />
         }<br />
      }<br />
   }<br />
<br />
   if(!begin_found) return;<br />
<br />
   for(ch = 0, l = 0; encrypt_pass[i*2+2]; i++, l++)<br />
   {<br />
      hs[0] = encrypt_pass[(i-2)*2]; hs[1] = encrypt_pass[(i-2)*2+1];<br />
      v1 = strtol(hs, 0, 16);<br />
      hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
      v2 = strtol(hs, 0, 16);<br />
      ch = (ch + (char)v1) ^ (char)v2;<br />
      str[l] = ch;<br />
   }<br />
   str[l] = 0;<br />
   CharToOem(str, s);<br />
}<br />
<br />
#pragma argsused<br />
int main(int argc, char **argv)<br />
{<br />
   char s[128];<br />
   char *encrypt_pass_str;<br />
<br />
   if(argc < 2)<br />
   {<br />
      printf("Usage: vbakey.exe filename\n");<br />
      return 1;<br />
   }<br />
<br />
   if(!(encrypt_pass_str = findEncryptPass(argv[1])))<br />
   {<br />
      //CharToOem("Ïàðîëü íå íàéäåí\n", s);<br />
      printf("Password not found\n");<br />
      return 1;<br />
   }<br />
<br />
   decryptPassword(encrypt_pass_str, s);<br />
   printf("File password: %s\n", s);<br />
   free(encrypt_pass_str);<br />
   printf("Press any key for continue ... \n");<br />
   getch();<br />
   return 0;<br />
}<br />

This is whole program. And I don't need any conversion or explanation on how to get arguments for file neither about function 'findEncryptPass' which I assume will return in this case "FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86". I am most interested in function 'decryptPassword'. How it works and what it returns.

Thanks for any help.
AnswerRe: Help in conversion from C++ to VB6 Pin
David Crow18-Sep-06 6:55
David Crow18-Sep-06 6:55 
GeneralRe: Help in conversion from C++ to VB6 Pin
Tomazas7719-Sep-06 6:45
Tomazas7719-Sep-06 6:45 
GeneralRe: Help in conversion from C++ to VB6 Pin
David Crow19-Sep-06 7:12
David Crow19-Sep-06 7:12 
QuestionPosting string using postmessage() function Pin
priyank_ldce18-Sep-06 5:08
priyank_ldce18-Sep-06 5:08 
QuestionRe: Posting string using postmessage() function Pin
David Crow18-Sep-06 5:21
David Crow18-Sep-06 5:21 
AnswerRe: Posting string using postmessage() function Pin
Zac Howland18-Sep-06 5:33
Zac Howland18-Sep-06 5:33 
AnswerRe: Posting string using postmessage() function Pin
Nish Nishant18-Sep-06 5:55
sitebuilderNish Nishant18-Sep-06 5:55 
AnswerRe: Posting string using postmessage() function Pin
tanvon malik18-Sep-06 6:38
tanvon malik18-Sep-06 6:38 
GeneralRe: Posting string using postmessage() function Pin
ThatsAlok18-Sep-06 18:51
ThatsAlok18-Sep-06 18:51 
AnswerRe: Posting string using postmessage() function Pin
Mohammad A Gdeisat18-Sep-06 7:26
Mohammad A Gdeisat18-Sep-06 7:26 
AnswerRe: Posting string using postmessage() function Pin
Jun Du18-Sep-06 8:06
Jun Du18-Sep-06 8:06 
GeneralRe: Posting string using postmessage() function Pin
ThatsAlok18-Sep-06 18:48
ThatsAlok18-Sep-06 18:48 
GeneralRe: Posting string using postmessage() function Pin
Jun Du19-Sep-06 15:58
Jun Du19-Sep-06 15:58 
QuestionRe: Posting string using postmessage() function Pin
priyank_ldce20-Sep-06 1:25
priyank_ldce20-Sep-06 1:25 
QuestionPosting string using postmessage() function Pin
priyank_ldce19-Sep-06 1:27
priyank_ldce19-Sep-06 1:27 
QuestionWMI performance counters Pin
Jim Crafton18-Sep-06 4:54
Jim Crafton18-Sep-06 4:54 
QuestionSingle instance Pin
Waldermort18-Sep-06 4:41
Waldermort18-Sep-06 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.