Comments (8)
Hi,
what would be the output that is expected it your case? AsmJit expects that the jump can be encoded by using relative addressing, but supports trampolines in case it's not possible (you hit it). If you modify your code slightly:
a.push(rax);
a.pop(rax);
a.jmp(&testFunc);
a.ret();
you would see that trampolines are put at the end of the machine code generated:
push rax
pop rax
jmp HERE
ret
HERE:
jmp qword ptr [testFuncPtr]
; 95 20 2a 3f 01 00 00 00
Well, I don't know how to solve this better.
Basically there are some other ways, like this post http://www.ragestorm.net/blogs/?p=107 , but all of the solutions have pros/cons. Basically in assembler I can't trash any register by doing a jmp.
from asmjit.
Hey, I'm aware that trashing a register is not an option, however it appears that at some cases it skips all the code by jumping around it. I'm not sure yet how to exactly reproduce the problem but it seems related to the trampolines.
from asmjit.
Well,
I think that the best solution in this case would be to remove the first jump, leaving just:
jmp qword ptr [testFuncPtr]
But the problem is that relocation is the last step, thus, it can't modify the size of the original jmp
instruction. Let me think about other possibilities.
from asmjit.
Well,
I was thinking about this and I think I can add more options to asmjit. Basically if I increase an instruction size from 5 to 6 bytes in 64-bit mode (when absolute address is used) I can encode jmp qword ptr[...] directly, thus removing the need for a second jump (and basically saving 6 bytes). The added byte would be REX prefix (which is fine).
What do you think about this solution?
from asmjit.
Sounds good, as long the jmp is no longer making all my code skip 👍
from asmjit.
My workaround is following:
_obfs(a, a.push(*rax));
_obfs(a, a.push(*zcx));
_obfs(a, a.pushf());
_obfs(a, a.mov(*rax, Imm(imageBase)));
_obfs(a, a.mov(*zcx, returnRva));
_obfs(a, a.add(*rax, *zcx));
_obfs(a, a.popf());
_obfs(a, a.pop(*zcx));
_obfs(a, a.xchg(qword_ptr(*zsp), *rax));
_obfs(a, a.ret());
Don't mind the pointers, I had to avoid initterm for other reasons.
from asmjit.
Let me know if my changes improved the behavior. I'm not sure if we can get rid off implicit trampolines in case that the jump is unencodable (and I'm not sure if this can be actually called trampoline after second jump disappeared).
from asmjit.
Seems solved.
from asmjit.
Related Issues (20)
- How can I convert a byte array to assembly code? HOT 3
- parse "faddp st1, st0" and "fsubp st1, st0" instruction failed HOT 1
- Unexpected error when load label address to register in AArch64 HOT 3
- InvalidDisplacement error when use loop instruction HOT 3
- Calling void function on a64 (android) not working HOT 2
- LAHF issue with x86_64 compiler HOT 2
- Return "Segmentation fault" when use std instruction HOT 4
- Jmp to label size HOT 3
- How to load the address of a label to a register? HOT 1
- "memfd_create() called without MFD_EXEC or MFD_NOEXEC_SEAL set" HOT 9
- No matter what I do. I am not able to get it working in my C++ CLI project. HOT 3
- Build Problem: Android Ndk build failed HOT 1
- Invalid movzx instruction generated by x86 EmitHelper::emitArgMove HOT 8
- Liveness analysis differs in Release mode vs Debug mode HOT 19
- calling names when use call instruction HOT 2
- Are the generated ISA databases still in the public domain? HOT 3
- Ports Meta Issue
- mov eax,[r11+rcx*4+00004C28] how? HOT 2
- [BUG] jmp far & call far (FF25 00000000 ptr & FF15 02000000 ptr) HOT 6
- The correctness question of InstInfo for sub and sub instructions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asmjit.