2020-09-13 21:32:55 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-22 23:30:17 -04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_set>
|
2020-12-17 15:48:07 -05:00
|
|
|
#include <unordered_map>
|
2021-02-27 14:40:18 -05:00
|
|
|
#include <optional>
|
2020-12-17 15:48:07 -05:00
|
|
|
#include "decompiler/Disasm/Register.h"
|
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
namespace decompiler {
|
2021-06-04 13:43:19 -04:00
|
|
|
struct RegisterTypeCast {
|
2021-03-13 16:10:39 -05:00
|
|
|
int atomic_op_idx = -1;
|
2020-12-17 15:48:07 -05:00
|
|
|
Register reg;
|
|
|
|
std::string type_name;
|
|
|
|
};
|
2020-08-22 23:30:17 -04:00
|
|
|
|
2021-06-04 13:43:19 -04:00
|
|
|
struct StackTypeCast {
|
|
|
|
int stack_offset = -1;
|
|
|
|
std::string type_name;
|
|
|
|
};
|
|
|
|
|
2021-02-20 11:42:46 -05:00
|
|
|
struct LabelType {
|
|
|
|
std::string type_name;
|
|
|
|
bool is_const = false;
|
2021-02-27 14:40:18 -05:00
|
|
|
std::optional<int> array_size;
|
2021-02-20 11:42:46 -05:00
|
|
|
};
|
|
|
|
|
2021-03-13 16:10:39 -05:00
|
|
|
struct LocalVarOverride {
|
|
|
|
std::string name;
|
|
|
|
// this may be left out, indicating that the variable should use the type determined
|
|
|
|
// by the type analysis pass.
|
|
|
|
std::optional<std::string> type;
|
|
|
|
};
|
|
|
|
|
2021-03-27 15:18:59 -04:00
|
|
|
/*!
|
2021-06-04 13:43:19 -04:00
|
|
|
* Information about a structure on the stack.
|
2021-03-27 15:18:59 -04:00
|
|
|
*/
|
2021-06-04 13:43:19 -04:00
|
|
|
struct StackStructureHint {
|
2021-03-27 15:18:59 -04:00
|
|
|
std::string element_type; // type of the thing stored
|
|
|
|
// todo - is boxed array on the stack supported?
|
|
|
|
enum class ContainerType {
|
|
|
|
NONE, // just store the plain thing.
|
|
|
|
ARRAY, // for refs, array of refs. For values, array of values.
|
|
|
|
INLINE_ARRAY // for refs, array of values, for values, invalid
|
|
|
|
} container_type = ContainerType::NONE;
|
|
|
|
int container_size = -1; // if container other than NONE, the number of elements.
|
|
|
|
int stack_offset = 0; // where it's located on the stack (relative to sp after prologue)
|
|
|
|
};
|
|
|
|
|
2021-05-24 19:52:19 -04:00
|
|
|
struct CondWithElseLengthHack {
|
|
|
|
std::unordered_map<std::string, int> max_length_by_start_block;
|
|
|
|
};
|
|
|
|
|
2021-05-11 20:49:54 -04:00
|
|
|
struct DecompileHacks {
|
|
|
|
std::unordered_set<std::string> types_with_bad_inspect_methods;
|
|
|
|
std::unordered_set<std::string> no_type_analysis_functions_by_name;
|
|
|
|
std::unordered_set<std::string> hint_inline_assembly_functions;
|
|
|
|
std::unordered_set<std::string> asm_functions_by_name;
|
|
|
|
std::unordered_set<std::string> pair_functions_by_name;
|
2021-05-24 19:52:19 -04:00
|
|
|
std::unordered_map<std::string, CondWithElseLengthHack> cond_with_else_len_by_func_name;
|
2021-05-30 19:57:11 -04:00
|
|
|
std::unordered_set<std::string> reject_cond_to_value;
|
2021-07-05 16:07:07 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_set<int>> blocks_ending_in_asm_branch_by_func_name;
|
2021-05-11 20:49:54 -04:00
|
|
|
};
|
|
|
|
|
2020-08-22 23:30:17 -04:00
|
|
|
struct Config {
|
|
|
|
int game_version = -1;
|
|
|
|
std::vector<std::string> dgo_names;
|
2020-11-19 21:22:16 -05:00
|
|
|
std::vector<std::string> object_file_names;
|
2020-11-21 15:58:51 -05:00
|
|
|
std::vector<std::string> str_file_names;
|
2021-05-11 20:49:54 -04:00
|
|
|
|
2021-07-18 19:28:56 -04:00
|
|
|
std::string audio_dir_file_name;
|
|
|
|
std::vector<std::string> streamed_audio_file_names;
|
|
|
|
|
2020-10-24 14:27:50 -04:00
|
|
|
std::string obj_file_name_map_file;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
|
|
|
bool disassemble_code = false;
|
|
|
|
bool decompile_code = false;
|
2020-08-22 23:30:17 -04:00
|
|
|
bool write_scripts = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
bool disassemble_data = false;
|
2020-11-16 19:57:45 -05:00
|
|
|
bool process_tpages = false;
|
2020-11-19 21:22:16 -05:00
|
|
|
bool process_game_text = false;
|
2020-11-24 20:48:38 -05:00
|
|
|
bool process_game_count = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
|
|
|
bool regenerate_all_types = false;
|
|
|
|
bool write_hex_near_instructions = false;
|
|
|
|
bool hexdump_code = false;
|
|
|
|
bool hexdump_data = false;
|
2020-11-24 20:48:38 -05:00
|
|
|
bool dump_objs = false;
|
2021-05-24 19:52:19 -04:00
|
|
|
bool print_cfgs = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
2021-05-31 10:43:25 -04:00
|
|
|
bool generate_symbol_definition_map = false;
|
|
|
|
|
2021-02-01 20:41:37 -05:00
|
|
|
std::unordered_set<std::string> allowed_objects;
|
2021-06-04 13:43:19 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::vector<RegisterTypeCast>>>
|
|
|
|
register_type_casts_by_function_by_atomic_op_idx;
|
|
|
|
std::unordered_map<std::string, std::unordered_map<int, StackTypeCast>>
|
|
|
|
stack_type_casts_by_function_by_stack_offset;
|
2020-12-26 11:09:59 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::string>>
|
|
|
|
anon_function_types_by_obj_by_id;
|
2021-02-09 20:59:14 -05:00
|
|
|
std::unordered_map<std::string, std::vector<std::string>> function_arg_names;
|
2021-03-13 16:10:39 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<std::string, LocalVarOverride>>
|
|
|
|
function_var_overrides;
|
2021-02-20 11:42:46 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<std::string, LabelType>> label_types;
|
2021-06-04 13:43:19 -04:00
|
|
|
std::unordered_map<std::string, std::vector<StackStructureHint>>
|
|
|
|
stack_structure_hints_by_function;
|
2021-04-26 21:40:08 -04:00
|
|
|
|
2021-07-01 21:38:19 -04:00
|
|
|
std::unordered_map<std::string, int> bad_format_strings;
|
|
|
|
|
2021-05-11 20:49:54 -04:00
|
|
|
DecompileHacks hacks;
|
2020-08-22 23:30:17 -04:00
|
|
|
};
|
|
|
|
|
2021-05-11 20:49:54 -04:00
|
|
|
Config read_config_file(const std::string& path_to_config_file);
|
2021-03-27 15:18:59 -04:00
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
} // namespace decompiler
|