int main(int argc, char *argv[]) { printf("Entering main()\n"); ShadowMap* my_sm = malloc(sizeof(ShadowMap)); shadow_initialize_with_mmap(my_sm); U8 tmp; shadow_set_bits(my_sm, 0, (U8)0xab); getbyte(0,tmp); print(tmp); assert(tmp == (U8)0xab); shadow_set_bits(my_sm, 0x1111, (U8)0xFF); shadow_unmark_bit(my_sm, 0x1111, 4); getbyte(0x1111,tmp); print(tmp); assert(tmp == (U8)0xEF); // TODO: assert getbit (0x1111,4,tmp); assert(tmp == 0); shadow_set_bits(my_sm, 0xBEEF, (U8)0x00); shadow_mark_bit(my_sm, 0xBEEF, 2); getbyte(0xBEEF,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xBEEF,2,tmp); assert(tmp == 1); printf("----\n"); shadow_set_bits(my_sm, 0xAAFF00AA, (U8)0x00); shadow_mark_bit(my_sm, 0xAAFF00AA, 2); getbyte(0xAAFF00AA,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xAAFF00AA,2,tmp); assert(tmp == 1); shadow_destroy_map(my_sm); free(my_sm); printf("Exiting main()\n"); return 0; }
static void md2_trans(void) { /* Convert a MicroDesign 2 area to PBM */ /* MD2 has RLE encoding that may go over */ int x1, y1, col; /* multiple lines. */ mdbyte b; int c; x1 = y1 = col = 0; while (y1 < nInRows) { b = getbyte(); if (b == 0 || b == 0xFF) { /* RLE sequence */ c = getbyte(); if (c == 0) c = 256; while (c > 0) { render_byte(&col, &x1, &y1, b); --c; } } else render_byte(&col, &x1, &y1, b); /* Not RLE */ } }
QVector<bit16> ExpandKey(bit16 KeySixteen) { byte W0 = getbyte(KeySixteen, 0); byte W1 = getbyte(KeySixteen, 1); byte RCon1(std::string("00000001")); //these are backwards because bitsets are stored Big-Endian byte RCon2(std::string("00001100")); //and our algorithm operates Little-Endian nibble W1part0 = getnib(W1, 0); nibble W1part1 = getnib(W1, 1); byte W2a = concatenate(SBox(W1part1), SBox(W1part0)); byte W2 = W2a ^ RCon1 ^ W0; byte W3 = W1 ^ W2; nibble W3part0 = getnib(W3, 0); nibble W3part1 = getnib(W3, 1); byte W4a = concatenate(SBox(W3part1), SBox(W3part0)); byte W4 = W4a ^ RCon2 ^ W2; byte W5 = W3 ^ W4; bit16 W01 = concatenate(W0, W1); bit16 W23 = concatenate(W2, W3); bit16 W45 = concatenate(W4, W5); QVector<bit16> out; out.push_back(W01); out.push_back(W23); out.push_back(W45); return out; }
int loadseg() { int ch; char *upto; ch = getbyte(); if (ch != 0xff) return(ch); ch = getbyte(); seglen=0; segin=0; if (ch>=0xd0 && ch<=0xd9) return(ch); seglen = getword()-2; if (seglen>segsize) { segsize = seglen; segbuf = realloc(segbuf, seglen); } while (segin < seglen) { segbuf[segin] = getbyte(); segin++; } segin = 0; return(ch); }
void surrogate(int s) { static int prev = 0; if(prev == 0) { if(surrogatesfound >= 0 && (s & 0xFC00) == 0xD800) // first word surrogat { ++surrogatesfound; prev = s; } else { getbyte(s); } } else { if(surrogatesfound >= 0 && (s & 0xFC00) == 0xDC00) // second word surrogat { s = (s & 0x3ff) + ((prev & 0x3ff) << 10) + 0x10000; getbyte(s); } else { // Assume it is UCS-2, not UTF-16 surrogatesfound = -1; getbyte(s); } prev = 0; } }
void DumpCobItem(BYTE ch) { WORD ch2; WORD f; short size; if ((ch & 0x80) == 0) { // dump numeric ch2 = getbyte(); StdOutPrintf(L" (0x%02x 0x%02x) ", ch, ch2); StdOutPuts(L"numeric "); if ((ch & 0x40) == 0x40) { StdOutPuts(L"not "); } StdOutPuts(L"DISPLAY "); if ((ch & 0x20) == 0x20) { StdOutPuts(L"not LITERAL "); } else { StdOutPrintf(L"LITERAL = %0x02x", getbyte()); } if ((ch2 & 0x80) == 0x80) { StdOutPuts(L"not "); } StdOutPuts(L"signed\n"); f = (ch2 & 0x60) >> 5; if (ch & 0x20) { StdOutPrintf(L"%s", display[f]); } else { StdOutPrintf(L"%s", notdisplay[f]); } StdOutPrintf(L"N1 = 0x%02x, N2 = 0x%02x\n", ch & 0x1f, ch2 & 0x1f); }
int main(int argc, char *argv[]) { printf("Entering main()\n"); ShadowMap* my_sm = malloc(sizeof(ShadowMap)); my_sm->shadow_bits = 1; my_sm->application_bits = 1; my_sm->num_distinguished = 1; shadow_initialize_map(my_sm); U8 tmp; shadow_set_bits(my_sm, 0, (U8)0xab); getbyte(0,tmp); print(tmp); assert(tmp == (U8)0xab); shadow_set_bits( my_sm, 0x1111, (U8)0xFF); shadow_unmark_bit(my_sm, 0x1111, 4); getbyte(0x1111,tmp); print(tmp); assert(tmp == (U8)0xEF); // TODO: assert getbit (0x1111,4,tmp); assert(tmp == 0); shadow_set_bits( my_sm, 0xBEEF, (U8)0x00); shadow_mark_bit( my_sm, 0xBEEF, 2); getbyte(0xBEEF,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xBEEF,2,tmp); assert(tmp == 1); shadow_destroy_map(my_sm); free(my_sm); printf("Exiting main()\n"); return 0; }
void DumpCobol(BYTE level) { BYTE ch; StdOutPrintf(L"\tLevel = %2d", level & 0x7f); if (level & 0x80) { StdOutPuts(L"(Group)"); } loop: // check next byte of type string ch = getbyte(); if ((ch & 0xfe) == 0xc0) { // output linkage informatioon byte DumpCobLinkage (ch); if (Leaf_pos < Leaf_bytes) { ch = getbyte(); } goto loop; } if (Leaf_pos <= Leaf_bytes) { if ((ch & 0xe0) == 0xe0) { // output OCCURS subscript information DumpCobOccurs (ch); goto loop; } } if (Leaf_pos <= Leaf_bytes) { DumpCobItem (ch); } dump_hex((Leaf_bytes - Leaf_pos), true); StdOutPuts(L"\n"); }
void DumpVCount() { BYTE ch; WORD ush; long lng; ch = getbyte(); if ((ch & 0x80) == 0) { StdOutPrintf(L"%d", ch); } else if ((ch & 0xc0) == 0x80) { ush = ((ch & 0x37) << 8) | getbyte(); StdOutPrintf(L"%d", ush); } else if ((ch & 0xf0) == 0xc0) { lng = (ch & 0x1f << 24) | getbyte() << 16 | getshort(); StdOutPrintf(L"%d", lng); } else if ((ch & 0xf0) == 0xf0) { lng = (ch << 24) | getbyte() << 16 | getshort(); StdOutPrintf(L"%d", lng); } else { StdOutPuts(L"unknown vcount format"); } }
void ite_fontinfo(struct ite_data *ip) { u_long fontaddr = getword(ip, getword(ip, FONTROM) + FONTADDR); ip->ftheight = getbyte(ip, fontaddr + FONTHEIGHT); ip->ftwidth = getbyte(ip, fontaddr + FONTWIDTH); ip->rows = ip->dheight / ip->ftheight; ip->cols = ip->dwidth / ip->ftwidth; if (ip->fbwidth > ip->dwidth) { /* * Stuff goes to right of display. */ ip->fontx = ip->dwidth; ip->fonty = 0; ip->cpl = (ip->fbwidth - ip->dwidth) / ip->ftwidth; ip->cblankx = ip->dwidth; ip->cblanky = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight; } else { /* * Stuff goes below the display. */ ip->fontx = 0; ip->fonty = ip->dheight; ip->cpl = ip->fbwidth / ip->ftwidth; ip->cblankx = 0; ip->cblanky = ip->fonty + ((128 / ip->cpl) + 1) * ip->ftheight; } }
static int yaz_gets(int (*getbyte)(void *client_data), void (*ungetbyte)(int b, void *client_data), void *client_data, WRBUF w) { size_t sz = 0; int ch = getbyte(client_data); while (ch != '\0' && ch != '\r' && ch != '\n') { wrbuf_putc(w, ch); sz++; ch = getbyte(client_data); } if (ch == '\r') { ch = getbyte(client_data); if (ch != '\n' && ch != '\0') ungetbyte(ch, client_data); } else if (ch == '\n') { ch = getbyte(client_data); if (ch != '\r' && ch != '\0') ungetbyte(ch, client_data); } if (sz) { return 1; } return 0; }
// the only difference here is do_yield() call DWORD unsqu_y (BYTE *i_buf,BYTE *o_buf, void* yield_) { const unsigned int bits[16] = { 1<<15, 1<<14, 1<<13, 1<<12, 1<<11, 1<<10, 1<<9, 1<<8, 1<<7, 1<<6, 1<<5, 1<<4, 1<<3, 1<<2, 1<<1, 1<<0 }; DWORD len; DWORD bit; int span; BYTE* s_fp = i_buf; BYTE* o_ptr = o_buf; void* yield = yield_; int y_count = 4; unsigned int s_buf; int s_count = 0; if (0 == yield_) return unsqu(i_buf,o_buf); fillbitbuf(); while(1){ getbit(bit); if(bit) { *o_ptr++=getbyte(); continue; } getbit(bit); if(!bit) { // len 2-5, span 0-ff getbit(bit); if (bit) len=2; else len=0; getbit(bit); if (bit) len++; len += 2; span=getbyte() | 0xffffff00; } else { span=getbyte(); len=getbyte(); span |= ((len & ~0x07)<<5) | 0xffffe000; len = (len & 0x07)+2; if (len==2) { len=getbyte(); if(len==0) break; // end mark of compressed load module if(len==1) continue; // segment change else len++; } do_yield(); } // "for" works better then memcpy for( ;len>0;len--,o_ptr++) *o_ptr=*(o_ptr+span); } return(o_ptr-o_buf); }
void notmain ( void ) { uart_init(); hexstring(0x12345678); hexstring(GETPC()); timer_init(); /* * 132 byte packet. All fields are 1 byte except for the 128 byte data * payload. * +-----+------+----------+--....----+-----+ * | SOH | blk# | 255-blk# | ..data.. | cksum | * +-----+------+----------+--....----+-----+ * Protocol: * - first block# = 1. * - CRC is over the whole packet * - after all packets sent, sender transmits a single EOT (must ACK). */ unsigned char block = 1; unsigned addr = ARMBASE; while (1) { unsigned char b; // We received an EOT, send an ACK, jump to beginning of code if((b = getbyte()) == EOT) { uart_send(ACK); BRANCHTO(ARMBASE); return; // NOTREACHED } /* * if first byte is not SOH, or second byte is not the * expected block number or the third byte is not its * negation, send a nak for a resend of this block. */ if(b != SOH || getbyte() != block || getbyte() != (0xFF - block)) { uart_send(NAK); continue; } // get the data bytes int i; unsigned char cksum; for(cksum = i = 0; i < PAYLOAD_SIZE; i++) { cksum += (b = getbyte()); PUT8(addr+i, b); } // Checksum failed: NAK the block if(getbyte() != cksum) uart_send(NAK); // Commit our addr pointer and go to next block. else { uart_send(ACK); addr += PAYLOAD_SIZE; block++; } } }
uint32_t getword(uint8_t *base_address, uint64_t offset) { uint32_t result; result=getbyte(base_address, offset); offset++; result=result | getbyte(base_address, offset) << 8; offset++; return result; }
void MIDIFile::parsepitchwheel(char ntrack,char chan, unsigned int dt){ unsigned char valhi,vallo; vallo=getbyte(); valhi=getbyte(); if (chan>=NUM_MIDI_CHANNELS) return; int value=(int)valhi*128+vallo; printf("[dt %d] Pitch wheel:%d\n",dt,value); };
static void md3_trans(void) { /* Convert MD3 file. MD3 are encoded as rows, and there are three types. */ int x1, y1, col; mdbyte b; int c, d, n; for (y1 = 0; y1 < nInRows; ++y1) { b = getbyte(); /* Row type */ switch(b) { case 0: /* All the same byte */ c = getbyte(); for (n = 0; n < nInCols; n++) mdrow[n] = c; break; case 1: /* Encoded data */ case 2: col = 0; /* Encoded as XOR with previous row */ while (col < nInCols) { c = getbyte(); if (c >= 129) { /* RLE sequence */ c = 257 - c; d = getbyte(); for (n = 0; n < c; ++n) { if (b == 1) mdrow[col++] = d; else mdrow[col++] ^= d; } } else { /* not RLE sequence */ ++c; for (n = 0; n < c; ++n) { d = getbyte(); if (b == 1) mdrow[col++] = d; else mdrow[col++] ^= d; } } } } /* Row loaded. Convert it. */ x1 = 0; col = 0; for (n = 0; n < nInCols; ++n) { d = y1; render_byte(&col, &x1, &d, mdrow[n]); } } }
// EF BB BF = 1110 1111 1011 1011 1011 1111 = 1111 11 1011 11 1111 = 11111110 11111111 = FEFF = Byte Order Mark // Added by many Windows programs to UTF8 files. bool UTF8(FILE * fi) { int k[6]; while((k[0] = fgetc(fi)) != EOF) { switch(k[0] & 0xc0) // 11bbbbbb { case 0xc0: { ascii = false; if((k[0] & 0xfe) == 0xfe) return false; // Start of multibyte int i = 1; //bitpat(k[0],8); while((k[0] << i) & 0x80) // Read the second, third and fourth // highest bits and read a byte for every bit == 1 { k[i] = fgetc(fi); //bitpat(k[i],8); if((k[i++] & 0xc0) != 0x80) // 10bbbbbb return false; } int K = ((k[0] << i) & 0xff) // shift high-bits out of byte << (5 * i - 6); // shift to high position //putchar('\n'); //bitpat(K,32); int I = --i; while(i > 0) { K |= (k[i] & 0x3f) << ((I - i) * 6); //putchar('\n'); //bitpat(K,32); --i; } //putchar('\n'); //char a[2] = {K,0}; if(K <= 0x7f) return false; // overlong UTF-8 sequence getbyte(K); break; } case 0x80: // 10bbbbbb // Not UTF-8 return false; default: getbyte(k[0]); } } return true; }
/* * Handling the alignment problem of struct ipart. */ static void fill_ipart(char *bootptr, struct ipart *partp) { #if defined(sparc) /* * Sparc platform: * * Packing short/word for struct ipart to resolve * little endian on Sparc since it is not * properly aligned on Sparc. */ partp->bootid = getbyte((uchar_t **)&bootptr); partp->beghead = getbyte((uchar_t **)&bootptr); partp->begsect = getbyte((uchar_t **)&bootptr); partp->begcyl = getbyte((uchar_t **)&bootptr); partp->systid = getbyte((uchar_t **)&bootptr); partp->endhead = getbyte((uchar_t **)&bootptr); partp->endsect = getbyte((uchar_t **)&bootptr); partp->endcyl = getbyte((uchar_t **)&bootptr); partp->relsect = getlong((uchar_t **)&bootptr); partp->numsect = getlong((uchar_t **)&bootptr); #elif defined(i386) /* * i386 platform: * * The fdisk table does not begin on a 4-byte boundary within * the master boot record; so, we need to recopy its contents * to another data structure to avoid an alignment exception. */ (void) bcopy(bootptr, partp, sizeof (struct ipart)); #else #error No Platform defined #endif /* defined(sparc) */ }
char *getstring() { char *p = Txt; unsigned char n; n = getbyte(); assert(n < SMALL_BUFFER); while (n--) { *p++ = (char) getbyte(); } *p = '\0'; return(Txt); }
// AVS // load [charmap ...] part to xlat int TMapLoader::LoadCharMap(string buf) { char wbuf[128]; char charmapname[128]; charmapname[0] = 0; // xlat.init(); now it done by KeyTranslator::Load() while ( buf.length() ) { wbuf[0]=0; if (!getline(buf,wbuf,sizeof(wbuf))) break; if ( wbuf[0]==0 ) break; if ( strnicmp(wbuf,"[charmap",8)==0 ) { strcpy(charmapname,wbuf); continue; }; char * host = strtok(wbuf, " "); char * console = strtok(NULL, " "); int bHost; int bConsole; if ( host == NULL || console == NULL ) { // cerr << charmapname << " -> Bad structure" << endl; printm(0, FALSE, MSG_KEYBADSTRUCT, charmapname); return 0; }; if ( strlen(host) > 1 && host[0] == '\\' ) bHost = getbyte(host+1); else bHost = (unsigned char)host[0]; if ( strlen(console) > 1 && console[0] == '\\' ) bConsole = getbyte(console+1); else bConsole = (unsigned char)console[0]; if ( bHost <= 0 || bConsole <= 0 ) { // cerr << charmapname << " -> Bad chars? " // << host << " -> " << console << endl; printm(0, FALSE, MSG_KEYBADCHARS, charmapname, host, console); return 0; }; // xlat.table[bHost] = bConsole; Charmap.modmap(bHost, 'B', bConsole); }; return (Charmap.enabled = 1); return 1; };
static int yaz_marc_line_gets(int (*getbyte)(void *client_data), void (*ungetbyte)(int b, void *client_data), void *client_data, WRBUF w) { int more; wrbuf_rewind(w); more = yaz_gets(getbyte, ungetbyte, client_data, w); if (!more) return 0; while (more) { int i; for (i = 0; i<4; i++) { int ch = getbyte(client_data); if (ch != ' ') { if (ch) ungetbyte(ch, client_data); return 1; } } if (wrbuf_len(w) > 60 && wrbuf_buf(w)[wrbuf_len(w)-1] == '=') wrbuf_cut_right(w, 1); else wrbuf_puts(w, " "); more = yaz_gets(getbyte, ungetbyte, client_data, w); } return 1; }
main(int argc,char **argv) { unsigned start,end,byte; if (argc!=3) { printf("Usage: %s file.wav file.tap\n",argv[0]); exit(1);} in=fopen(argv[1],"rb"); if (in==NULL) { printf("Unable to open WAV file\n"); exit(1);} fread(&sample_riff,sizeof(sample_riff),1,in); if (sample_riff.channels!=1 || sample_riff.freq!=4800 || sample_riff.byte_per_sample!=1) { printf("Invalid WAV format: should be 4800 Hz, 8-bit, mono\n"); exit(1); } out=fopen(argv[2],"wb"); if (out==NULL) { printf("Unable to create TAP file\n"); exit(1);} for (;;) { synchronize(); printf("Synchro found, decoding bytes...\n"); putc(0x16,out); putc(0x16,out); putc(0x16,out); sync_ok=1; offset+=3; byte=0x24; while (sync_ok) { putc(byte,out); offset++; byte=getbyte(); } } }
mod_export char * bracketedstring(void) { static const char endesc[] = "\033[201~"; int endpos = 0; size_t psize = 64; char *pbuf = zalloc(psize); size_t current = 0; int next, timeout; while (endesc[endpos]) { if (current + 1 >= psize) pbuf = zrealloc(pbuf, psize *= 2); if ((next = getbyte(1L, &timeout)) == EOF) break; if (!endpos || next != endesc[endpos++]) endpos = (next == *endesc); if (imeta(next)) { pbuf[current++] = Meta; pbuf[current++] = next ^ 32; } else if (next == '\r') pbuf[current++] = '\n'; else pbuf[current++] = next; } pbuf[current-endpos] = '\0'; return pbuf; }
bool get_respond( unsigned char* rec_str) { u32 respond_time; u8 i = 0 ; respond_time = OSTime ; while( OSTime - respond_time < AT_TIMEOUT ) { OSTimeDlyHMSM(0, 0, 0, 20); while ( !my_icar.stm32_u2_rx.empty ) {//receive some data... //reset timer here my_icar.mg323.at_timer = OSTime ; rec_str[i] = getbyte( COM2 ); if ( my_icar.debug > 2) putbyte( COM1, rec_str[i]); if ( rec_str[i] != 0 ) { //prevent 0x0 i++; } if ( i > AT_CMD_LENGTH ) {//overflow return false ; } if ( rec_str[i-1] == 0x0A && rec_str[i-2] == 0x0D ) { return true ; } } } return false ; }
synchronize() { int decaleur=0,val; printf("Searching synchro...\n"); while(1) { while((decaleur&0xff) != 0x68) decaleur=(decaleur<<1)|getbit(); if (getbyte()!=0x16) continue; if (getbyte()!=0x16) continue; if (getbyte()!=0x16) continue; do { val=getbyte(); } while (val==0x16); if (val==0x24) break; } }
unsigned int MIDIFile::getvarint32(){ unsigned long result=0; unsigned char b; /// printf("\n[start]"); if ((result = getbyte()) & 0x80) { result &= 0x7f; do { b=getbyte(); result = (result << 7) + (b & 0x7f); }while (b & 0x80); } /// printf("[end - result= %d]\n",result); return result; };
static void decompile(void) { int b; char *s; col = 0; prefix = 0; modrmv = -1; /* No modrm byte yet */ sibv = -1; /* No SIB byte yet */ #if 0 opsize = 32; addrsize = 32; #endif ubufp = ubuf; /* Reset internal buffer */ insl = 0; /* Reset instruction length */ b = getbyte(); wordop = b & 1; must_do_size = do_size; s = opmap1[b]; /* Do primary decode */ if(s == 0) { /* Invalid instruction? ... */ uputchar('D'); /* ... then output byte define */ uputchar('B'); uputchar('\t'); uprintf("%02X", b); } else { ua_str(s); /* Valid instruction */ } fprintf(listfp, "%*s", 15 - col, " "); col = 15 + strlen(ubuf); do { uputchar(' '); col++; } while (col < 43); fprintf(listfp, "%s\n", ubuf); }
static __inline__ void swd_getbyte(ucl_swd_t * s) { int c; if ((c = getbyte(*(s->c))) < 0) { if (s->look > 0) --s->look; #if defined(__UCL_CHECKER) /* initialize memory - value doesn't matter */ s->b[s->ip] = 0; if (s->ip < s->f) s->b_wrap[s->ip] = 0; #endif } else { s->b[s->ip] = UCL_BYTE(c); if (s->ip < s->f) s->b_wrap[s->ip] = UCL_BYTE(c); } if (++s->ip == s->b_size) s->ip = 0; if (++s->bp == s->b_size) s->bp = 0; if (++s->rp == s->b_size) s->rp = 0; }
U32 disassemble(void) { int i; char *cmp, *brp; U8 *wp; U32 delta; char *name, *lname; prefix = 0; fmodrmv = 0; fsibv = 0; nRaw = 0; opsize = addrsize = seg_size; fprintf(out_fh, "%08lX ", addrIn); expand_out(opmap1[getbyte()]); /* decode instruction and output */ if (fRaw) { i = 0; fprintf(out_fh, " "); while (nRaw--) { put_hexb(RawBuf[i++], out_fh); fprintf(out_fh, " "); } } fprintf(out_fh, "\r\n"); return addrIn; }
void process(FILE *f,long namepos,unsigned long datapos) { byte name[1040]; byte namelen; static int count=0; FILE *out; int i; unsigned long len; if(namepos==-1) sprintf(name,"%s%d.data",thename,count++); else { myseek(f,namepos); namelen=getbyte(f); if((int)fread(name,1,namelen,f)!=(int)namelen) err("Error reading resource name\n"); name[namelen]=0; for(i=0;i<namelen;i++) { if(name[i]>126 || name[i]<32 || name[i]=='\\' || name[i]=='?' || name[i]==':' || name[i]=='/' || name[i]=='%' || name[i]=='<' || name[i]=='>' || name[i]=='*' || name[i]=='"') name[i]='_'; } strcat(name,".data"); } out=myfopen(name,"wb"); printf("Extracting: %s\n",name); myseek(f,datapos); len=getdword(f); while(len--) fputc(myfgetc(f),out); fclose(out); }