C++/c# - 如何使用顶部反汇编器
我正在一个项目,它需要一个反汇编器conevert机器代码汇编指令...我决定使用任何开源反汇编程序,我试过zydis和capstone ...他们似乎没有工作,我使用Visual Studio 15个专业......我已经尝试过做github上顶峰的例子,但它没有工作,我用C++绑定和验证码:::C++/c# - 如何使用顶部反汇编器
#pragma once #include <cccapstone/cppbindings/X86Disasm.hh>
namespace CapstoneBindingsTest
{
#define RANDOM_CODE "\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x07\xf7\xeb\x2a\xff\xff\x7f\x57\xe3\x01\xff\xff\x7f\x57\xeb\x00\xf0\x00\x00\x24\xb2\x4f\x00\x78"
static
size_t
SkipDataCallback(
__in const uint8_t *buffer,
__in uint64_t offset,
__in void *p
)
{
printf("\nskip data callback ! : %x %p !", offset, buffer);
return 1;//just for test, skip 1instr *data*
}
static
void
DisasmData(
__in CCsDisasm<CX86InsClass>& dis,
__in const void* code,
__in size_t size
)
{
dis.SetSyntax(cs_opt_value::CS_OPT_SYNTAX_INTEL);
auto insn = dis.Disasm(code, size);
if (!insn.get())
return;
printf("\n\nDISASM :\n\n");
for (size_t i = 0; i < insn->Count; i++)
{
printf("-> 0x%p:\t%s\t%s\n", insn->Instructions(i)->address, insn->Instructions(i)->mnemonic, insn->Instructions(i)->op_str);
//TODO
#if 0
if (!insn->Instructions(i).IsInInsGroup(x86_insn_group::X86_GRP_JUMP))
continue;
printf("\nCONTROL FLOW CHANGE instruction detected!\n");
printf("-> 0x%p:\t%s\t%s\n", insn->Instructions(i)->address, insn->Instructions(i)->mnemonic, insn->Instructions(i)->op_str);
#endif
}
}
static
void
X64Disasm(
__in const void* code,
__in size_t size,
__in bool allInfo = false
)
{
CX86Disasm64 dis;
if (dis.GetError())
return;
DisasmData(dis, code, size);
}
static
void
X64DisasmCallback(
__in const void* code,
__in size_t size,
__in bool allInfo = false
)
{
CX86Disasm64 dis;
if (dis.GetError())
return;
if (allInfo)
dis.SetDetail(cs_opt_value::CS_OPT_ON);
dis.SetSkipDataCallback(cs_opt_skipdata{ ".UNKOWNBYTES : ", SkipDataCallback, nullptr });
DisasmData(dis, code, size);
}
};
我复制并将cppbinginds文件夹粘贴到我的项目文件夹中,并尝试编译win32控制台应用程序的代码以及稍后的clr控制台应用程序,但是我为变量insn和其他一些人获取了多个错误...我也尝试了zydis的此代码:: :
#include <stdio.h> #include <Zydis/Zydis.h>
int main()
{
uint8_t data[] =
{
0x51, 0x8D, 0x45, 0xFF, 0x50, 0xFF, 0x75, 0x0C, 0xFF, 0x75,
0x08, 0xFF, 0x15, 0xA0, 0xA5, 0x48, 0x76, 0x85, 0xC0, 0x0F,
0x88, 0xFC, 0xDA, 0x02, 0x00
};
// Initialize decoder context.
ZydisDecoder decoder;
ZydisDecoderInit(
&decoder,
ZYDIS_MACHINE_MODE_LONG_64,
ZYDIS_ADDRESS_WIDTH_64);
// Initialize formatter. Only required when you actually plan to
// do instruction formatting ("disassembling"), like we do here.
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
// Loop over the instructions in our buffer.
uint64_t instructionPointer = 0x007FFFFFFF400000;
uint8_t* readPointer = data;
size_t length = sizeof(data);
ZydisDecodedInstruction instruction;
while (ZYDIS_SUCCESS(ZydisDecoderDecodeBuffer(
&decoder, readPointer, length, instructionPointer, &instruction)))
{
// Print current instruction pointer.
printf("%016" PRIX64 " ", instructionPointer);
// Format & print the binary instruction
// structure to human readable format.
char buffer[256];
ZydisFormatterFormatInstruction(
&formatter, &instruction, buffer, sizeof(buffer));
puts(buffer);
readPointer += instruction.length;
length -= instruction.length;
instructionPointer += instruction.length;
}
}
我期望得到的结果是:::
007FFFFFFF400000 push rcx 007FFFFFFF400001 lea eax, [rbp-0x01]
007FFFFFFF400004 push rax
007FFFFFFF400005 push qword ptr [rbp+0x0C]
007FFFFFFF400008 push qword ptr [rbp+0x08]
007FFFFFFF40000B call [0x008000007588A5B1]
007FFFFFFF400011 test eax, eax
007FFFFFFF400013 js 0x007FFFFFFF42DB15
,但我得到的编译错误,我不记得的错误,但我会尽快为我去我的电脑更新这个帖子...
所以我只是想知道我做错了什么,或者如果有更好的示例我可以尝试,我不希望任何人为我构造整个代码...我只想能够将字节转换为一个地址到窗口汇编指令,任何帮助将不胜感激。任何在C++/c#/ python中的示例答案将不胜感激... thnx提前
ps,plz不要downvote这篇文章,因为你不喜欢/你认为这是一个noob问题,我只是想学习,我已经做了研究,就像我可能会
也,代码样本从GitHub
得到回答:
答案很简单,使用C#,安装NuGet包Gee.External.Capstone
后来看到“简单的例子”从their GitHub page。
如果您需要拆解实际的Win32模块而不仅仅是字节数组,请使用PeNet library解析文件并找到.text
部分和my utility class进行反汇编。
以上是 C++/c# - 如何使用顶部反汇编器 的全部内容, 来源链接: utcz.com/qa/257626.html