static void editfile(char *filename){ int mode = 0; //1 edit mode printbuffer(); int location = k_strlen(file_buffer); typeTeBottom(); while(1){ if(mode){ if(!newInput()) continue; char next = getchar(); if(next==27) { mode =0; typeTeBottom(); continue; } if(next==0) continue; if(next!='\b') file_buffer[location++]=next; else file_buffer[--location]=0; clearScreen(); printbuffer(); } else{ if(!newInput()) continue; char next = getchar(); if(next=='q') break; else if(next=='w') createorreplacefile(filename, file_buffer); else if(next=='e') { mode = 1; clearScreen(); printbuffer();} } } }
static void editfile(char *filename){ int mode = 0; //1 edit mode printbuffer(); int location = k_strlen(file_buffer); typeOffset =(location+1)*2; updateCursor(typeOffset/2); typeTeBottom(); key next; while(1){ if(key_queue_is_empty()) continue; next = remove_key(); if(mode){ if(next.scancode==75 && location>0){ location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//left arrow if(next.scancode==77 && location<fileBufferLength()-1){ location++; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//right arrow if(next.scancode==72 && getScreenPos(location)>VGA_W){ int desired = getScreenPos(location)-VGA_W; while(getScreenPos(location)>desired) location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//up arrow if(next.scancode==80 && getScreenPos(location)/VGA_W<getScreenPos(fileBufferLength())/VGA_W){ int desired = getScreenPos(location)+VGA_W; while(getScreenPos(location)<desired && location<fileBufferLength()-1) location++; if(getScreenPos(location)>desired) location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//down arrow if(next.key==27) { mode =0; typeTeBottom(); continue; } if(next.key==0) continue; if(next.key!='\b') addToFileBuff(next.key, location++);//file_buffer[location++]=next.key; else removeFromFileBuff(location--);//file_buffer[--location]=0; clearScreen(); printbuffer(); typeOffset = 2*getScreenPos(location); updateCursor(typeOffset/2); } else{ if(next.key=='q') break; else if(next.key=='w') createorreplacefile(filename, file_buffer); else if(next.key=='e') { mode = 1; clearScreen(); printbuffer();} } } }
/* ====================================================================== Function: getReceivedData Purpose : Get module received data and display it Input : Module Index from modules table Output : - Comments: - ====================================================================== */ void getReceivedData( uint8_t index) { RHGenericDriver * driver = drivers[index]; if (driver->available()) { // RH_RF95_MAX_MESSAGE_LEN is > RH_RF69_MAX_MESSAGE_LEN, // So we take the maximum size to be able to handle all uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); uint8_t from = driver->headerFrom(); uint8_t to = driver->headerTo(); uint8_t id = driver->headerId(); uint8_t flags= driver->headerFlags();; int8_t rssi = driver->lastRssi(); if (driver->recv(buf, &len)) { time_t timer; char time_buff[16]; struct tm* tm_info; time(&timer); tm_info = localtime(&timer); strftime(time_buff, sizeof(time_buff), "%H:%M:%S", tm_info); printf("%s Mod%s [%02d] #%d => #%d %ddB: ", time_buff, MOD_name[index], len, from, to, rssi); printbuffer(buf, len); } else { printf("receive failed"); } printf("\n"); } }
int main(){ char *p = "abcdefghijklmn"; /* init code */ bufptr = buffer; //bufwrite1(p, strlen(p)); bufwrite2(p, strlen(p)); printf("Print buffer!\n"); printbuffer(); return 1; }
/** ****************************************************************************** * @brief 在loglib中输出指定的缓冲区数据 * @param[in] pbuf : 需要输出的缓冲区指针 * @param[in] len : 需要输出的缓冲区数据长度 * * @retval ERROR: 发送日志消息失败 * @retval OK : 发送日志消息成功 ****************************************************************************** */ status_t logbuf(const uint8_t *pbuf, uint32_t len) { log_msg_t *msg; if (the_logmsg_taskid == NULL) { printbuffer("", pbuf, len); return OK; } msg = malloc(sizeof(log_msg_t)); /* 判断是否在中断中调用 */ msg->id = (intContext() == TRUE) ? -1 : (int32_t)taskIdSelf(); int32_t i; for (i = 0; i < MIN(len , ((MAX_BYTES_IN_A_MSG - 2) / 3)); i++) { (void)sprintf((char *)msg->buf + (i*3) , "%02x ", *pbuf); msg->len += 3; pbuf++; } msg->buf[i*3] = '\r'; msg->buf[(i*3)+1] = '\n'; msg->len += 2; if (msg->len > (MAX_BYTES_IN_A_MSG - 1)) { the_logmsgs_outoflen++; /* shit out of buf length */ } msg->buf[msg->len] = '\0'; if (msgQSend(the_logmsg_qid, (void *) msg) != OK) { ++the_logmsgs_lost; return ERROR; } return OK; }
size_t write_verify_read(void* com_port, unsigned char* in, size_t inlen, unsigned char* out, size_t outlen) { size_t ret; unsigned char buf[4096]; ret = write_serial(com_port, in, inlen); if(ret != inlen) { return (unsigned int)-1; } ret = read_serial(com_port, buf, inlen+outlen); if(ret < inlen || memcmp(in, buf, inlen)) { printf("%s: Read %Ix bytes\n", __FUNCTION__, ret); printbuffer(buf, ret); return (unsigned int)-1; } //printbuffer(buf, ret); memmove(out, buf+inlen, ret-inlen); return ret-inlen; }
/** ****************************************************************************** * @brief 在loglib中输出指定的缓冲区数据 * @param[in] pbuf : 需要输出的缓冲区指针 * @param[in] len : 需要输出的缓冲区数据长度 * * @retval ERROR: 发送日志消息失败 * @retval OK : 发送日志消息成功 ****************************************************************************** */ status_t logbuf(const uint8_t *pbuf, uint32_t len) { printbuffer("", pbuf, len); return OK; }
int main(int argc, char *argv[]) { srand(time(NULL)); int fileSize, i, j, subkeySize = 1024, totalBytes = 0; // LOOOOOOOOOL int padMisses = 0; int got, numcrypts; char magic[2], dmagic[2]; uchar *aesKey, backbuffer[16], subkey[1024], verifyBlock[16]; uchar *plaintext = ":Dbyinfamouspat\0"; uchar encbuf[4080], decbuf[4080]; aes_encrypt_ctx ctx[1]; char *openFile, *destFile; FILE *fd, *dfd; printIntro("ITG2"); if (argc < 3) { printf("usage: %s <input file> <output file>\n", argv[0]); exit(0); } openFile = argv[1]; destFile = argv[2]; if ((fd = fopen(openFile, "rb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], argv[1]); exit(-1); } for (i = 0; i < subkeySize; i++) subkey[i] = rand() * 255; printf("retrieving key from dongle...\n"); aesKey = (uchar*)malloc(24 * sizeof(uchar)); if (getKey(subkey, aesKey) != 0) { fclose(fd); exit(-1); } aes_encrypt_key(aesKey, 24, ctx); aes_encrypt(plaintext, verifyBlock, ctx); #ifdef KD_DEBUG printKey(aesKey); printbuffer("plaintext",plaintext); printbuffer("verifyBlock",verifyBlock); #endif printf("encrypting into %s...\n", destFile); if ((dfd = fopen(destFile, "wb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], destFile); fclose(fd); exit(-1); } fseek(fd, 0, SEEK_END); fileSize = ftell(fd); fseek(fd, 0, SEEK_SET); fwrite(":|", 2, 1, dfd); fwrite(&fileSize, 1, 4, dfd); fwrite(&subkeySize, 1, 4, dfd); fwrite(subkey, 1, subkeySize, dfd); fwrite(verifyBlock, 1, 16, dfd); do { if ((got = fread(decbuf, 1, 4080, fd)) == -1) { fprintf(stderr, "%s: error: fread(%s) returned -1, exiting...\n", argv[0], openFile); fclose(dfd); fclose(dfd); exit(-1); } totalBytes += got; numcrypts = got / 16; if (got % 16 > 0) { numcrypts++; } if (got > 0) { memset(backbuffer, '\0', 16); for (i = 0; i < numcrypts; i++) { for (j = 0; j < 16; j++) { ((uchar*)(decbuf+(16*i)))[j] ^= (((uchar)backbuffer[j]) - j); } aes_encrypt(decbuf+(16*i), encbuf+(16*i), ctx); memcpy(backbuffer, encbuf+(16*i), 16); } fwrite(encbuf, 1, numcrypts*16, dfd); } } while (got > 0); printf("done :D\n"); fclose(dfd); fclose(fd); return 0; }
///main program int main() { int i,j,k,upos=11,cpos=11,cmove,winner=0,uhealth=10,chealth=40,bullets=500,qtyofboomerang=20,qtyofwall=50,boost=0,nofboost=1; int boomerang[4]={188,187,201,200},wall[4]={219,178,177,176}; clock_t start=-1,reloadtime=-1; SetConsoleTitle("ASCII Showdown"); printf("controls:\n'a': left\n'd': right\n'w': fire bullet\n'o': fire homing boomerang\n'p': place a wall\n'i': Engage triple bullet firing mode\n"); system("pause"); titlescreen(); system("cls"); printbuffer(); printscoreboard(); getch(); srand(time(NULL)); ///seeds random numbers using system time while(1) { ///user's turn if(kbhit()) ///listens if user pressed a key { switch(getch()) ///takes the key input { case 'w': if(bullets>0) { if(boost==0) { grid[17][upos]='b'; ///fires a bullet bullets--; } else { if(bullets>2) { for(i=-1;i<=1;i++) { if(upos+i>0 && upos+i<39) { grid[17][upos+i]='b'; ///fires 3 bullets via weapon boost bullets--; } } } } } break; case 'a': ///moves user left if(upos>1) { grid[18][upos]=' '; upos=upos-1; grid[18][upos]='u'; } break; case 'd': ///moves user right if(upos<38) { grid[18][upos]=' '; upos=upos+1; grid[18][upos]='u'; } break; case 'o': if(qtyofboomerang>0) { grid[17][upos]=boomerang[0]; ///fires homing boomerang qtyofboomerang--; } break; case 'p': if(qtyofwall>0) { grid[16][upos]=219; ///sets up a wall qtyofwall--; } break; case 'i': if(nofboost>0) {boost=1; ///starts weapon boost start=clock(); nofboost--; } break; } } ///cpu's turn cmove=rand()%4; ///randomizing cpu's move switch(cmove) { case 0: if(chealth>10) grid[2][cpos]='B'; ///fires a bullet else { for(i=-1;i<=1;i++) { if(cpos+i>0 && cpos+i<39) grid[2][cpos+i]='B'; ///fires 3 bullets when health goes 10 or below 10 } } break; case 1: if(cpos>1) ///moves left { grid[1][cpos]=' '; cpos=cpos-1; grid[1][cpos]='c'; } break; case 2: ///moves right if(cpos<38) { grid[1][cpos]=' '; cpos=cpos+1; grid[1][cpos]='c'; } break; case 3: ///does nothing break; } ///prints the arena printbuffer(); ///prints score score(uhealth,chealth,bullets,qtyofboomerang,qtyofwall,boost,nofboost); ///time delay Sleep(70); ///user bullets for(i=0;i<20;i++) { for(j=0;j<40;j++) { if(grid[i][j]=='b' && i>1 && grid[i-1][j]==' ') { grid[i][j]=' '; grid[i-1][j]='b'; ///moves the bullets forward } if(grid[i][j]=='b' && i==1) grid[i][j]=' '; ///bullets collision with wall if(grid[i][j]=='b' && grid[i-1][j]=='B') { grid[i][j]=' '; ///bullets collision grid[i-1][j]=' '; } if(grid[i][j]=='b' && grid[i-1][j]=='c') { grid[i][j]=' '; ///bullet hits cpu chealth--; screenflash(); } for(k=0;k<4;k++) { if(grid[i][j]==boomerang[k]-256 && (grid[i-1][j]=='c' || grid[i-1][j-1]=='c' || grid[i-1][j+1]=='c')) { grid[i][j]=' '; ///boomerang hits cpu chealth-=1; screenflash(); screenflash(); } if(grid[i][j]==boomerang[k]-256 && i>1 && grid[i-1][j]==' ') { grid[i][j]=' '; if(j>cpos) grid[i-1][j-1]=boomerang[(k+1)%4]; /// boomerang moves forward if(j<cpos) grid[i-1][j+1]=boomerang[(k+1)%4]; ///homing boomerang if(j==cpos) grid[i-1][j]=boomerang[(k+1)%4]; break; } if(grid[i][j]==boomerang[k]-256 && grid[i-1][j]=='B') { grid[i][j]=' '; ///bullet and boomerang collision grid[i-1][j]=boomerang[(k+1)%4]; } if(grid[i][j]==boomerang[k]-256 && i==1) grid[i][j]=' '; ///boomerang hits wall } for(k=0;k<4;k++) { if(grid[i][j]=='b' && grid[i-1][j]==wall[k]-256) { grid[i][j]=' '; grid[i-2][j]='b'; ///bullets collision with user's wall } if(grid[i][j]==boomerang[0]-256 && grid[i-1][j]==wall[k]-256) { grid[i][j]=' '; grid[i-1][j]=' '; ///boomerang collision with user's wall grid[i-2][j]=boomerang[2]; } } } } ///cpu bullets for(i=19;i>-1;i--) { for(j=0;j<40;j++) { if(grid[i][j]=='B' && i<18 && grid[i+1][j]==' ') { grid[i][j]=' '; ///moves the bullets forward grid[i+1][j]='B'; } if(grid[i][j]=='B' && i==18) grid[i][j]=' '; ///bullets collision with wall if(grid[i][j]=='B' && grid[i+1][j]=='u') { grid[i][j]=' '; ///bullet hits user uhealth--; screenflash(); } for(k=0;k<4;k++) { if(grid[i][j]=='B' && grid[i+1][j]==wall[k]-256) { grid[i][j]=' '; ///cpu's bullets collision with user's wall if(k<3) grid[i+1][j]=wall[k+1]; else grid[i+1][j]=' '; } } } } if(clock()-start>5000 && start>0) { boost=0; ///stops the weapon boost start=-1; reloadtime=clock(); } if(clock()-reloadtime>10000 && reloadtime>0) { if(nofboost==0) nofboost++; ///reloads the weapon boost reloadtime=-1; } if(chealth<=0) { winner=1; ///user wins break; } if(uhealth<=0 || (bullets<=0 && qtyofboomerang==0)) { winner=2; ///cpu wins break; } } win(winner); ///selects the winner. 0 : no winner, 1 : user wins, 2 : cpu wins return 0; ///end of program }
void flushbuffer(){ printf("Flush buffer!\n"); printbuffer(); bufptr = buffer; }
int main(int argc, char *argv[]) { srand(time(NULL)); int fileSize, i, j, subkeySize = 1024, totalBytes = 0; // LOOOOOOOOOL int padMisses = 0; int got, numcrypts; char magic[2], dmagic[2]; uchar *aesKey, verifyBlock[22], backbuffer[16], subkey[1024]; uchar *plaintext = "<<'08infamouspat"; uchar *SHAworkspace; uchar salt[16], salted[16], dsalted[16]; uchar encbuf[4080], decbuf[4080]; aes_encrypt_ctx ctx[1]; char *openFile, *destFile; FILE *fd, *dfd; printIntro("Pump It Up Pro"); if (argc < 3) { printf("usage: %s <input file> <output file>\n", argv[0]); exit(0); } openFile = argv[1]; destFile = argv[2]; if ((fd = fopen(openFile, "rb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], argv[1]); exit(-1); } for (i = 0; i < subkeySize; i++) subkey[i] = rand() * 255; SHAworkspace = (uchar*)malloc(sizeof(uchar) * (subkeySize+47)); memcpy(SHAworkspace, subkey, subkeySize); memcpy(SHAworkspace+subkeySize, PProSubkeySalt, 47); aesKey = (uchar*)malloc(24 * sizeof(uchar)); memset(aesKey, '\0', 24); gcry_md_hash_buffer(GCRY_MD_SHA1, aesKey, SHAworkspace, subkeySize+47); printKey(aesKey); aes_encrypt_key(aesKey, 24, ctx); for (i = 0; i < 16; i++) salt[i] = rand() * 255; saltHash(salted, salt, 0x123456); aes_encrypt(salted, dsalted, ctx); for (i = 0; i < 16; i++) { verifyBlock[i] = plaintext[i] ^ dsalted[i]; } #ifdef KD_DEBUG printKey(aesKey); printbuffer("salt", salt); printbuffer("salted", salted); printbuffer("dsalted", dsalted); printbuffer("plaintext", plaintext); printbuffer("verifyBlock", verifyBlock); #endif if ((dfd = fopen(destFile, "wb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], destFile); fclose(fd); exit(-1); } fwrite("8O", 1, 2, dfd); fwrite(&subkeySize, 1, 4, dfd); fwrite(subkey, 1, subkeySize, dfd); fwrite(salt, 1, 16, dfd); fseek(fd, 0, SEEK_END); fileSize = ftell(fd); fseek(fd, 0, SEEK_SET); printf("file size: %u\n", fileSize); fwrite(&fileSize, 1, 4, dfd); fwrite(verifyBlock, 1, 16, dfd); printf("encrypting into %s...\n", destFile); do { if ((got = fread(decbuf, 1, 4080, fd)) == -1) { fprintf(stderr, "wtf..?\n"); fclose(dfd); fclose(fd); exit(-1); } numcrypts = got / 16; if (got % 16 > 0) { numcrypts++; } if (got > 0) { for (i = 0; i < numcrypts; i++) { //saltHash(salted, salt, numcrypts); //memcpy(salted, salt, 16); //salted[0] += numcrypts; aes_encrypt(salt, dsalted, ctx); // LOLOLOLOLOL // this should cover about a 320GB file, so we should be good... if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255 && salt[3] == 255 && salt[4] == 255) salt[5]++; if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255 && salt[3] == 255) salt[4]++; if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255) salt[3]++; if (salt[0] == 255 && salt[1] == 255) salt[2]++; if (salt[0] == 255) salt[1]++; salt[0]++; for (j = 0; j < 16; j++) { encbuf[(i*16)+j] = dsalted[j] ^ decbuf[(i*16)+j]; } //decbuf[i] = dsalted[i%16] ^ encbuf[i]; } totalBytes += got; if (totalBytes > fileSize) { got -= totalBytes - fileSize; totalBytes -= totalBytes - fileSize; } fwrite(encbuf, 1, numcrypts * 16, dfd); } } while (got > 0); fclose(dfd); fclose(fd); return 0; }
int main (int argc, char *argv[]) { int i, l, ct; boolean first; rewriting_system rws, *rwsptr; static char gpname[100], outf[100]; setbuf(stdout,(char*)0); setbuf(stderr,(char*)0); rwsptr= &rws; rwsptr->maxeqns = MAXEQNS; rwsptr->maxreducelen = MAXREDUCELEN; rwsptr->cosets=FALSE; rwsptr->inv_of=0; rwsptr->weight=0;rwsptr->level=0;rwsptr->history=0; rwsptr->slowhistory=0;rwsptr->slowhistorysp=0; rwsptr->preflen=0;rwsptr->prefno=0; if (argc!=2) badusage_ppgap(); strcpy(gpname,argv[1]); strcpy(outf,gpname); strcat(outf,".gap"); /* First read in the defining relations for the group. */ if ((rfile = fopen(gpname,"r")) == 0) { fprintf(stderr,"Cannot open file %s.\n",gpname); exit(1); } read_kbinput_simple(rfile,TRUE,rwsptr); fclose(rfile); wfile = fopen(outf,"w"); kbm_buffer[0]='\0'; add_to_buffer(0,"_RWS.gpMon := FreeGroup("); first = TRUE; if (rws.num_gens==0) add_to_buffer(0,"0"); else for (i=1;i<=rws.num_gens;i++){ l = stringlen(rws.gen_name[i]); if (l<=3 || strcmp(rws.gen_name[i]+l-3,"^-1")) { if (!first) add_to_buffer(0,","); first = FALSE; sprintf(kbm_buffer+stringlen(kbm_buffer),"\"%s\"",rws.gen_name[i]); } } add_to_buffer(0,");"); printbuffer(wfile); ct = 0; for (i=1;i<=rws.num_gens;i++) { l = stringlen(rws.gen_name[i]); if (l<=3 || strcmp(rws.gen_name[i]+l-3,"^-1")) { ct++; fprintf(wfile,"%s := _RWS.gpMon.%d;\n",rws.gen_name[i],ct); } } fprintf(wfile,"_ := IdWord;\n"); fclose(wfile); rws_clear(rwsptr); exit(0); }
void FCF_Log (uint32_t fourcc, const unsigned char *buf, int act_len) { write_tagged_message(fourcc, buf, act_len); printbuffer(fourcc, buf, act_len); //flush_buffers(); }