@@ -238,10 +238,77 @@ void InitFunction_and_LiftInstructions(const ZyanU64 runtime_address,
238238 return ;
239239}
240240
241+ int testInit () {
242+ llvm::LLVMContext context;
243+ std::string mod_name = " my_lifting_module" ;
244+ llvm::Module lifting_module = llvm::Module (mod_name.c_str (), context);
245+
246+ std::vector<llvm::Type*> argTypes;
247+ argTypes.push_back (llvm::Type::getInt64Ty (context));
248+ argTypes.push_back (llvm::Type::getInt64Ty (context));
249+ argTypes.push_back (llvm::Type::getInt64Ty (context));
250+ argTypes.push_back (llvm::Type::getInt64Ty (context));
251+ argTypes.push_back (llvm::Type::getInt64Ty (context));
252+ argTypes.push_back (llvm::Type::getInt64Ty (context));
253+ argTypes.push_back (llvm::Type::getInt64Ty (context));
254+ argTypes.push_back (llvm::Type::getInt64Ty (context));
255+ argTypes.push_back (llvm::Type::getInt64Ty (context));
256+ argTypes.push_back (llvm::Type::getInt64Ty (context));
257+ argTypes.push_back (llvm::Type::getInt64Ty (context));
258+ argTypes.push_back (llvm::Type::getInt64Ty (context));
259+ argTypes.push_back (llvm::Type::getInt64Ty (context));
260+ argTypes.push_back (llvm::Type::getInt64Ty (context));
261+ argTypes.push_back (llvm::Type::getInt64Ty (context));
262+ argTypes.push_back (llvm::Type::getInt64Ty (context));
263+ argTypes.push_back (llvm::PointerType::get (context, 0 ));
264+ argTypes.push_back (llvm::PointerType::get (context, 0 )); // temp fix TEB
265+
266+ auto functionType =
267+ llvm::FunctionType::get (llvm::Type::getInt64Ty (context), argTypes, 0 );
268+
269+ const std::string function_name = " main" ;
270+ auto function =
271+ llvm::Function::Create (functionType, llvm::Function::ExternalLinkage,
272+ function_name.c_str (), lifting_module);
273+ const std::string block_name = " entry" ;
274+ auto bb = llvm::BasicBlock::Create (context, block_name.c_str (), function);
275+
276+ llvm::InstSimplifyFolder Folder (lifting_module.getDataLayout ());
277+ llvm::IRBuilder<llvm::InstSimplifyFolder> builder =
278+ llvm::IRBuilder<llvm::InstSimplifyFolder>(bb, Folder);
279+
280+ // auto RegisterList = InitRegisters(builder, function, runtime_address);
281+
282+ lifterClass* main = new lifterClass (builder, 0x133700 );
283+ // main->InitRegisters(function, );
284+ // main->blockInfo = BBInfo(0x133700, bb);
285+
286+ auto tester = Tester (main, true );
287+ std::vector<uint8_t > bytes = {0x48 , 0x01 , 0xc8 };
288+ tester.setRegister (ZYDIS_REGISTER_RAX, 5 );
289+ tester.setRegister (ZYDIS_REGISTER_RCX, 5 );
290+ tester.disassembleBytesAndLift (bytes);
291+ auto a = tester.getRegister (ZYDIS_REGISTER_RAX);
292+ tester.getRegister (ZYDIS_REGISTER_RCX);
293+
294+ if (auto a_c = dyn_cast<ConstantInt>(a)) {
295+ return !(a_c->equalsInt (10 ));
296+ }
297+ return 1 ;
298+ }
299+
300+ // #define TEST
301+
241302int main (int argc, char * argv[]) {
242303 vector<string> args (argv, argv + argc);
243304 argparser::parseArguments (args);
244305 timer::startTimer ();
306+
307+ #ifdef MERGEN_TEST
308+ if (1 == 1 )
309+ return testInit ();
310+ #endif
311+
245312 // use parser
246313 if (args.size () < 3 ) {
247314 cerr << " Usage: " << args[0 ] << " <filename> <startAddr>" << endl;
0 commit comments