-
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
Open
paulmcquad
wants to merge
12
commits into
REDasmOrg:master
Choose a base branch
from
paulmcquad:MOS65xx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cefe490
MOS65xx: Include mos65xx.h (WIP)
paulmcquad 911cf01
MOS65xx Folder (WIP) - Crashes Build
paulmcquad 0fa5bc7
MOS65xx Plugin - Init (WIP) - Crashes Build
paulmcquad 0688e4c
MOS65xx Plugin 2 - Arch Setup (WIP)
paulmcquad 25b0456
MOS65xx Plugin 3 - Class Setup (WIP)
paulmcquad 632348c
MOS65xx Plugin 4 - lift function (WIP)
paulmcquad f12c34b
MOS65xx Plugin 4 - GUI Support (FIX Build)
paulmcquad 36844b7
MOS65xx Plugin 5 - Remove Lifter Part
paulmcquad 92e4890
Revert "MOS65xx Plugin 5 - Remove Lifter Part"
paulmcquad 47c8c3b
MOS65xx Plugin 6 - Emulate Part
paulmcquad c5c3eba
MOS65xx Plugin 6.1 - Emulate Part Branch
paulmcquad ca2052b
MOS65xx Plugin 7 - Render Part
paulmcquad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ | |
|
||
#include "arm/common.h" | ||
#include "arm/arm.h" | ||
|
||
#include "mos65xx/mos65xx.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||
// mos65xx.cpp | ||||
#include "mos65xx.h" | ||||
|
||||
MOS65XX::MOS65XX(RDContext* ctx, cs_mode mode): Capstone(ctx, CS_ARCH_MOS65XX, mode) { } | ||||
|
||||
void MOS65XX::emulate(RDEmulateResult* result) | ||||
{ | ||||
rd_address address = RDEmulateResult_GetAddress(result); | ||||
auto* insn = this->decode(address, RDEmulateResult_GetView(result)); | ||||
if(!insn) return; | ||||
|
||||
// Instruction is decoded, you can use Capstone API to analyze it | ||||
|
||||
RDContext_SetAddressAssembler(m_context, address, this->endianness() == Endianness_Big ? MOS65XXBE_ID : MOS65XXLE_ID); | ||||
if(!this->decode(address, RDEmulateResult_GetView(result))) return; | ||||
|
||||
RDEmulateResult_SetSize(result, m_insn->size); | ||||
|
||||
} | ||||
|
||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Try to show the instruction's mnemonic with Like here:
|
||||
|
||||
} | ||||
|
||||
void MOS65XX::lift(const Capstone* capstone, rd_address address, const RDBufferView* view, RDILFunction* il) { MOS65XXLifter::lift(capstone, address, view, il); } | ||||
|
||||
|
||||
//ARMLE::ARMLE(RDContext* ctx): ARM(ctx, CS_MODE_LITTLE_ENDIAN) { } | ||||
//ARMBE::ARMBE(RDContext* ctx): ARM(ctx, CS_MODE_BIG_ENDIAN) { } | ||||
|
||||
MOS65XXLE::MOS65XXLE(RDContext* ctx): MOS65XX(ctx, CS_MODE_LITTLE_ENDIAN) { } | ||||
MOS65XXBE::MOS65XXBE(RDContext* ctx): MOS65XX(ctx, CS_MODE_BIG_ENDIAN) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// mos65xx.h | ||
#pragma once | ||
|
||
#define MOS65XXLE_USERDATA "mos65xxle_userdata" | ||
#define MOS65XXBE_USERDATA "mos65xxbe_userdata" | ||
|
||
#define MOS65XXLE_ID "mos65xxle" | ||
#define MOS65XXBE_ID "mos65xxbe" | ||
|
||
#include <rdapi/rdapi.h> | ||
#include <utility> | ||
#include "../capstone.h" | ||
|
||
class MOS65XX: public Capstone { | ||
public: | ||
// Capstone(RDContext* ctx); // There is also a "cs_mode" argument, I don't know if this architecture needs it | ||
MOS65XX(RDContext* ctx, cs_mode mode); | ||
void emulate(RDEmulateResult* result) override; // This implements the algorithm (jumps, calls etc) | ||
void render(const RDRendererParams* rp) override; // This renders instructions visually | ||
void lift(const Capstone* capstone, rd_address address, const RDBufferView* view, RDILFunction* il) override; | ||
}; | ||
|
||
|
||
class MOS65XXLifter | ||
{ | ||
public: | ||
MOS65XXLifter() = delete; | ||
static void lift(const Capstone* capstone, rd_address address, const RDBufferView* view, RDILFunction* il); | ||
|
||
private: | ||
static RDILExpression* liftOperand(const Capstone* capstone, rd_address address, const cs_insn* insn, size_t idx, const RDILFunction* il); | ||
}; | ||
|
||
|
||
class MOS65XXLE: public MOS65XX { public: MOS65XXLE(RDContext* ctx); }; | ||
class MOS65XXBE: public MOS65XX { public: MOS65XXBE(RDContext* ctx); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ static void initUserData() | |
CS_ITEMS[hashArch(CS_ARCH_ARM64, CS_MODE_BIG_ENDIAN)] = { ARM64BE_USERDATA, [](RDContext* ctx) { return new ARM64BE(ctx); } }; | ||
CS_ITEMS[hashArch(CS_ARCH_ARM, CS_MODE_LITTLE_ENDIAN)] = { ARM32LE_USERDATA, [](RDContext* ctx) { return new ARM32LE(ctx); } }; | ||
CS_ITEMS[hashArch(CS_ARCH_ARM, CS_MODE_BIG_ENDIAN)] = { ARM32BE_USERDATA, [](RDContext* ctx) { return new ARM32BE(ctx); } }; | ||
|
||
// Editing | ||
CS_ITEMS[hashArch(CS_ARCH_MOS65XX, CS_MODE_LITTLE_ENDIAN)] = { MOS65XXLE_USERDATA, [](RDContext* ctx) { return new MOS65XXLE(ctx); } }; | ||
CS_ITEMS[hashArch(CS_ARCH_MOS65XX, CS_MODE_BIG_ENDIAN)] = { MOS65XXBE_USERDATA, [](RDContext* ctx) { return new MOS65XXBE(ctx); } }; | ||
// End Editing | ||
|
||
CS_ITEMS[hashArch(CS_ARCH_ARM, CS_MODE_THUMB | CS_MODE_LITTLE_ENDIAN)] = { THUMB32LE_USERDATA, [](RDContext* ctx) { return new ThumbLE(ctx); } }; | ||
CS_ITEMS[hashArch(CS_ARCH_ARM, CS_MODE_THUMB | CS_MODE_BIG_ENDIAN)] = { THUMB32BE_USERDATA, [](RDContext* ctx) { return new ThumbBE(ctx); } }; | ||
} | ||
|
@@ -110,6 +116,26 @@ void rdplugin_init(RDContext*, RDPluginModule* pm) | |
arm32be.bits = 32; | ||
RDAssembler_Register(pm, &arm32be); | ||
|
||
// Editing | ||
|
||
RD_PLUGIN_ENTRY(RDEntryAssembler, mos65xxbe, "MOS65xxx (Big Endian)"); | ||
mos65xxbe.emulate = &emulate<CS_ARCH_MOS65XX, CS_MODE_BIG_ENDIAN>; | ||
mos65xxbe.renderinstruction = &render<CS_ARCH_MOS65XX, CS_MODE_BIG_ENDIAN>; | ||
mos65xxbe.lift = &lift<CS_ARCH_MOS65XX, CS_MODE_BIG_ENDIAN>; | ||
mos65xxbe.bits = 8; | ||
RDAssembler_Register(pm, &mos65xxbe); | ||
|
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the lifter part, is not mandatory |
||
mos65xxle.bits = 8; | ||
RDAssembler_Register(pm, &mos65xxle); | ||
|
||
|
||
// Editing Ended | ||
|
||
RD_PLUGIN_ENTRY(RDEntryAssembler, thumble, "THUMB (Little Endian)"); | ||
thumble.emulate = &emulate<CS_ARCH_ARM, CS_MODE_THUMB | CS_MODE_LITTLE_ENDIAN>; | ||
thumble.renderinstruction = &render<CS_ARCH_ARM, CS_MODE_THUMB | CS_MODE_LITTLE_ENDIAN>; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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