immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,190 @@
1
+ ----------------------------------------------------------------------------
2
+ -- LuaJIT bytecode listing module.
3
+ --
4
+ -- Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5
+ -- Released under the MIT license. See Copyright Notice in luajit.h
6
+ ----------------------------------------------------------------------------
7
+ --
8
+ -- This module lists the bytecode of a Lua function. If it's loaded by -jbc
9
+ -- it hooks into the parser and lists all functions of a chunk as they
10
+ -- are parsed.
11
+ --
12
+ -- Example usage:
13
+ --
14
+ -- luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; print(x)'
15
+ -- luajit -jbc=- foo.lua
16
+ -- luajit -jbc=foo.list foo.lua
17
+ --
18
+ -- Default output is to stderr. To redirect the output to a file, pass a
19
+ -- filename as an argument (use '-' for stdout) or set the environment
20
+ -- variable LUAJIT_LISTFILE. The file is overwritten every time the module
21
+ -- is started.
22
+ --
23
+ -- This module can also be used programmatically:
24
+ --
25
+ -- local bc = require("jit.bc")
26
+ --
27
+ -- local function foo() print("hello") end
28
+ --
29
+ -- bc.dump(foo) --> -- BYTECODE -- [...]
30
+ -- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello"
31
+ --
32
+ -- local out = {
33
+ -- -- Do something with each line:
34
+ -- write = function(t, ...) io.write(...) end,
35
+ -- close = function(t) end,
36
+ -- flush = function(t) end,
37
+ -- }
38
+ -- bc.dump(foo, out)
39
+ --
40
+ ------------------------------------------------------------------------------
41
+
42
+ -- Cache some library functions and objects.
43
+ local jit = require("jit")
44
+ assert(jit.version_num == 20100, "LuaJIT core/library version mismatch")
45
+ local jutil = require("jit.util")
46
+ local vmdef = require("jit.vmdef")
47
+ local bit = require("bit")
48
+ local sub, gsub, format = string.sub, string.gsub, string.format
49
+ local byte, band, shr = string.byte, bit.band, bit.rshift
50
+ local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck
51
+ local funcuvname = jutil.funcuvname
52
+ local bcnames = vmdef.bcnames
53
+ local stdout, stderr = io.stdout, io.stderr
54
+
55
+ ------------------------------------------------------------------------------
56
+
57
+ local function ctlsub(c)
58
+ if c == "\n" then return "\\n"
59
+ elseif c == "\r" then return "\\r"
60
+ elseif c == "\t" then return "\\t"
61
+ else return format("\\%03d", byte(c))
62
+ end
63
+ end
64
+
65
+ -- Return one bytecode line.
66
+ local function bcline(func, pc, prefix)
67
+ local ins, m = funcbc(func, pc)
68
+ if not ins then return end
69
+ local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128)
70
+ local a = band(shr(ins, 8), 0xff)
71
+ local oidx = 6*band(ins, 0xff)
72
+ local op = sub(bcnames, oidx+1, oidx+6)
73
+ local s = format("%04d %s %-6s %3s ",
74
+ pc, prefix or " ", op, ma == 0 and "" or a)
75
+ local d = shr(ins, 16)
76
+ if mc == 13*128 then -- BCMjump
77
+ return format("%s=> %04d\n", s, pc+d-0x7fff)
78
+ end
79
+ if mb ~= 0 then
80
+ d = band(d, 0xff)
81
+ elseif mc == 0 then
82
+ return s.."\n"
83
+ end
84
+ local kc
85
+ if mc == 10*128 then -- BCMstr
86
+ kc = funck(func, -d-1)
87
+ kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub))
88
+ elseif mc == 9*128 then -- BCMnum
89
+ kc = funck(func, d)
90
+ if op == "TSETM " then kc = kc - 2^52 end
91
+ elseif mc == 12*128 then -- BCMfunc
92
+ local fi = funcinfo(funck(func, -d-1))
93
+ if fi.ffid then
94
+ kc = vmdef.ffnames[fi.ffid]
95
+ else
96
+ kc = fi.loc
97
+ end
98
+ elseif mc == 5*128 then -- BCMuv
99
+ kc = funcuvname(func, d)
100
+ end
101
+ if ma == 5 then -- BCMuv
102
+ local ka = funcuvname(func, a)
103
+ if kc then kc = ka.." ; "..kc else kc = ka end
104
+ end
105
+ if mb ~= 0 then
106
+ local b = shr(ins, 24)
107
+ if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end
108
+ return format("%s%3d %3d\n", s, b, d)
109
+ end
110
+ if kc then return format("%s%3d ; %s\n", s, d, kc) end
111
+ if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits
112
+ return format("%s%3d\n", s, d)
113
+ end
114
+
115
+ -- Collect branch targets of a function.
116
+ local function bctargets(func)
117
+ local target = {}
118
+ for pc=1,1000000000 do
119
+ local ins, m = funcbc(func, pc)
120
+ if not ins then break end
121
+ if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end
122
+ end
123
+ return target
124
+ end
125
+
126
+ -- Dump bytecode instructions of a function.
127
+ local function bcdump(func, out, all)
128
+ if not out then out = stdout end
129
+ local fi = funcinfo(func)
130
+ if all and fi.children then
131
+ for n=-1,-1000000000,-1 do
132
+ local k = funck(func, n)
133
+ if not k then break end
134
+ if type(k) == "proto" then bcdump(k, out, true) end
135
+ end
136
+ end
137
+ out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined))
138
+ local target = bctargets(func)
139
+ for pc=1,1000000000 do
140
+ local s = bcline(func, pc, target[pc] and "=>")
141
+ if not s then break end
142
+ out:write(s)
143
+ end
144
+ out:write("\n")
145
+ out:flush()
146
+ end
147
+
148
+ ------------------------------------------------------------------------------
149
+
150
+ -- Active flag and output file handle.
151
+ local active, out
152
+
153
+ -- List handler.
154
+ local function h_list(func)
155
+ return bcdump(func, out)
156
+ end
157
+
158
+ -- Detach list handler.
159
+ local function bclistoff()
160
+ if active then
161
+ active = false
162
+ jit.attach(h_list)
163
+ if out and out ~= stdout and out ~= stderr then out:close() end
164
+ out = nil
165
+ end
166
+ end
167
+
168
+ -- Open the output file and attach list handler.
169
+ local function bcliston(outfile)
170
+ if active then bclistoff() end
171
+ if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end
172
+ if outfile then
173
+ out = outfile == "-" and stdout or assert(io.open(outfile, "w"))
174
+ else
175
+ out = stderr
176
+ end
177
+ jit.attach(h_list, "bc")
178
+ active = true
179
+ end
180
+
181
+ -- Public module functions.
182
+ return {
183
+ line = bcline,
184
+ dump = bcdump,
185
+ targets = bctargets,
186
+ on = bcliston,
187
+ off = bclistoff,
188
+ start = bcliston -- For -j command line option.
189
+ }
190
+
@@ -0,0 +1,661 @@
1
+ ----------------------------------------------------------------------------
2
+ -- LuaJIT module to save/list bytecode.
3
+ --
4
+ -- Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5
+ -- Released under the MIT license. See Copyright Notice in luajit.h
6
+ ----------------------------------------------------------------------------
7
+ --
8
+ -- This module saves or lists the bytecode for an input file.
9
+ -- It's run by the -b command line option.
10
+ --
11
+ ------------------------------------------------------------------------------
12
+
13
+ local jit = require("jit")
14
+ assert(jit.version_num == 20100, "LuaJIT core/library version mismatch")
15
+ local bit = require("bit")
16
+
17
+ -- Symbol name prefix for LuaJIT bytecode.
18
+ local LJBC_PREFIX = "luaJIT_BC_"
19
+
20
+ ------------------------------------------------------------------------------
21
+
22
+ local function usage()
23
+ io.stderr:write[[
24
+ Save LuaJIT bytecode: luajit -b[options] input output
25
+ -l Only list bytecode.
26
+ -s Strip debug info (default).
27
+ -g Keep debug info.
28
+ -n name Set module name (default: auto-detect from input name).
29
+ -t type Set output file type (default: auto-detect from output name).
30
+ -a arch Override architecture for object files (default: native).
31
+ -o os Override OS for object files (default: native).
32
+ -e chunk Use chunk string as input.
33
+ -- Stop handling options.
34
+ - Use stdin as input and/or stdout as output.
35
+
36
+ File types: c h obj o raw (default)
37
+ ]]
38
+ os.exit(1)
39
+ end
40
+
41
+ local function check(ok, ...)
42
+ if ok then return ok, ... end
43
+ io.stderr:write("luajit: ", ...)
44
+ io.stderr:write("\n")
45
+ os.exit(1)
46
+ end
47
+
48
+ local function readfile(input)
49
+ if type(input) == "function" then return input end
50
+ if input == "-" then input = nil end
51
+ return check(loadfile(input))
52
+ end
53
+
54
+ local function savefile(name, mode)
55
+ if name == "-" then return io.stdout end
56
+ return check(io.open(name, mode))
57
+ end
58
+
59
+ ------------------------------------------------------------------------------
60
+
61
+ local map_type = {
62
+ raw = "raw", c = "c", h = "h", o = "obj", obj = "obj",
63
+ }
64
+
65
+ local map_arch = {
66
+ x86 = true, x64 = true, arm = true, arm64 = true, ppc = true,
67
+ mips = true, mipsel = true,
68
+ }
69
+
70
+ local map_os = {
71
+ linux = true, windows = true, osx = true, freebsd = true, netbsd = true,
72
+ openbsd = true, dragonfly = true, solaris = true,
73
+ }
74
+
75
+ local function checkarg(str, map, err)
76
+ str = string.lower(str)
77
+ local s = check(map[str], "unknown ", err)
78
+ return s == true and str or s
79
+ end
80
+
81
+ local function detecttype(str)
82
+ local ext = string.match(string.lower(str), "%.(%a+)$")
83
+ return map_type[ext] or "raw"
84
+ end
85
+
86
+ local function checkmodname(str)
87
+ check(string.match(str, "^[%w_.%-]+$"), "bad module name")
88
+ return string.gsub(str, "[%.%-]", "_")
89
+ end
90
+
91
+ local function detectmodname(str)
92
+ if type(str) == "string" then
93
+ local tail = string.match(str, "[^/\\]+$")
94
+ if tail then str = tail end
95
+ local head = string.match(str, "^(.*)%.[^.]*$")
96
+ if head then str = head end
97
+ str = string.match(str, "^[%w_.%-]+")
98
+ else
99
+ str = nil
100
+ end
101
+ check(str, "cannot derive module name, use -n name")
102
+ return string.gsub(str, "[%.%-]", "_")
103
+ end
104
+
105
+ ------------------------------------------------------------------------------
106
+
107
+ local function bcsave_tail(fp, output, s)
108
+ local ok, err = fp:write(s)
109
+ if ok and output ~= "-" then ok, err = fp:close() end
110
+ check(ok, "cannot write ", output, ": ", err)
111
+ end
112
+
113
+ local function bcsave_raw(output, s)
114
+ local fp = savefile(output, "wb")
115
+ bcsave_tail(fp, output, s)
116
+ end
117
+
118
+ local function bcsave_c(ctx, output, s)
119
+ local fp = savefile(output, "w")
120
+ if ctx.type == "c" then
121
+ fp:write(string.format([[
122
+ #ifdef _cplusplus
123
+ extern "C"
124
+ #endif
125
+ #ifdef _WIN32
126
+ __declspec(dllexport)
127
+ #endif
128
+ const char %s%s[] = {
129
+ ]], LJBC_PREFIX, ctx.modname))
130
+ else
131
+ fp:write(string.format([[
132
+ #define %s%s_SIZE %d
133
+ static const char %s%s[] = {
134
+ ]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname))
135
+ end
136
+ local t, n, m = {}, 0, 0
137
+ for i=1,#s do
138
+ local b = tostring(string.byte(s, i))
139
+ m = m + #b + 1
140
+ if m > 78 then
141
+ fp:write(table.concat(t, ",", 1, n), ",\n")
142
+ n, m = 0, #b + 1
143
+ end
144
+ n = n + 1
145
+ t[n] = b
146
+ end
147
+ bcsave_tail(fp, output, table.concat(t, ",", 1, n).."\n};\n")
148
+ end
149
+
150
+ local function bcsave_elfobj(ctx, output, s, ffi)
151
+ ffi.cdef[[
152
+ typedef struct {
153
+ uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];
154
+ uint16_t type, machine;
155
+ uint32_t version;
156
+ uint32_t entry, phofs, shofs;
157
+ uint32_t flags;
158
+ uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;
159
+ } ELF32header;
160
+ typedef struct {
161
+ uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];
162
+ uint16_t type, machine;
163
+ uint32_t version;
164
+ uint64_t entry, phofs, shofs;
165
+ uint32_t flags;
166
+ uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;
167
+ } ELF64header;
168
+ typedef struct {
169
+ uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize;
170
+ } ELF32sectheader;
171
+ typedef struct {
172
+ uint32_t name, type;
173
+ uint64_t flags, addr, ofs, size;
174
+ uint32_t link, info;
175
+ uint64_t align, entsize;
176
+ } ELF64sectheader;
177
+ typedef struct {
178
+ uint32_t name, value, size;
179
+ uint8_t info, other;
180
+ uint16_t sectidx;
181
+ } ELF32symbol;
182
+ typedef struct {
183
+ uint32_t name;
184
+ uint8_t info, other;
185
+ uint16_t sectidx;
186
+ uint64_t value, size;
187
+ } ELF64symbol;
188
+ typedef struct {
189
+ ELF32header hdr;
190
+ ELF32sectheader sect[6];
191
+ ELF32symbol sym[2];
192
+ uint8_t space[4096];
193
+ } ELF32obj;
194
+ typedef struct {
195
+ ELF64header hdr;
196
+ ELF64sectheader sect[6];
197
+ ELF64symbol sym[2];
198
+ uint8_t space[4096];
199
+ } ELF64obj;
200
+ ]]
201
+ local symname = LJBC_PREFIX..ctx.modname
202
+ local is64, isbe = false, false
203
+ if ctx.arch == "x64" then
204
+ is64 = true
205
+ elseif ctx.arch == "ppc" or ctx.arch == "mips" then
206
+ isbe = true
207
+ end
208
+
209
+ -- Handle different host/target endianess.
210
+ local function f32(x) return x end
211
+ local f16, fofs = f32, f32
212
+ if ffi.abi("be") ~= isbe then
213
+ f32 = bit.bswap
214
+ function f16(x) return bit.rshift(bit.bswap(x), 16) end
215
+ if is64 then
216
+ local two32 = ffi.cast("int64_t", 2^32)
217
+ function fofs(x) return bit.bswap(x)*two32 end
218
+ else
219
+ fofs = f32
220
+ end
221
+ end
222
+
223
+ -- Create ELF object and fill in header.
224
+ local o = ffi.new(is64 and "ELF64obj" or "ELF32obj")
225
+ local hdr = o.hdr
226
+ if ctx.os == "bsd" or ctx.os == "other" then -- Determine native hdr.eosabi.
227
+ local bf = assert(io.open("/bin/ls", "rb"))
228
+ local bs = bf:read(9)
229
+ bf:close()
230
+ ffi.copy(o, bs, 9)
231
+ check(hdr.emagic[0] == 127, "no support for writing native object files")
232
+ else
233
+ hdr.emagic = "\127ELF"
234
+ hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0
235
+ end
236
+ hdr.eclass = is64 and 2 or 1
237
+ hdr.eendian = isbe and 2 or 1
238
+ hdr.eversion = 1
239
+ hdr.type = f16(1)
240
+ hdr.machine = f16(({ x86=3, x64=62, arm=40, arm64=183, ppc=20, mips=8, mipsel=8 })[ctx.arch])
241
+ if ctx.arch == "mips" or ctx.arch == "mipsel" then
242
+ hdr.flags = 0x50001006
243
+ end
244
+ hdr.version = f32(1)
245
+ hdr.shofs = fofs(ffi.offsetof(o, "sect"))
246
+ hdr.ehsize = f16(ffi.sizeof(hdr))
247
+ hdr.shentsize = f16(ffi.sizeof(o.sect[0]))
248
+ hdr.shnum = f16(6)
249
+ hdr.shstridx = f16(2)
250
+
251
+ -- Fill in sections and symbols.
252
+ local sofs, ofs = ffi.offsetof(o, "space"), 1
253
+ for i,name in ipairs{
254
+ ".symtab", ".shstrtab", ".strtab", ".rodata", ".note.GNU-stack",
255
+ } do
256
+ local sect = o.sect[i]
257
+ sect.align = fofs(1)
258
+ sect.name = f32(ofs)
259
+ ffi.copy(o.space+ofs, name)
260
+ ofs = ofs + #name+1
261
+ end
262
+ o.sect[1].type = f32(2) -- .symtab
263
+ o.sect[1].link = f32(3)
264
+ o.sect[1].info = f32(1)
265
+ o.sect[1].align = fofs(8)
266
+ o.sect[1].ofs = fofs(ffi.offsetof(o, "sym"))
267
+ o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0]))
268
+ o.sect[1].size = fofs(ffi.sizeof(o.sym))
269
+ o.sym[1].name = f32(1)
270
+ o.sym[1].sectidx = f16(4)
271
+ o.sym[1].size = fofs(#s)
272
+ o.sym[1].info = 17
273
+ o.sect[2].type = f32(3) -- .shstrtab
274
+ o.sect[2].ofs = fofs(sofs)
275
+ o.sect[2].size = fofs(ofs)
276
+ o.sect[3].type = f32(3) -- .strtab
277
+ o.sect[3].ofs = fofs(sofs + ofs)
278
+ o.sect[3].size = fofs(#symname+1)
279
+ ffi.copy(o.space+ofs+1, symname)
280
+ ofs = ofs + #symname + 2
281
+ o.sect[4].type = f32(1) -- .rodata
282
+ o.sect[4].flags = fofs(2)
283
+ o.sect[4].ofs = fofs(sofs + ofs)
284
+ o.sect[4].size = fofs(#s)
285
+ o.sect[5].type = f32(1) -- .note.GNU-stack
286
+ o.sect[5].ofs = fofs(sofs + ofs + #s)
287
+
288
+ -- Write ELF object file.
289
+ local fp = savefile(output, "wb")
290
+ fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))
291
+ bcsave_tail(fp, output, s)
292
+ end
293
+
294
+ local function bcsave_peobj(ctx, output, s, ffi)
295
+ ffi.cdef[[
296
+ typedef struct {
297
+ uint16_t arch, nsects;
298
+ uint32_t time, symtabofs, nsyms;
299
+ uint16_t opthdrsz, flags;
300
+ } PEheader;
301
+ typedef struct {
302
+ char name[8];
303
+ uint32_t vsize, vaddr, size, ofs, relocofs, lineofs;
304
+ uint16_t nreloc, nline;
305
+ uint32_t flags;
306
+ } PEsection;
307
+ typedef struct __attribute((packed)) {
308
+ union {
309
+ char name[8];
310
+ uint32_t nameref[2];
311
+ };
312
+ uint32_t value;
313
+ int16_t sect;
314
+ uint16_t type;
315
+ uint8_t scl, naux;
316
+ } PEsym;
317
+ typedef struct __attribute((packed)) {
318
+ uint32_t size;
319
+ uint16_t nreloc, nline;
320
+ uint32_t cksum;
321
+ uint16_t assoc;
322
+ uint8_t comdatsel, unused[3];
323
+ } PEsymaux;
324
+ typedef struct {
325
+ PEheader hdr;
326
+ PEsection sect[2];
327
+ // Must be an even number of symbol structs.
328
+ PEsym sym0;
329
+ PEsymaux sym0aux;
330
+ PEsym sym1;
331
+ PEsymaux sym1aux;
332
+ PEsym sym2;
333
+ PEsym sym3;
334
+ uint32_t strtabsize;
335
+ uint8_t space[4096];
336
+ } PEobj;
337
+ ]]
338
+ local symname = LJBC_PREFIX..ctx.modname
339
+ local is64 = false
340
+ if ctx.arch == "x86" then
341
+ symname = "_"..symname
342
+ elseif ctx.arch == "x64" then
343
+ is64 = true
344
+ end
345
+ local symexport = " /EXPORT:"..symname..",DATA "
346
+
347
+ -- The file format is always little-endian. Swap if the host is big-endian.
348
+ local function f32(x) return x end
349
+ local f16 = f32
350
+ if ffi.abi("be") then
351
+ f32 = bit.bswap
352
+ function f16(x) return bit.rshift(bit.bswap(x), 16) end
353
+ end
354
+
355
+ -- Create PE object and fill in header.
356
+ local o = ffi.new("PEobj")
357
+ local hdr = o.hdr
358
+ hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2, mips=0x366, mipsel=0x366 })[ctx.arch])
359
+ hdr.nsects = f16(2)
360
+ hdr.symtabofs = f32(ffi.offsetof(o, "sym0"))
361
+ hdr.nsyms = f32(6)
362
+
363
+ -- Fill in sections and symbols.
364
+ o.sect[0].name = ".drectve"
365
+ o.sect[0].size = f32(#symexport)
366
+ o.sect[0].flags = f32(0x00100a00)
367
+ o.sym0.sect = f16(1)
368
+ o.sym0.scl = 3
369
+ o.sym0.name = ".drectve"
370
+ o.sym0.naux = 1
371
+ o.sym0aux.size = f32(#symexport)
372
+ o.sect[1].name = ".rdata"
373
+ o.sect[1].size = f32(#s)
374
+ o.sect[1].flags = f32(0x40300040)
375
+ o.sym1.sect = f16(2)
376
+ o.sym1.scl = 3
377
+ o.sym1.name = ".rdata"
378
+ o.sym1.naux = 1
379
+ o.sym1aux.size = f32(#s)
380
+ o.sym2.sect = f16(2)
381
+ o.sym2.scl = 2
382
+ o.sym2.nameref[1] = f32(4)
383
+ o.sym3.sect = f16(-1)
384
+ o.sym3.scl = 2
385
+ o.sym3.value = f32(1)
386
+ o.sym3.name = "@feat.00" -- Mark as SafeSEH compliant.
387
+ ffi.copy(o.space, symname)
388
+ local ofs = #symname + 1
389
+ o.strtabsize = f32(ofs + 4)
390
+ o.sect[0].ofs = f32(ffi.offsetof(o, "space") + ofs)
391
+ ffi.copy(o.space + ofs, symexport)
392
+ ofs = ofs + #symexport
393
+ o.sect[1].ofs = f32(ffi.offsetof(o, "space") + ofs)
394
+
395
+ -- Write PE object file.
396
+ local fp = savefile(output, "wb")
397
+ fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))
398
+ bcsave_tail(fp, output, s)
399
+ end
400
+
401
+ local function bcsave_machobj(ctx, output, s, ffi)
402
+ ffi.cdef[[
403
+ typedef struct
404
+ {
405
+ uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags;
406
+ } mach_header;
407
+ typedef struct
408
+ {
409
+ mach_header; uint32_t reserved;
410
+ } mach_header_64;
411
+ typedef struct {
412
+ uint32_t cmd, cmdsize;
413
+ char segname[16];
414
+ uint32_t vmaddr, vmsize, fileoff, filesize;
415
+ uint32_t maxprot, initprot, nsects, flags;
416
+ } mach_segment_command;
417
+ typedef struct {
418
+ uint32_t cmd, cmdsize;
419
+ char segname[16];
420
+ uint64_t vmaddr, vmsize, fileoff, filesize;
421
+ uint32_t maxprot, initprot, nsects, flags;
422
+ } mach_segment_command_64;
423
+ typedef struct {
424
+ char sectname[16], segname[16];
425
+ uint32_t addr, size;
426
+ uint32_t offset, align, reloff, nreloc, flags;
427
+ uint32_t reserved1, reserved2;
428
+ } mach_section;
429
+ typedef struct {
430
+ char sectname[16], segname[16];
431
+ uint64_t addr, size;
432
+ uint32_t offset, align, reloff, nreloc, flags;
433
+ uint32_t reserved1, reserved2, reserved3;
434
+ } mach_section_64;
435
+ typedef struct {
436
+ uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize;
437
+ } mach_symtab_command;
438
+ typedef struct {
439
+ int32_t strx;
440
+ uint8_t type, sect;
441
+ int16_t desc;
442
+ uint32_t value;
443
+ } mach_nlist;
444
+ typedef struct {
445
+ uint32_t strx;
446
+ uint8_t type, sect;
447
+ uint16_t desc;
448
+ uint64_t value;
449
+ } mach_nlist_64;
450
+ typedef struct
451
+ {
452
+ uint32_t magic, nfat_arch;
453
+ } mach_fat_header;
454
+ typedef struct
455
+ {
456
+ uint32_t cputype, cpusubtype, offset, size, align;
457
+ } mach_fat_arch;
458
+ typedef struct {
459
+ struct {
460
+ mach_header hdr;
461
+ mach_segment_command seg;
462
+ mach_section sec;
463
+ mach_symtab_command sym;
464
+ } arch[1];
465
+ mach_nlist sym_entry;
466
+ uint8_t space[4096];
467
+ } mach_obj;
468
+ typedef struct {
469
+ struct {
470
+ mach_header_64 hdr;
471
+ mach_segment_command_64 seg;
472
+ mach_section_64 sec;
473
+ mach_symtab_command sym;
474
+ } arch[1];
475
+ mach_nlist_64 sym_entry;
476
+ uint8_t space[4096];
477
+ } mach_obj_64;
478
+ typedef struct {
479
+ mach_fat_header fat;
480
+ mach_fat_arch fat_arch[2];
481
+ struct {
482
+ mach_header hdr;
483
+ mach_segment_command seg;
484
+ mach_section sec;
485
+ mach_symtab_command sym;
486
+ } arch[2];
487
+ mach_nlist sym_entry;
488
+ uint8_t space[4096];
489
+ } mach_fat_obj;
490
+ ]]
491
+ local symname = '_'..LJBC_PREFIX..ctx.modname
492
+ local isfat, is64, align, mobj = false, false, 4, "mach_obj"
493
+ if ctx.arch == "x64" then
494
+ is64, align, mobj = true, 8, "mach_obj_64"
495
+ elseif ctx.arch == "arm" then
496
+ isfat, mobj = true, "mach_fat_obj"
497
+ elseif ctx.arch == "arm64" then
498
+ is64, align, isfat, mobj = true, 8, true, "mach_fat_obj"
499
+ else
500
+ check(ctx.arch == "x86", "unsupported architecture for OSX")
501
+ end
502
+ local function aligned(v, a) return bit.band(v+a-1, -a) end
503
+ local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE.
504
+
505
+ -- Create Mach-O object and fill in header.
506
+ local o = ffi.new(mobj)
507
+ local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align)
508
+ local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12}, arm64={0x01000007,0x0100000c} })[ctx.arch]
509
+ local cpusubtype = ({ x86={3}, x64={3}, arm={3,9}, arm64={3,0} })[ctx.arch]
510
+ if isfat then
511
+ o.fat.magic = be32(0xcafebabe)
512
+ o.fat.nfat_arch = be32(#cpusubtype)
513
+ end
514
+
515
+ -- Fill in sections and symbols.
516
+ for i=0,#cpusubtype-1 do
517
+ local ofs = 0
518
+ if isfat then
519
+ local a = o.fat_arch[i]
520
+ a.cputype = be32(cputype[i+1])
521
+ a.cpusubtype = be32(cpusubtype[i+1])
522
+ -- Subsequent slices overlap each other to share data.
523
+ ofs = ffi.offsetof(o, "arch") + i*ffi.sizeof(o.arch[0])
524
+ a.offset = be32(ofs)
525
+ a.size = be32(mach_size-ofs+#s)
526
+ end
527
+ local a = o.arch[i]
528
+ a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface
529
+ a.hdr.cputype = cputype[i+1]
530
+ a.hdr.cpusubtype = cpusubtype[i+1]
531
+ a.hdr.filetype = 1
532
+ a.hdr.ncmds = 2
533
+ a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym)
534
+ a.seg.cmd = is64 and 0x19 or 0x1
535
+ a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)
536
+ a.seg.vmsize = #s
537
+ a.seg.fileoff = mach_size-ofs
538
+ a.seg.filesize = #s
539
+ a.seg.maxprot = 1
540
+ a.seg.initprot = 1
541
+ a.seg.nsects = 1
542
+ ffi.copy(a.sec.sectname, "__data")
543
+ ffi.copy(a.sec.segname, "__DATA")
544
+ a.sec.size = #s
545
+ a.sec.offset = mach_size-ofs
546
+ a.sym.cmd = 2
547
+ a.sym.cmdsize = ffi.sizeof(a.sym)
548
+ a.sym.symoff = ffi.offsetof(o, "sym_entry")-ofs
549
+ a.sym.nsyms = 1
550
+ a.sym.stroff = ffi.offsetof(o, "sym_entry")+ffi.sizeof(o.sym_entry)-ofs
551
+ a.sym.strsize = aligned(#symname+2, align)
552
+ end
553
+ o.sym_entry.type = 0xf
554
+ o.sym_entry.sect = 1
555
+ o.sym_entry.strx = 1
556
+ ffi.copy(o.space+1, symname)
557
+
558
+ -- Write Macho-O object file.
559
+ local fp = savefile(output, "wb")
560
+ fp:write(ffi.string(o, mach_size))
561
+ bcsave_tail(fp, output, s)
562
+ end
563
+
564
+ local function bcsave_obj(ctx, output, s)
565
+ local ok, ffi = pcall(require, "ffi")
566
+ check(ok, "FFI library required to write this file type")
567
+ if ctx.os == "windows" then
568
+ return bcsave_peobj(ctx, output, s, ffi)
569
+ elseif ctx.os == "osx" then
570
+ return bcsave_machobj(ctx, output, s, ffi)
571
+ else
572
+ return bcsave_elfobj(ctx, output, s, ffi)
573
+ end
574
+ end
575
+
576
+ ------------------------------------------------------------------------------
577
+
578
+ local function bclist(input, output)
579
+ local f = readfile(input)
580
+ require("jit.bc").dump(f, savefile(output, "w"), true)
581
+ end
582
+
583
+ local function bcsave(ctx, input, output)
584
+ local f = readfile(input)
585
+ local s = string.dump(f, ctx.strip)
586
+ local t = ctx.type
587
+ if not t then
588
+ t = detecttype(output)
589
+ ctx.type = t
590
+ end
591
+ if t == "raw" then
592
+ bcsave_raw(output, s)
593
+ else
594
+ if not ctx.modname then ctx.modname = detectmodname(input) end
595
+ if t == "obj" then
596
+ bcsave_obj(ctx, output, s)
597
+ else
598
+ bcsave_c(ctx, output, s)
599
+ end
600
+ end
601
+ end
602
+
603
+ local function docmd(...)
604
+ local arg = {...}
605
+ local n = 1
606
+ local list = false
607
+ local ctx = {
608
+ strip = true, arch = jit.arch, os = string.lower(jit.os),
609
+ type = false, modname = false,
610
+ }
611
+ while n <= #arg do
612
+ local a = arg[n]
613
+ if type(a) == "string" and string.sub(a, 1, 1) == "-" and a ~= "-" then
614
+ table.remove(arg, n)
615
+ if a == "--" then break end
616
+ for m=2,#a do
617
+ local opt = string.sub(a, m, m)
618
+ if opt == "l" then
619
+ list = true
620
+ elseif opt == "s" then
621
+ ctx.strip = true
622
+ elseif opt == "g" then
623
+ ctx.strip = false
624
+ else
625
+ if arg[n] == nil or m ~= #a then usage() end
626
+ if opt == "e" then
627
+ if n ~= 1 then usage() end
628
+ arg[1] = check(loadstring(arg[1]))
629
+ elseif opt == "n" then
630
+ ctx.modname = checkmodname(table.remove(arg, n))
631
+ elseif opt == "t" then
632
+ ctx.type = checkarg(table.remove(arg, n), map_type, "file type")
633
+ elseif opt == "a" then
634
+ ctx.arch = checkarg(table.remove(arg, n), map_arch, "architecture")
635
+ elseif opt == "o" then
636
+ ctx.os = checkarg(table.remove(arg, n), map_os, "OS name")
637
+ else
638
+ usage()
639
+ end
640
+ end
641
+ end
642
+ else
643
+ n = n + 1
644
+ end
645
+ end
646
+ if list then
647
+ if #arg == 0 or #arg > 2 then usage() end
648
+ bclist(arg[1], arg[2] or "-")
649
+ else
650
+ if #arg ~= 2 then usage() end
651
+ bcsave(ctx, arg[1], arg[2])
652
+ end
653
+ end
654
+
655
+ ------------------------------------------------------------------------------
656
+
657
+ -- Public module functions.
658
+ return {
659
+ start = docmd -- Process -b command line option.
660
+ }
661
+