-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Migrate from Capstone to Zydis (x86 architecture) #4832
base: dev
Are you sure you want to change the base?
Conversation
Changes in the tests/code :
|
Very well done. |
Please fix the compilation issues. see the CI jobs. also run clang format (via the python script) |
Yes, I did not get time yesterday. I will do it asap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice job! Looks good so far.
Regarding the renaming:
I think it is better if you add a file which maps ZYDIS_
enums to the X86_
enums. Simply for readability and less changes.
Building:
Capstone can be built without any x86 code. You just have to remove -DCAPSTONE_HAS_X86
in subprojects/packagefiles/capstone-*/meson.build
. This also makes the binary way smaller.
cc @wargio
subprojects/zydis.wrap
Outdated
directory = zydis | ||
patch-directory = zydis | ||
depth = 1 | ||
revision = master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any big change in the master
branch? Otherwise sticking to a released package (and using wrap-file
) is preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping on this one :)
Did we agreed on something and I just forgot it?
Hello, I am working on these and I will commit the changes soon. |
Ouh, nice. Didn't know it uses Meson as well. Why is cc @wargio For what to do about updating meson. But bumping the version seems fine to me. I build with |
Seems like we need the old meson version for TinyCC and old debian builds. So it must be the patch then :( |
It customises the build process, doesn't overwrite it.
Okay, i will look into this. There are a few things that old version of meson doesn't have like |
dont diff patch. just create a folder with the patched files and define it in the wrap file. this will overwrite the files in the pulled folder. |
The latest version of Zydis (4.1.0) does not support meson build system so we cannot use a wrap-file. |
capstone does not support meson neither but we use meson anyway. just create a meson.build file in the patch dir and add the sources and defines. Examples: |
8854385
to
ed87201
Compare
@wargio So the current issue with the builds is that there is no Zycore dependency installed in Zydis by default. To do that, we would have to build Zycore inside Zydis using another meson.build file. |
Why not just add a folder with the wrap file of the dependency within the patch folder of zydis? Or if available just use a source which contains all the deps needed. This is quite common |
Agree with @wargio. Meson has (luckily) the ability to make subprojects depend on subprojects. |
ed87201
to
75ecbfd
Compare
Hello. So I tried building zycore inside zydis but I faced the following issues:
I think there must definitely be a solution but I cannot seem to get it due to my inexperience in meson build system. So I would really like some help in this direction. As of now, I have pushed the changes with amalgamated form of zydis. In the meanwhile, I resolved ~150 tests that were mostly formatting related. There are still ~70 tests that I need to review and debug code accordingly. I'm working on it. Thanks. Edit : I think I merged dev into my branch as well. Should I remove it? |
3e72d6c
to
187ebe4
Compare
134a850
to
2702f06
Compare
@wargio, @notxvilka, @Rot127 I have resolved the tests. Please review the changes. Should I also refactor I will also remove the unused code asap. |
76 * pointers | ||
66 * pointers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you check what exactly is different? you can use the fl
commands and diff this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fl
result remains unchanged
0x00400730 f3c3 repz ret | ||
0x00400730 f3c3 ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, interesting change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, so many changes, great work. most of them looks good. i will take some days to review everything.
Could you do us a favour and try to use rz-ghidra and jsdec on various x86 binaries just to see if they crashes?
Yes, you can refactor that file. |
Yes, I will check. |
@tushar3q34 please rebase. |
2702f06
to
f9e83e3
Compare
f9e83e3
to
b31ab81
Compare
b31ab81
to
1e8b102
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only reviewed the first two commits, but so far fantastic job!
I have mostly nitpicks (they should be really quick to resolve, so don't be scared of the number :) ).
I can't see who made the original edits, so apologies if I requested changes to code not from you. Please be so kind and fix them anyways, since it improves the overall stability.
Please also compile Rizin with ASAN enabled (see BUILDING.md
) and run the asm
tests with the LEAK sanitizer enabled.
Also the x86 esil tests (db/analysis/x86*
).
You can ignore leaks which are not part of the x86 code (you can also suppress them: https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions).
Some general comments:
- Take care of marking all pointers as
const
if you know they should not change (be it during initialization or for function parameters). - Use
size_t
instead ofint
if you know the value should never be negative. - Initialize indices (
i
) of loops always within the loop. If they are not used outside of it.
subprojects/zydis.wrap
Outdated
directory = zydis | ||
patch-directory = zydis | ||
depth = 1 | ||
revision = master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping on this one :)
Did we agreed on something and I just forgot it?
struct Getarg { | ||
ZydisDecodedInstruction *zydecode; | ||
ZydisDecodedOperand *zydeop; | ||
int bits; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be a size_t
? bits
shouldn't be negative.
|
||
static void hidden_op(ZydisDecodedInstruction *zydecode, ZydisDecodedOperand *zydeop, int mode) { | ||
unsigned int mnemonic = zydecode->mnemonic; | ||
int regsz = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, size_t
.
static void opex(RzStrBuf *buf, X86ZYDISContext *zydx, int mode, ut64 addr) { | ||
ZydisDecodedInstruction *zydecode = zydx->zydecode; | ||
ZydisDecodedOperand *zydeop = zydx->zydeop; | ||
int i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not to be used outside of the loop. So please initialize it in the for
loop.
pj_end(pj); | ||
} | ||
|
||
static bool is_xmm_reg(ZydisDecodedOperand op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ZydisDecodedOperand op
case ZYDIS_MNEMONIC_PUSHFQ: | ||
switch (zydeop[0].type) { | ||
case ZYDIS_OPERAND_TYPE_MEMORY: | ||
if (zydeop[0].mem.disp.value && !zydeop[0].mem.base && !zydeop[0].mem.index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't assume here zydeop[0].mem.base
is 0 for the invalid case please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also for index
char mnemonic[256]; | ||
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL); | ||
ZydisFormatterFormatInstruction(&formatter, zydx->zydecode, zydx->zydeop, | ||
zydx->zydecode->operand_count, mnemonic, sizeof(mnemonic), addr, NULL); | ||
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE); | ||
op->mnemonic = rz_str_dup(mnemonic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly allocate to op->mnemonic
and pass it instead.
zydx->zydecode = RZ_NEW0(ZydisDecodedInstruction); | ||
zydx->zydeop = RZ_NEWS(ZydisDecodedOperand, ZYDIS_MAX_OPERAND_COUNT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you free them before returning. Please don't allocate them on the heap then. Just allocate them on the stack and assign the pointer here. You can set them to NULL
before returning.
@Rot127
Would it be possible to review from the latest commit? Lots of changes since the first few, especially in |
Your checklist for this pull request
Detailed description
ZydisDecodedInstruction
andZydisDecodedOperand
instead ofcs_x86
andcs_x86_op
TODO in further commits :
lcall
,ljump
etc)analysis_x86
andasm_x86
filesTest plan
...
Closing issues
closes #4709
...