TEST(FirstPass, get_string_data) { char s1[] = {".string \"I'm an englishman in New York\""}; char s2[] = {".string \"home\""}; char s3[] = {".string \"jakarta"}; char s4[] = {".string home\""}; EXPECT_STREQ(get_string_data(s1), "I'm an englishman in New York"); EXPECT_STREQ(get_string_data(s2), "home"); EXPECT_STREQ(get_string_data(s3), NULL); EXPECT_STREQ(get_string_data(s4), NULL); }
char *get_type_item_name(DexFileFormat *dex, int type_id) { type_id_item *type_item = get_type_item(dex, type_id); if (type_item != 0) return get_string_data(dex, type_item->descriptor_idx); return 0; }
int get_method_name( DexFileFormat *dex, int method_id, char *name ) { method_id_item *m = get_method_item( dex, method_id ); type_id_item *type_class = 0; proto_id_item *proto_item = 0; char *method_name = 0; char *class_name = 0; if ( m != 0 ) { method_name = get_string_data(dex, m->name_idx); type_class = get_type_item( dex, m->class_idx ); if ( type_class != 0 ) { class_name = get_string_data(dex, type_class->descriptor_idx); } proto_item = get_proto_item( dex, m->proto_idx ); } return 0; }
static int string_read(IOStream *io, void *buf, size_t n){ StringData *data = get_string_data(io); int k; k = data->end - data->in; if(n > k) n = k; memcpy(buf, data->in, k); data->in += n; return n; }
static int string_write(IOStream *io, const void *msg, size_t n){ StringData *data = get_string_data(io); int k; k = data->end - data->out; if(n > k) n = k; memcpy(data->out, msg, n); data->out += n; return n; }
int java_lang_string_builder_append( DexFileFormat *dex, simple_dalvik_vm *vm, char*type ) { invoke_parameters *p = &vm->p; int string_id = 0; if ( is_verbose() ) { printf("call java.lang.StringBuilder.append\n"); } load_reg_to(vm, p->reg_idx[1], (unsigned char*)&string_id); if ( type != 0 ){ //printf("type = %s\n", type ); if ( strcmp(type, "Ljava/lang/String;") == 0 ) { buf_ptr += snprintf( buf + buf_ptr, 1024,"%s", get_string_data(dex, string_id)); } else if ( strcmp(type,"I") == 0 ) { buf_ptr += snprintf( buf + buf_ptr, 1024,"%d", string_id); } } return 0; }
int java_io_print_stream_println( DexFileFormat *dex, simple_dalvik_vm *vm, char*type ) { invoke_parameters *p = &vm->p; int i = 0; int string_id = 0; if ( is_verbose() ) { printf("call java.io.PrintStream.println\n"); } load_reg_to(vm, p->reg_idx[1], (unsigned char*)&string_id); if ( use_buf == 1 ) { printf("%s\n", buf); use_buf = 0; memset(buf,0,1024); buf_ptr = 0; } else { printf("%s\n", get_string_data(dex, string_id)); } return 0; }
/** Close a string stream. * * @param io string stream * @return 0 */ static int string_close(IOStream *io){ StringData *data = get_string_data(io); data->in = NULL; data->out = NULL; return 0; }
/** Test if a string stream has an error. * * @param io string stream * @return 0 if ok, error code otherwise */ static int string_error(IOStream *io){ StringData *data = get_string_data(io); return data->out == NULL; }
/** Free a string stream. * The stream state is freed, but the underlying string is not. * * @param io string stream */ static void string_free(IOStream *io){ StringData *data = get_string_data(io); memzero(data, sizeof(*data)); deallocate(data); }