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 = Input(&state->patch_file,
"Assembly patch file (.asm)");
28 auto apply_button = Button(
"Apply Asar Patch", [state] {
29 if (state->patch_file.empty()) {
30 app_context.error_message =
"Please specify an assembly patch file";
35 if (!app_context.rom.is_loaded()) {
36 app_context.error_message =
"No ROM loaded. Please load a ROM first.";
42 core::AsarWrapper wrapper;
43 auto init_status = wrapper.Initialize();
44 if (!init_status.ok()) {
45 app_context.error_message = absl::StrCat(
"Failed to initialize Asar: ", init_status.message());
50 auto rom_data = app_context.rom.vector();
51 auto patch_result = wrapper.ApplyPatch(state->patch_file, rom_data);
53 if (!patch_result.ok()) {
54 app_context.error_message = absl::StrCat(
"Patch failed: ", patch_result.status().message());
59 const auto& result = patch_result.value();
60 if (!result.success) {
61 app_context.error_message = absl::StrCat(
"Patch failed: ", absl::StrJoin(result.errors,
"; "));
66 state->output_message = absl::StrFormat(
67 "✅ Patch applied successfully!\n"
68 "📊 ROM size: %d bytes\n"
69 "🏷️ Symbols found: %d",
70 result.rom_size, result.symbols.size());
72 state->symbols_list.clear();
73 for (
const auto& symbol : result.symbols) {
74 state->symbols_list.push_back(absl::StrFormat(
"% -20s @ $%06X",
75 symbol.name, symbol.address));
77 state->show_symbols = !state->symbols_list.empty();
79 }
catch (
const std::exception& e) {
80 app_context.error_message =
"Exception: " + std::string(e.what());
85 auto show_symbols_button = Button(
"Show Symbols", [state] {
86 state->show_symbols = !state->show_symbols;
89 auto back_button = Button(
"Back to Main Menu", [state] {
90 state->output_message.clear();
91 state->symbols_list.clear();
92 state->show_symbols =
false;
96 auto container = Container::Vertical({
103 return Renderer(container, [patch_file_input, apply_button, show_symbols_button,
104 back_button, state] {
105 std::vector<Element> elements = {
106 text(
"Apply Asar Patch") | bold | center,
109 patch_file_input->Render(),
111 apply_button->Render() | center,
114 if (!state->output_message.empty()) {
115 elements.push_back(separator());
116 elements.push_back(text(state->output_message) | color(Color::Green));
118 if (state->show_symbols && !state->symbols_list.empty()) {
119 elements.push_back(separator());
120 elements.push_back(text(
"Symbols:") | bold);
121 elements.push_back(show_symbols_button->Render() | center);
123 std::vector<Element> symbol_elements;
124 for (
const auto& symbol : state->symbols_list) {
125 symbol_elements.push_back(text(symbol) | color(Color::Cyan));
127 elements.push_back(vbox(symbol_elements) | frame | size(HEIGHT, LESS_THAN, 10));
128 }
else if (!state->symbols_list.empty()) {
129 elements.push_back(separator());
130 elements.push_back(show_symbols_button->Render() | center);
134 elements.push_back(separator());
135 elements.push_back(back_button->Render() | center);
137 return vbox(elements) | center | border;