HyperDbg Debugger
Loading...
Searching...
No Matches
assembler.cpp File Reference

Turns assembly codes into bytes. More...

#include "pch.h"

Functions

AssembleDatacreate_AssembleData ()
BOOLEAN HyperDbgAssembleGetLength (const CHAR *AssemblyCode, UINT64 StartAddress, UINT32 *Length)
 Assembler function.
BOOLEAN HyperDbgAssemble (const CHAR *AssemblyCode, UINT64 StartAddress, PVOID BufferToStoreAssembledData, UINT32 BufferSize)
 Assembler function.

Detailed Description

Turns assembly codes into bytes.

Author
Abbas Masoumi Gorji (Abbas.nosp@m.MG@h.nosp@m.yperd.nosp@m.bg.o.nosp@m.rg)
Version
0.10
Date
2024-07-16

Function Documentation

◆ create_AssembleData()

AssembleData * create_AssembleData ( )
182{
183 return new AssembleData;
184}
Definition assembler.h:16

◆ HyperDbgAssemble()

BOOLEAN HyperDbgAssemble ( const CHAR * AssemblyCode,
UINT64 StartAddress,
PVOID BufferToStoreAssembledData,
UINT32 BufferSize )

Assembler function.

Parameters
AssemblyCodeThe assembly code
StartAddressThe start address of the assembly code
BufferToStoreAssembledDataThe buffer to store the assembled data
BufferSizeThe size of the buffer
Returns
BOOLEAN Returns true if it was successful
235{
237
238 //
239 // Convert assembly code to string
240 //
241 std::string AsmCode = AssemblyCode;
242
243 AssembleData.AsmRaw = AsmCode;
245
246 if (AssembleData.Assemble(StartAddress))
247 {
248 return FALSE;
249 }
250 else
251 {
252 if (AssembleData.BytesCount > BufferSize)
253 {
254 return FALSE;
255 }
256
257 //
258 // Copy the assembled data to the buffer
259 //
260 memcpy(BufferToStoreAssembledData, AssembleData.EncodedBytes, AssembleData.BytesCount);
261
262 return TRUE;
263 }
264}
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
VOID ParseAssemblyData()
tries to solve the symbol issue with Keystone, which apparently originates from LLVM-MC.
Definition assembler.cpp:20
UCHAR * EncodedBytes
Definition assembler.h:22
SIZE_T BytesCount
Definition assembler.h:21
INT Assemble(UINT64 StartAddr, ks_arch Arch=KS_ARCH_X86, INT Mode=KS_MODE_64, INT Syntax=KS_OPT_SYNTAX_INTEL)
Definition assembler.cpp:119
std::string AsmRaw
Definition assembler.h:18

◆ HyperDbgAssembleGetLength()

BOOLEAN HyperDbgAssembleGetLength ( const CHAR * AssemblyCode,
UINT64 StartAddress,
UINT32 * Length )

Assembler function.

Parameters
AssemblyCodeThe assembly code
StartAddressThe start address of the assembly code
LengthThe length of the assembly code in bytes (to be returned)
Returns
BOOLEAN Returns true if it was successful
197{
199
200 //
201 // Convert assembly code to string
202 //
203 std::string AsmCode = AssemblyCode;
204
205 AssembleData.AsmRaw = AsmCode;
207
208 if (AssembleData.Assemble(StartAddress))
209 {
210 return FALSE;
211 }
212 else
213 {
214 //
215 // Get the BytesCount
216 //
217 *Length = (UINT32)AssembleData.BytesCount;
218
219 return TRUE;
220 }
221}
unsigned int UINT32
Definition BasicTypes.h:54