#include "StdAfx.h" #include "utl.h" #include "StrArray.h" #include #include //************************************************************************** Cutl::Cutl(void) { } //************************************************************************** Cutl::~Cutl(void) { } //************************************************************************** void Cutl::big_little( BYTE* b,int nb ) { BYTE*aux=(BYTE*)malloc(nb); for (int i=0;i>1); bit=bit|((b[i]& 0x08)>>3); bit=bit|((b[i]& 0x10)<<3); bit=bit|((b[i]& 0x20)<<1); bit=bit|((b[i]& 0x40)>>1); bit=bit|((b[i]& 0x80)>>3); //inverso---------------- if (i%2==0) bit=~bit; else bit=bit; //orden------------------ if (i==0) { n=255-bit-(char)(nb%256); aux[0]=bit; } else aux[1+(n1+i)%(nb-1)]=bit-n; } memcpy(b,aux,nb); free(aux); } //*************************************************************************** void Cutl::cifra1( char*b ) { cifra1((BYTE*)b,(int)strlen(b)); } //*************************************************************************** void Cutl::descifra1( BYTE* b,int nb ) { BYTE *aux=(BYTE*)malloc(nb); BYTE bit; BYTE bit1; char n=0; int n1=(nb-1)/2; for (int i=0;i>1); bit=bit|((bit1& 0x08)>>3); bit=bit|((bit1& 0x10)<<3); bit=bit|((bit1& 0x20)<<1); bit=bit|((bit1& 0x40)>>1); bit=bit|((bit1& 0x80)>>3); aux[i]=bit; } memcpy(b,aux,nb); free(aux); } //*************************************************************************** void Cutl::descifra1( char*b ) { descifra1((BYTE*)b,(int)strlen(b)); } //*************************************************************************** int Cutl::busca( BYTE*lista,int n,int z,BYTE *e, int (*funcion)(BYTE*,BYTE*) ) { int i,f,c,r; i=0; f=n-1; c=n/2; while(ci) { r=funcion(&lista[z*c],e); if (r<0) f=r; else if(r>0) i=r; else return c; c=(f-i)/2; } //quedan como mucho 2 elementos if (funcion(&lista[z*i],e)<=0) return i; return f; } //******************************************************************************************** int pon_id(char* idm, int nb, int nbAct, char *buf, int nbbuf ) { int i; for(i=0; i10) return NULL; continue; } if(ERROR_SUCCESS!=er) return NULL; ii=pon_id(idm, nb,ii,str,strlen(str)); } RegCloseKey( hKey1); er = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\BIOS", 0,KEY_READ,&hKey1); if (er != ERROR_SUCCESS) { return NULL; } for (i=0; i<12; i++) { l2=2048; er=RegQueryValueEx(hKey1,prop_bios[i],0,NULL,(LPBYTE) str,(LPDWORD) &l2); if(er==ERROR_FILE_NOT_FOUND) { v_er++; if(v_er>10) return NULL; continue; } if(ERROR_SUCCESS!=er) return NULL; ii=pon_id(idm, nb,ii,str,strlen(str)); } RegCloseKey( hKey1); er = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0,KEY_READ,&hKey1); if (er != ERROR_SUCCESS) { return NULL; } for (i=0; i<3; i++) { l2=2048; er=RegQueryValueEx(hKey1,prop_proce[i],0,NULL,(LPBYTE) str,(LPDWORD) &l2); if(er==ERROR_FILE_NOT_FOUND) { v_er++; if(v_er>10) return NULL; continue; } if(ERROR_SUCCESS!=er) return NULL; ii=pon_id(idm, nb,ii,str,strlen(str)); } for (; i<5; i++) { l2 = sizeof(DWORD); er=RegQueryValueEx(hKey1, prop_proce[i], NULL, NULL, (LPBYTE)&dwData, (LPDWORD)&l2); if(ERROR_SUCCESS!=er) { v_er++; if(v_er>10) return FALSE; continue; } sprintf(str,"%u",dwData); ii=pon_id(idm, nb,ii,str,strlen(str)); } //QueryPerformanceFrequency( &lpFrequency); //RegQueryValueEx(hKey1,prop_proce[i],0,NULL,(LPBYTE) &dd,(LPDWORD) &l2); // sprintf(str,"%ld",i); //l2=strlen(str); //ii=pon_id(id,ii,(char*)&lpFrequency,sizeof(LARGE_INTEGER)); RegCloseKey( hKey1); //lo pasa a string int n1='z'-'a'+1; int n2='Z'-'A'+1; int nt=n1+n2+'9'-'0'+1; for (i=0; i='0' && *s<='9') res=(res<<4)|(int)(*s-'0'); else if(*s>='a' && *s<='f') res=(res<<4)|(10+(int)(*s-'a')); else if(*s>='A' && *s<='F') res=(res<<4)|(10+(int)(*s-'A')); else break; s++; } return res; } //*************************************************************************** void Cutl::int2str_hex( char* st , int n) { int i,a; strcpy(st,"0x00000000"); for(i=0; i<8; i++) { a=(n>>4*i)&0xf; if(a<10) st[2+7-i]='0'+(char)a; else st[2+7-i]='a'+(char)a-10; } } //*************************************************************************** DWORDLONG Cutl::getMemoDisp() { MEMORYSTATUSEX status; status.dwLength = sizeof(status); GlobalMemoryStatusEx(&status); return status.ullAvailVirtual; } //*************************************************************************** bool Cutl::lanza_exe(char *appName, char *comline, DWORD *processId) { // additional information STARTUPINFO si; PROCESS_INFORMATION pi; BOOL is_alive=FALSE; // set the size of the structures ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // start the program up CreateProcess( appName, // the path comline, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses) ); //check is alive DWORD lpExitCode; GetExitCodeProcess(pi.hProcess,&lpExitCode); is_alive=(lpExitCode==STILL_ACTIVE); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); if(is_alive==TRUE && processId) *processId=pi.dwProcessId; return is_alive==TRUE; } //*************************************************************************** DWORDLONG Cutl::getMemoDisp1Malloc() { void* bufprinci = NULL; //en un malloc----------------------- DWORDLONG i=0; DWORDLONG paso; //ia=paso; //for (int j=0; j<3; j++) //{ paso=1024*1024*1024; while(TRUE) { bufprinci=malloc(size_t(i+paso)); if (bufprinci) { free(bufprinci); i+=paso; } else { if (paso<1) break; paso=paso/2; if (paso<1) break; } } if (bufprinci) free(bufprinci); return i; } //*************************************************************************** StrArray* Cutl::stringSplit( char *orig,char* subStr, StrArray*buf ) { char *s = orig; char *s1, *s2; int siz =strlen(subStr); s1 = strstr(s, subStr); int n; while(s1) { n = (int)(s1-s); buf->add(NULL, n+1); s2 = buf->get(buf->n_i-1); if(!s1) return NULL; for (int i =0; iadd(s); s2 = buf->get(buf->n_i-1); if(!s2) return NULL; return buf; } //*************************************************************************** char* Cutl::getWinUser( char* buf ) { DWORD username_len = UNLEN+1; GetUserName(buf, &username_len); return buf; } //***************************************************************************