11#include " core.h"
22#include " ../dmdism/disassembly.h"
3- #include " ../debug_server/debug_server.h"
43#include " ../crash_guard/crash_guard.h"
54
65#include < fstream>
@@ -78,25 +77,6 @@ class ext_vector : std::vector<T>
7877 }
7978};
8079
81- #ifdef _WIN32
82- opcode_handler _generate_number_op_localm_localn_store_localx (unsigned char op, int localm, int localn, int localx)
83- {
84- unsigned char * func = (unsigned char *)VirtualAlloc (NULL , 64 , MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
85- if (!func)
86- {
87- return nullptr ;
88- }
89- std::memcpy (func, _number_op_localm_localn_store_localx, 26 );
90- func[16 ] = op;
91- func[13 ] = 4 + 8 * localm;
92- func[18 ] = 4 + 8 * localn;
93- func[23 ] = 4 + 8 * localx;
94- DWORD old_prot;
95- VirtualProtect (func, 64 , PAGE_EXECUTE_READ, &old_prot);
96- return (opcode_handler)func;
97- }
98- #endif
99-
10080extern " C" EXPORT void add_subvars_of_locals (ExecutionContext* ctx)
10181{
10282 Value a = ctx->local_variables [0 ];
@@ -123,109 +103,6 @@ void init_testing()
123103 {
124104 o << i.offset () << " \t\t\t " << i.bytes_str () << " \t\t\t " << i.opcode ().mnemonic () << " " << i.comment () << " \n " ;
125105 }
126- // Value a(5.0f);
127- // Value b = a + 5.0f;
128- // b += 1.0f;
129- // Core::Alert(std::to_string(b));
130- // ManagedValue a = Value::World().get("name");
131- // dump_full_obj_mem_usage();
132- // Core::Alert("end func");
133- // Core::global_direct_set("internal_tick_usage", "AYYLMAO");
134- // Core::Alert(Core::global_direct_get("internal_tick_usage"));
135- // Core::Alert(Core::GetStringFromId(0x86));
136- // Core::get_proc("/proc/get_string_by_id").hook(test_invoke);
137- // Core::Alert(Core::get_proc("/client/verb/hidden").proc_table_entry->procFlags);
138- // Core::Alert(Core::get_proc("/client/verb/nothidden").proc_table_entry->procFlags);
139- // Core::get_proc("/client/verb/toggle_hidden_verb").hook(toggle_verb_hidden);
140- // Core::get_proc("/client/verb/hidden").proc_table_entry->procFlags = 4;
141- // initialize_profiler_access();
142- // enable_crash_guard();
143- // optimizer_initialize();
144- // Core::Alert(Core::stringify({ 0x0C, 0x00 }));
145- // Core::Proc p = "/proc/pickdism";
146- // std::ofstream o("out.txt");
147- // for (Instruction& i : p.disassemble())
148- // {
149- // o << i.offset() << "\t\t\t" << i.bytes_str() << "\t\t\t" << i.opcode().mnemonic() << "\n";
150- // }
151- /* Core::Proc p = "/proc/bench_intrinsic_add";
152- Disassembly d = p.disassemble();
153- Core::Proc intrinsic_add = "/proc/__intrinsic_add_locals";
154- std::vector<std::uint32_t>* new_bytecode = new std::vector<std::uint32_t>;
155- for (int i = 0; i < d.size(); i++)
156- {
157- if (d.at(i) == CALLGLOB && d.at(i).bytes().at(2) == intrinsic_add.id)
158- {
159- Instruction first_arg = d.at(i - 2);
160- Instruction second_arg = d.at(i - 1);
161- Instruction destination = d.at(i + 1);
162- new_bytecode->resize(new_bytecode->size() - 6);
163- int intrinsic_op = Core::register_opcode("INTRINSIC_ADD_NUMBERS_"+std::to_string(rand()), _generate_number_op_localm_localn_store_localx(ADD, first_arg.bytes().at(2), second_arg.bytes().at(2), destination.bytes().at(2)));
164- new_bytecode->push_back(intrinsic_op);
165- i += 1;
166- }
167- else
168- {
169- for (unsigned int& byte : d.at(i).bytes())
170- {
171- new_bytecode->push_back(byte);
172- }
173- }
174- }
175- for (int i = 0; i < 10; i++)
176- {
177- new_bytecode->push_back(0x00);
178- }
179- p.set_bytecode(new_bytecode);
180- std::ofstream o("out.txt");
181- for (Instruction& i : Core::get_proc("/proc/bench_dm_add").disassemble())
182- {
183- o << i.offset() << "\t\t\t" << i.bytes_str() << "\t\t\t" << i.opcode().mnemonic() << "\n";
184- }*/ /*
185- bool find_unknowns = false;
186- if (find_unknowns)
187- {
188- std::ofstream log("unknown_opcodes.txt");
189- for (Core::Proc& p : Core::get_all_procs())
190- {
191- if (!p.name.empty() && p.name.back() == ')')
192- {
193- continue;
194- }
195- Disassembly d = p.disassemble();
196- for (Instruction& i : d)
197- {
198- if (i == UNK)
199- {
200- log << "Unknown instruction in " + p.name + "\n";
201- break;
202- }
203- }
204- }
205- log.close();
206- }*/
207-
208- // debugger_connect();
209- // Core::get_proc("/datum/explosion/New").extended_profile();
210- // Core::get_proc("/client/verb/test_reentry").extended_profile();
211- // Core::get_proc("/client/verb/test_extended_profiling").extended_profile();
212- // extended_profiling_procs[.id] = true;
213- // Core::get_proc("/proc/cheap_hypotenuse_hook").hook(cheap_hypotenuse);
214- // Core::get_proc("/proc/measure_get_variable").hook(measure_get_variable);
215- // Core::get_proc("/proc/laugh").hook(show_profiles);
216-
217- /* int hypotenuse_opcode = Core::register_opcode("CHEAP_HYPOTENUSE", cheap_hypotenuse_opcode);
218- Core::Proc& hypotenuse_bench = Core::get_proc("/proc/bench_cheap_hypotenuse_native");
219- Disassembly dis = hypotenuse_bench.disassemble();
220- for (Instruction& instr : dis)
221- {
222- if (instr == Bytecode::CALLGLOB)
223- {
224- instr = Instruction(hypotenuse_opcode);
225- break;
226- }
227- }
228- hypotenuse_bench.assemble(dis);*/
229106}
230107
231108void run_tests ()
0 commit comments