void UIKeyEventCollector::send(int value) { assert(value == 0 || value == 1); if (value) { if (m_value >= static_cast<int>(m_emitters.size())) { log_error("got press event while all emitter where already pressed"); } m_value += 1; if (m_value == 1) { m_uinput.send(get_device_id(), get_type(), get_code(), m_value); } } else { if (m_value <= 0) { log_error("got release event while collector was in release state"); } m_value -= 1; if (m_value == 0) { m_uinput.send(get_device_id(), get_type(), get_code(), 0); } } }
basic_two_stage_index( string_type &str, size_t num_indexed_chars ) : string(&str), num_indexed_chars(num_indexed_chars) { // Todo: use threads to speed this up. // consider using std::sort for better cache performance. if ( num_indexed_chars <= 1 || num_indexed_chars > 32 || string->size() < num_indexed_chars || (addr_type)string->size() != string->size() ) { throw std::invalid_argument("two_stage_index::reindex()"); } size_t str_size = string->size(); size_t index_size = (size_t)1 << (num_indexed_chars*2); index.resize(0); index.resize(index_size+1); addr.resize(str_size); // Lead-in: fill acc0 with first DNA codes. size_t acc0 = 0; for (size_t i = 0; i != num_indexed_chars-1; ++i) { acc0 = acc0 * 4 + get_code(*string, i); } // Count phase: count bucket sizes size_t acc = acc0; for (size_t i = num_indexed_chars; i != str_size; ++i) { acc = (acc * 4 + get_code(*string, i)) & (index_size-1); index[acc]++; if (i % 0x100000 == 0) printf("c %5.2f\n", (double)i * (100.0/str_size)); } // Compute running sum of buckets to convert counts to offsets. addr_type cur = 0; for (size_t i = 0; i != index_size; ++i) { addr_type val = index[i]; index[i] = cur; cur += val; } index[index_size] = cur; // Store phase: fill "addr" with addresses of values. acc = acc0; for (size_t i = num_indexed_chars; i != str_size; ++i) { acc = (acc * 4 + get_code(*string, i)) & (index_size-1); addr[index[acc]++] = (addr_type)(i - num_indexed_chars + 1); if (i % 0x100000 == 0) printf("s %5.2f\n", (double)i * (100.0/str_size)); } // Shift the index up one so ends become starts. addr_type prev = 0; for (size_t i = 0; i != index_size; ++i) { std::swap(prev, index[i]); } }
static void add_imm32(void) { uint32_t imm = get_code(); imm |= (uint32_t)get_code() << 8; imm |= (uint32_t)get_code() << 16; imm |= (uint32_t)get_code() << 24; add_str("0x"); add_hex_uint32(imm); }
static void add_disp32(void) { uint32_t disp = get_code(); disp |= (uint32_t)get_code() << 8; disp |= (uint32_t)get_code() << 16; disp |= (uint32_t)get_code() << 24; add_str("0x"); add_hex_uint32(disp); }
void MultiMethodInliner::inline_callees( InlineContext& inline_context, std::vector<DexMethod*>& callees) { size_t found = 0; auto caller = inline_context.caller; auto insns = caller->get_code()->get_instructions(); // walk the caller opcodes collecting all candidates to inline // Build a callee to opcode map std::vector<std::pair<DexMethod*, DexOpcodeMethod*>> inlinables; for (auto insn = insns.begin(); insn != insns.end(); ++insn) { if (!is_invoke((*insn)->opcode())) continue; auto mop = static_cast<DexOpcodeMethod*>(*insn); auto callee = resolver(mop->get_method(), opcode_to_search(*insn)); if (callee == nullptr) continue; if (std::find(callees.begin(), callees.end(), callee) == callees.end()) { continue; } always_assert(callee->is_concrete()); found++; inlinables.push_back(std::make_pair(callee, mop)); if (found == callees.size()) break; } if (found != callees.size()) { always_assert(found <= callees.size()); info.not_found += callees.size() - found; } // attempt to inline all inlinable candidates for (auto inlinable : inlinables) { auto callee = inlinable.first; auto mop = inlinable.second; if (!is_inlinable(callee, caller)) continue; auto op = mop->opcode(); if (is_invoke_range(op)) { info.invoke_range++; continue; } TRACE(MMINL, 4, "inline %s (%d) in %s (%d)\n", SHOW(callee), caller->get_code()->get_registers_size(), SHOW(caller), callee->get_code()->get_registers_size() - callee->get_code()->get_ins_size()); change_visibility(callee); MethodTransform::inline_16regs(inline_context, callee, mop); info.calls_inlined++; inlined.insert(callee); } }
//////////////////////////////////////////////////////////////////////////////// // // This module deals with skills. // //////////////////////////////////////////////////////////////////////////////// // private void Skills::send_message(string name) { uint8 *buf=new uint8[get_msg_len(name)]; buf[0] = CODE_CAST_SPELL_USE_SKILL; buf[1] = 0; buf[2] = get_msg_len(name); buf[3] = 0x24; strcpy((char *)(buf+4), get_code(name).c_str()); buf[4+get_code(name).length()] = 0x20; buf[5+get_code(name).length()] = 0x30; buf[6+get_code(name).length()] = 0x00; m_client.send_server(buf, get_msg_len(name)); delete buf; }
t_fsym *fsym_from_call(int pid, Elf64_Shdr *sh_text, Elf64_Shdr *sh_plt) { unsigned long i; unsigned long end_text; unsigned long call_addr; struct cs_insn *ins; t_fsym *fsym; fsym = NULL; i = sh_text->sh_addr; end_text = i + sh_text->sh_size; while (i < end_text) { if ((get_code(pid, i, 1, &ins, NULL)) != 1) return (fsym); if (ins->bytes[0] == 0xe8) { /* Call target address is relative to next instruction address */ call_addr = fsym_call_off(ins->bytes + 1) + i + ins->size; if (call_addr < sh_plt->sh_addr || call_addr > sh_plt->sh_addr + sh_plt->sh_size) { if (!(fsym_new(&fsym, call_addr))) return (NULL); } } i += ins->size; free(ins); } return (fsym); }
bool response::is_cacheable() const { return state == BODYFULL && checkCacheControl() && get_header("ETag") != "" && get_header("Vary") == "" && get_code() == "200"; }
void HuffmanEncoder::encode(dict d) { ofstream out; out.open((path + ".ashf").c_str()); vector < Code > word_concat; for (int i = 0; i < d.size(); i++) { if (d[i].c.q == -1 || d[i].c.r == -1) continue; word_concat.push_back(d[i].c); } // coding of min(i1, i2) vector < string > r_s; int k = 0; for (int i = 0; i < word_concat.size(); i++) { int q_log = get_log(word_concat[i].q); string kemp = ""; for (int i = 0; i <= q_log; i++) { kemp += (1 << i) & word_concat[i].r ? "1" : "0"; } reverse(kemp.begin(), kemp.end()); r_s.push_back(kemp); int r = word_concat[i].q; word_concat[i].q -= k; k = r; } root = build_tree(word_concat); get_codes(root); print_tree(root); string long_string = ""; int q = 0; for (int i = 0; i < word_concat.size(); i++) { string tempor = get_code(word_concat[i].q) + r_s[i] + (word_concat[i].d == true ? "1" : "0"); long_string = long_string + tempor; } int l_str_size = long_string.size(); int cur_p = 0; while (cur_p < l_str_size) { unsigned char c = 0; for (int i = 0; i < min(8, l_str_size - cur_p); i++) { int t = long_string[i + cur_p] == '0' ? 0 : 1; c += (t << i); } cur_p += 8; out << c; } out.close(); }
bool http_response::is_cacheable() const { return (state == FULL_BODY && checkCacheControl() && get_header("ETag") != "" && get_header("Vary") == "" && get_code() == "200"); }
int main() { static char * checks [] = { "482BD64C6C9F098C9EF8B77B8F870517BF33A1B9", "853DBB72EC6A4E40CAE1D376BAAEF27A6377A51E", "3925CB09D39EB08063542A0CA8C38D80CDBFAA50", "26C2CE28D0DF94C010C5255203B885CBA81B9018", "8BE02D8167CF08EC81D06EC54E9AE55977C864EA" }; static char hash[20] = ""; static char hexdigest[200] = ""; char flag [20] = ""; printf("Armory v1.0\nAccess code:"); get_code(flag); if(strlen(flag) != 10){ access_denied(); } for(int i = 0; i < 10; i += 2) { SHA1(hash, (char*)flag+i, 2); for(int j = 0; j < 20; j++){ sprintf((char*)hexdigest+(j*2), "%02X", hash[j]); } if(strncmp(hexdigest, checks[i/2], 40) != 0){ access_denied(); } } access_granted(flag); return 0; }
const string Token::get_c_val() const { ostringstream rval; if (get_code() == STRING_LITERAL) rval << '\"'; else if (get_code() == CHAR_LITERAL) rval << '\''; rval << get_name(); if (get_code() == STRING_LITERAL) rval << '\"'; else if (get_code() == CHAR_LITERAL) rval << '\''; return rval.str(); }
int vstashf(struct dbuf_iter *o, const char *fmt, va_list ap) { int modifier_l; dbuf_put_string(o, fmt); while((fmt = strchr(fmt, '%'))) { int code = get_code(&fmt, &modifier_l); switch(code) { case '%': break; case 'c': case 'd': case 'i': case 'x': case 'u': case 'X': if(modifier_l) { case 'p': dbuf_put_long(o, va_arg(ap, long)); } else { dbuf_put_int(o, va_arg(ap, int)); } break; case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': dbuf_put_double(o, va_arg(ap, double)); break; case 's': dbuf_put_string(o, va_arg(ap, const char *)); break; default: return SET_ERRNO(-EINVAL); break; } } return 0; }
state menu_execute(void* data, void*) { menu_t* menu = (menu_t*)data; menu_show(menu); do { switch (get_code()) { case KEY_ENTER: if (menu->selected->action->cb) { menu->menu_state = menu->selected->action->cb(menu->selected->action->data, menu->selected->action->params); } break; case ARROW_UP: if (menu->head != menu->selected) { menu_item_t* current = menu->head; while (current->next != menu->selected) { current = current->next; } menu->selected = current; menu->menu_state = REDRAW; } break; case ARROW_DOWN: if (menu->selected->next) { menu->selected = menu->selected->next; menu->menu_state = REDRAW; } break; } menu_show(menu); } while (menu->menu_state); return REDRAW; }
TEST_F(PreVerify, InlineCallerTryCalleeIfThrows) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testCallerTryCalleeIfThrows"); auto invoke = find_invoke(m, OPCODE_INVOKE_DIRECT, "throwsInIf"); ASSERT_NE(nullptr, invoke); // verify that the callee has an if-else statement, and that the if block // (which throws an exception) comes before the return opcode auto callee_insns = invoke->get_method()->get_code()->get_instructions(); auto ifop = std::find_if(callee_insns.begin(), callee_insns.end(), [](DexInstruction* insn) { return insn->opcode() == OPCODE_IF_NEZ; }); ASSERT_NE(callee_insns.end(), ifop); auto retop = std::find_if(callee_insns.begin(), callee_insns.end(), [](DexInstruction* insn) { return insn->opcode() == OPCODE_RETURN_VOID; }); ASSERT_NE(callee_insns.end(), retop); auto invoke_throw = find_invoke(ifop, retop, OPCODE_INVOKE_VIRTUAL, "wrapsThrow"); ASSERT_NE(nullptr, invoke_throw); auto& code = m->get_code(); ASSERT_EQ(code->get_tries().size(), 1); }
char *find_spec(const char *format,char *str,int *form_pos){ int i,k,ind,l; struct rparam *next; if(!cur_file)fatal_error("Param File is not initialized.\n"); /* i=0; while(format[i]==' ')i++; ind=format[i]&0x7f;*/ ind=get_code(format); if(!ind)fatal_error("Incorrect format string %s!\n",format); if(ind<0)l=0; //asterik found, complete search else l=ind-1; ac_helppos=-1; ac_formpos=-1; do{ next=Cashe[l]; while(next!=NULL){ fseek(cur_file,next->pos,SEEK_SET); get_next_string(str,1); k=0; i=0; do{ while(str[k]==' ')k++; while(format[i]==' ')i++; if(format[i]==WC_char){ while(str[k] && str[k]!=dc[0])k++; while(format[i] && format[i]!=dc[0])i++; } if(format[i]!=str[k])break; /* bad spec */ if(format[i]==dc[0] || format[i]== 0){ /* reading */ if(format[i]==0)fatal_error("Incorrect format specification. There must be %c.\n",dc[0]); *form_pos=i+1; strncpy(AcFormat,str,k); AcFormat[k]='\0'; ac_helppos=next->helppos; ac_formpos=next->pos; return str+k+1; } k++;i++; }while(1); next=next->next; } l++; }while(ind<0 && l<CASHE_SIZE); AcFormat[0]='\0'; if(stop_on_error>0){ fatal_error("Can't find specification '%s' in file '%s' \n",format,cur_file_name); } if(stop_on_error<0){ msg_error("Can't find specification '%s' in file '%s' \n",format,cur_file_name); } return NULL; }
int get_fields(unsigned* pycbuf, struct code_obj* pobj, int cur, int size) { cur = get_code(pycbuf, pobj, cur, size); cur = get_consts(pycbuf, pobj, cur, size); cur = get_names(pycbuf, pobj, cur); cur = get_varnames(pycbuf, pobj, cur); return get_name_of_code(pycbuf, pobj, cur); }
/* * Obtain the huffman code and store in the table. */ void generate_table(node_t *root, table_t *table, frequency_t *frequency){ uint8_t i, j = 0; for(i = 0; i < MAX_SAMPLE; i++){ if (frequency[i] > 0) { (*table).rows[j].index = i; memset((*table).rows[j].code, '\0', MAX_HUFF_CODE * sizeof(char)); (*table).rows[j].code = get_code(root, i); j++; } } if (frequency[i] > 0) { (*table).rows[j].index = i; memset((*table).rows[j].code, '\0', MAX_HUFF_CODE * sizeof(char)); (*table).rows[j].code = get_code(root, i); } }
NSCAPI::nagiosReturn lua::lua_wrapper::pop_code() { int pos = lua_gettop(L); if (pos == 0) return NSCAPI::returnUNKNOWN; NSCAPI::nagiosReturn ret = get_code(pos); pop(); return ret; }
TEST_F(PostVerify, testArrayDataInCaller) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testArrayDataInCaller"); ASSERT_EQ(nullptr, find_invoke(m, OPCODE_INVOKE_DIRECT, "callerWithIf")); auto last_insn = m->get_code()->get_instructions().back(); ASSERT_EQ(last_insn->opcode(), FOPCODE_FILLED_ARRAY); }
TEST_F(PreVerify, InlineCalleeTryTwice) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testInlineCalleeTryTwice"); auto invoke = find_invoke(m, OPCODE_INVOKE_DIRECT, "inlineCalleeTryTwice"); ASSERT_NE(nullptr, invoke); auto& code = m->get_code(); ASSERT_EQ(code->get_tries().size(), 1); }
int pbvprintf( machinetalk_RTAPI_Message *msg, int level, const char *fmt, va_list ap) { int modifier_l, code; machinetalk_Value *v; msg->msglevel = level; strncpy(msg->format, fmt, MIN(strlen(fmt), sizeof(msg->format))); msg->arg_count = 0; while((fmt = strchr(fmt, '%'))) { v = &msg->arg[msg->arg_count]; code = get_code(&fmt, &modifier_l); switch(code) { case '%': break; case 'c': case 'd': case 'i': case 'x': case 'u': case 'X': if(modifier_l) { case 'p': // dbuf_put_long(o, va_arg(ap, long)); v->type = machinetalk_ValueType_INT32; v->has_v_int32 = true; v->v_int32 = va_arg(ap, long); msg->arg_count++; } else { // XXX not sure about long vs int encoding in protobuf types // dbuf_put_int(o, va_arg(ap, int)); v->type = machinetalk_ValueType_INT32; v->has_v_int32 = true; v->v_int32 = va_arg(ap, long); msg->arg_count++; } break; case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': // dbuf_put_double(o, va_arg(ap, double)); v->type = machinetalk_ValueType_DOUBLE; v->has_v_double = true; v->v_double = va_arg(ap, double); msg->arg_count++; break; case 's': // dbuf_put_string(o, va_arg(ap, const char *)); v->type = machinetalk_ValueType_STRING; v->has_v_string = true; strncpy(v->v_string,va_arg(ap, const char *), sizeof(v->v_string)); msg->arg_count++; break; default: //return SET_ERRNO(-EINVAL); // XXX return -EINVAL; break; } }
/** * @brief Skip log_level from a buffer and update it's size * * @return Buffer without log_level code at the beginning */ PUBLIC const char *skip_code(const char *buffer, int *i) { if (get_code(buffer)) { *i = *i-2; return buffer+2; } return buffer; }
/******************************************************************************* * Copyright (c) 2015 Xilinx, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * You may elect to redistribute this code under either of these licenses. * * Contributors: * Xilinx - initial API and implementation *******************************************************************************/ #include <tcf/config.h> #if SERVICE_Disassembly #include <assert.h> #include <stdio.h> #include <tcf/framework/context.h> #include <tcf/services/symbols.h> #include <machine/x86_64/tcf/disassembler-x86_64.h> #define PREFIX_LOCK 0x0001 #define PREFIX_REPNZ 0x0002 #define PREFIX_REPZ 0x0004 #define PREFIX_CS 0x0008 #define PREFIX_SS 0x0010 #define PREFIX_DS 0x0020 #define PREFIX_ES 0x0040 #define PREFIX_FS 0x0080 #define PREFIX_GS 0x0100 #define PREFIX_DATA_SIZE 0x0200 #define PREFIX_ADDR_SIZE 0x0400 #define REX_W 0x08 #define REX_R 0x04 #define REX_X 0x02 #define REX_B 0x01 static char buf[128]; static size_t buf_pos = 0; static DisassemblerParams * params = NULL; static uint64_t instr_addr = 0; static uint8_t * code_buf = NULL; static size_t code_pos = 0; static size_t code_len = 0; static uint32_t prefix = 0; static uint32_t vex = 0; static uint8_t rex = 0; static unsigned data_size = 0; static unsigned addr_size = 0; static int x86_64 = 0; static uint8_t get_code(void) { uint8_t c = 0; if (code_pos < code_len) c = code_buf[code_pos]; code_pos++; return c; } static void add_char(char ch) { if (buf_pos >= sizeof(buf) - 1) return; buf[buf_pos++] = ch; } static void add_str(const char * s) { while (*s) add_char(*s++); } static void add_dec_uint32(uint32_t n) { char s[32]; size_t i = 0; do { s[i++] = (char)('0' + n % 10); n = n / 10; } while (n != 0); while (i > 0) add_char(s[--i]); } #if 0 /* Not used yet */ static void add_dec_uint64(uint64_t n) { char s[64]; size_t i = 0; do { s[i++] = (char)('0' + (int)(n % 10)); n = n / 10; } while (n != 0); while (i > 0) add_char(s[--i]); } #endif static void add_hex_uint32(uint32_t n) { char s[32]; size_t i = 0; while (i < 8) { uint32_t d = n & 0xf; if (i > 0 && n == 0) break; s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10); n = n >> 4; } while (i > 0) add_char(s[--i]); } static void add_hex_uint64(uint64_t n) { char s[64]; size_t i = 0; while (i < 16) { uint32_t d = n & 0xf; if (i > 0 && n == 0) break; s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10); n = n >> 4; } while (i > 0) add_char(s[--i]); } #if 0 /* Not used yet */ static void add_flt_uint32(uint32_t n) { char buf[32]; union { uint32_t n; float f; } u; u.n = n; snprintf(buf, sizeof(buf), "%g", u.f); add_str(buf); } static void add_flt_uint64(uint64_t n) { char buf[32]; union { uint64_t n; double d; } u; u.n = n; snprintf(buf, sizeof(buf), "%g", u.d); add_str(buf); } #endif static void add_addr(uint64_t addr) { while (buf_pos < 16) add_char(' '); add_str("; addr=0x"); add_hex_uint64(addr); #if ENABLE_Symbols if (params->ctx != NULL) { Symbol * sym = NULL; char * name = NULL; ContextAddress sym_addr = 0; if (find_symbol_by_addr(params->ctx, STACK_NO_FRAME, (ContextAddress)addr, &sym) < 0) return; if (get_symbol_name(sym, &name) < 0 || name == NULL) return; if (get_symbol_address(sym, &sym_addr) < 0) return; if (sym_addr <= addr) { add_str(": "); add_str(name); if (sym_addr < addr) { add_str(" + 0x"); add_hex_uint64(addr - (uint64_t)sym_addr); } } } #endif } static void add_reg(unsigned reg, unsigned size) { if (reg >= 8) { add_char('r'); add_dec_uint32(reg); switch (size) { case 1: add_char('l'); break; case 2: add_char('w'); break; case 4: add_char('d'); break; } return; } if (x86_64 && size == 1 && reg >= 4 && reg <= 7) { switch (reg) { case 4: add_str("spl"); break; case 5: add_str("bpl"); break; case 6: add_str("sil"); break; case 7: add_str("dil"); break; } return; } if (size == 1) { switch (reg) { case 0: add_str("al"); break; case 1: add_str("cl"); break; case 2: add_str("dl"); break; case 3: add_str("bl"); break; case 4: add_str("ah"); break; case 5: add_str("ch"); break; case 6: add_str("dh"); break; case 7: add_str("bh"); break; } } else { switch (size) { case 4: add_char('e'); break; case 8: add_char('r'); break; } switch (reg) { case 0: add_str("ax"); break; case 1: add_str("cx"); break; case 2: add_str("dx"); break; case 3: add_str("bx"); break; case 4: add_str("sp"); break; case 5: add_str("bp"); break; case 6: add_str("si"); break; case 7: add_str("di"); break; } } } static void add_seg_reg(unsigned reg) { switch (reg) { case 0: add_str("es"); break; case 1: add_str("cs"); break; case 2: add_str("ss"); break; case 3: add_str("ds"); break; case 4: add_str("fs"); break; case 5: add_str("gs"); break; case 6: add_str("s6"); break; case 7: add_str("s7"); break; } } #if 0 static void add_ctrl_reg(unsigned reg) { add_str("cr"); add_dec_uint32(reg); } static void add_dbg_reg(unsigned reg) { add_str("dr"); add_dec_uint32(reg); } #endif static void add_ttt(unsigned ttt) { switch (ttt) { case 0: add_str("o"); break; case 1: add_str("no"); break; case 2: add_str("b"); break; case 3: add_str("ae"); break; case 4: add_str("e"); break; case 5: add_str("ne"); break; case 6: add_str("be"); break; case 7: add_str("a"); break; case 8: add_str("s"); break; case 9: add_str("ns"); break; case 10: add_str("pe"); break; case 11: add_str("po"); break; case 12: add_str("l"); break; case 13: add_str("ge"); break; case 14: add_str("le"); break; case 15: add_str("g"); break; } } static void add_disp8(void) { uint32_t disp = get_code(); if (disp < 0x80) { add_char('+'); } else { add_char('-'); disp = (disp ^ 0xff) + 1; } add_str("0x"); add_hex_uint32(disp); } static void add_disp16(void) { uint32_t disp = get_code(); disp |= (uint32_t)get_code() << 8; add_str("0x"); add_hex_uint32(disp); } static void add_disp32(void) { uint32_t disp = get_code(); disp |= (uint32_t)get_code() << 8; disp |= (uint32_t)get_code() << 16; disp |= (uint32_t)get_code() << 24; add_str("0x"); add_hex_uint32(disp); } static void add_imm8(void) { uint32_t imm = get_code(); add_str("0x"); add_hex_uint32(imm); } static void add_imm16(void) { uint32_t imm = get_code(); imm |= (uint32_t)get_code() << 8; add_str("0x"); add_hex_uint32(imm); } static void add_imm32(void) { uint32_t imm = get_code(); imm |= (uint32_t)get_code() << 8; imm |= (uint32_t)get_code() << 16; imm |= (uint32_t)get_code() << 24; add_str("0x"); add_hex_uint32(imm); } #if 0 /* Not used yet */ static void add_imm64(void) { uint64_t imm = get_code(); imm |= (uint64_t)get_code() << 8; imm |= (uint64_t)get_code() << 16; imm |= (uint64_t)get_code() << 24; imm |= (uint64_t)get_code() << 32; imm |= (uint64_t)get_code() << 40; imm |= (uint64_t)get_code() << 48; imm |= (uint64_t)get_code() << 56; add_str("0x"); add_hex_uint64(imm); }
TEST_F(PostVerify, InlineCallerNestedTry) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testCallerNestedTry"); auto invoke = find_invoke(m, OPCODE_INVOKE_DIRECT, "throwsInElse2"); ASSERT_EQ(nullptr, invoke); auto& code = m->get_code(); ASSERT_EQ(code->get_tries().size(), 3); }
int Open_param_file(const char *file){ char str[1000]; long pos, helppos; int ind,i/*,j*/; struct rparam *elem; if(cur_file)fatal_error("Parameter file is already initialized!\n"); cur_file = fopen(file,"rb"); if(!cur_file){ if(stop_on_error==1)fatal_error("Cant open the file '%s'\n", file); else if(stop_on_error==-1)msg_error("Cant open the file '%s'\n", file); return 0; } strcpy(cur_file_name,file); init_Cashe(); helppos=-1; do{ i=0; pos=get_next_string(str,0); if(pos<0)return 1; while(str[i]==' ')i++; if(helppos<0 && str[i]==Help_char)helppos=pos; if(str[i]==Com_char)continue; /* j=0; while(str[i+j]!=':'){ if(str[i+j]==0)break; j++; } if(!str[i+j])continue; ind=str[i]&0x07f;*/ ind=get_code(str+i); //printf("%lx, %s, %d\n",pos,str,ind); if(ind==0){ if(str[i]!=Help_char)helppos=-1; continue; } if(ind<0)ind=-ind; ind--; /*Err_malloc(elem,sizeof(struct rparam));*/ elem=(struct rparam *)malloc(sizeof(struct rparam)); if(!elem)fatal_error("Memory allocation error!\n"); elem->next=Cashe[ind]; Cashe[ind]=elem; elem->pos=pos; elem->helppos=helppos; helppos=-1; }while(1); }
TEST_F(PostVerify, InlineCallerTryCalleeIfThrows) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testCallerTryCalleeElseThrows"); // verify that we've removed the throwsInIf() call auto invoke = find_invoke(m, OPCODE_INVOKE_DIRECT, "throwsInIf"); ASSERT_EQ(nullptr, invoke); auto& code = m->get_code(); ASSERT_EQ(code->get_tries().size(), 2); }
TEST_F(PostVerify, InlineCalleeTryUncaught) { auto cls = find_class_named( classes, "Lcom/facebook/redexinline/InlineTest;"); auto m = find_vmethod_named(*cls, "testCalleeTryUncaught"); auto invoke = find_invoke(m, OPCODE_INVOKE_DIRECT, "throwsUncaught"); ASSERT_EQ(nullptr, invoke); auto invoke_throws = find_invoke(m, OPCODE_INVOKE_VIRTUAL, "wrapsThrow"); ASSERT_NE(nullptr, invoke_throws); auto& code = m->get_code(); ASSERT_EQ(code->get_tries().size(), 2); }
bool CffPlayer::cff_unpacker::startup(const std::vector<std::vector<uint8_t>>& dictionary, std::vector<uint8_t>& obuf, std::vector<uint8_t>::const_iterator& it) { auto oldCode = get_code(it); translate_code(oldCode, m_theString, dictionary); for(int i = 0; i < m_theString[0]; i++) obuf.emplace_back( m_theString[i + 1] ); return true; }
static void add_disp8(void) { uint32_t disp = get_code(); if (disp < 0x80) { add_char('+'); } else { add_char('-'); disp = (disp ^ 0xff) + 1; } add_str("0x"); add_hex_uint32(disp); }