18 std::string patch_file;
19 std::string output_message;
20 std::vector<std::string> symbols_list;
21 bool show_symbols =
false;
24 auto state = std::make_shared<AsarState>();
26 auto patch_file_input =
27 Input(&state->patch_file,
"Assembly patch file (.asm)");
29 auto apply_button = Button(
"Apply Asar Patch", [state] {
30 if (state->patch_file.empty()) {
31 app_context.error_message =
"Please specify an assembly patch file";
36 if (!app_context.rom.is_loaded()) {
37 app_context.error_message =
"No ROM loaded. Please load a ROM first.";
43 core::AsarWrapper wrapper;
44 auto init_status = wrapper.Initialize();
45 if (!init_status.ok()) {
46 app_context.error_message =
47 absl::StrCat(
"Failed to initialize Asar: ", init_status.message());
52 auto rom_data = app_context.rom.vector();
53 auto patch_result = wrapper.ApplyPatch(state->patch_file, rom_data);
55 if (!patch_result.ok()) {
56 app_context.error_message =
57 absl::StrCat(
"Patch failed: ", patch_result.status().message());
62 const auto& result = patch_result.value();
63 if (!result.success) {
64 app_context.error_message =
65 absl::StrCat(
"Patch failed: ", absl::StrJoin(result.errors,
"; "));
70 state->output_message = absl::StrFormat(
71 "✅ Patch applied successfully!\n"
72 "📊 ROM size: %d bytes\n"
73 "🏷️ Symbols found: %d",
74 result.rom_size, result.symbols.size());
76 state->symbols_list.clear();
77 for (
const auto& symbol : result.symbols) {
78 state->symbols_list.push_back(
79 absl::StrFormat(
"% -20s @ $%06X", symbol.name, symbol.address));
81 state->show_symbols = !state->symbols_list.empty();
83 }
catch (
const std::exception& e) {
84 app_context.error_message =
"Exception: " + std::string(e.what());
89 auto show_symbols_button = Button(
90 "Show Symbols", [state] { state->show_symbols = !state->show_symbols; });
92 auto back_button = Button(
"Back to Main Menu", [state] {
93 state->output_message.clear();
94 state->symbols_list.clear();
95 state->show_symbols =
false;
99 auto container = Container::Vertical({
106 return Renderer(container, [patch_file_input, apply_button,
107 show_symbols_button, back_button, state] {
108 std::vector<Element> elements = {
109 text(
"Apply Asar Patch") | bold | center,
112 patch_file_input->Render(),
114 apply_button->Render() | center,
117 if (!state->output_message.empty()) {
118 elements.push_back(separator());
119 elements.push_back(text(state->output_message) | color(Color::Green));
121 if (state->show_symbols && !state->symbols_list.empty()) {
122 elements.push_back(separator());
123 elements.push_back(text(
"Symbols:") | bold);
124 elements.push_back(show_symbols_button->Render() | center);
126 std::vector<Element> symbol_elements;
127 for (
const auto& symbol : state->symbols_list) {
128 symbol_elements.push_back(text(symbol) | color(Color::Cyan));
130 elements.push_back(vbox(symbol_elements) | frame |
131 size(HEIGHT, LESS_THAN, 10));
132 }
else if (!state->symbols_list.empty()) {
133 elements.push_back(separator());
134 elements.push_back(show_symbols_button->Render() | center);
138 elements.push_back(separator());
139 elements.push_back(back_button->Render() | center);
141 return vbox(elements) | center | border;