سلام دوستان 😃
امروز یکی از بچه ها تو کانال
@pyspyquiz
ی چالش خفنی رو استارت زد
کلیت چالش اینه که کد خیلی ساده
print("hello world")
رو هرچقد میتونید بپیچونید و پیچیده ترش کنید

⭐️ و اما قسمت جذاب ماجرا ⭐️
جواب
های دوستان رو نظر سنجی میزاریم و اون کدی ک بیشترین امتیاز بیاره جایزه نقدی دارههه
🤑🤑🤑🤑🤑😏😎

@pyspyquiz
@pyspyquiz
@pyspyquiz
@pyspyquiz


پس بشتاااابید 🎉

2 comments

import subprocess, os, tempfile
from ctypes import *

PAGE_SIZE = 4096    

class AssemblerFunction(object):
  
  def __init__(self, code, ret_type, *arg_types):
    fd, source = tempfile.mkstemp(".S", "assembly", os.getcwd())
    os.write(fd, code)
    os.close(fd)
    target = os.path.splitext(source)[0]
    subprocess.check_call(["nasm",source])
    os.unlink(source)
    binary = file(target,"rb").read()
    os.unlink(target)
    bin_len = len(binary)
    self.code_buffer = create_string_buffer(PAGE_SIZE*2+bin_len)
    addr = (addressof(self.code_buffer) + PAGE_SIZE) & (~(PAGE_SIZE-1))
    memmove(addr, binary, bin_len)    
  
    self.mprotect = cdll.LoadLibrary("libc.so.6").mprotect
    mp_ret = self.mprotect(addr, bin_len, 4)   # execute only. 
    if mp_ret: raise OSError("Unable to change memory protection")
    
    self.func = CFUNCTYPE(ret_type, *arg_types)(addr)
    self.addr = addr
    self.bin_len = bin_len
    
  def __call__(self, *args):
    return self.func(*args)
    
  def __del__(self):
    if hasattr(self,"mprotect"):
      self.mprotect(self.addr, self.bin_len, 3)   

 
if __name__ == "__main__":
  add_func = """section .text align=0

global _start

msg db 'Hello world', 0x0a

len equ $ - msg

_start:
    mov eax, 4 
    mov ebx, 1 
    mov ecx, msg 
    mov edx, len 
    int 0x80

    mov eax, 1
    int 0x8
            """
            
  Add = AssemblerFunction(add_func, c_int, c_int, c_int)
  Add(1, 2)
  
</Mohammad Sajjad>
import subprocess, os, tempfile from ctypes import * PAGE_SIZE = 4096     class AssemblerFunction(object):      def __init__(self, code, ret_type, *arg_types):     fd, source = tempfile.mkstemp(".S", "assembly", os.getcwd())     os.write(fd, code)     os.close(fd)     target = os.path.splitext(source)[0]     subprocess.check_call(["nasm",source])     os.unlink(source)     binary = file(target,"rb").read()     os.unlink(target)     bin_len = len(binary)     self.code_buffer = create_string_buffer(PAGE_SIZE*2+bin_len)     addr = (addressof(self.code_buffer) + PAGE_SIZE) & (~(PAGE_SIZE-1))     memmove(addr, binary, bin_len)            self.mprotect = cdll.LoadLibrary("libc.so.6").mprotect     mp_ret = self.mprotect(addr, bin_len, 4)   # execute only.      if mp_ret: raise OSError("Unable to change memory protection")          self.func = CFUNCTYPE(ret_type, *arg_types)(addr)     self.addr = addr     self.bin_len = bin_len        def __call__(self, *args):     return self.func(*args)        def __del__(self):     if hasattr(self,"mprotect"):       self.mprotect(self.addr, self.bin_len, 3)      if __name__ == "__main__":   add_func = """section .text align=0 global _start msg db 'Hello world', 0x0a len equ $ - msg _start:     mov eax, 4      mov ebx, 1      mov ecx, msg      mov edx, len      int 0x80     mov eax, 1     int 0x8             """                Add = AssemblerFunction(add_func, c_int, c_int, c_int)   Add(1, 2)   
ایول خیلی باحاله
جوابتون رو داخل گروه @pyspyquiz بفرسید تاداخل مسابقه شرکت کنید و بقیه اعضا بتونن رای بدن