Skip to content

Instantly share code, notes, and snippets.

@BeRo1985
Last active August 29, 2015 14:27
Show Gist options
  • Save BeRo1985/c50ea2881da0be1653c1 to your computer and use it in GitHub Desktop.
Save BeRo1985/c50ea2881da0be1653c1 to your computer and use it in GitHub Desktop.
ScriptableAssembler (SASM) syntax example
/*
** Multi line comment
*/
// Single line commit
PE_SCN_CNT_CODE = 0x00000020
PE_SCN_CNT_INITIALIZED_DATA = 0x00000040
PE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080
PE_SCN_MEM_EXECUTE = 0x20000000
PE_SCN_MEM_READ = 0x40000000
PE_SCN_MEM_WRITE = 0x80000000
.target pe32 /* comment */ (imagebase = 0x400000, codebase = 0x1000)
.cpu all
.bits 32
.script {
Assembler.defineFunction("replaceEAXwithEBX", function(args, content){
Assembler.parse(content.replace("eax","ebx"));
});
Assembler.defineMacro("invoke", function(){
// 32-bit x86 stdcall invoke
var functionName = arguments[0];
for(var i = arguments.length - 1; i > 0; i--){
var functionParameter = arguments[i];
Assembler.parse("push "+functionParameter);
}
Assembler.parse("call dword ptr ["+functionName+"]");
});
};
.macro oldSchoolMacro(a0, a1){
.local label0
cmp a0, a1
jz label0
xor a0, a0
label0:
}
.section(".text", PE_SCN_CNT_CODE | PE_SCN_MEM_READ | PE_SCN_MEM_EXECUTE){
.entrypoint
invoke MessageBox, byte 0, dword Title, dword Text, byte 0
invoke ExitProcess, byte 0
oldSchoolMacro eax, ebx
// statement terminator semicolons like in javascript incl. automatic semicolon insertion for
// oldschool semicolon-free x86 assembler coding
inc eax; dec eax; ret
// Support for modern instruction sets
vex2 vcomisd xmm0,xmm1
vex3 vcomisd xmm0,xmm1
evex vcomisd xmm0,xmm1
.bits 64
vaddps zmm30{k7}{z},zmm29,zmm28
.bits 32
// Support for 64-bit x86 assembler code
.bits 64
mov r9,rax
.bits 32
// Support for 16-bit x86 assembler code
.bits 16
mov word ptr [bx+di],ax
.bits 32
};
.section(".data", PE_SCN_CNT_INITIALIZED_DATA | PE_SCN_MEM_READ | PE_SCN_MEM_WRITE){
Title: db "Test", 0 // bla
Text: db "Hello world!\0"
// Big integer arithmetics (internally up to 1024-bit)
dz (0x1234567812345678123456781234567812345678 * 2) - 1
// Big float support (up to 512-bit, but only parsing only without arithmetics)
dz 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
// 80-bit Packed BCD support
dt 0p1337
// db / resb = byte (8-bit)
// dw / resw = word (16-bit)
// dd / resd = dword (32-bit)
// ddq / resdq = dqword (64-bit)
// dt / rest = tword (80-bit)
// dq / resq / do / reso = qword / oword / xmmword (128-bit)
// dy / resy = yword / ymmword (256-bit)
// dz / resz = zword / zmmword (512-bit)
};
.section(".bss", PE_SCN_CNT_UNINITIALIZED_DATA | PE_SCN_MEM_READ | PE_SCN_MEM_WRITE, 65536){
TestData2: db 0, 0
}
.library("kernel32.dll"){
ExitProcess = "ExitProcess"
GetTickCount = "GetTickCount"
};
.library("user32.dll"){
MessageBox = "MessageBoxA"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment