Struktur wird nicht übernommen
-
Hallö, ich hab n kleines Problem, von dem ich selber net so genau weiß, wo es liegt. Ich lasse Daten in eine verschlüsselte datei schreiben. Zu diesen daten gehört auch eine Struktur mit 3 Elementen. Lediglich das erste übernimmt er in die Datei. Die anderen 2 werden einfach übergangen. Ich hab hier mal nen Code ausschnitt:
HLRUS_SLOTINFO *pSIS = new HLRUS_SLOTINFO[mv_slots]; for (int i=0; i<mv_slots; i++) { pSIS[i].max_user = slotList[3*i+1]; //mv_sval pSIS[i].exp_date = slotList[3*i]; //mv_sexp pSIS[i].flag = slotList[3*i+2]; //mv_ssng } // get HW Descriptor int hw; switch(mv_hw) { case 0: hw = HL_MEMORY; break; case 1: hw = HL_SERVER; break; case 2: hw = HL_USB1; break; } // buffers for result unsigned char EEP[128]; unsigned long lenEEP = 128; unsigned long lenLic = 10; int res = HLM_LICGEN ( mv_ma, (unsigned char *)((LPCTSTR)mv_vkpwd), svk, lensvk, mv_sid, mv_cnt, mv_exp, mv_server ? 1 : 0, mv_slots, pSIS, hw, EEP, NULL, &lenLic, mv_update ); unsigned char *Lic = new unsigned char [lenLic]; memset (Lic, 0, lenLic); res = HLM_LICGEN ( mv_ma, (unsigned char *)((LPCTSTR)mv_vkpwd), svk, lensvk, mv_sid, mv_cnt, mv_exp, mv_server ? 1 : 0, mv_slots, pSIS, hw, (unsigned char *)EEP, (unsigned char *)Lic, &lenLic, mv_update ); mv_server = 1 ; if (res!=LICGEN_SUCCESS) { switch (res) { case LICGEN_ERR_INVALID_DATA: mc_status.SetWindowText("Invalid data"); break; case LICGEN_ERR_MORE_DATA: mc_status.SetWindowText("Error - bad data length"); break; case LICGEN_ERR_NOT_ENOUGH_MEM: mc_status.SetWindowText("Not enough memory"); break; case LICGEN_ERR_INTERNAL: mc_status.SetWindowText("Internal error"); break; case LICGEN_ERR_BADPASSWD: mc_status.SetWindowText("Bad Vendor Key Password"); break; default: mc_status.SetWindowText("Unknown error"); } } else { // write EEP and License File if(f.Open(mv_eep, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) { f.Write((void*)EEP, lenEEP); f.Close(); } else { mc_status.SetWindowText("Writing EEP file failed."); return; } if(mv_server || mv_update) if(f.Open(mv_lic, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) { f.Write((void*)Lic, lenLic-1); f.Close(); } else { mc_status.SetWindowText("Writing license file failed."); return; } mc_status.SetWindowText("Ready."); } // free allocated memory if (svk!=NULL) delete svk; if (pSIS!=NULL) delete pSIS; if (Lic!=NULL) delete Lic; }
Die Struktur ist wie folgt definiert:
typedef struct { /* maximum number of users. Should be 1 if no Licence file is generated. */ Long max_user; /* expiration date. Pass the number of days since Jan. 1st 1999 */ Long exp_date; //Word /* singularity flag */ Byte flag; } HLRUS_SLOTINFO;
ich weiß nimmer weiter
Teddy
-
Ich seh nirgendwo nen code, wo du deine struct schreibst ...
-
(unsigned char *)((LPCTSTR)mv_vkpwd)
ist mehr als ein unschöner Cast !!!
2.f.Write((void*)Lic, lenLic-1);
schreibt genau lenLic-1 Zeichen in die Datei!. Deine Struktur ist genau 4+4+1=9Byte gross, also wieso sollte er mehr als 1 Struktur schreiben?
3.// free allocated memory if (svk!=NULL) delete svk; if (pSIS!=NULL) delete pSIS; if (Lic!=NULL) delete Lic;
Dieser Code ist FALSCH, da Deine Zeiger Felder sind!
-
die Structur pSIS, bzw. pSIS ist ein Zeiger auf die Struct wird an HLM_LICGEN übergeben. Dort wird daraus LIC gebildet und dieses LIC wird dann in die Datei geschrieben.
HLM_LICGEN:
Word HLM_LICGEN ( Word modadr, /* module adress, necessary if VTC shall be generated */ Byte *password, /* password to open SVK data */ Byte *svk_data, /* data from SVK file */ Long svk_data_len, /* length of SVK data */ Long serialno, /* serial # for Hardlock */ Long counter_limit, /* counter limt for global counter */ Word exp_date, /* expiration date as offset to 01/01/1999 in days */ Byte is_server, /* 0 = local, 1 = server (with license file) */ Word slots, /* maximum number of slots to use, if local automatically use 96 */ HLRUS_SLOTINFO *sis, /* pointer to sis (length = slots * SIZEOF(SIS)) */ int hw_desc, /* hardware descriptor: HL_MEMORY, HL_SERVER, HL_USB1 */ Byte *eep_buffer, /* where to put resulting EEP image */ Byte *lic_buffer, /* where to put license file data */ Long *lic_buflen, /* in + out: license data length */ Byte flags /* 0 = generate EEP/Lic, 1 = generate VTC */ );