unsigned char HexFileParser::parseHexByte(const std::string& line, int idx) { char c1, c2; c1 = line[idx]; c2 = line[idx+1]; return (hexValue(c1) << 4) | hexValue(c2); }
inline std::string Unescape(std::string const & aText) { if (!aText.empty()) { std::string unescaped; size_t len = aText.length(); for (size_t i = 0; i < len; i++) { if (i+2 < len && aText[i] == '%' && isHex(aText[i+1]) && isHex(aText[i+2])) { unescaped.push_back((char) ((hexValue(aText[i+1]) << 4) | hexValue(aText[i+2]))); i += 2; } else if (aText[i] == '+') unescaped.push_back(' '); else unescaped.push_back(aText[i]); } return unescaped; } return aText; }
static char *uri2string(const char *uri) { size_t len= strlen(uri); char *string= (char *)xmalloc(len + 3); /* whoever wrote the URL stuff in the the image was too damn stupid to understand file URIs */ if (!strncmp(uri, "file:", 5)) { char *in= string, *out= string; strncpy(string, /* chop file:///absolute/path to /absolute/path */ uri + (uri[5] == '/' && uri[6] == '/' && uri[7] == '/' ? 7 : 5), len); while (*in) if ((in[0] == '%') && isxdigit(in[1]) && isxdigit(in[2])) { *out++= hexValue(in[1]) * 16 + hexValue(in[2]); in += 3; } else *out++= *in++; *out= '\0'; } else { strncpy(string, uri, len+1); } fdebugf((stderr, " uri2string: <%s>\n", string)); return string; }
static int hexByte(char hi, char lo) { int nhi = hexValue(hi); if(nhi < 0) return -1; int nlo = hexValue(lo); if(nlo < 0) return -1; int value = (hexValue(hi) << 4) + hexValue(lo); return value; }
/** * Perform the reverse conversion of unicodeToEscapedAscii(). * * @param str a string previously returned by escape() * @return the original string before the conversion by escape(). */ static pcsl_string_status escaped_ascii_to_unicode(const pcsl_string* str, pcsl_string* result) { int result_len=0; jchar* result_data = NULL; pcsl_string_status status = PCSL_STRING_OK; GET_PCSL_STRING_DATA_AND_LENGTH(str) do { int i; result_data = (jchar*)midpMalloc(str_len * sizeof (jchar)); if (result_data == NULL) { status = PCSL_STRING_ENOMEM; break; } for (i = 0, result_len = 0; i < str_len; i++) { jchar c = str_data[i]; if (c == '%') { jchar v = 0; v += hexValue(str_data[i+1]); v <<= 4; v += hexValue(str_data[i+2]); v <<= 4; v += hexValue(str_data[i+3]); v <<= 4; v += hexValue(str_data[i+4]); i += 4; result_data[result_len] = v; result_len++; } else if (c == '#') { /* drop c */ } else { result_data[result_len] = c; result_len++; } } } while(0); RELEASE_PCSL_STRING_DATA_AND_LENGTH if (PCSL_STRING_OK == status) { if (PCSL_STRING_OK != pcsl_string_convert_from_utf16(result_data, result_len, result)) { status = PCSL_STRING_ENOMEM; } } midpFree(result_data); return status; }
static unsigned long hextoi(char* s) { unsigned long result = 0; while (*s) { int val = hexValue(*s); if (val != -1) // skip over non hex digits { result *= 16; result += val; } s++; } return result; }
/*** Detect possible AddrSet of scalar access and compute access scope ***/ int analyze_scalar_access(dat_inst_t *d_inst, inf_node_t* ib) { int dbg = 0; int pos; int addr; insn_t* insn; loop_t *loop; saddr_p memblk; ts_p memTS; worklist_p tsNode,orgTS, blkNode; if (d_inst->addrExpr.varNum != 0) { printf("\nERR: not scalar access");printDataRef(stdout, d_inst); } addr = d_inst->addrExpr.k; tsNode = NULL; orgTS = NULL; loop = getIbLoop(ib); while (loop!=NULL) { if (dbg) { fprintf(dbgAddr,"\n In loop L%d, lbound %d",loop->id,loop->bound-1); fflush(dbgAddr);} memTS = (ts_p) malloc(sizeof(ts_s)); memTS->loop_id = loop->id; memTS->lw = 0; memTS->up = max(loop->bound-1,0); memTS->flag = 0; memTS->flag |= RENEWABLE; addAfterNode(memTS, &tsNode, &orgTS); //addToWorkList( &(orgTS),memTS); loop = loop->parent; } blkNode = NULL; insn = (insn_t*)(d_inst->insn); memblk = createSAddr(GET_MEM(addr),hexValue(insn->addr), 1, orgTS); addAfterNode(memblk, &blkNode, &(d_inst->addr_set)); return 0; }
// Turn the string of printable, hexadecimal characters into a binary buffer. static int stringToBuffer(const QString &stringData, uint8_t *buffer, int bufferLength) { int consumed = 0; for (int i = 0; i < bufferLength; i++) { const int hex = hexValue(stringData.at(i).toAscii()); if (hex >= 0) { if ((consumed % 2) == 0) { buffer[(consumed / 2)] = hex << 4; } else { buffer[(consumed / 2)] |= hex; } consumed++; } } // Round up the number of bytes we consumed to a multiple of 2. if ((consumed % 2) != 0) ++consumed; return consumed; }
void CharacteristicsEditor::setCharacteristicValueText(const QString &in) { m_characteristicValueText.clear(); char out[1024]; int characteristicLen = in.size(); int i, consumed = 0; uint8_t *data = (uint8_t *)alloca((characteristicLen / 2) + 1); memset(data, 0, (characteristicLen / 2) + 1); if (0 == data) return; for(i = 0; i < characteristicLen; i++ ) { int hex = hexValue( in.at( i ).toAscii() ); if( hex >= 0 ) { if( ( consumed % 2 ) == 0 ) { data[consumed/2] = hex << 4; } else { data[consumed/2] |= hex; } consumed++; } } int len = parse_characteristic_uuid_buffer(m_characteristicUUID.toAscii().constData(), data, consumed / 2, out, sizeof(out)); /* Could not parse entry */ if (len < 0) { for (i = 0; i < consumed / 2; i++) { m_characteristicValueText.append( isprint( data[i] )? data[i] : '.' ); } } else { m_characteristicValueText.append(out); } emit characteristicValueTextChanged(); }
/*** Detect possible AddrSet of unpred. access and compute access scope ***/ int analyze_unpred_access(dat_inst_t *d_inst, inf_node_t* ib) { int dbg = 0; /* A[x] -> assume array A is global array * AddrSet(A) -> obtained from symbol table * Identifying access variable: compute addr.expr, ignoring unknown elem. * Addr. Expression A[x] = A[0] + T*4, how reg. expression derive now * Not necessary correct in all cases, or more aggressive optimization * Work with array index A[x] * Not work with pointer value */ int initAddr = -1, addr; symbol_i *gVar, *var; int i; loop_t *loop; saddr_p memblk,curblk; ts_p memTS; worklist_p tsNode, orgTS, blkNode; insn_t *insn; int foundRange; expr_p exp; //create access scope for all possible address loop = getIbLoop(ib); tsNode = NULL;orgTS = NULL; while (loop!=NULL) { memTS = malloc(sizeof(ts_s)); memTS->loop_id = loop->id; memTS->lw = 0; memTS->up = max(loop->bound-1,0); memTS->flag = 0; addAfterNode(memTS, &tsNode, &orgTS); //addToWorkList( &orgTS,memTS); loop = loop->parent; } curblk = NULL; blkNode = NULL; foundRange = 0; exp = &(d_inst->addrExpr); insn = (insn_t*)(d_inst->insn); initAddr = exp->k; //locate the symbol table segment for (i=0; i<prog.num_vars; i++) { gVar = &(prog.v_info[i]); if (gVar->addr <= initAddr && initAddr < gVar->addr + gVar->size) { foundRange = 1; break; } } if (foundRange) {//unpredictable access, but find global var /*NOTE: stepSizeTable hts only 89 integer, but segment size = 1024*/ /*can set this ts some user constraint, hard code for now*/ if (strcmp(gVar->name,"stepsizeTable")==0) { gVar->size = 89*4; /*a kind of user constraint*/ } if (strcmp(gVar->name,"indexTable")==0) { gVar->size = 16*4; /*a kind of user constraint*/ } //Addr range of global var. too large --> consider unknown if (gVar->size > CACHE_SIZE) goto UNKNOWN_RANGE; if (dbg) { fprintf(dbgAddr,"\n Global var: %s [%x,%x], array sa: %x, size %d", gVar->name, gVar->addr,gVar->addr+gVar->size,initAddr,gVar->size); fflush(dbgAddr); } for (addr = gVar->addr; addr < gVar->addr+gVar->size; addr+=4) { if (curblk && GET_MEM(addr)==curblk->blkAddr) continue; memblk = createSAddr(GET_MEM(addr), hexValue(insn->addr),0,orgTS); addAfterNode(memblk, &blkNode, &(d_inst->addr_set)); curblk = memblk; } } else {//unpredictable access, unknown address range UNKNOWN_RANGE: if (dbg) { fprintf(dbgAddr,"\nUnknown addr range");fflush(dbgAddr); } memblk = createSAddr(UNKNOWN_ADDR,hexValue(insn->addr),0,orgTS); addAfterNode(memblk,&blkNode,&(d_inst->addr_set)); return 0; } return 0; }