Zhang Qiuyu
2004-Sep-21 21:25 UTC
[LLVMdev] Re:Re:Is there any way to modify basic block like adding junk code
Thanks Chris. I did inserting function into code before using the way you mentioned, such as call a external function. But coud I insert some assemble instructions into *.bc ? what I want to do is to implement polymorphic engine like ADM. It can change the binary code which looks like different but the functionality is exactly same. The simple way to do it is to add some junk code like NOP( 0x90) or dead code. But it is easy to identify the different binary codes by the above way which have same functionality. So there are some other ways to do it, however these are a little difficult. For example, after you analyse the a bunch of codes in one BB, if there are some independent code, we can shuffle those codes which will change the final binary code and keep same functionality.Or we can find some alternative codes to replace it...... Does llvm have the option for these? Thanks.> On Mon, 20 Sep 2004, Zhang Qiuyu wrote: > > > Is there any way to modify code like adding junk code or mess up the > > order of a bunch of codes(in same basic block) which is no dependency? I > > saw some options like -dce -deadargelim for 'opt' , but what I want is > > to reverse to do it. I mean adding some dead code or junk code. Actually > > what I want is to implement a ploymorphic engine. Coud I do those by > > using llvm? > > Sure, modifying and adding to the LLVM IR is easy. Please read the > programmers manual for more info: > > http://llvm.org/docs/ProgrammersManual.html > > For example, "Creating and inserting new Instructions" might be useful: > http://llvm.org/docs/ProgrammersManual.html#schanges_creating >
Misha Brukman
2004-Sep-21 21:33 UTC
[LLVMdev] Re:Re:Is there any way to modify basic block like adding junk code
On Tue, Sep 21, 2004 at 02:25:32PM -0700, Zhang Qiuyu wrote:> I did inserting function into code before using the way you mentioned, > such as call a external function. But coud I insert some assemble > instructions into *.bc ?You cannot insert NATIVE assembly instructions at this time, but you can insert LLVM assembly instructions into a .bc (LLVM bytecode) file.> what I want to do is to implement polymorphic engine like ADM. It can > change the binary code which looks like different but the > functionality is exactly same. The simple way to do it is to add some > junk code like NOP( 0x90) or dead code. But it is easy to identify the > different binary codes by the above way which have same functionality. > So there are some other ways to do it, however these are a little > difficult. For example, after you analyse the a bunch of codes in one > BB, if there are some independent code, we can shuffle those codes > which will change the final binary code and keep same functionality.Or > we can find some alternative codes to replace it...... > > Does llvm have the option for these?As Chris mentioned in his previous email, the links will point you to ways you can modify the LLVM IR (which is the LLVM assembly language). Perhaps some clarification is in order: * LLVM bytecode contains a binary version of LLVM assembly instructions These files are usually with a .bc extension * If you disassemble LLVM bytecode, you get an LLVM text assembly (.ll) * The compiler IR is the SAME as the LLVM assembly instructions, there is a 1:1 mapping These 3 ways of representing LLVM code all have a 1:1 mapping between each other. So when we say "you can modify the LLVM IR" what we're also saying is that you can modify the LLVM assembly instructions, because they are the same thing. However, at this point in time, you cannot mix native machine assembly with LLVM bytecode in the same file, if that is what you're looking for. Instead, what you could do is re-write LLVM bytecode to have additional dead code, or "junk" code as you put it, or reorganize the LLVM code as you wish. You can then use one of our native machine backends to generate code, statically (via LLC) or dynamically (via LLI). Hope that helps, -- Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
Seemingly Similar Threads
- [LLVMdev] Is there any way to modify basic block like adding junk code or ...
- [LLVMdev] How could I get memory address for each basic block?
- [LLVMdev] How could I get memory address for each basic block?
- [LLVMdev] How could I get memory address for each basic block?
- [LLVMdev] How could I get memory address for each basic block?