Streamtools: Add FLAC output driver
[jpcrr.git] / lua / memorysearch
blob39fa119d4f421e0f7e473aa2a0708648a699e751
1 instance = jpcrr.memorysearch.create();
2 win = jpcrr.window.create("Memory search");
4 buttoningrid = function(name, text, x, y)
5         win:create_component({gridx = x, gridy = y, gridwidth = 1, gridheight = 1, name = name, type = "button", text = text,
6                 fill = win:HORIZONTAL(), weightx = 1, weighty = 1});
7 end
9 labelingrid = function(name, text, x, y)
10         win:create_component({gridx = x, gridy = y, gridwidth = 1, gridheight = 1, name = name, type = "label", text = text,
11                 fill = win:HORIZONTAL(), weightx = 1, weighty = 1});
12 end
14 buttoningrid("reset", "reset", 0, 0);
15 win:create_component({gridx = 1, gridy = 0, gridwidth = 8, gridheight = 1, name = "candidates", type = "label", text = "0 candidates",
16         fill = win:HORIZONTAL(), weightx = 1, weighty = 1});
17 labelingrid("L1", "signed byte", 0, 1);
18 buttoningrid("update 0", "<", 1, 1);
19 buttoningrid("update 8", "<=", 2, 1);
20 buttoningrid("update 16", ">=", 3, 1);
21 buttoningrid("update 24", ">", 4, 1);
22 buttoningrid("update 32", "==", 5, 1);
23 buttoningrid("update 36", "!=", 6, 1);
24 buttoningrid("hexcandidates 4", "hex", 7, 1);
25 buttoningrid("deccandidates 4", "dec", 8, 1);
26 labelingrid("L2", "unsigned byte", 0, 2);
27 buttoningrid("update 4", "<", 1, 2);
28 buttoningrid("update 12", "<=", 2, 2);
29 buttoningrid("update 20", ">=", 3, 2);
30 buttoningrid("update 28", ">", 4, 2);
31 buttoningrid("update 32", "==", 5, 2);
32 buttoningrid("update 36", "!=", 6, 2);
33 buttoningrid("hexcandidates 0", "hex", 7, 2);
34 buttoningrid("deccandidates 0", "dec", 8, 2);
35 labelingrid("L3", "signed word", 0, 3);
36 buttoningrid("update 1", "<", 1, 3);
37 buttoningrid("update 9", "<=", 2, 3);
38 buttoningrid("update 17", ">=", 3, 3);
39 buttoningrid("update 25", ">", 4, 3);
40 buttoningrid("update 33", "==", 5, 3);
41 buttoningrid("update 37", "!=", 6, 3);
42 buttoningrid("hexcandidates 5", "hex", 7, 3);
43 buttoningrid("deccandidates 5", "dec", 8, 3);
44 labelingrid("L4", "unsigned word", 0, 4);
45 buttoningrid("update 5", "<", 1, 4);
46 buttoningrid("update 13", "<=", 2, 4);
47 buttoningrid("update 21", ">=", 3, 4);
48 buttoningrid("update 29", ">", 4, 4);
49 buttoningrid("update 33", "==", 5, 4);
50 buttoningrid("update 37", "!=", 6, 4);
51 buttoningrid("hexcandidates 1", "hex", 7, 4);
52 buttoningrid("deccandidates 1", "dec", 8, 4);
53 labelingrid("L5", "signed dword", 0, 5);
54 buttoningrid("update 2", "<", 1, 5);
55 buttoningrid("update 10", "<=", 2, 5);
56 buttoningrid("update 18", ">=", 3, 5);
57 buttoningrid("update 26", ">", 4, 5);
58 buttoningrid("update 34", "==", 5, 5);
59 buttoningrid("update 38", "!=", 6, 5);
60 buttoningrid("hexcandidates 6", "hex", 7, 5);
61 buttoningrid("deccandidates 6", "dec", 8, 5);
62 labelingrid("L6", "unsigned dword", 0, 6);
63 buttoningrid("update 6", "<", 1, 6);
64 buttoningrid("update 14", "<=", 2, 6);
65 buttoningrid("update 22", ">=", 3, 6);
66 buttoningrid("update 30", ">", 4, 6);
67 buttoningrid("update 34", "==", 5, 6);
68 buttoningrid("update 38", "!=", 6, 6);
69 buttoningrid("hexcandidates 2", "hex", 7, 6);
70 buttoningrid("deccandidates 2", "dec", 8, 6);
71 labelingrid("L7", "signed qword", 0, 7);
72 buttoningrid("update 3", "<", 1, 7);
73 buttoningrid("update 11", "<=", 2, 7);
74 buttoningrid("update 19", ">=", 3, 7);
75 buttoningrid("update 27", ">", 4, 7);
76 buttoningrid("update 35", "==", 5, 7);
77 buttoningrid("update 39", "!=", 6, 7);
78 buttoningrid("hexcandidates 7", "hex", 7, 7);
79 buttoningrid("deccandidates 7", "dec", 8, 7);
80 labelingrid("L8", "unsigned qword", 0, 8);
81 buttoningrid("update 7", "<", 1, 8);
82 buttoningrid("update 15", "<=", 2, 8);
83 buttoningrid("update 23", ">=", 3, 8);
84 buttoningrid("update 31", ">", 4, 8);
85 buttoningrid("update 35", "==", 5, 8);
86 buttoningrid("update 39", "!=", 6, 8);
87 buttoningrid("hexcandidates 3", "hex", 7, 8);
88 buttoningrid("deccandidates 3", "dec", 8, 8);
89 labelingrid("L9", "float", 0, 9);
90 buttoningrid("update 64", "<", 1, 9);
91 buttoningrid("update 72", "<=", 2, 9);
92 buttoningrid("update 80", ">=", 3, 9);
93 buttoningrid("update 88", ">", 4, 9);
94 buttoningrid("update 96", "==", 5, 9);
95 buttoningrid("update 100", "!=", 6, 9);
96 buttoningrid("deccandidates 8", "dec", 8, 9);
97 labelingrid("L10", "double", 0, 10);
98 buttoningrid("update 65", "<", 1, 10);
99 buttoningrid("update 73", "<=", 2, 10);
100 buttoningrid("update 81", ">=", 3, 10);
101 buttoningrid("update 89", ">", 4, 10);
102 buttoningrid("update 97", "==", 5, 10);
103 buttoningrid("update 101", "!=", 6, 10);
104 buttoningrid("deccandidates 9", "dec", 8, 10);
105 labelingrid("L11", "long double", 0, 11);
106 buttoningrid("update 66", "<", 1, 11);
107 buttoningrid("update 74", "<=", 2, 11);
108 buttoningrid("update 82", ">=", 3, 11);
109 buttoningrid("update 90", ">", 4, 11);
110 buttoningrid("update 98", "==", 5, 11);
111 buttoningrid("update 102", "!=", 6, 11);
112 buttoningrid("deccandidates 10", "dec", 8, 11);
113 win:show();
116 print_count = function()
117         win:set_text("candidates", tostring(instance:candidate_count()) .. " candidates.");
120 splitwords = function(str)
121         tab = jpcrr.component_decode(str);
122         if not tab then
123                 print("Bad syntax: " .. str);
124         end
126         for k, v in ipairs(tab) do
127                 tab[k] = string.lower(v);
128         end
129         return tab;
132 jpcrr.register_redraw_function(function() end);
136 process_command = function(cmd)
137         local arr = splitwords(cmd);
138         if arr[1] == "reset" then
139                 instance:reset();
140         elseif arr[1] == "update" then
141                 instance:update(tonumber(arr[2]));
142         elseif arr[1] == "hexcandidates" then
143                 if instance:candidate_count() > 100 then
144                         print("Too many candidates to display.");
145                 else
146                         print("-----------------------------");
147                         base = 0;
148                         mode = tonumber(arr[2]);
149                         while base >= 0 do
150                                 base = instance:next_candidate(base);
151                                 if base >= 0 then
152                                         print(string.format("Candidate: %08X[%s]", base,
153                                                 jpcrr.memorysearch.format(base, mode, true)));
154                                         base = base + 1;
155                                 end
156                         end
157                 end
158         elseif arr[1] == "deccandidates" then
159                 if instance:candidate_count() > 100 then
160                         print("Too many candidates to display.");
161                 else
162                         print("---------------------------------");
163                         base = 0;
164                         mode = tonumber(arr[2]);
165                         while base >= 0 do
166                                 base = instance:next_candidate(base);
167                                 if base >= 0 then
168                                         print(string.format("Candidate: %08X[%s]", base,
169                                                 jpcrr.memorysearch.format(base, mode, false)));
170                                         base = base + 1;
171                                 end
172                         end
173                 end
174         end
175         print_count();
178 jpcrr.register_uiaction_function(process_command);
179 jpcrr.register_attach_function(function() process_command("reset"); end);
181 while true do
182         mtype, message = jpcrr.wait_event();