You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

784 lines
29 KiB

  1. from __future__ import unicode_literals
  2. import collections
  3. import io
  4. import zlib
  5. from .utils import (
  6. compat_str,
  7. ExtractorError,
  8. struct_unpack,
  9. )
  10. def _extract_tags(file_contents):
  11. if file_contents[1:3] != b'WS':
  12. raise ExtractorError(
  13. 'Not an SWF file; header is %r' % file_contents[:3])
  14. if file_contents[:1] == b'C':
  15. content = zlib.decompress(file_contents[8:])
  16. else:
  17. raise NotImplementedError(
  18. 'Unsupported compression format %r' %
  19. file_contents[:1])
  20. # Determine number of bits in framesize rectangle
  21. framesize_nbits = struct_unpack('!B', content[:1])[0] >> 3
  22. framesize_len = (5 + 4 * framesize_nbits + 7) // 8
  23. pos = framesize_len + 2 + 2
  24. while pos < len(content):
  25. header16 = struct_unpack('<H', content[pos:pos + 2])[0]
  26. pos += 2
  27. tag_code = header16 >> 6
  28. tag_len = header16 & 0x3f
  29. if tag_len == 0x3f:
  30. tag_len = struct_unpack('<I', content[pos:pos + 4])[0]
  31. pos += 4
  32. assert pos + tag_len <= len(content), \
  33. ('Tag %d ends at %d+%d - that\'s longer than the file (%d)'
  34. % (tag_code, pos, tag_len, len(content)))
  35. yield (tag_code, content[pos:pos + tag_len])
  36. pos += tag_len
  37. class _AVMClass_Object(object):
  38. def __init__(self, avm_class):
  39. self.avm_class = avm_class
  40. def __repr__(self):
  41. return '%s#%x' % (self.avm_class.name, id(self))
  42. class _ScopeDict(dict):
  43. def __init__(self, avm_class):
  44. super(_ScopeDict, self).__init__()
  45. self.avm_class = avm_class
  46. def __repr__(self):
  47. return '%s__Scope(%s)' % (
  48. self.avm_class.name,
  49. super(_ScopeDict, self).__repr__())
  50. class _AVMClass(object):
  51. def __init__(self, name_idx, name):
  52. self.name_idx = name_idx
  53. self.name = name
  54. self.method_names = {}
  55. self.method_idxs = {}
  56. self.methods = {}
  57. self.method_pyfunctions = {}
  58. self.variables = _ScopeDict(self)
  59. self.constants = {}
  60. def make_object(self):
  61. return _AVMClass_Object(self)
  62. def __repr__(self):
  63. return '_AVMClass(%s)' % (self.name)
  64. def register_methods(self, methods):
  65. self.method_names.update(methods.items())
  66. self.method_idxs.update(dict(
  67. (idx, name)
  68. for name, idx in methods.items()))
  69. class _Multiname(object):
  70. def __init__(self, kind):
  71. self.kind = kind
  72. def __repr__(self):
  73. return '[MULTINAME kind: 0x%x]' % self.kind
  74. def _read_int(reader):
  75. res = 0
  76. shift = 0
  77. for _ in range(5):
  78. buf = reader.read(1)
  79. assert len(buf) == 1
  80. b = struct_unpack('<B', buf)[0]
  81. res = res | ((b & 0x7f) << shift)
  82. if b & 0x80 == 0:
  83. break
  84. shift += 7
  85. return res
  86. def _u30(reader):
  87. res = _read_int(reader)
  88. assert res & 0xf0000000 == 0
  89. return res
  90. _u32 = _read_int
  91. def _s32(reader):
  92. v = _read_int(reader)
  93. if v & 0x80000000 != 0:
  94. v = - ((v ^ 0xffffffff) + 1)
  95. return v
  96. def _s24(reader):
  97. bs = reader.read(3)
  98. assert len(bs) == 3
  99. last_byte = b'\xff' if (ord(bs[2:3]) >= 0x80) else b'\x00'
  100. return struct_unpack('<i', bs + last_byte)[0]
  101. def _read_string(reader):
  102. slen = _u30(reader)
  103. resb = reader.read(slen)
  104. assert len(resb) == slen
  105. return resb.decode('utf-8')
  106. def _read_bytes(count, reader):
  107. assert count >= 0
  108. resb = reader.read(count)
  109. assert len(resb) == count
  110. return resb
  111. def _read_byte(reader):
  112. resb = _read_bytes(1, reader=reader)
  113. res = struct_unpack('<B', resb)[0]
  114. return res
  115. StringClass = _AVMClass('(no name idx)', 'String')
  116. ByteArrayClass = _AVMClass('(no name idx)', 'ByteArray')
  117. _builtin_classes = {
  118. StringClass.name: StringClass,
  119. ByteArrayClass.name: ByteArrayClass,
  120. }
  121. class _Undefined(object):
  122. def __boolean__(self):
  123. return False
  124. def __hash__(self):
  125. return 0
  126. undefined = _Undefined()
  127. class SWFInterpreter(object):
  128. def __init__(self, file_contents):
  129. self._patched_functions = {}
  130. code_tag = next(tag
  131. for tag_code, tag in _extract_tags(file_contents)
  132. if tag_code == 82)
  133. p = code_tag.index(b'\0', 4) + 1
  134. code_reader = io.BytesIO(code_tag[p:])
  135. # Parse ABC (AVM2 ByteCode)
  136. # Define a couple convenience methods
  137. u30 = lambda *args: _u30(*args, reader=code_reader)
  138. s32 = lambda *args: _s32(*args, reader=code_reader)
  139. u32 = lambda *args: _u32(*args, reader=code_reader)
  140. read_bytes = lambda *args: _read_bytes(*args, reader=code_reader)
  141. read_byte = lambda *args: _read_byte(*args, reader=code_reader)
  142. # minor_version + major_version
  143. read_bytes(2 + 2)
  144. # Constant pool
  145. int_count = u30()
  146. self.constant_ints = [0]
  147. for _c in range(1, int_count):
  148. self.constant_ints.append(s32())
  149. self.constant_uints = [0]
  150. uint_count = u30()
  151. for _c in range(1, uint_count):
  152. self.constant_uints.append(u32())
  153. double_count = u30()
  154. read_bytes(max(0, (double_count - 1)) * 8)
  155. string_count = u30()
  156. self.constant_strings = ['']
  157. for _c in range(1, string_count):
  158. s = _read_string(code_reader)
  159. self.constant_strings.append(s)
  160. namespace_count = u30()
  161. for _c in range(1, namespace_count):
  162. read_bytes(1) # kind
  163. u30() # name
  164. ns_set_count = u30()
  165. for _c in range(1, ns_set_count):
  166. count = u30()
  167. for _c2 in range(count):
  168. u30()
  169. multiname_count = u30()
  170. MULTINAME_SIZES = {
  171. 0x07: 2, # QName
  172. 0x0d: 2, # QNameA
  173. 0x0f: 1, # RTQName
  174. 0x10: 1, # RTQNameA
  175. 0x11: 0, # RTQNameL
  176. 0x12: 0, # RTQNameLA
  177. 0x09: 2, # Multiname
  178. 0x0e: 2, # MultinameA
  179. 0x1b: 1, # MultinameL
  180. 0x1c: 1, # MultinameLA
  181. }
  182. self.multinames = ['']
  183. for _c in range(1, multiname_count):
  184. kind = u30()
  185. assert kind in MULTINAME_SIZES, 'Invalid multiname kind %r' % kind
  186. if kind == 0x07:
  187. u30() # namespace_idx
  188. name_idx = u30()
  189. self.multinames.append(self.constant_strings[name_idx])
  190. elif kind == 0x09:
  191. name_idx = u30()
  192. u30()
  193. self.multinames.append(self.constant_strings[name_idx])
  194. else:
  195. self.multinames.append(_Multiname(kind))
  196. for _c2 in range(MULTINAME_SIZES[kind]):
  197. u30()
  198. # Methods
  199. method_count = u30()
  200. MethodInfo = collections.namedtuple(
  201. 'MethodInfo',
  202. ['NEED_ARGUMENTS', 'NEED_REST'])
  203. method_infos = []
  204. for method_id in range(method_count):
  205. param_count = u30()
  206. u30() # return type
  207. for _ in range(param_count):
  208. u30() # param type
  209. u30() # name index (always 0 for youtube)
  210. flags = read_byte()
  211. if flags & 0x08 != 0:
  212. # Options present
  213. option_count = u30()
  214. for c in range(option_count):
  215. u30() # val
  216. read_bytes(1) # kind
  217. if flags & 0x80 != 0:
  218. # Param names present
  219. for _ in range(param_count):
  220. u30() # param name
  221. mi = MethodInfo(flags & 0x01 != 0, flags & 0x04 != 0)
  222. method_infos.append(mi)
  223. # Metadata
  224. metadata_count = u30()
  225. for _c in range(metadata_count):
  226. u30() # name
  227. item_count = u30()
  228. for _c2 in range(item_count):
  229. u30() # key
  230. u30() # value
  231. def parse_traits_info():
  232. trait_name_idx = u30()
  233. kind_full = read_byte()
  234. kind = kind_full & 0x0f
  235. attrs = kind_full >> 4
  236. methods = {}
  237. constants = None
  238. if kind == 0x00: # Slot
  239. u30() # Slot id
  240. u30() # type_name_idx
  241. vindex = u30()
  242. if vindex != 0:
  243. read_byte() # vkind
  244. elif kind == 0x06: # Const
  245. u30() # Slot id
  246. u30() # type_name_idx
  247. vindex = u30()
  248. vkind = 'any'
  249. if vindex != 0:
  250. vkind = read_byte()
  251. if vkind == 0x03: # Constant_Int
  252. value = self.constant_ints[vindex]
  253. elif vkind == 0x04: # Constant_UInt
  254. value = self.constant_uints[vindex]
  255. else:
  256. return {}, None # Ignore silently for now
  257. constants = {self.multinames[trait_name_idx]: value}
  258. elif kind in (0x01, 0x02, 0x03): # Method / Getter / Setter
  259. u30() # disp_id
  260. method_idx = u30()
  261. methods[self.multinames[trait_name_idx]] = method_idx
  262. elif kind == 0x04: # Class
  263. u30() # slot_id
  264. u30() # classi
  265. elif kind == 0x05: # Function
  266. u30() # slot_id
  267. function_idx = u30()
  268. methods[function_idx] = self.multinames[trait_name_idx]
  269. else:
  270. raise ExtractorError('Unsupported trait kind %d' % kind)
  271. if attrs & 0x4 != 0: # Metadata present
  272. metadata_count = u30()
  273. for _c3 in range(metadata_count):
  274. u30() # metadata index
  275. return methods, constants
  276. # Classes
  277. class_count = u30()
  278. classes = []
  279. for class_id in range(class_count):
  280. name_idx = u30()
  281. cname = self.multinames[name_idx]
  282. avm_class = _AVMClass(name_idx, cname)
  283. classes.append(avm_class)
  284. u30() # super_name idx
  285. flags = read_byte()
  286. if flags & 0x08 != 0: # Protected namespace is present
  287. u30() # protected_ns_idx
  288. intrf_count = u30()
  289. for _c2 in range(intrf_count):
  290. u30()
  291. u30() # iinit
  292. trait_count = u30()
  293. for _c2 in range(trait_count):
  294. trait_methods, constants = parse_traits_info()
  295. avm_class.register_methods(trait_methods)
  296. assert constants is None
  297. assert len(classes) == class_count
  298. self._classes_by_name = dict((c.name, c) for c in classes)
  299. for avm_class in classes:
  300. u30() # cinit
  301. trait_count = u30()
  302. for _c2 in range(trait_count):
  303. trait_methods, trait_constants = parse_traits_info()
  304. avm_class.register_methods(trait_methods)
  305. if trait_constants:
  306. avm_class.constants.update(trait_constants)
  307. # Scripts
  308. script_count = u30()
  309. for _c in range(script_count):
  310. u30() # init
  311. trait_count = u30()
  312. for _c2 in range(trait_count):
  313. parse_traits_info()
  314. # Method bodies
  315. method_body_count = u30()
  316. Method = collections.namedtuple('Method', ['code', 'local_count'])
  317. for _c in range(method_body_count):
  318. method_idx = u30()
  319. u30() # max_stack
  320. local_count = u30()
  321. u30() # init_scope_depth
  322. u30() # max_scope_depth
  323. code_length = u30()
  324. code = read_bytes(code_length)
  325. for avm_class in classes:
  326. if method_idx in avm_class.method_idxs:
  327. m = Method(code, local_count)
  328. avm_class.methods[avm_class.method_idxs[method_idx]] = m
  329. exception_count = u30()
  330. for _c2 in range(exception_count):
  331. u30() # from
  332. u30() # to
  333. u30() # target
  334. u30() # exc_type
  335. u30() # var_name
  336. trait_count = u30()
  337. for _c2 in range(trait_count):
  338. parse_traits_info()
  339. assert p + code_reader.tell() == len(code_tag)
  340. def patch_function(self, avm_class, func_name, f):
  341. self._patched_functions[(avm_class, func_name)] = f
  342. def extract_class(self, class_name):
  343. try:
  344. return self._classes_by_name[class_name]
  345. except KeyError:
  346. raise ExtractorError('Class %r not found' % class_name)
  347. def extract_function(self, avm_class, func_name):
  348. p = self._patched_functions.get((avm_class, func_name))
  349. if p:
  350. return p
  351. if func_name in avm_class.method_pyfunctions:
  352. return avm_class.method_pyfunctions[func_name]
  353. if func_name in self._classes_by_name:
  354. return self._classes_by_name[func_name].make_object()
  355. if func_name not in avm_class.methods:
  356. raise ExtractorError('Cannot find function %s.%s' % (
  357. avm_class.name, func_name))
  358. m = avm_class.methods[func_name]
  359. def resfunc(args):
  360. # Helper functions
  361. coder = io.BytesIO(m.code)
  362. s24 = lambda: _s24(coder)
  363. u30 = lambda: _u30(coder)
  364. registers = [avm_class.variables] + list(args) + [None] * m.local_count
  365. stack = []
  366. scopes = collections.deque([
  367. self._classes_by_name, avm_class.variables])
  368. while True:
  369. opcode = _read_byte(coder)
  370. if opcode == 9: # label
  371. pass # Spec says: "Do nothing."
  372. elif opcode == 16: # jump
  373. offset = s24()
  374. coder.seek(coder.tell() + offset)
  375. elif opcode == 17: # iftrue
  376. offset = s24()
  377. value = stack.pop()
  378. if value:
  379. coder.seek(coder.tell() + offset)
  380. elif opcode == 18: # iffalse
  381. offset = s24()
  382. value = stack.pop()
  383. if not value:
  384. coder.seek(coder.tell() + offset)
  385. elif opcode == 19: # ifeq
  386. offset = s24()
  387. value2 = stack.pop()
  388. value1 = stack.pop()
  389. if value2 == value1:
  390. coder.seek(coder.tell() + offset)
  391. elif opcode == 20: # ifne
  392. offset = s24()
  393. value2 = stack.pop()
  394. value1 = stack.pop()
  395. if value2 != value1:
  396. coder.seek(coder.tell() + offset)
  397. elif opcode == 21: # iflt
  398. offset = s24()
  399. value2 = stack.pop()
  400. value1 = stack.pop()
  401. if value1 < value2:
  402. coder.seek(coder.tell() + offset)
  403. elif opcode == 32: # pushnull
  404. stack.append(None)
  405. elif opcode == 33: # pushundefined
  406. stack.append(undefined)
  407. elif opcode == 36: # pushbyte
  408. v = _read_byte(coder)
  409. stack.append(v)
  410. elif opcode == 37: # pushshort
  411. v = u30()
  412. stack.append(v)
  413. elif opcode == 38: # pushtrue
  414. stack.append(True)
  415. elif opcode == 39: # pushfalse
  416. stack.append(False)
  417. elif opcode == 40: # pushnan
  418. stack.append(float('NaN'))
  419. elif opcode == 42: # dup
  420. value = stack[-1]
  421. stack.append(value)
  422. elif opcode == 44: # pushstring
  423. idx = u30()
  424. stack.append(self.constant_strings[idx])
  425. elif opcode == 48: # pushscope
  426. new_scope = stack.pop()
  427. scopes.append(new_scope)
  428. elif opcode == 66: # construct
  429. arg_count = u30()
  430. args = list(reversed(
  431. [stack.pop() for _ in range(arg_count)]))
  432. obj = stack.pop()
  433. res = obj.avm_class.make_object()
  434. stack.append(res)
  435. elif opcode == 70: # callproperty
  436. index = u30()
  437. mname = self.multinames[index]
  438. arg_count = u30()
  439. args = list(reversed(
  440. [stack.pop() for _ in range(arg_count)]))
  441. obj = stack.pop()
  442. if obj == StringClass:
  443. if mname == 'String':
  444. assert len(args) == 1
  445. assert isinstance(args[0], (
  446. int, compat_str, _Undefined))
  447. if args[0] == undefined:
  448. res = 'undefined'
  449. else:
  450. res = compat_str(args[0])
  451. stack.append(res)
  452. continue
  453. else:
  454. raise NotImplementedError(
  455. 'Function String.%s is not yet implemented'
  456. % mname)
  457. elif isinstance(obj, _AVMClass_Object):
  458. func = self.extract_function(obj.avm_class, mname)
  459. res = func(args)
  460. stack.append(res)
  461. continue
  462. elif isinstance(obj, _AVMClass):
  463. func = self.extract_function(obj, mname)
  464. res = func(args)
  465. stack.append(res)
  466. continue
  467. elif isinstance(obj, _ScopeDict):
  468. if mname in obj.avm_class.method_names:
  469. func = self.extract_function(obj.avm_class, mname)
  470. res = func(args)
  471. else:
  472. res = obj[mname]
  473. stack.append(res)
  474. continue
  475. elif isinstance(obj, compat_str):
  476. if mname == 'split':
  477. assert len(args) == 1
  478. assert isinstance(args[0], compat_str)
  479. if args[0] == '':
  480. res = list(obj)
  481. else:
  482. res = obj.split(args[0])
  483. stack.append(res)
  484. continue
  485. elif mname == 'charCodeAt':
  486. assert len(args) <= 1
  487. idx = 0 if len(args) == 0 else args[0]
  488. assert isinstance(idx, int)
  489. res = ord(obj[idx])
  490. stack.append(res)
  491. continue
  492. elif isinstance(obj, list):
  493. if mname == 'slice':
  494. assert len(args) == 1
  495. assert isinstance(args[0], int)
  496. res = obj[args[0]:]
  497. stack.append(res)
  498. continue
  499. elif mname == 'join':
  500. assert len(args) == 1
  501. assert isinstance(args[0], compat_str)
  502. res = args[0].join(obj)
  503. stack.append(res)
  504. continue
  505. raise NotImplementedError(
  506. 'Unsupported property %r on %r'
  507. % (mname, obj))
  508. elif opcode == 71: # returnvoid
  509. res = undefined
  510. return res
  511. elif opcode == 72: # returnvalue
  512. res = stack.pop()
  513. return res
  514. elif opcode == 74: # constructproperty
  515. index = u30()
  516. arg_count = u30()
  517. args = list(reversed(
  518. [stack.pop() for _ in range(arg_count)]))
  519. obj = stack.pop()
  520. mname = self.multinames[index]
  521. assert isinstance(obj, _AVMClass)
  522. # We do not actually call the constructor for now;
  523. # we just pretend it does nothing
  524. stack.append(obj.make_object())
  525. elif opcode == 79: # callpropvoid
  526. index = u30()
  527. mname = self.multinames[index]
  528. arg_count = u30()
  529. args = list(reversed(
  530. [stack.pop() for _ in range(arg_count)]))
  531. obj = stack.pop()
  532. if isinstance(obj, _AVMClass_Object):
  533. func = self.extract_function(obj.avm_class, mname)
  534. res = func(args)
  535. assert res is undefined
  536. continue
  537. if isinstance(obj, _ScopeDict):
  538. assert mname in obj.avm_class.method_names
  539. func = self.extract_function(obj.avm_class, mname)
  540. res = func(args)
  541. assert res is undefined
  542. continue
  543. if mname == 'reverse':
  544. assert isinstance(obj, list)
  545. obj.reverse()
  546. else:
  547. raise NotImplementedError(
  548. 'Unsupported (void) property %r on %r'
  549. % (mname, obj))
  550. elif opcode == 86: # newarray
  551. arg_count = u30()
  552. arr = []
  553. for i in range(arg_count):
  554. arr.append(stack.pop())
  555. arr = arr[::-1]
  556. stack.append(arr)
  557. elif opcode == 93: # findpropstrict
  558. index = u30()
  559. mname = self.multinames[index]
  560. for s in reversed(scopes):
  561. if mname in s:
  562. res = s
  563. break
  564. else:
  565. res = scopes[0]
  566. if mname not in res and mname in _builtin_classes:
  567. stack.append(_builtin_classes[mname])
  568. else:
  569. stack.append(res[mname])
  570. elif opcode == 94: # findproperty
  571. index = u30()
  572. mname = self.multinames[index]
  573. for s in reversed(scopes):
  574. if mname in s:
  575. res = s
  576. break
  577. else:
  578. res = avm_class.variables
  579. stack.append(res)
  580. elif opcode == 96: # getlex
  581. index = u30()
  582. mname = self.multinames[index]
  583. for s in reversed(scopes):
  584. if mname in s:
  585. scope = s
  586. break
  587. else:
  588. scope = avm_class.variables
  589. if mname in scope:
  590. res = scope[mname]
  591. else:
  592. res = avm_class.constants[mname]
  593. stack.append(res)
  594. elif opcode == 97: # setproperty
  595. index = u30()
  596. value = stack.pop()
  597. idx = self.multinames[index]
  598. if isinstance(idx, _Multiname):
  599. idx = stack.pop()
  600. obj = stack.pop()
  601. obj[idx] = value
  602. elif opcode == 98: # getlocal
  603. index = u30()
  604. stack.append(registers[index])
  605. elif opcode == 99: # setlocal
  606. index = u30()
  607. value = stack.pop()
  608. registers[index] = value
  609. elif opcode == 102: # getproperty
  610. index = u30()
  611. pname = self.multinames[index]
  612. if pname == 'length':
  613. obj = stack.pop()
  614. assert isinstance(obj, (compat_str, list))
  615. stack.append(len(obj))
  616. elif isinstance(pname, compat_str): # Member access
  617. obj = stack.pop()
  618. assert isinstance(obj, (dict, _ScopeDict)), \
  619. 'Accessing member %r on %r' % (pname, obj)
  620. res = obj.get(pname, undefined)
  621. stack.append(res)
  622. else: # Assume attribute access
  623. idx = stack.pop()
  624. assert isinstance(idx, int)
  625. obj = stack.pop()
  626. assert isinstance(obj, list)
  627. stack.append(obj[idx])
  628. elif opcode == 115: # convert_
  629. value = stack.pop()
  630. intvalue = int(value)
  631. stack.append(intvalue)
  632. elif opcode == 128: # coerce
  633. u30()
  634. elif opcode == 130: # coerce_a
  635. value = stack.pop()
  636. # um, yes, it's any value
  637. stack.append(value)
  638. elif opcode == 133: # coerce_s
  639. assert isinstance(stack[-1], (type(None), compat_str))
  640. elif opcode == 147: # decrement
  641. value = stack.pop()
  642. assert isinstance(value, int)
  643. stack.append(value - 1)
  644. elif opcode == 149: # typeof
  645. value = stack.pop()
  646. return {
  647. _Undefined: 'undefined',
  648. compat_str: 'String',
  649. int: 'Number',
  650. float: 'Number',
  651. }[type(value)]
  652. elif opcode == 160: # add
  653. value2 = stack.pop()
  654. value1 = stack.pop()
  655. res = value1 + value2
  656. stack.append(res)
  657. elif opcode == 161: # subtract
  658. value2 = stack.pop()
  659. value1 = stack.pop()
  660. res = value1 - value2
  661. stack.append(res)
  662. elif opcode == 162: # multiply
  663. value2 = stack.pop()
  664. value1 = stack.pop()
  665. res = value1 * value2
  666. stack.append(res)
  667. elif opcode == 164: # modulo
  668. value2 = stack.pop()
  669. value1 = stack.pop()
  670. res = value1 % value2
  671. stack.append(res)
  672. elif opcode == 168: # bitand
  673. value2 = stack.pop()
  674. value1 = stack.pop()
  675. assert isinstance(value1, int)
  676. assert isinstance(value2, int)
  677. res = value1 & value2
  678. stack.append(res)
  679. elif opcode == 171: # equals
  680. value2 = stack.pop()
  681. value1 = stack.pop()
  682. result = value1 == value2
  683. stack.append(result)
  684. elif opcode == 175: # greaterequals
  685. value2 = stack.pop()
  686. value1 = stack.pop()
  687. result = value1 >= value2
  688. stack.append(result)
  689. elif opcode == 192: # increment_i
  690. value = stack.pop()
  691. assert isinstance(value, int)
  692. stack.append(value + 1)
  693. elif opcode == 208: # getlocal_0
  694. stack.append(registers[0])
  695. elif opcode == 209: # getlocal_1
  696. stack.append(registers[1])
  697. elif opcode == 210: # getlocal_2
  698. stack.append(registers[2])
  699. elif opcode == 211: # getlocal_3
  700. stack.append(registers[3])
  701. elif opcode == 212: # setlocal_0
  702. registers[0] = stack.pop()
  703. elif opcode == 213: # setlocal_1
  704. registers[1] = stack.pop()
  705. elif opcode == 214: # setlocal_2
  706. registers[2] = stack.pop()
  707. elif opcode == 215: # setlocal_3
  708. registers[3] = stack.pop()
  709. else:
  710. raise NotImplementedError(
  711. 'Unsupported opcode %d' % opcode)
  712. avm_class.method_pyfunctions[func_name] = resfunc
  713. return resfunc