![]() |
CPP zu Delphi
Hallo!
Ich bräuchte mal wieder ein wenig Hilfe. Also zunächst einmal muss ich sagen, dass ich absolut keine Ahnung von CPP habe. Ich habe den folgenden Quellcode und möchte diesen in Delphi nutzen/umwandeln.
Code:
Es wäre super, wenn jemand mir helfen könnte den Code zu konvertieren.
#include "stdafx.h"
#include <windows.h> #include <stdlib.h> char* GetHash(HANDLE file,const char* pattern) { DWORD bytes=(DWORD)strlen(pattern)+1; char* buffer=new char[bytes]; DWORD pbytes=0; UINT offset=0; do{ if (SetFilePointer(file,(LONG)offset++,0,FILE_BEGIN)==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - invalid set file pointer (system error code %d)\n"),GetLastError()); delete [] buffer; buffer=NULL; return NULL; } if (ReadFile(file,(LPVOID)buffer,bytes,&pbytes,NULL)==NULL && GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - could not read file (system error code %d)\n"),GetLastError()); delete [] buffer; buffer=NULL; return NULL; } *(buffer+bytes-1)=NULL; }while(strcmp(buffer,pattern)&&pbytes!=0); if(pbytes==0) { delete [] buffer; buffer=NULL; return NULL; } delete [] buffer; buffer=NULL; DWORD offsett=offset+bytes; UINT counter=0; buffer=new char[2]; do{ if (SetFilePointer(file,offsett++,0,FILE_BEGIN)==INVALID_SET_FILE_POINTER&&GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - invalid set file pointer (system error code %d)\n"),GetLastError()); delete [] buffer; buffer=NULL; return NULL; } if (ReadFile(file,(LPVOID)buffer,(DWORD)1,&pbytes,NULL)==NULL&&GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - could not read file (system error code %d)\n"),GetLastError()); delete [] buffer; buffer=NULL; return NULL; } if((*buffer!=0)&&(pbytes>0)) counter++; }while(*buffer!=0&&pbytes!=0); if(pbytes==0) { delete [] buffer; buffer=NULL; return NULL; } delete [] buffer; buffer=NULL; char * value=new char[counter+1]; offset=offset+bytes; if (SetFilePointer(file,offset,0,FILE_BEGIN)==INVALID_SET_FILE_POINTER&&GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - invalid set file pointer (system error code %d)\n"),GetLastError()); delete [] value; value=NULL; return NULL; } if (ReadFile(file,(LPVOID)value,(DWORD)(counter+1),&pbytes,NULL)==NULL&&GetLastError()!=NO_ERROR) { _tprintf_s(_T(" error - could not read file (system error code %d)\n"),GetLastError()); delete [] value; value=NULL; return NULL; } return (char*)value; }//----------------- char* ServerPasswordDecode(const char* hash) { size_t passsize=strlen(hash)/2+1; char* pass=new char[passsize]; char* t=new char[2]; *t=NULL; *pass=NULL; *(t+1)=NULL; for(UINT i=0;i<strlen(hash);i++) if(i%2) { if(*(hash+i)=='D') { *t=*(hash+i-1)-17; strcat_s(pass,passsize,t); }else if(*(hash+i)=='G') { *t=*(hash+i-1)+31; strcat_s(pass,passsize,t); }else if(*(hash+i)=='H') { *t=*(hash+i-1)+47; strcat_s(pass,passsize,t); } } delete [] t; return pass; }//--------- char* ProfilePasswordDecode(const char* hash) { size_t passsize=strlen(hash)+1; char* pass=new char[passsize]; *pass=NULL; for(size_t i=0;i<passsize-1;i++) { pass[i]=(~hash[i]); pass[i+1]=NULL; } return pass; }//----------------- BOOL CheckGG(HANDLE file) { char buffer[5]; DWORD rbytes=0; if (SetFilePointer(file,(LONG)0,0,FILE_BEGIN)==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) return FALSE; if (ReadFile(file,(LPVOID)buffer,(DWORD)5,&rbytes,NULL)==NULL && GetLastError()!=NO_ERROR && rbytes!=0) return FALSE; buffer[4]=NULL; if(strcmp(buffer,"cfg1")) return FALSE; else return TRUE; }//------------------------- int _tmain(int argc, TCHAR **argv) { _tprintf_s(_T("\n %s v1.01 - gadu-gadu config file decoder\n"),*argv); _tprintf_s(_T(" copyright (c) g-n-d.net www.g-n-d.net\n\n")); if (argc<2||(_tcsstr(*(argv+1),_T("config.dat"))==NULL)) { _tprintf_s(_T(" usage: %s <gadu-gadu config.dat file>\n"),*argv); return 0; } HANDLE hFile; hFile=CreateFile(*(argv+1), // file to open GENERIC_READ, // open for reading FILE_SHARE_READ, // share for reading NULL, // default security OPEN_EXISTING, // existing file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template if (hFile == INVALID_HANDLE_VALUE) { _tprintf_s(_T(" could not open file %s (system error code %d)\n"),*(argv+1),GetLastError()); return 0; } if(!CheckGG(hFile)) { _tprintf_s(_T(" given %s file is not the gadu-gadu config file\n"),*(argv+1)); return 0; } char* hash=NULL; char* value=NULL; hash=GetHash(hFile,"Number"); if(hash!=NULL) { DWORD *p=(DWORD*)hash; printf_s(" identity number: %ld\n",*p); } delete [] hash; hash=GetHash(hFile,"Password2"); if(hash!=NULL) { value=ServerPasswordDecode(hash); printf_s(" password for server: %s\n",value); delete [] value; } delete [] hash; hash=GetHash(hFile,"passwordstr"); if(hash!=NULL) { value=ProfilePasswordDecode(hash); printf_s(" password for profile: %s\n",value); delete [] value; } delete [] hash; CloseHandle(hFile); return 0; } Vielen Dank schon einmal für eure Hilfe :) |
Re: CPP zu Delphi
An was denkst du im Besonderen?
|
Re: CPP zu Delphi
Naja, am besten wie man erstmal anfangen sollte.
Ich denke mal nicht das es einen automatischen Konverter gibt. Und nur um diesen Quellcode zu konvertieren extra CPP lernen ist denke ich ein wenig zu viel. Deshalb bin ich für jeden Tipp dankbar. |
Re: CPP zu Delphi
Wenn bekannt wäre, was für ein Hash das ist, könnte man u.U. eine alternative Implementierung dessen verwenden
|
Re: CPP zu Delphi
Hmm,
hab erstmal überlegt was das Programm eigentlich macht und frag mich im Moment wofür man das braucht. Wenn ich es jetzt nicht verpeilt habe, ließt das Programm den Benutzer und das Passwort von einem config.file aus nem Messenger namens gadu gadu aus. sowas wie ICO und gibt das Passwort zu nem Benutzeracc zurück. Wenn ich jetzt falsch liege korrigiere mich. Wenn du dein Passwort vergessen hast, gibt es da keine Passwort vergessen funktion per Mail oder kompeliere es dir in cpp, brauchst es ja nur einmal. Oder bin ich jetzt total auf Holzweg :gruebel: greetz Lun |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:34 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz