void test_move() { assert(NULL != sexp_parse("(move/from16 v12,v1234)", &sexp)); /*assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0, NULL)); assert(inst.opcode == DVM_MOVE); assert(inst.num_operands == 2); assert(inst.operands[0].payload.uint16 == 12); assert(inst.operands[1].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 0);*/ sexp_free(sexp); assert(NULL != sexp_parse("(move-wide/from16 v12,v1234)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MOVE); assert(inst.num_operands == 2); assert(inst.operands[0].payload.uint16 == 12); assert(inst.operands[1].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 1); assert(inst.operands[1].header.info.size == 1); sexp_free(sexp); assert(NULL != sexp_parse("(move v12,v1234)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MOVE); assert(inst.num_operands == 2); assert(inst.operands[0].payload.uint16 == 12); assert(inst.operands[1].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 0); assert(inst.operands[1].header.info.size == 0); sexp_free(sexp); assert(NULL != sexp_parse("(move-result/wide v1234)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MOVE); assert(inst.num_operands == 2); assert(inst.operands[0].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 1); assert(inst.operands[1].header.info.is_result); sexp_free(sexp); assert(NULL != sexp_parse("(move-result-object v1234)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MOVE); assert(inst.num_operands == 2); assert(inst.operands[0].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 0); assert(inst.operands[0].header.info.type = DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[1].header.info.type = DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[1].header.info.is_result); sexp_free(sexp); }
void test_packed() { assert(NULL != sexp_parse( "(packed-switch v123, 456,\n" " l456, ;case456\n" " l457, ;case457\n" " l458, ;case458\n" " ldefault ;default\n" ")", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(DVM_SWITCH == inst.opcode); assert(3 == inst.num_operands); assert(123 == inst.operands[0].payload.uint16); assert(0 == inst.operands[0].header.flags); assert(1 == inst.operands[1].header.info.is_const); assert(456 == inst.operands[1].payload.uint16); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_INT); assert(inst.operands[2].header.info.type == DVM_OPERAND_TYPE_LABELVECTOR); assert(inst.operands[2].header.info.is_const == 1); assert(inst.operands[2].payload.branches != NULL); vector_t* v = inst.operands[2].payload.branches; assert(0 == *(int*)vector_get(v, 0)); assert(1 == *(int*)vector_get(v, 1)); assert(2 == *(int*)vector_get(v, 2)); assert(3 == *(int*)vector_get(v, 3)); assert(0 == dalvik_label_get_label_id(stringpool_query("l456"))); assert(1 == dalvik_label_get_label_id(stringpool_query("l457"))); assert(2 == dalvik_label_get_label_id(stringpool_query("l458"))); assert(3 == dalvik_label_get_label_id(stringpool_query("ldefault"))); sexp_free(sexp); dalvik_instruction_free(&inst); }
int main(int argc, char *argv[]) { secd_t secd; cell_t *heap = (cell_t *)malloc(sizeof(cell_t) * N_CELLS); init_secd(&secd, heap, N_CELLS); #if ((CTRLDEBUG) || (MEMDEBUG)) secd_setport(&secd, SECD_STDDBG, secd_fopen(&secd, "secd.log", "w")); #endif cell_t *cmdport = SECD_NIL; if (argc == 2) cmdport = secd_fopen(&secd, argv[1], "r"); cell_t *inp = sexp_parse(&secd, cmdport); // cmdport is dropped after if (is_nil(inp) || !is_cons(inp)) { secd_errorf(&secd, "list of commands expected\n"); dbg_printc(&secd, inp); return 1; } cell_t *ret; ret = run_secd(&secd, inp); return (is_error(ret) ? EXIT_FAILURE : EXIT_SUCCESS); }
int main() { adam_init(); sexpression_t* svoid; assert(NULL != sexp_parse("void", &svoid)); tvoid = dalvik_type_from_sexp(svoid); sexp_free(svoid); assert(NULL != tvoid); /* load package */ dalvik_loader_from_directory("test/cases/block_analyzer"); /* run test cases */ case1(); case2(); case3(); dalvik_type_free(tvoid); /* finalize */ adam_finalize(); return 0; }
void test_arrayops() { #if DALVIK_ARRAY_SUPPORT assert(NULL != sexp_parse("(aput v1 v2 v3)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_ARRAY); assert(inst.flags = DVM_FLAG_ARRAY_PUT); assert(inst.num_operands == 3); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].payload.uint16 == 1); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[1].payload.uint16 == 2); assert(inst.operands[2].header.info.type == DVM_OPERAND_TYPE_INT); assert(inst.operands[2].payload.uint16 == 3); sexp_free(sexp); dalvik_instruction_free(&inst); assert(NULL != sexp_parse("(aput-object v1 v2 v3)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_ARRAY); assert(inst.flags = DVM_FLAG_ARRAY_PUT); assert(inst.num_operands == 3); assert(inst.operands[0].header.info.type == DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[0].payload.uint16 == 1); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[1].payload.uint16 == 2); assert(inst.operands[2].header.info.type == DVM_OPERAND_TYPE_INT); assert(inst.operands[2].payload.uint16 == 3); sexp_free(sexp); dalvik_instruction_free(&inst); assert(NULL != sexp_parse("(aget-object v1 v2 v3)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_ARRAY); assert(inst.flags = DVM_FLAG_ARRAY_GET); assert(inst.num_operands == 3); assert(inst.operands[0].header.info.type == DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[0].payload.uint16 == 1); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_OBJECT); assert(inst.operands[1].payload.uint16 == 2); assert(inst.operands[2].header.info.type == DVM_OPERAND_TYPE_INT); assert(inst.operands[2].payload.uint16 == 3); sexp_free(sexp); dalvik_instruction_free(&inst); #endif }
void test_return() { assert(NULL != sexp_parse("(return-object v1234)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_RETURN); assert(inst.num_operands == 1); assert(inst.operands[0].payload.uint16 == 1234); assert(inst.operands[0].header.info.size == 0); assert(inst.operands[0].header.info.type = DVM_OPERAND_TYPE_OBJECT); sexp_free(sexp); assert(NULL != sexp_parse("(return-void)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_RETURN); assert(inst.num_operands == 1); assert(inst.operands[0].header.info.type = DVM_OPERAND_TYPE_VOID); sexp_free(sexp); }
void test_invoke() { assert(NULL != sexp_parse("(invoke-virtual {v1,v2,v3} this/is/a/test (int int int) int)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp,&inst, 0)); assert(inst.opcode == DVM_INVOKE); assert(inst.flags == DVM_FLAG_INVOKE_VIRTUAL); assert(inst.num_operands == 7); //TODO: test it }
void test_instanceops() { assert(NULL != sexp_parse("(iput v1 v2 myclass.Property1 [array [object java.lang.String]])", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_INSTANCE); assert(inst.flags = DVM_FLAG_INSTANCE_PUT); assert(inst.num_operands == 5); sexp_free(sexp); dalvik_instruction_free(&inst); }
void test_monitor() { assert(NULL != sexp_parse("(monitor-enter v123)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MONITOR); assert(inst.num_operands == 1); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[0].header.info.is_const == 0); assert(inst.flags == DVM_FLAG_MONITOR_ENT); sexp_free(sexp); assert(NULL != sexp_parse("(monitor-exit v123)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_MONITOR); assert(inst.num_operands == 1); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[0].header.info.is_const == 0); assert(inst.flags == DVM_FLAG_MONITOR_EXT); sexp_free(sexp); }
int main() { char* sexp_str = "(@\"main.c\":20:50 struct\n" " (union)\n" " 23\n" " \"a string with a backslash (\\\\) and a quote (\\\"). woo\" \n" " (@\"main.c\":21:52 struct (struct) 43))\n" "(struct \"something else\")\n"; struct sexp* s = sexp_parse(sexp_str); printf("Original:\n%s\n", sexp_str); printf("Parsed and dumped: \n"); sexp_dump(s); sexp_free(s); return 0; }
int main(int argc, char** argv){ if (argc <= 1){ fprintf(stderr, "usage: %s [run|dump] <program>, where <program> is a sexp-compiled C file\n", argv[0]); exit(1); } char* file = argv[argc-1]; FILE* prog = fopen(file, "r"); if (!prog){ perror("Couldn't open program"); } char progbuf[MAXFILE]; fread(progbuf, MAXFILE, 1, prog); if (!feof(prog)){ fprintf(stderr, "Couldn't read all of %s", file); exit(1); } struct sexp* sexpcode = sexp_parse(progbuf); if (!sexpcode){ fprintf(stderr, "Couldn't parse s-expressions in %s", file); exit(1); } struct program* program = compile(sexpcode); sexp_free(sexpcode); if (!program){ fprintf(stderr, "Couldn't compile\n"); exit(1); } if (argc == 3){ if (!strcmp(argv[1], "run")){ run(program); }else if (!strcmp(argv[1], "dump")){ program_dump(program); } }else{ while(1){ get_command(); if(parse_command(program)){ break; } } } return 0; }
void test_sparse() { assert(NULL != sexp_parse( "(sparse-switch v4 \n" " (9 sp1) \n" " (10 sp2) \n" " (13 sp3) \n" " (65535 sp4)\n" " (default sp5))", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_SWITCH); assert(inst.flags == DVM_FLAG_SWITCH_SPARSE); assert(inst.num_operands == 2); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].payload.uint16 = 4); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_SPARSE); assert(inst.operands[1].payload.sparse != NULL); vector_t* v = inst.operands[1].payload.branches; assert(4 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 0))->labelid); assert(5 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 1))->labelid); assert(6 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 2))->labelid); assert(7 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 3))->labelid); assert(8 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 4))->labelid); assert(9 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 0))->cond); assert(10 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 1))->cond); assert(13 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 2))->cond); assert(65535 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 3))->cond); assert(0 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 4))->cond); assert(0 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 0))->is_default); assert(0 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 1))->is_default); assert(0 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 2))->is_default); assert(0 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 3))->is_default); assert(1 ==((dalvik_sparse_switch_branch_t *)vector_get(v, 4))->is_default); assert(5 == vector_size(v)); sexp_free(sexp); dalvik_instruction_free(&inst); }
/* Should be called with input->token being the first token of the * expression, to be converted, and return with input->token being the * last token of the expression. */ static void sexp_convert_item(struct sexp_parser *parser, struct sexp_compound_token *token, struct sexp_output *output, enum sexp_mode mode_out, unsigned indent) { if (mode_out == SEXP_TRANSPORT) { sexp_put_char(output, '{'); sexp_put_code_start(output, &nettle_base64); sexp_convert_item(parser, token, output, SEXP_CANONICAL, 0); sexp_put_code_end(output); sexp_put_char(output, '}'); } else switch(token->type) { case SEXP_LIST_END: die("Unmatched end of list.\n"); case SEXP_EOF: die("Unexpected end of file.\n"); case SEXP_CODING_END: die("Unexpected end of coding.\n"); case SEXP_LIST_START: { unsigned item; sexp_put_char(output, '('); for (item = 0; sexp_parse(parser, token), token->type != SEXP_LIST_END; item++) { if (mode_out == SEXP_ADVANCED) { /* FIXME: Adapt pretty printing to handle a big first * element. */ switch (item) { case 0: if (token->type == SEXP_COMMENT) { indent = output->pos; /* Disable the indentation setup for next item */ item++; } break; case 1: sexp_put_char(output, ' '); indent = output->pos; break; default: sexp_put_newline(output, indent); break; } } sexp_convert_item(parser, token, output, mode_out, indent); } sexp_put_char(output, ')'); break; } case SEXP_STRING: sexp_put_string(output, mode_out, &token->string); break; case SEXP_DISPLAY: sexp_put_char(output, '['); sexp_put_string(output, mode_out, &token->display); sexp_put_char(output, ']'); sexp_put_string(output, mode_out, &token->string); break; case SEXP_COMMENT: if (mode_out == SEXP_ADVANCED) { sexp_put_data(output, token->string.size, token->string.contents); sexp_put_soft_newline(output, indent); } break; default: /* Internal error */ abort(); } }
int main(int argc, char **argv) { struct conv_options options; struct sexp_input input; struct sexp_parser parser; struct sexp_compound_token token; struct sexp_output output; parse_options(&options, argc, argv); sexp_input_init(&input, stdin); sexp_parse_init(&parser, &input, SEXP_ADVANCED); sexp_compound_token_init(&token); sexp_output_init(&output, stdout, options.width, options.prefer_hex); #if HAVE_FCNTL_LOCKING if (options.lock) { struct flock fl; memset(&fl, 0, sizeof(fl)); fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; /* Means entire file. */ if (fcntl(STDOUT_FILENO, F_SETLKW, &fl) == -1) die("Locking output file failed: %s\n", strerror(errno)); } #endif /* HAVE_FCNTL_LOCKING */ if (options.hash) { /* Leaks the context, but that doesn't matter */ void *ctx = xalloc(options.hash->context_size); sexp_output_hash_init(&output, options.hash, ctx); } sexp_get_char(&input); sexp_parse(&parser, &token); if (token.type == SEXP_EOF) { if (options.once) die("sexp-conv: No input expression.\n"); return EXIT_SUCCESS; } do { sexp_convert_item(&parser, &token, &output, options.mode, 0); if (options.hash) { sexp_put_digest(&output); sexp_put_newline(&output, 0); } else if (options.mode != SEXP_CANONICAL) sexp_put_newline(&output, 0); sexp_parse(&parser, &token); } while (!options.once && token.type != SEXP_EOF); sexp_compound_token_clear(&token); if (fflush(output.f) < 0) die("Final fflush failed: %s.\n", strerror(errno)); return EXIT_SUCCESS; }
void test_const() { assert(NULL != sexp_parse("(const/high16 v123,1)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint32 == 0x10000); sexp_free(sexp); assert(NULL != sexp_parse("(const v123,1235)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint32 == 1235); sexp_free(sexp); assert(NULL != sexp_parse("(const/4 v123,1235)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint32 == 1235); sexp_free(sexp); assert(NULL != sexp_parse("(const/16 v123,1235)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.flags == 0); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint32 == 1235); sexp_free(sexp); assert(NULL != sexp_parse("(const-wide v123,123456789)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.info.size == 1); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint64 == 123456789); sexp_free(sexp); assert(NULL != sexp_parse("(const-wide v123,123456789)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.info.size == 1); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint64 == 123456789); sexp_free(sexp); assert(NULL != sexp_parse("(const-wide/high16 v123,1)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[0].header.info.size == 1); assert(inst.operands[0].header.info.type == 0); assert(inst.operands[0].payload.uint16 == 123); assert(inst.operands[1].header.info.is_const == 1); assert(inst.operands[1].payload.uint64 == 0x0001000000000000ull); sexp_free(sexp); assert(NULL != sexp_parse("(const-string v123,\"this is a test case for const-string\")", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_STRING); assert(inst.operands[1].payload.string == stringpool_query("this is a test case for const-string")); assert(inst.operands[1].header.info.is_const == 1); sexp_free(sexp); assert(NULL != sexp_parse("(const-class v123,this/is/a/test/class)", &sexp)); assert(0 == dalvik_instruction_from_sexp(sexp, &inst, 0)); assert(inst.opcode == DVM_CONST); assert(inst.num_operands == 2); assert(inst.operands[1].header.info.type == DVM_OPERAND_TYPE_CLASS); assert(inst.operands[1].payload.string == stringpool_query("this/is/a/test/class")); assert(inst.operands[1].header.info.is_const == 1); sexp_free(sexp); }
int main() { adam_init(); /* Runnability test */ assert(dalvik_loader_from_directory("test/data/AndroidAntlr") >= 0); sexpression_t* sexp; sexp_parse("[object java/lang/String]", &sexp); dalvik_type_t *type = dalvik_type_from_sexp(sexp); sexp_free(sexp); const char* classname = stringpool_query("antlr/ANTLRParser"); const char* methodname = stringpool_query("treeParserSpec"); dalvik_type_t* arglist[] = {NULL ,NULL}; arglist[0] = type; sexpression_t* svoid; assert(NULL != sexp_parse("void", &svoid)); dalvik_type_t* tvoid = dalvik_type_from_sexp(svoid); sexp_free(svoid); dalvik_block_t* block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); dalvik_type_free(type); assert(NULL != block); /* setup function test */ assert(dalvik_loader_from_directory("test/cases/dalvik_block") >= 0); arglist[0] = NULL; classname = stringpool_query("TestClass"); /* Case 1 */ methodname = stringpool_query("case1"); block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); const dalvik_method_t* method = dalvik_memberdict_get_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); assert(NULL != method); assert(NULL != block); assert(block->begin == method->entry); assert(block->end == method->entry + 3); assert(block->nbranches == 1); assert(block->branches[0].conditional == 0); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_JUMP(block->branches[0])); dalvik_block_t* retblk = block->branches[0].block; assert(NULL != retblk); assert(1 == retblk->nbranches); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_RETURN(retblk->branches[0])); /* Case 2 */ methodname = stringpool_query("case2"); block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); method = dalvik_memberdict_get_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); assert(NULL != block); assert(NULL != method); /* verify block0 */ assert(block->begin == method->entry); assert(block->end == method->entry + 2); assert(block->nbranches == 2); assert(block->branches[0].disabled == 0); assert(block->branches[0].linked == 1); assert(block->branches[0].conditional == 1); assert(block->branches[0].eq == 1); assert(block->branches[0].lt == 0); assert(block->branches[0].gt == 0); assert(block->branches[0].left_inst == 0); assert(block->branches[0].left->header.flags == 0); assert(block->branches[0].left->payload.uint16 == 1); assert(block->branches[0].right->header.flags == 0); assert(block->branches[0].right->payload.uint16 == 2); assert(block->branches[0].block != NULL); assert(block->branches[1].disabled == 0); assert(block->branches[1].linked == 1); assert(block->branches[1].conditional == 0); assert(block->branches[1].block != NULL); /* verify block2 */ dalvik_block_t* block2 = block->branches[0].block; assert(block2->begin == method->entry + 5); assert(block2->end == method->entry + 6); assert(block2->nbranches == 1); assert(block2->branches[0].disabled == 0); assert(block2->branches[0].linked == 1); assert(block2->branches[0].conditional == 0); assert(block2->branches[0].block != NULL); /* verify block1 */ dalvik_block_t* block1 = block->branches[1].block; assert(block1->begin == method->entry + 3); assert(block1->end == method->entry + 4); assert(block1->nbranches == 1); assert(block1->branches[0].disabled == 0); assert(block1->branches[0].linked == 1); assert(block1->branches[0].conditional == 0); assert(block1->branches[0].block != NULL); assert(block1->branches[0].block == block2->branches[0].block); /* verify block3 */ dalvik_block_t* block3 = block1->branches[0].block; assert(block3->begin == method->entry + 6); assert(block3->end == method->entry + 6); assert(block3->nbranches == 1); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_RETURN(block3->branches[0])); assert(block3->branches[0].block == NULL); assert(block3->branches[0].left->payload.uint16 == 1); assert(block3->branches[0].block == NULL); /* Case 3 */ methodname = stringpool_query("case3"); block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); method = dalvik_memberdict_get_method(classname, methodname, (const dalvik_type_t**)arglist, tvoid); assert(NULL != block); assert(NULL != method); /* verify block 1 */ assert(block->begin == method->entry + 0); assert(block->end == method->entry + 2); assert(block->nbranches == 1); assert(block->branches[0].linked == 1); assert(block->branches[0].disabled == 0); assert(block->branches[0].conditional == 0); assert(block->branches[0].block != NULL); /* verify block 3*/ block3 = block->branches[0].block; assert(block3->begin == method->entry + 6); assert(block3->end == method->entry + 7); assert(block3->nbranches == 1); assert(block3->branches[0].linked == 1); assert(block3->branches[0].disabled == 0); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_JUMP(block3->branches[0])); /*verify block 4 */ dalvik_block_t* block4 = block3->branches[0].block; assert(block4->begin == method->entry + 7); assert(block4->end == method->entry + 7); assert(block4->nbranches == 1); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_RETURN(block4->branches[0])); assert(block4->branches[0].left->payload.uint16 == 9); assert(block4->branches[0].block == NULL); /* Case 4 */ methodname = stringpool_query("case4"); block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**) arglist, tvoid); method = dalvik_memberdict_get_method(classname, methodname, (const dalvik_type_t**) arglist, tvoid); assert(NULL != block); assert(NULL != method); /* verify block 1 */ assert(block->begin == method->entry + 0); assert(block->end == method->entry + 1); assert(block->nbranches == 1); assert(block->branches[0].linked == 1); assert(block->branches[0].disabled == 0); assert(block->branches[0].conditional == 0); assert(block->branches[0].block != NULL); /* verify block 2 */ block2 = block->branches[0].block; assert(block2->begin == method->entry + 1); assert(block2->end == method->entry + 2); assert(block2->nbranches == 1); assert(block2->branches[0].linked == 1); assert(block2->branches[0].conditional == 0); assert(block2->branches[0].disabled == 0); assert(block2->branches[0].block != NULL); /* verify block3 */ block3 = block2->branches[0].block; assert(block3->begin == method->entry + 2); assert(block3->end == method->entry + 3); assert(block3->nbranches == 1); assert(block3->branches[0].linked == 1); assert(block3->branches[0].conditional == 0); assert(block3->branches[0].disabled == 0); block4 = block3->branches[0].block; assert(NULL != block4); assert(DALVIK_BLOCK_BRANCH_UNCOND_TYPE_IS_RETURN(block4->branches[0])); assert(block4->branches[0].block == NULL); /* Case 5 */ methodname = stringpool_query("case5"); block = dalvik_block_from_method(classname, methodname, (const dalvik_type_t**) arglist, tvoid); method = dalvik_memberdict_get_method(classname, methodname, (const dalvik_type_t**) arglist, tvoid); assert(NULL != block); assert(NULL != method); adam_finalize(); return 0; }