Assemble

OllyDbg Plugin API

Assemble

Function Assemble, as expected, converts command in ASCII form to binary 32-bit code. It shares command table with Disasm, so if some command can be disassembled, it can be assembled back too, with one exception: Assemble doesn't support 16-bit addresses. Some commands have more than one encoding. By calling Assemble with parameter attempt=0,1... and constsize=0,1,2,3 one can get alternative variants and then select the shortest possible form (this is how OllyDbg implements assembling). However, only one address form is generated in each case ([EAX*2] but not [EAX+EAX]; [EBX+EAX] but not [EAX+EBX]; [EAX] will not use SIB byte; no DS: prefix and so on).

Assemble compiles imprecise commands (where, for example, R32 replaces any general-purpose 32-bit register). This allows to generate imprecise search patterns, where mask contains zeros at the position occupied in code by register). Returns number of bytes in assembled code or non-positive number in case of detected error or when variant selected by combination of attempt and constsize doesn't exist. This number is the negative position of error in the input command.

int Assemble(char *cmd,ulong ip,t_asmmodel *model,int attempt,int constsize,char *errtext);

Parameters:

cmd - pointer to zero-terminated ASCII command;

ip - address of the generated binary code in memory;

model - pointer to structure that receives machine code and mask;

attempt - index of alternative verison of the command. Call Assemble with attempt=0,1,2... to obtain all possible versions of the command. Stop this sequence when Assemble reports error;

constsize - requested size of address constant and immediate data. Call Assemble with constsize=0,1,2,3 to obtain all possible variants of the version selected by attempt;

errtext - pointer to text buffer of length at least TEXTLEN that receives description of detected error.

See also: Disasm