Ejemplo n.º 1
0
void KeyValue::process_line(std::string line, const std::string& filename,
    ZipReader *zip) throw (KeyValueException)
{
    hash_value += get_hash_of_string(line.c_str());
    line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
    if (line.length()) {
        size_t pos = line.find('=');
        if (pos != std::string::npos) {
            std::string key = line.substr(0, pos);
            std::string value = line.substr(pos + 1);
            if (key == "include") {
                size_t pos = filename.rfind('.');
                if (pos != std::string::npos) {
                    std::string suffix = filename.substr(pos);
                    pos = filename.rfind('/');
                    std::string prefix;
                    if (pos != std::string::npos) {
                        prefix = filename.substr(0, pos + 1);
                    }
                    std::string new_filename = prefix + value + suffix;
                    read(new_filename, zip);
                }
            } else {
                entries[key] = value;
            }
        } else {
            throw KeyValueException("Malformed expression in key value file: " + filename);
        }
    }
}
Ejemplo n.º 2
0
void idaapi dump_type_info(int file_id, const VTBL_info_t& vtbl_info, const qstring& type_name, const std::map<ea_t, VTBL_info_t>& vtbl_map) {
	struc_t * struc_type = get_struc(get_struc_id(type_name.c_str()));
	if (!struc_type)
		return;

	qstring file_entry_key;
	qstring key_hash;
	bool filtered = false;

	get_struct_key(struc_type, vtbl_info, file_entry_key, filtered, vtbl_map);
	get_hash_of_string(file_entry_key, key_hash);

	if (filtered)
		return;

	qstring file_entry_val;
	tinfo_t new_type = create_typedef(type_name.c_str());

	if (new_type.is_correct() && new_type.print(&file_entry_val, NULL, PRTYPE_DEF | PRTYPE_1LINE)) {
		qstring line;

		line = key_hash + ";" + file_entry_key + ";";
		line.cat_sprnt("%a;", vtbl_info.ea_begin);
		line += file_entry_val + ";";

		if (rtti_vftables.count(vtbl_info.ea_begin) != 0) {
			VTBL_info_t vi = rtti_vftables[vtbl_info.ea_begin];
			line += vi.vtbl_name;
		}
		line.rtrim();
		line += "\r\n";
		qwrite(file_id, line.c_str(), line.length());
	}
}
void dump_ctrees_in_file(std::map<ea_t, ctree_dump_line> &data_to_dump, qstring &crypto_prefix) {
	int file_id = create_open_file("ctrees.txt");
	if (file_id != -1) {

		size_t crypt_prefix_len = crypto_prefix.length();

		for (std::map<ea_t, ctree_dump_line>::iterator ctrees_iter = data_to_dump.begin(); ctrees_iter != data_to_dump.end() ; ctrees_iter ++) {
			qstring sha_hash;
			int err = get_hash_of_string((*ctrees_iter).second.ctree_for_hash, sha_hash);
			if (err == shaSuccess) {
				qstring dump_line = sha_hash + ";";
				err = get_hash_of_string((*ctrees_iter).second.ctree_dump, sha_hash);
				if (err == shaSuccess) {
					dump_line += sha_hash + ";";
					dump_line += (*ctrees_iter).second.ctree_dump;
					dump_line.cat_sprnt(";%d", (*ctrees_iter).second.func_depth);
					dump_line.cat_sprnt(";%08X", (*ctrees_iter).second.func_start);
					dump_line.cat_sprnt(";%08X", (*ctrees_iter).second.func_end);
					if (((*ctrees_iter).second.func_name.length() > crypt_prefix_len) && (crypt_prefix_len > 0) && ((*ctrees_iter).second.func_name.find(crypto_prefix) == 0))
						dump_line.cat_sprnt(";E", (*ctrees_iter).second.func_end);
					else
						dump_line.cat_sprnt(";N", (*ctrees_iter).second.func_end);
					
					if (((*ctrees_iter).second.heuristic_flag))
						dump_line.cat_sprnt(";H", (*ctrees_iter).second.func_end);
					else
						dump_line.cat_sprnt(";N", (*ctrees_iter).second.func_end);
					
					dump_line += "\n";
				}
				
				qwrite(file_id, dump_line.c_str(), dump_line.length());
					
			} 
			if (err != shaSuccess) {
				logmsg(ERROR, "Error in computing SHA1 hash\r\n");
			}
		}

		qclose(file_id);
	} else {
		logmsg(ERROR, "Failed to open file for dumping ctress\r\n");
	}
}
Ejemplo n.º 4
0
void idaapi dump_type_info(int file_id, VTBL_info_t vtbl_info, qstring type_name, std::map<ea_t, VTBL_info_t> vtbl_map) {
	tid_t type_id = get_struc_id(type_name.c_str());
	if (type_id != BADADDR) {
		struc_t * struc_type = get_struc(type_id);
		if(struc_type != NULL) {
			qstring file_entry_key;
			qstring key_hash;
			bool filtered = false;
			
			get_struct_key(struc_type, vtbl_info, file_entry_key, filtered, vtbl_map);
			get_hash_of_string(file_entry_key, key_hash);

			if (!filtered) {
				qstring file_entry_val;
				tinfo_t new_type = create_typedef(type_name.c_str());
				if(new_type.is_correct()) {
					if (new_type.print(&file_entry_val, NULL, PRTYPE_DEF | PRTYPE_1LINE)) {
						qstring line;

						line = key_hash + ";" + file_entry_key + ";";
						line.cat_sprnt("%p;", vtbl_info.ea_begin);
						line += file_entry_val + ";";
						
						if (rtti_vftables.count(vtbl_info.ea_begin) != 0) {
							vftable::vtinfo vi = rtti_vftables[vtbl_info.ea_begin];
							line += vi.type_info;
						}
						line.rtrim();
						line += "\r\n";
						qwrite(file_id, line.c_str(), line.length());
					}
				}
			}
		}
	}
}