<html dir=""><head><style id="axi-htmleditor-style" type="text/css">p { margin: 0px; }</style></head><body style="font-size: 10pt; font-family: Arial; background-image: none; background-repeat: repeat; background-attachment: fixed;"><font face="Arial"><span style="font-size: 10pt;">​Hi all,</span></font><div style="font-family: Arial; font-size: 10pt;"><br></div><div style="font-family: Arial; font-size: 10pt;">I am using llvmlite for pyvex and I want the output of my code (which is written based on llvmlite) to be like pyvex. In pyvex, (https://github.com/angr/pyvex). Considering pyvex, I tried to implement the following statements in pyvex to llvmlite:</div><div style="font-family: Arial; font-size: 10pt;"><br></div><div><div><font face="Arial"><span style="font-size: 13.3333px;">for stmt in irsb.statements:</span></font></div></div><div><font face="Arial"><span style="font-size: 13.3333px;">   if isinstance(stmt, pyvex.IRStmt.Store):</span></font></div><div><font face="Arial"><span style="font-size: 13.3333px;">      <font color="#d73a49">print</font></span></font><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"> </span><span class="pl-s" style="box-sizing: border-box; color: rgb(3, 47, 98); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><span class="pl-pds" style="box-sizing: border-box;">"</span>ST<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%s</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%s</span>) = <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">%s</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"> </span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">%</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"> (</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">self</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">.endness[</span><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">-</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">2</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">:].lower(), </span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">self</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">.addr, </span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">self</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">.data)  (which gets the data in a register and store it in another register)</span></div><div><span style="color: rgb(36, 41, 46); font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><font face="tahoma"><br></font></span></div><div><span style="color: rgb(36, 41, 46); font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><font face="tahoma">I translate it in llvmlite as follows:</font></span></div><div><span style="color: rgb(36, 41, 46); font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><font face="tahoma"><br></font></span></div><div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">from ctypes import CFUNCTYPE, c_int</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">import archinfo</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">import llvmlite.ir as ll</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">import llvmlite.binding as llvm</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">import pyvex</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">mehran = -100</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">llvm.initialize()</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">llvm.initialize_native_target()</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">llvm.initialize_native_asmprinter()</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">module = ll.Module()</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">func_ty = ll.FunctionType(ll.VoidType(), [])</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">func = ll.Function(module, func_ty, name='read_instructions')</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">a = func.args</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">bb_entry = func.append_basic_block('entry')</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">irbuilder = ll.IRBuilder(bb_entry)</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">int_type = ll.IntType(64);</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">irsb = pyvex.block.IRSB(CODE, 0x400400, archinfo.ArchAMD64())</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><br></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">for stmt in irsb.statements:</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">    #if isinstance(pyvex.IRStmt.Store):</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">    with irbuilder.if_then(stmt, pyvex.IRStmt.Store):</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);"><br></span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       t = irbuilder.load_reg(ll.IntType(64), stmt.data)</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       t1 = irbuilder.load_reg(ll.IntType(64), stmt.addr)</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       tcall = irbuilder.call(func, [t])</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       t1call = irbuilder.call(func, [t1])</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       result  =  irbuilder.store_reg(ll.Constant(ll.IntType(64), t), ll.IntType(64), t1)</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       irbuilder.ret( result )</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       print( module )</span></font></div><div><font color="#24292e" face="tahoma"><span style="font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);">       target = llvm.Target.from_default_triple()</span></font></div></div><div>       <font size="2" face="tahoma">target_machine = target.create_target_machine()</font></div><div><font size="2" face="tahoma">       backing_mod = llvm.parse_assembly("")</font></div><div><font size="2" face="tahoma">       engine = llvm.create_mcjit_compiler(backing_mod, target_machine)</font></div><div><font size="2" face="tahoma">       mod = llvm.parse_assembly( str( module ) )</font></div><div><font size="2" face="tahoma">       mod.verify()</font></div><div><font size="2" face="tahoma">       engine.add_module(mod)</font></div><div><font size="2" face="tahoma">       engine.finalize_object()</font></div><div><font size="2" face="tahoma">       func_ptr = engine.get_function_address("read_instructions")</font></div><div><font size="2" face="tahoma">       c_fn_fib = CFUNCTYPE(c_int64, c_int64)(func_ptr)</font></div><div><br></div><div>           </div><div>Having the above code, when running it, I am stopped with error:</div><div><div>AttributeError: 'IMark' object has no attribute 'data'</div></div><div><br></div><div>Can anyone help me in this way?</div><div>Thank you</div></body></html><pre>
-- 
This email was Anti Virus checked by  Security Gateway.</pre>