Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function asmBlock(addr, asm, ctx, ceself)
- ceself = not not ceself
- addr = type(addr)~='number' and getAddressSafe(addr, ceself) or addr
- if type(addr)~='number' or addr==0 then return nil,'invalid addr'end
- ctx = ctx or {}
- ctx.RID, ctx._Start = '_'..math.random(0x10000,0x99999), addr
- asm = string.format([[
- unregisterSymbol(<!RID>)
- label(<!RID>)
- <!_Start>:
- %s
- <!RID>:
- registerSymbol(<!RID>)
- ]],asm)
- asm = asm:gsub("<!([_#%.%a][_#%.%w]*)>",function(k)
- local v = ctx[k]
- if type(v)=='number' and math.tointeger(v)then
- return v<0 and string.format('-%X',-v)or string.format('%X',v)
- else
- return tostring(v)
- end
- end)
- local ok = not ceself and autoAssemble(asm) or ceself and autoAssemble(asm,true)
- local endAddr = ok and getAddressSafe(ctx.RID, ceself),unregisterSymbol(ctx.RID)
- if not endAddr then return nil,'failed asmBlock'end
- local size = endAddr-addr
- if ceself then
- return readBytesLocal(addr,size,true),size
- else
- return readBytes(addr,size,true),size
- end
- end
- ---- test
- autoAssemble("globalalloc(___,$1000)")
- print(byteTableToString(asmBlock('___', [[
- mov rax,1000
- mov rbx,<!.TestVar>
- mov rcx,<!TestVar>
- ret
- ]], {['.TestVar']=0x123456789, TestVar=0x987654321} ) or {0}):
- gsub('.',function(c)return string.format(' %02X',c:byte())end):sub(2))
Add Comment
Please, Sign In to add comment