-
Notifications
You must be signed in to change notification settings - Fork 9
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
MOS65xx: Include mos65xx.h (WIP) #4
base: master
Are you sure you want to change the base?
Conversation
Starting to build a plugin around Capstone Signed-off-by: Paul McQuade <[email protected]>
Step 1 - Attempt to build plugin Signed-off-by: Paul McQuade <[email protected]>
Started structure of Plugin Signed-off-by: Paul McQuade <[email protected]>
CS_ARCH_MOS65XX Added to plugin Signed-off-by: Paul McQuade <[email protected]>
Create a Class for MOS65xx Signed-off-by: Paul McQuade <[email protected]>
Created a Lifter class Signed-off-by: Paul McQuade <[email protected]>
Doesn't output anything throught. Signed-off-by: Paul McQuade <[email protected]>
|
||
// Instruction is decoded, you can use Capstone API to analyze it | ||
|
||
RDContext_SetAddressAssembler(m_context, address, this->endianness() == Endianness_Big ? MOS65XXBE_ID : MOS65XXLE_ID); |
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.
This is used only in ARM, afaik is not neeed for MOS65XX, because it provides a single instruction set.
Tell REDasm to increase the view to the next possible instruction by calling
RDEmulateResult_SetSize(result, insn->size); // Next time "emulate" is called is after insn->size bytes
After that you need to classify instructions in order to have a detailed listing (more case you handle and more detailed will become), see here (it just a big switch case statement): https://github.com/REDasmOrg/REDasm-Assemblers/blob/db0d698029d6776f4b9f3612498439621b473987/capstonebundle/plugin/arm32/common.cpp
The easiest way is to begin to catch return, call and jump statement
RD_PLUGIN_ENTRY(RDEntryAssembler, mos65xxle, "MOS65xxx (Little Endian)"); | ||
mos65xxle.emulate = &emulate<CS_ARCH_MOS65XX, CS_MODE_LITTLE_ENDIAN>; | ||
mos65xxle.renderinstruction = &render<CS_ARCH_MOS65XX, CS_MODE_LITTLE_ENDIAN>; | ||
mos65xxle.lift = &lift<CS_ARCH_MOS65XX, CS_MODE_LITTLE_ENDIAN>; |
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 remove the lifter part, is not mandatory
void MOS65XX::render(const RDRendererParams* rp) | ||
{ | ||
// You can render instructions here | ||
auto* insn = this->decode(rp->address, &rp->view); |
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.
Try to show the instruction's mnemonic with RDRenderer_MnemonicWord
API:
Like here:
RDRenderer_MnemonicWord(rp->renderer, insn->mnemonic, ARM32Common::mnemonicTheme(insn)); |
not mandatory Signed-off-by: Paul McQuade <[email protected]>
@Dax89 |
Mmmmh, it's a bug. So restore the lifter part, I will investigate when I have some free time |
This reverts commit 36844b7.
Signed-off-by: Paul McQuade <[email protected]>
Yes, it looks ok. I have checked for "BVS" instruction (this one? https://www.c64-wiki.com/wiki/BVS): is it a conditional jump? RDEmulateResult_AddBranchTrue(result, jump_target);
RDEmulateResult_AddBranchFalse(result, address + insn->size); // If not jumps, try to emulate the next instruction It is very important to check for "return" type instructions too
With the If the decoded instruction is not a jump, call or return, the engine relies to the decoded instruction's size which is set by calling For example:
|
@Dax89 - Thanks for your help but for the |
It was just for reference: all The only APIs you need are |
@Dax89 |
Nothing, case MOS65XX_INS_BVS: {
RDEmulateResult_AddBranchTrue(result, mos65xx.operands[0].imm);
RDEmulateResult_AddBranchFalse(result, address + insn->size);
return;
} |
Added MOS65XX_INS_BVS case Signed-off-by: Paul McQuade <[email protected]>
RDRenderer_MnemonicWord API Signed-off-by: Paul McQuade <[email protected]>
@Dax89 Am i doing this the right way, the Render Part?
|
Yes, but you need to call |
Starting to build a plugin around Capstone
Signed-off-by: Paul McQuade [email protected]