-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BasicBlock class #1121
Comments
First example. Disassembling and print a basic blockusing namespace triton::arch;
// Creating the block
BasicBlock block = BasicBlock({
Instruction((unsigned char *)"\x89\xd0", 2), /* mov eax, edx */
Instruction((unsigned char *)"\x80\xf4\x99", 3), /* xor ah, 0x99 */
Instruction((unsigned char *)"\x85\xc0", 2), /* test eax, eax */
Instruction((unsigned char *)"\x74\x08", 2), /* jz 10 */
});
// Disassemble the block
api.disassembly(block);
// Print the block
std::cout << block << std::endl;
// Result:
// 0x0: mov eax, edx
// 0x2: xor ah, 0x99
// 0x5: test eax, eax
// 0x7: je 0x11 Disassembling an instruction and add it to the block// Create an instruction
auto i = Instruction((unsigned char *)"\x90", 1); /* nop */
// Disass the instruction
api.disassembly(i);
// Add it 3 times to the block
block.add(i);
block.add(i);
block.add(i);
// Print the block
std::cout << block << std::endl;
// Result
// 0x0: mov eax, edx
// 0x2: xor ah, 0x99
// 0x5: test eax, eax
// 0x7: je 0x11
// 0x9: nop
// 0xa: nop
// 0xb: nop Disassembling a block from a base addressapi.disassembly(block, 0x1000);
std::cout << block << std::endl;
// Result
// 0x1000: mov eax, edx
// 0x1002: xor ah, 0x99
// 0x1005: test eax, eax
// 0x1007: je 0x1011
// 0x1009: nop
// 0x100a: nop
// 0x100b: nop Process a block// Removing the instruction JE in order to not have instruction after a branch instruction
// Note that I could have also removed NOPs instead of the the JE.
block.remove(3);
// Process the block
// processing() raises an exception if there are instructions after a branch instruction.
// You can also execute a block which do not contains branch instruction.
api.processing(block); |
@SweetVishnya, when implementing this I remembered those lines you added months ago. I know you use those methods and I'm wondering if we can return a |
Actually, we do not use that method :P We manage memory mapped files and get single instruction after insruction from it and manually call processing instruction-level. |
Introducing basic blocks could bring cool features in the future. Currently i'm adding this to perform dead code elimination but it can be used in the future to represent CFG for example.
The text was updated successfully, but these errors were encountered: