找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 14597|回复: 2

简单套用BeaEngine实现VB Disassembler

[复制链接]
发表于 2016-3-27 01:29:23 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 tangptr@126.com 于 2016-3-27 01:29 编辑

BeaEngine可谓是一个极其简单实用的一个反汇编引擎了,这里呢本人用VB制作了一个反汇编器,某些原因呢只做Win32的。
首先把网上的原版BeaEngine.lib下载下来,然后用它包装到到DLL里方便我们调用。
官方的BeaEngine.h是用来调用BeaEngine的,这里我们有必要把它翻译成VB的代码,这也挺耗时的,翻译结果如下。
  1. Option Explicit
  2. Public Declare Function Disasm Lib "BeaEngine.dll" Alias "_Disasm@4" (ByRef pDisasm As Disasm) As Integer
  3. Public Type REX_STRUCT
  4.     W As Byte
  5.     R As Byte
  6.     X As Byte
  7.     B As Byte
  8.     State As Byte
  9. End Type

  10. Public Type PRIFIX_INFO
  11.     Number As Integer
  12.     NbUndefined As Integer
  13.     LockPrefix As Byte
  14.     OperandSize As Byte
  15.     AddressSize As Byte
  16.     RepnePrefix As Byte
  17.     RepPrefix As Byte
  18.     FSPrefix As Byte
  19.     SSPrefix As Byte
  20.     GSPrefix As Byte
  21.     ESPrefix As Byte
  22.     CSPrefix As Byte
  23.     DSPrefix As Byte
  24.     BranchTaken As Byte
  25.     BranchNotTaken As Byte
  26.     Rex As REX_STRUCT
  27. End Type

  28. Public Type EFL_STRUCT
  29.     OF As Byte
  30.     SF As Byte
  31.     ZF As Byte
  32.     AF As Byte
  33.     PF As Byte
  34.     CF As Byte
  35.     TF As Byte
  36.     IF As Byte
  37.     DF As Byte
  38.     NT As Byte
  39.     RF As Byte
  40.     Alignment As Byte
  41. End Type

  42. Public Type MEMORY_TYPE
  43.     BaseRegister As Long
  44.     IndexRegister As Long
  45.     Scale As Long
  46.     DisplacementLow As Long
  47.     DisplacementHigh As Long
  48. End Type

  49. Public Type INSTRTTYPE
  50.     Category As Long
  51.     Opcode As Long
  52.     Mnemonic(1 To 16) As Byte
  53.     BranchType As Long
  54.     Flags As EFL_STRUCT
  55.     AddrValueLow As Long
  56.     AddrValueHigh As Long
  57.     ImmediateLow As Long
  58.     ImmediateHigh As Long
  59.     ImplicitModifiedRegs As Long
  60. End Type

  61. Public Type ARGTYPE
  62.     ArgMnemonic(1 To 32) As Byte
  63.     ARGTYPE As Long
  64.     ArgSize As Long
  65.     ArgPosition As Long
  66.     AccessMode As Long
  67.     Memory As MEMORY_TYPE
  68.     SegmentReg As Long
  69. End Type

  70. Public Type Disasm
  71.     EIP As Long
  72.     VirtualAddressLow As Long
  73.     VirtualAddressHigh As Long
  74.     SecurityBlock As Long
  75.     CompleteInstr(1 To 64) As Byte
  76.     Archi As Long
  77.     OptionsLow As Long
  78.     OptionsHigh As Long
  79.     Instruction As INSTRTTYPE
  80.     Argument1 As ARGTYPE
  81.     Argument2 As ARGTYPE
  82.     Argument3 As ARGTYPE
  83.     Prefix As PRIFIX_INFO
  84.     Reserved(1 To 40) As Long
  85. End Type

  86. Public Const ESReg = 1
  87. Public Const DSReg = 2
  88. Public Const FSReg = 3
  89. Public Const GSReg = 4
  90. Public Const CSReg = 5
  91. Public Const SSReg = 6

  92. Public Const InvalidPrefix = 4
  93. Public Const SuperfluousPrefix = 2
  94. Public Const NotUsedPrefix = 0
  95. Public Const MandatoryPrefix = 8
  96. Public Const InUsePrefix = 1

  97. Public Const LowPosition = 0
  98. Public Const HighPosition = 1

  99. Public Enum INSTRUCTION_TYPE
  100.     GENERAL_PURPOSE_INSTRUCTION = &H10000
  101.     FPU_INSTRUCTION = &H20000
  102.     MMX_INSTRUCTION = &H40000
  103.     SSE_INSTRUCTION = &H80000
  104.     SSE2_INSTRUCTION = &H100000
  105.     SSE3_INSTRUCTION = &H200000
  106.     SSSE3_INSTRUCTION = &H400000
  107.     SSE41_INSTRUCTION = &H800000
  108.     SSE42_INSTRUCTION = &H1000000
  109.     SYSTEM_INSTRUCTION = &H2000000
  110.     VM_INSTRUCTION = &H4000000
  111.     UNDOCUMENTED_INSTRUCTION = &H8000000
  112.     AMD_INSTRUCTION = &H10000000
  113.     ILLEGAL_INSTRUCTION = &H20000000
  114.     AES_INSTRUCTION = &H40000000
  115.     CLMUL_INSTRUCTION = &H80000000
  116.     DATA_TRANSFER = &H1
  117.     ARITHMETIC_INSTRUCTION
  118.     LOGICAL_INSTRUCTION
  119.     SHIFT_ROTATE
  120.     BIT_UInt8
  121.     CONTROL_TRANSFER
  122.     STRING_INSTRUCTION
  123.     InOutINSTRUCTION
  124.     ENTER_LEAVE_INSTRUCTION
  125.     FLAG_CONTROL_INSTRUCTION
  126.     SEGMENT_REGISTER
  127.     MISCELLANEOUS_INSTRUCTION
  128.     COMPARISON_INSTRUCTION
  129.     LOGARITHMIC_INSTRUCTION
  130.     TRIGONOMETRIC_INSTRUCTION
  131.     UNSUPPORTED_INSTRUCTION
  132.     LOAD_CONSTANTS
  133.     FPUCONTROL
  134.     STATE_MANAGEMENT
  135.     CONVERSION_INSTRUCTION
  136.     SHUFFLE_UNPACK
  137.     PACKED_SINGLE_PRECISION
  138.     SIMD128bits
  139.     SIMD64bits
  140.     CACHEABILITY_CONTROL
  141.     FP_INTEGER_CONVERSION
  142.     SPECIALIZED_128bits
  143.     SIMD_FP_PACKED
  144.     SIMD_FP_HORIZONTAL
  145.     AGENT_SYNCHRONISATION
  146.     PACKED_ALIGN_RIGHT
  147.     PACKED_SIGN
  148.     PACKED_BLENDING_INSTRUCTION
  149.     PACKED_TEST
  150.     PACKED_MINMAX
  151.     HORIZONTAL_SEARCH
  152.     PACKED_EQUALITY
  153.     STREAMING_LOAD
  154.     INSERTION_EXTRACTION
  155.     DOT_PRODUCT
  156.     SAD_INSTRUCTION
  157.     ACCELERATOR_INSTRUCTION
  158.     ROUND_INSTRUCTION
  159. End Enum

  160. Public Enum EFLAGS_STATE
  161.     TE = 1
  162.     MO = 2
  163.     RE = 4
  164.     SE = 8
  165.     UN = &H10
  166.     PR = &H20
  167. End Enum

  168. Public Enum ARGUMENTS_TYPE
  169.     NO_ARGUMENT = &H10000000
  170.     REGISTER_TYPE = &H20000000
  171.     MEMORY_TYPE = &H40000000
  172.     CONSTANT_TYPE = &H80000000
  173.     MMX_REG = &H10000
  174.     GENERAL_REG = &H20000
  175.     FPU_REG = &H40000
  176.     SSE_REG = &H80000
  177.     CR_REG = &H100000
  178.     DR_REG = &H200000
  179.     SPECIAL_REG = &H400000
  180.     MEMORY_MANAGEMENT_REG = &H800000
  181.     SEGMENT_REG = &H1000000
  182.     RELATIVE_ = &H4000000
  183.     ABSOLUTE_ = &H8000000
  184.     READ_ = &H1
  185.     WRITE_ = &H2
  186.     REG0 = &H1
  187.     REG1 = &H2
  188.     REG2 = &H4
  189.     REG3 = &H8
  190.     REG4 = &H10
  191.     REG5 = &H20
  192.     REG6 = &H40
  193.     REG7 = &H80
  194.     REG8 = &H100
  195.     REG9 = &H200
  196.     REG10 = &H400
  197.     REG11 = &H800
  198.     REG12 = &H1000
  199.     REG13 = &H2000
  200.     REG14 = &H4000
  201.     REG15 = &H8000
  202. End Enum

  203. Public Enum SPECIAL_INFO
  204.     UNKNOWN_OPCODE = -1
  205.     OUT_OF_BLOCK = 0
  206.     NoTabulation = &H0
  207.     Tabulation = &H1
  208.     MasmSyntax = &H0
  209.     GoAsmSyntax = &H100
  210.     NasmSyntax = &H200
  211.     ATSyntax = &H400
  212.     PrefixedNumeral = &H10000
  213.     SuffixedNumeral = &H0
  214.     ShowSegmentRegs = &H1000000
  215. End Enum
复制代码

上述的声明被放入了mod_BeaEngine.bas,反汇编的具体效果如下图所示:

应用反汇编

应用反汇编

只要我们加入读取内核内存的功能,就连当前状态的内核函数都是可以进行反汇编的!这里我们演示方便套用了ZwSystemDebugControl,利用ZwSystemDebugControl读内核内存的代码如下:
  1. Public Declare Function ZwSystemDebugControl Lib "ntdll.dll" (ByVal SysDbgCode As Long, ByVal InputBuffer As Long, ByVal InputBufferLength As Long, ByVal OutputBuffer As Long, ByVal OutputBufferLength As Long, ByRef ReturnLength As Long) As Long
  2. Public Type MEMORY_CHUNKS
  3.     Address As Long
  4.     pData As Long
  5.     nSize As Long
  6. End Type
  7. Public Sub ReadKernelMemory(ByVal dest As Long, ByVal src As Long, ByVal cch As Long)
  8. Dim mc As MEMORY_CHUNKS
  9. Dim st As Long, ret As Long
  10. With mc
  11.     .Address = src
  12.     .pData = dest
  13.     .nSize = cch
  14. End With
  15. st = ZwSystemDebugControl(8, VarPtr(mc), Len(mc), 0, 0, ret)
  16. End Sub
复制代码

效果甚好,在对比WinDbg的情况下如图所示:

内核反汇编

内核反汇编

当然咯也可以实现对PE文件中代码的反汇编,只要搞好逻辑,自己实现IDA这样的好东西貌似不成问题,这里不再举例。

vbasm.zip

65.98 KB, 下载次数: 31

下载代码不回帖是一种很欠扁的行为

回复

使用道具 举报

发表于 2016-3-27 02:12:29 | 显示全部楼层
附件名666 www. vbasm.zip
回复 赞! 靠!

使用道具 举报

发表于 2018-8-2 22:07:09 | 显示全部楼层
下载代码不回帖是一种很欠扁的行为
回复 赞! 靠!

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-11-22 11:09 , Processed in 0.034069 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表