void AssociateArray::load_data(const std::string & data, int method) { unsigned int pos = 0; while (pos < data.size()) { if (data[pos] == '\x00') // probably EOF, NULL-byte due to encryption padding break; int start = pos; while (data[pos] != ' ') pos++; int len = string_to_int(data.substr(start, pos-start)); pos++; // read key start = pos; while (data[pos] != '\x00') pos++; std::string key = data.substr(start, pos-start); decode_method(key, method); pos++; len -= key.size(); // read string start = pos; while (data[pos] != '\x00') pos++; std::string string = data.substr(start, pos-start); decode_method(string, method); pos++; len -= string.size(); // read value std::string value = data.substr(pos, len); decode_method(value, method); pos += len; AssociateArrayItem & item = (*map)[key]; item.value = string_to_int(value); item.string = string; } }
static object* read_object(resource_mgr_t *resmgr, int script, int positions[1000]) { resource_t* r = scir_find_resource(resmgr, sci_script, script, 0); unsigned char* raw; int pos; object* obj; printf("Searching for object in script %03d\n", script); if (r == 0) return 0; /*Skip to the next object*/ #ifdef SCRIPT_DEBUG printf("pre skip: pos=%#x\n", positions[script]); #endif pos = find_frame(r, 1, positions[script]); #ifdef SCRIPT_DEBUG printf("post skip: pos=%#x\n", pos); #endif if (pos == -1) return 0; else positions[script] = pos + get_length(r->data + pos); #ifdef SCRIPT_DEBUG printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos)); #endif /*Construct the object*/ obj = object_new(); raw = r->data + pos; /*Fill in the name*/ if (get_selector_count(raw) < 4) obj->name = "<anonymous>"; else { if (get_selector_value(raw, 3)) obj->name = (char *) r->data + get_selector_value(raw, 3); else obj->name = "<null>"; } /*Fill in the class*/ if (get_selector_count(raw) == 0) obj->parent = object_root; else { int parent_id = get_selector_value(raw, 1); if (parent_id >= fobjects.used) { free(obj); return 0; } if (parent_id < 1) obj->parent = object_root; else obj->parent = fobjects.data[parent_id]; } /*Add the object to the class*/ if (!obj->parent) { free(obj); return 0; } if (add_child(obj->parent, obj)) { free(obj); return 0; } if (add_object(obj)) { free(obj); return 0; } /*FIXME: decode selectors here*/ obj->method_count = get_method_count(raw); obj->methods = (script_method**)sci_malloc(obj->method_count * sizeof(script_method)); if (obj->methods == 0) { free(obj); return 0; } else { int i; for (i = 0; i < obj->method_count; i++) { int number = get_method_number(raw, i); int position = get_method_location(raw, i); if ((obj->methods[i] = decode_method(r->data + position)) == 0) { obj->method_count = i - 1; break; } obj->methods[i]->number = number; } } return obj; }