/*************************************************************************** * * Pass a pointer to the ROM base address. ***************************************************************************/ void getrominfo(char *romheader) { /* Clear ROM info structure */ memset (&rominfo, 0, sizeof (ROMINFO)); /* Genesis ROM header support */ if (system_hw & SYSTEM_MD) { int i,j; memcpy (&rominfo.consoletype, romheader + ROMCONSOLE, 16); memcpy (&rominfo.copyright, romheader + ROMCOPYRIGHT, 16); /* Domestic (japanese) name */ rominfo.domestic[0] = romheader[ROMDOMESTIC]; j = 1; for (i=1; i<48; i++) { if ((rominfo.domestic[j-1] != 32) || (romheader[ROMDOMESTIC + i] != 32)) { rominfo.domestic[j] = romheader[ROMDOMESTIC + i]; j++; } } rominfo.domestic[j] = 0; /* International name */ rominfo.international[0] = romheader[ROMWORLD]; j=1; for (i=1; i<48; i++) { if ((rominfo.international[j-1] != 32) || (romheader[ROMWORLD + i] != 32)) { rominfo.international[j] = romheader[ROMWORLD + i]; j++; } } rominfo.international[j] = 0; /* ROM informations */ memcpy (&rominfo.ROMType, romheader + ROMTYPE, 2); memcpy (&rominfo.product, romheader + ROMPRODUCT, 12); memcpy (&rominfo.checksum, romheader + ROMCHECKSUM, 2); memcpy (&rominfo.romstart, romheader + ROMROMSTART, 4); memcpy (&rominfo.romend, romheader + ROMROMEND, 4); memcpy (&rominfo.country, romheader + ROMCOUNTRY, 16); /* Checksums */ #ifdef LSB_FIRST rominfo.checksum = (rominfo.checksum >> 8) | ((rominfo.checksum & 0xff) << 8); #endif rominfo.realchecksum = getchecksum(((uint8 *) cart.rom) + 0x200, cart.romsize - 0x200); /* Supported peripherals */ rominfo.peripherals = 0; for (i = 0; i < 14; i++) for (j=0; j < 14; j++) if (romheader[ROMIOSUPPORT+i] == peripheralinfo[j].pID[0]) rominfo.peripherals |= (1 << j); }
void frmBoxes::on_actionSave_changes_triggered() { QMessageBox msgBox; msgBox.setWindowTitle("Save Data"); msgBox.setText("Changes have been made to this save."); msgBox.setInformativeText("Do you want to overwrite the file and save your changes?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save); int ret = msgBox.exec(); // You can simply use QMessageBox::<ButtonType> as the result code if(ret == QMessageBox::Save) // 2048 (or 0x800) = Save, 4194304 (or 0x400000) = Cancel { if((sav > 0)/* && (cursavblock->adventurestarted != 0)*/) { bw2sav_obj * savout = new bw2sav_obj; *savout = *sav; bool isbw2 = savisbw2(savout); savout->cur.curbox = frmCurBoxNum; // ui->cbBoxes->currentIndex(); for(uint32 pslot = 0; pslot < savout->cur.party.size; pslot++) { encryptpkm(&(savout->cur.party.pokemon[pslot])); } calcpartychecksum(&(savout->cur),isbw2); for(int boxnum = 0; boxnum < 24; boxnum++) { for(int boxslot = 0; boxslot < 30; boxslot++) { encryptpkm(&(savout->cur.boxes[boxnum].pokemon[boxslot])); } calcboxchecksum(&(savout->cur),boxnum,isbw2); } savout->cur.block1checksum = getchecksum(&(savout->cur),0x0,0x3e0); fixsavchecksum(savout, isbw2); write(SaveFileName.toStdString().c_str(),savout); msgBox.setText("The file has been saved."); msgBox.setInformativeText(""); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); } else { msgBox.setText("The file will not be saved."); msgBox.setInformativeText(""); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); } } else { msgBox.setText("The file will not be saved."); msgBox.setInformativeText(""); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); } ret = msgBox.exec(); }
int main(){ printf("Привет! Я - программа, которая считает хэш файла и проверяет его.\n"); printf("Пожалуйста, введите название файла, с которым мне работать (по умолчанию - 'asd.dat').\n"); char nazvaniye[50]; scanf("%s", nazvaniye); getchar(); if (nazvaniye == "") *(&nazvaniye[0]) = "asd.dat"; char bo; printf("Желаете создать хеш-сумму файла %s? (y/n)\n", nazvaniye); scanf("%c", &bo); switch (bo){ case 'y' : bo = bo; unsigned sub = getchecksum(nazvaniye); FILE *fw = fopen("checksum.dat", "wb"); int i=0; for (; i<2; i++){ putc(sub & 255, fw); sub >>= 8; } fclose(fw); break; case 'n' : break; } printf("Желаете проверить хеш-сумму файла %s? (y/n)\n", nazvaniye); scanf("%c", &bo); scanf("%c", &bo); switch (bo){ case 'y' : printf("От вас получили багаж: Диван, Чемодан, Саквояж, Картину, Корзину, Картонку И маленькую собачонку.\n"); unsigned truesum = getchecksum(nazvaniye); unsigned gotsum; FILE *fr = fopen("checksum.dat", "rb"); gotsum = getc(fr); gotsum += getc(fr) << 8; fclose(fr); if (gotsum == truesum) printf("Байты доставленны без потерь\n"); else printf("Однако за время пути. Собака могла подрасти.\n"); break; case 'n' : break; } return 0; }
int cli_untar(const char *dir, unsigned int posix, cli_ctx *ctx) { int size = 0, ret, fout=-1; int in_block = 0; int last_header_bad = 0; int limitnear = 0; unsigned int files = 0; char fullname[NAME_MAX + 1]; size_t pos = 0; size_t currsize = 0; char zero[BLOCKSIZE]; unsigned int num_viruses = 0; cli_dbgmsg("In untar(%s)\n", dir); memset(zero, 0, sizeof(zero)); for(;;) { const char *block; size_t nread; block = fmap_need_off_once_len(*ctx->fmap, pos, BLOCKSIZE, &nread); cli_dbgmsg("cli_untar: pos = %lu\n", (unsigned long)pos); if(!in_block && !nread) break; if (!nread) block = zero; if(!block) { if(fout>=0) close(fout); cli_errmsg("cli_untar: block read error\n"); return CL_EREAD; } pos += nread; if(!in_block) { char type; int directory, skipEntry = 0; int checksum = -1; char magic[7], name[101], osize[TARSIZELEN + 1]; currsize = 0; if(fout>=0) { lseek(fout, 0, SEEK_SET); ret = cli_magic_scandesc(fout, ctx); close(fout); if (!ctx->engine->keeptmp) if (cli_unlink(fullname)) return CL_EUNLINK; if (ret==CL_VIRUS) { if (!SCAN_ALL) return CL_VIRUS; else num_viruses++; } fout = -1; } if(block[0] == '\0') /* We're done */ break; if((ret=cli_checklimits("cli_untar", ctx, 0, 0, 0))!=CL_CLEAN) return ret; checksum = getchecksum(block); cli_dbgmsg("cli_untar: Candidate checksum = %d, [%o in octal]\n", checksum, checksum); if(testchecksum(block, checksum) != 0) { // If checksum is bad, dump and look for next header block cli_dbgmsg("cli_untar: Invalid checksum in tar header. Skip to next...\n"); if (last_header_bad == 0) { last_header_bad++; cli_dbgmsg("cli_untar: Invalid checksum found inside archive!\n"); } continue; } else { last_header_bad = 0; cli_dbgmsg("cli_untar: Checksum %d is valid.\n", checksum); } /* Notice assumption that BLOCKSIZE > 262 */ if(posix) { strncpy(magic, block+257, 5); magic[5] = '\0'; if(strcmp(magic, "ustar") != 0) { cli_dbgmsg("cli_untar: Incorrect magic string '%s' in tar header\n", magic); return CL_EFORMAT; } } type = block[TARFILETYPEOFFSET]; switch(type) { default: cli_dbgmsg("cli_untar: unknown type flag %c\n", type); case '0': /* plain file */ case '\0': /* plain file */ case '7': /* contiguous file */ case 'M': /* continuation of a file from another volume; might as well scan it. */ files++; directory = 0; break; case '1': /* Link to already archived file */ case '5': /* directory */ case '2': /* sym link */ case '3': /* char device */ case '4': /* block device */ case '6': /* fifo special */ case 'V': /* Volume header */ directory = 1; break; case 'K': case 'L': /* GNU extension - ././@LongLink * Discard the blocks with the extended filename, * the last header will contain parts of it anyway */ case 'N': /* Old GNU format way of storing long filenames. */ case 'A': /* Solaris ACL */ case 'E': /* Solaris Extended attribute s*/ case 'I': /* Inode only */ case 'g': /* Global extended header */ case 'x': /* Extended attributes */ case 'X': /* Extended attributes (POSIX) */ directory = 0; skipEntry = 1; break; } if(directory) { in_block = 0; continue; } strncpy(osize, block+TARSIZEOFFSET, TARSIZELEN); osize[TARSIZELEN] = '\0'; size = octal(osize); if(size < 0) { cli_dbgmsg("cli_untar: Invalid size in tar header\n"); skipEntry++; } else { cli_dbgmsg("cli_untar: size = %d\n", size); ret = cli_checklimits("cli_untar", ctx, size, 0, 0); switch(ret) { case CL_EMAXFILES: // Scan no more files skipEntry++; limitnear = 0; break; case CL_EMAXSIZE: // Either single file limit or total byte limit would be exceeded cli_dbgmsg("cli_untar: would exceed limit, will try up to max"); limitnear = 1; break; default: // Ok based on reported content size limitnear = 0; break; } } if(skipEntry) { const int nskip = (size % BLOCKSIZE || !size) ? size + BLOCKSIZE - (size % BLOCKSIZE) : size; if(nskip < 0) { cli_dbgmsg("cli_untar: got negative skip size, giving up\n"); return CL_CLEAN; } cli_dbgmsg("cli_untar: skipping entry\n"); pos += nskip; continue; } strncpy(name, block, 100); name[100] = '\0'; if(cli_matchmeta(ctx, name, size, size, 0, files, 0, NULL) == CL_VIRUS) { if (!SCAN_ALL) return CL_VIRUS; else num_viruses++; } snprintf(fullname, sizeof(fullname)-1, "%s"PATHSEP"tar%02u", dir, files); fullname[sizeof(fullname)-1] = '\0'; fout = open(fullname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600); if(fout < 0) { char err[128]; cli_errmsg("cli_untar: Can't create temporary file %s: %s\n", fullname, cli_strerror(errno, err, sizeof(err))); return CL_ETMPFILE; } cli_dbgmsg("cli_untar: extracting to %s\n", fullname); in_block = 1; } else { /* write or continue writing file contents */ int nbytes, nwritten; int skipwrite = 0; char err[128]; nbytes = size>512? 512:size; if (nread && nread < (size_t)nbytes) nbytes = nread; if (limitnear > 0) { currsize += nbytes; cli_dbgmsg("cli_untar: Approaching limit...\n"); if (cli_checklimits("cli_untar", ctx, (unsigned long)currsize, 0, 0) != CL_SUCCESS) { // Limit would be exceeded by this file, suppress writing beyond limit // Need to keep reading to get to end of file chunk skipwrite++; } } if (skipwrite == 0) { nwritten = (int)cli_writen(fout, block, (size_t)nbytes); if(nwritten != nbytes) { cli_errmsg("cli_untar: only wrote %d bytes to file %s (out of disc space?): %s\n", nwritten, fullname, cli_strerror(errno, err, sizeof(err))); close(fout); return CL_EWRITE; } } size -= nbytes; if ((size != 0) && (nread == 0)) { // Truncated tar file, so end file content like tar behavior cli_dbgmsg("cli_untar: No bytes read! Forcing end of file content.\n"); size = 0; } } if (size == 0) in_block = 0; } if(fout>=0) { lseek(fout, 0, SEEK_SET); ret = cli_magic_scandesc(fout, ctx); close(fout); if (!ctx->engine->keeptmp) if (cli_unlink(fullname)) return CL_EUNLINK; if (ret==CL_VIRUS) return CL_VIRUS; } if (num_viruses) return CL_VIRUS; return CL_CLEAN; }