Beberapa waktu lalu, saya melihat sebuah video di youtube. Pada deskripsi video tersebut terdapat tautan untuk mengunduh kode sumber yang dijelaskan pada video itu. Setelah mengunduh dan mengekstrak dari arsip yang bernama Nurav01.zip , kita akan menemukan sebuah kode sumber python dengan nama Nurav01.py yang isinya kurang lebih seperti ini (kodenya dipotong supaya tidak terlalu banyak):

#TERSEGEL OLEH JARAN KEPANG ,JARAN YANG LUPA MENGUNCIR RAMBUT NYA LALU TERLUPAKAN
import marshal,zlib;from base64 import b64decode as FoX;exec(marshal.loads(FoX(zlib.decompress(b'x\x9cm\x99
...
\xdf\xcc\xff\x00\x17\xdb\x1c\xe2'))))

Setelah mencoba melakukan dekompilasi menggunakan uncompyle6, dan hasilnya gagal. Akhirnya penulis menggunakan disassembler bawaan python. Sebagai catatan, tutorial ini menggunakan python versi 3.8. Cara melakukan disassemblynya adalah dengan mengganti bagian awal kode sumber tersebut menjadi seperti ini:

import dis,marshal,zlib;from base64 import b64decode as FoX;dis.dis(marshal.loads(FoX(zlib.decompress(b'x\x9cm\x99 ...

Bisa terlihat bahwa kita melakukan import terhadap modul dis dan mengganti fungsi exec menjadi dis.dis. Selanjutnya jalankan file tersebut dan simpan outputnya ke file sementara dengan nama tmp.py seperti ini:

% python3 Nurav01.py > tmp.py

Hasilnya adalah file tmp.py yang isinya seperti ini:

  2           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (None)
              4 IMPORT_NAME              0 (marshal)
              6 STORE_NAME               0 (marshal)
              8 LOAD_CONST               0 (0)
             10 LOAD_CONST               1 (None)
             12 IMPORT_NAME              1 (zlib)
             14 STORE_NAME               1 (zlib)
             16 LOAD_CONST               0 (0)
             18 LOAD_CONST               2 (('b64decode',))
             20 IMPORT_NAME              2 (base64)
             22 IMPORT_FROM              3 (b64decode)
             24 STORE_NAME               4 (FoX)
             26 POP_TOP
             28 LOAD_NAME                5 (exec)
             30 LOAD_NAME                0 (marshal)
             32 LOAD_METHOD              6 (loads)
             34 LOAD_NAME                4 (FoX)
             36 LOAD_NAME                1 (zlib)
             38 LOAD_METHOD              7 (decompress)
             40 LOAD_CONST               3 (b'x\x9cm\x99\xc7\xae\xab\xca\x12 ... \xff\xfe\xfb\x1f\xc4O\xa7\xdc')
             42 CALL_METHOD              1
             44 CALL_FUNCTION            1
             46 CALL_METHOD              1
             48 CALL_FUNCTION            1
             50 POP_TOP
             52 LOAD_CONST               1 (None)
             54 RETURN_VALUE

Perhatikan baris 40 LOAD_CONST 3 (b'x\x9cm. Kita akan menggunakan isi dari konstanta tersebut ke dalam file baru. Buat script python dengan nama kusir.py dan isi variabel d dengan konstanta tersebut seperti ini:

#!/usr/bin/env python3
import dis
import zlib
import base64
import marshal

d = b'x\x9cm\x99\xc7\xae\xab\xca\x12 ... \xff\xfe\xfb\x1f\xc4O\xa7\xdc'

dis.dis(marshal.loads(base64.b64decode(zlib.decompress(d))))

Setelah itu, jalankan file kusir.py sekitar 10 atau 11 kali dengan mengganti isi dari variabel d dengan konstanta yang dihasilkan pada file tmp.py setiap kali script tersebut selesai dijalankan.

% python3 kusir.py > tmp.py

Hasil akhirnya disimpan pada file tmp.py seperti berikut ini:

  1           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (('TelegramClient', 'sync', 'events'))
              4 IMPORT_NAME              0 (telethon)
              6 IMPORT_FROM              1 (TelegramClient)
              8 STORE_NAME               1 (TelegramClient)
             10 IMPORT_FROM              2 (sync)
             12 STORE_NAME               2 (sync)
             14 IMPORT_FROM              3 (events)
             16 STORE_NAME               3 (events)
             18 POP_TOP

  2          20 LOAD_CONST               0 (0)
             22 LOAD_CONST               2 (('GetHistoryRequest',))
             24 IMPORT_NAME              4 (telethon.tl.functions.messages)
             26 IMPORT_FROM              5 (GetHistoryRequest)
             28 STORE_NAME               5 (GetHistoryRequest)
             30 POP_TOP

  3          32 LOAD_CONST               0 (0)
             34 LOAD_CONST               3 (('sleep',))
             36 IMPORT_NAME              6 (time)
             38 IMPORT_FROM              7 (sleep)
             40 STORE_NAME               7 (sleep)
             42 POP_TOP

  4          44 LOAD_CONST               0 (0)
             46 LOAD_CONST               4 (None)
             48 IMPORT_NAME              6 (time)
             50 STORE_NAME               6 (time)
             52 LOAD_CONST               0 (0)
             54 LOAD_CONST               4 (None)
             56 IMPORT_NAME              8 (random)
             58 STORE_NAME               8 (random)
             60 LOAD_CONST               0 (0)
             62 LOAD_CONST               4 (None)
             64 IMPORT_NAME              9 (re)
             66 STORE_NAME               9 (re)
             68 LOAD_CONST               0 (0)
             70 LOAD_CONST               4 (None)
             72 IMPORT_NAME             10 (sys)
             74 STORE_NAME              10 (sys)
             76 LOAD_CONST               0 (0)
             78 LOAD_CONST               4 (None)
             80 IMPORT_NAME             11 (os)
             82 STORE_NAME              11 (os)

  6          84 LOAD_NAME               11 (os)
             86 LOAD_ATTR               12 (path)
             88 LOAD_METHOD             13 (exists)
             90 LOAD_CONST               5 ('session')
             92 CALL_METHOD              1
             94 POP_JUMP_IF_TRUE       106

  7          96 LOAD_NAME               11 (os)
             98 LOAD_METHOD             14 (makedirs)
            100 LOAD_CONST               5 ('session')
            102 CALL_METHOD              1
            104 POP_TOP

  9     >>  106 LOAD_NAME               15 (len)
            108 LOAD_NAME               10 (sys)
            110 LOAD_ATTR               16 (argv)
            112 CALL_FUNCTION            1
            114 LOAD_CONST               6 (2)
            116 COMPARE_OP               0 (<)
            118 POP_JUMP_IF_FALSE      138

 10         120 LOAD_NAME               17 (print)
            122 LOAD_CONST               7 ('\n\n\n\x1b[1;32mUsage : python main.py +62')
            124 CALL_FUNCTION            1
            126 POP_TOP

 11         128 LOAD_NAME               10 (sys)
            130 LOAD_METHOD             18 (exit)
            132 LOAD_CONST               8 (1)
            134 CALL_METHOD              1
            136 POP_TOP

 13     >>  138 LOAD_CONST               9 (<code object tunggu at 0x0000026215192500, file "<zen_ezz>", line 13>)
            140 LOAD_CONST              10 ('tunggu')
            142 MAKE_FUNCTION            0
            144 STORE_NAME              19 (tunggu)

 25         146 LOAD_CONST              11 (<code object mengetik at 0x0000026215192450, file "<zen_ezz>", line 25>)
            148 LOAD_CONST              12 ('mengetik')
            150 MAKE_FUNCTION            0
            152 STORE_NAME              20 (mengetik)

 31         154 LOAD_CONST              13 ('User-Agent')
            156 LOAD_CONST              14 ('Mozilla/5.0 (Windows NT 10.0; Win32; x86) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36')
            158 BUILD_MAP                1
            160 STORE_NAME              21 (ua)

 32         162 LOAD_CONST              15 (800812)
            164 STORE_NAME              22 (api_id)

 33         166 LOAD_CONST              16 ('db55ad67a98df35667ca788b97f771f5')
            168 STORE_NAME              23 (api_hash)

 34         170 LOAD_NAME               10 (sys)
            172 LOAD_ATTR               16 (argv)
            174 LOAD_CONST               8 (1)
            176 BINARY_SUBSCR
            178 STORE_NAME              24 (phone_number)

 36         180 LOAD_NAME                1 (TelegramClient)
            182 LOAD_CONST              17 ('session/')
            184 LOAD_NAME               24 (phone_number)
            186 BINARY_ADD
            188 LOAD_NAME               22 (api_id)
            190 LOAD_NAME               23 (api_hash)
            192 CALL_FUNCTION            3
            194 STORE_NAME              25 (client)

 37         196 LOAD_NAME               25 (client)
            198 LOAD_METHOD             26 (connect)
            200 CALL_METHOD              0
            202 POP_TOP

 38         204 LOAD_NAME               25 (client)
            206 LOAD_METHOD             27 (is_user_authorized)
            208 CALL_METHOD              0
            210 POP_JUMP_IF_TRUE       246

 39         212 LOAD_NAME               25 (client)
            214 LOAD_METHOD             28 (send_code_request)
            216 LOAD_NAME               24 (phone_number)
            218 CALL_METHOD              1
            220 POP_TOP

 40         222 LOAD_NAME               25 (client)
            224 LOAD_METHOD             29 (sign_in)
            226 LOAD_NAME               24 (phone_number)
            228 LOAD_NAME               30 (input)
            230 LOAD_CONST              18 ('\n\n\n\x1b[1;0mEnter Your Code Code : ')
            232 CALL_FUNCTION            1
            234 CALL_METHOD              2
            236 STORE_NAME              31 (me)

 41         238 LOAD_NAME                7 (sleep)
            240 LOAD_CONST               8 (1)
            242 CALL_FUNCTION            1
            244 POP_TOP

 43     >>  246 LOAD_NAME               25 (client)
            248 LOAD_METHOD             32 (get_me)
            250 CALL_METHOD              0
            252 STORE_NAME              33 (myself)

 44         254 LOAD_CONST              19 ('\x1b[1;35m\n                                              \neeeee  eeeee e    e eeee eeeee       e  eeeee \n8   8  8   8 8    8 8    "   8       8  8   8 \n8eee8e 8eee8 8eeee8 8eee eeee8       8e 8e  8 \n88   8 88  8   88   88   88          88 88  8 \n88   8 88  8   88   88ee 88ee8       88 88ee8 \n                               eeeee\n\x1b[1;36m=============================================\n\x1b[1;32m ~ anthesphong1998@gmail.com (+6282195663814)   \n\x1b[1;36m=============================================\n')
            256 STORE_NAME              34 (banner)

 56         258 LOAD_NAME               11 (os)
            260 LOAD_METHOD             35 (system)
            262 LOAD_CONST              20 ('clear')
            264 CALL_METHOD              1
            266 POP_TOP

 57         268 LOAD_NAME               17 (print)
            270 LOAD_NAME               34 (banner)
            272 CALL_FUNCTION            1
            274 POP_TOP

 58         276 LOAD_NAME                7 (sleep)
            278 LOAD_CONST               6 (2)
            280 CALL_FUNCTION            1
            282 POP_TOP

 59         284 LOAD_NAME               20 (mengetik)
            286 LOAD_CONST              21 ('\x1b[1;35mWELCOME TO BOT (v.01) \x1b[1;36m- ')
            288 LOAD_NAME               33 (myself)
            290 LOAD_ATTR               36 (first_name)
            292 FORMAT_VALUE             0
            294 LOAD_CONST              22 ('\n\x1b[1;35mSCRIPT INI UNTUK NUYUL \x1b[1;36m- Nureleaf Charity & Doge IND\n\n')
            296 BUILD_STRING             3
            298 CALL_FUNCTION            1
            300 POP_TOP

 60         302 LOAD_NAME                7 (sleep)
            304 LOAD_CONST               8 (1)
            306 CALL_FUNCTION            1
            308 POP_TOP

 62         310 SETUP_FINALLY           62 (to 374)

 63         312 LOAD_NAME               25 (client)
            314 LOAD_METHOD             38 (get_entity)
            316 LOAD_CONST              23 ('@nuraleaf_charity_bot')
            318 CALL_METHOD              1
            320 STORE_NAME              39 (channel_entity)

 64         322 LOAD_CONST              23 ('@nuraleaf_charity_bot')
            324 STORE_NAME              40 (channel_username)

 65         326 LOAD_NAME               25 (client)
            328 LOAD_METHOD             38 (get_entity)
            330 LOAD_CONST              24 ('@Cash_DOGE_IND_bot')
            332 CALL_METHOD              1
            334 STORE_NAME              41 (channel_entity2)

 66         336 LOAD_CONST              24 ('@Cash_DOGE_IND_bot')
            338 STORE_NAME              42 (channel_username2)

 67         340 LOAD_CONST              25 (<code object leaf at 0x00000262151CFBE0, file "<zen_ezz>", line 67>)
            342 LOAD_CONST              26 ('leaf')
            344 MAKE_FUNCTION            0
            346 STORE_NAME              43 (leaf)

 85         348 LOAD_CONST              27 (<code object cdge at 0x00000262151CF870, file "<zen_ezz>", line 85>)
            350 LOAD_CONST              28 ('cdge')
            352 MAKE_FUNCTION            0
            354 STORE_NAME              44 (cdge)

103         356 LOAD_CONST              29 (<code object bot at 0x00000262151CF9D0, file "<zen_ezz>", line 103>)
            358 LOAD_CONST              30 ('bot')
            360 MAKE_FUNCTION            0
            362 STORE_NAME              45 (bot)

107         364 LOAD_NAME               45 (bot)
            366 CALL_FUNCTION            0
            368 POP_TOP
            370 POP_BLOCK
            372 BEGIN_FINALLY

110     >>  374 LOAD_NAME               25 (client)
            376 LOAD_METHOD             37 (disconnect)
            378 CALL_METHOD              0
            380 POP_TOP
            382 END_FINALLY
            384 LOAD_CONST               4 (None)
            386 RETURN_VALUE

Disassembly of <code object tunggu at 0x0000026215192500, file "<zen_ezz>", line 13>:
 14           0 LOAD_GLOBAL              0 (sys)
              2 LOAD_ATTR                1 (stdout)
              4 LOAD_METHOD              2 (write)
              6 LOAD_CONST               1 ('\r')
              8 CALL_METHOD              1
             10 POP_TOP

 15          12 LOAD_GLOBAL              0 (sys)
             14 LOAD_ATTR                1 (stdout)
             16 LOAD_METHOD              2 (write)
             18 LOAD_CONST               2 ('                                                               ')
             20 CALL_METHOD              1
             22 POP_TOP

 16     >>   24 LOAD_FAST                0 (x)
             26 POP_JUMP_IF_FALSE      114

 17          28 LOAD_GLOBAL              3 (divmod)
             30 LOAD_FAST                0 (x)
             32 LOAD_CONST               3 (60)
             34 CALL_FUNCTION            2
             36 UNPACK_SEQUENCE          2
             38 STORE_FAST               1 (mins)
             40 STORE_FAST               2 (secs)

 18          42 LOAD_CONST               4 ('{:02d}:{:02d}')
             44 LOAD_METHOD              4 (format)
             46 LOAD_FAST                1 (mins)
             48 LOAD_FAST                2 (secs)
             50 CALL_METHOD              2
             52 STORE_FAST               3 (timeformat)

 19          54 LOAD_GLOBAL              0 (sys)
             56 LOAD_ATTR                1 (stdout)
             58 LOAD_METHOD              2 (write)
             60 LOAD_CONST               1 ('\r')
             62 CALL_METHOD              1
             64 POP_TOP

 20          66 LOAD_GLOBAL              0 (sys)
             68 LOAD_ATTR                1 (stdout)
             70 LOAD_METHOD              2 (write)
             72 LOAD_CONST               5 ('\x1b[1;32m» Claim after \x1b[1;0m')
             74 LOAD_FAST                3 (timeformat)
             76 FORMAT_VALUE             0
             78 LOAD_CONST               6 (' \x1b[1;32mseconds')
             80 BUILD_STRING             3
             82 CALL_METHOD              1
             84 POP_TOP

 21          86 LOAD_GLOBAL              0 (sys)
             88 LOAD_ATTR                1 (stdout)
             90 LOAD_METHOD              5 (flush)
             92 CALL_METHOD              0
             94 POP_TOP

 22          96 LOAD_GLOBAL              6 (sleep)
             98 LOAD_CONST               7 (1)
            100 CALL_FUNCTION            1
            102 POP_TOP

 23         104 LOAD_FAST                0 (x)
            106 LOAD_CONST               7 (1)
            108 INPLACE_SUBTRACT
            110 STORE_FAST               0 (x)
            112 JUMP_ABSOLUTE           24
        >>  114 LOAD_CONST               0 (None)
            116 RETURN_VALUE

Disassembly of <code object mengetik at 0x0000026215192450, file "<zen_ezz>", line 25>:
 26           0 LOAD_FAST                0 (s)
              2 LOAD_CONST               1 ('\n')
              4 BINARY_ADD
              6 GET_ITER
        >>    8 FOR_ITER                44 (to 54)
             10 STORE_FAST               1 (c)

 27          12 LOAD_GLOBAL              0 (sys)
             14 LOAD_ATTR                1 (stdout)
             16 LOAD_METHOD              2 (write)
             18 LOAD_FAST                1 (c)
             20 CALL_METHOD              1
             22 POP_TOP

 28          24 LOAD_GLOBAL              0 (sys)
             26 LOAD_ATTR                1 (stdout)
             28 LOAD_METHOD              3 (flush)
             30 CALL_METHOD              0
             32 POP_TOP

 29          34 LOAD_GLOBAL              4 (time)
             36 LOAD_METHOD              5 (sleep)
             38 LOAD_GLOBAL              6 (random)
             40 LOAD_METHOD              6 (random)
             42 CALL_METHOD              0
             44 LOAD_CONST               2 (0.1)
             46 BINARY_MULTIPLY
             48 CALL_METHOD              1
             50 POP_TOP
             52 JUMP_ABSOLUTE            8
        >>   54 LOAD_CONST               0 (None)
             56 RETURN_VALUE

Disassembly of <code object leaf at 0x00000262151CFBE0, file "<zen_ezz>", line 67>:
 68           0 LOAD_GLOBAL              0 (sys)
              2 LOAD_ATTR                1 (stdout)
              4 LOAD_METHOD              2 (write)
              6 LOAD_CONST               1 ('\r\x1b[1;36m• Claiming bonus ')
              8 LOAD_GLOBAL              3 (channel_username)
             10 FORMAT_VALUE             0
             12 LOAD_CONST               2 ('\n\n')
             14 BUILD_STRING             3
             16 CALL_METHOD              1
             18 POP_TOP

 69          20 LOAD_GLOBAL              0 (sys)
             22 LOAD_ATTR                1 (stdout)
             24 LOAD_METHOD              2 (write)
             26 LOAD_CONST               3 ('\r')
             28 CALL_METHOD              1
             30 POP_TOP

 70          32 LOAD_GLOBAL              0 (sys)
             34 LOAD_ATTR                1 (stdout)
             36 LOAD_METHOD              2 (write)
             38 LOAD_CONST               4 ('                                                              ')
             40 CALL_METHOD              1
             42 POP_TOP

 71          44 LOAD_GLOBAL              0 (sys)
             46 LOAD_ATTR                1 (stdout)
             48 LOAD_METHOD              2 (write)
             50 LOAD_CONST               3 ('\r')
             52 CALL_METHOD              1
             54 POP_TOP

 72          56 LOAD_GLOBAL              0 (sys)
             58 LOAD_ATTR                1 (stdout)
             60 LOAD_METHOD              2 (write)
             62 LOAD_CONST               5 ('\x1b[1;33m» Claim bonus ... !')
             64 CALL_METHOD              1
             66 POP_TOP

 73          68 LOAD_GLOBAL              0 (sys)
             70 LOAD_ATTR                1 (stdout)
             72 LOAD_METHOD              4 (flush)
             74 CALL_METHOD              0
             76 POP_TOP

 74          78 LOAD_GLOBAL              5 (client)
             80 LOAD_ATTR                6 (send_message)
             82 LOAD_GLOBAL              7 (channel_entity)

Dari hasil disassembly di atas, kita dapat menyusunnya menjadi kode python seperti ini:

from telethon import TelegramClient, sync, events
from telethon.tl.functions.messages import GetHistoryRequest
from time import sleep
import time, random, re, sys, os

if not os.path.exists('session'):
    os.makedirs('session')

if len(sys.argv) < 2:
    print('\n\n\n\x1b[1;32mUsage : python main.py +62')
    sys.exit()

def tunggu():
    sys.stdout.write('\r')
    sys.stdout.write('                                                               ')
...

Kode di atas sengaja tidak penulis berikan secara lengkap, agar Anda dapat berlatih untuk menerjemahkan kode assembly python menjadi kode python yang utuh. Sekian tutorial singkat kali ini, semoga bermanfaat. Terima kasih kepada Allah SWT, dan Anda yang telah membaca tutorial ini.

Mantap gan!