librex 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. data/README.md +12 -0
  2. data/lib/rex.rb +0 -0
  3. data/lib/rex.rb.ts.rb +0 -0
  4. data/lib/rex/LICENSE +0 -0
  5. data/lib/rex/arch.rb +0 -0
  6. data/lib/rex/arch/sparc.rb +0 -0
  7. data/lib/rex/arch/sparc.rb.ut.rb +0 -0
  8. data/lib/rex/arch/x86.rb +0 -0
  9. data/lib/rex/arch/x86.rb.ut.rb +0 -0
  10. data/lib/rex/assembly/nasm.rb +0 -0
  11. data/lib/rex/assembly/nasm.rb.ut.rb +0 -0
  12. data/lib/rex/codepage.map +0 -0
  13. data/lib/rex/compat.rb +0 -0
  14. data/lib/rex/constants.rb +0 -0
  15. data/lib/rex/elfparsey.rb +0 -0
  16. data/lib/rex/elfparsey/elf.rb +0 -0
  17. data/lib/rex/elfparsey/elfbase.rb +2 -4
  18. data/lib/rex/elfparsey/exceptions.rb +0 -0
  19. data/lib/rex/elfscan.rb +0 -0
  20. data/lib/rex/elfscan/scanner.rb +0 -0
  21. data/lib/rex/elfscan/search.rb +10 -10
  22. data/lib/rex/encoder/alpha2.rb +0 -0
  23. data/lib/rex/encoder/alpha2/alpha_mixed.rb +0 -0
  24. data/lib/rex/encoder/alpha2/alpha_upper.rb +0 -0
  25. data/lib/rex/encoder/alpha2/generic.rb +0 -0
  26. data/lib/rex/encoder/alpha2/unicode_mixed.rb +0 -0
  27. data/lib/rex/encoder/alpha2/unicode_upper.rb +0 -0
  28. data/lib/rex/encoder/ndr.rb +0 -0
  29. data/lib/rex/encoder/ndr.rb.ut.rb +0 -0
  30. data/lib/rex/encoder/nonalpha.rb +0 -0
  31. data/lib/rex/encoder/nonupper.rb +0 -0
  32. data/lib/rex/encoder/xdr.rb +0 -0
  33. data/lib/rex/encoder/xdr.rb.ut.rb +0 -0
  34. data/lib/rex/encoder/xor.rb +0 -0
  35. data/lib/rex/encoder/xor/dword.rb +0 -0
  36. data/lib/rex/encoder/xor/dword_additive.rb +0 -0
  37. data/lib/rex/encoders/xor_dword.rb +0 -0
  38. data/lib/rex/encoders/xor_dword_additive.rb +0 -0
  39. data/lib/rex/encoders/xor_dword_additive.rb.ut.rb +0 -0
  40. data/lib/rex/encoding/xor.rb +0 -0
  41. data/lib/rex/encoding/xor.rb.ts.rb +0 -0
  42. data/lib/rex/encoding/xor/byte.rb +0 -0
  43. data/lib/rex/encoding/xor/byte.rb.ut.rb +0 -0
  44. data/lib/rex/encoding/xor/dword.rb +0 -0
  45. data/lib/rex/encoding/xor/dword.rb.ut.rb +0 -0
  46. data/lib/rex/encoding/xor/dword_additive.rb +0 -0
  47. data/lib/rex/encoding/xor/dword_additive.rb.ut.rb +0 -0
  48. data/lib/rex/encoding/xor/exceptions.rb +0 -0
  49. data/lib/rex/encoding/xor/generic.rb +0 -0
  50. data/lib/rex/encoding/xor/generic.rb.ut.rb +0 -0
  51. data/lib/rex/encoding/xor/qword.rb +0 -0
  52. data/lib/rex/encoding/xor/word.rb +0 -0
  53. data/lib/rex/encoding/xor/word.rb.ut.rb +0 -0
  54. data/lib/rex/exceptions.rb +0 -0
  55. data/lib/rex/exceptions.rb.ut.rb +0 -0
  56. data/lib/rex/exploitation/cmdstager.rb +0 -0
  57. data/lib/rex/exploitation/cmdstager/base.rb +6 -1
  58. data/lib/rex/exploitation/cmdstager/debug_asm.rb +0 -0
  59. data/lib/rex/exploitation/cmdstager/debug_write.rb +0 -0
  60. data/lib/rex/exploitation/cmdstager/tftp.rb +8 -8
  61. data/lib/rex/exploitation/cmdstager/vbs.rb +0 -0
  62. data/lib/rex/exploitation/egghunter.rb +143 -36
  63. data/lib/rex/exploitation/egghunter.rb.ut.rb +0 -0
  64. data/lib/rex/exploitation/encryptjs.rb +0 -0
  65. data/lib/rex/exploitation/heaplib.js.b64 +0 -0
  66. data/lib/rex/exploitation/heaplib.rb +0 -0
  67. data/lib/rex/exploitation/javascriptosdetect.rb +114 -15
  68. data/lib/rex/exploitation/obfuscatejs.rb +0 -0
  69. data/lib/rex/exploitation/omelet.rb +320 -0
  70. data/lib/rex/exploitation/omelet.rb.ut.rb +13 -0
  71. data/lib/rex/exploitation/opcodedb.rb +0 -0
  72. data/lib/rex/exploitation/opcodedb.rb.ut.rb +0 -0
  73. data/lib/rex/exploitation/seh.rb +0 -0
  74. data/lib/rex/exploitation/seh.rb.ut.rb +0 -0
  75. data/lib/rex/file.rb +1 -1
  76. data/lib/rex/file.rb.ut.rb +0 -0
  77. data/lib/rex/image_source.rb +0 -0
  78. data/lib/rex/image_source/disk.rb +0 -0
  79. data/lib/rex/image_source/image_source.rb +0 -0
  80. data/lib/rex/image_source/memory.rb +0 -0
  81. data/lib/rex/io/bidirectional_pipe.rb +0 -0
  82. data/lib/rex/io/datagram_abstraction.rb +0 -0
  83. data/lib/rex/io/stream.rb +1 -1
  84. data/lib/rex/io/stream_abstraction.rb +0 -0
  85. data/lib/rex/io/stream_server.rb +0 -0
  86. data/lib/rex/job_container.rb +0 -1
  87. data/lib/rex/logging.rb +0 -0
  88. data/lib/rex/logging/log_dispatcher.rb +0 -0
  89. data/lib/rex/logging/log_sink.rb +0 -0
  90. data/lib/rex/logging/sinks/flatfile.rb +0 -0
  91. data/lib/rex/logging/sinks/stderr.rb +0 -0
  92. data/lib/rex/machparsey.rb +0 -0
  93. data/lib/rex/machparsey/exceptions.rb +0 -0
  94. data/lib/rex/machparsey/machbase.rb +0 -0
  95. data/lib/rex/machscan.rb +0 -0
  96. data/lib/rex/machscan/scanner.rb +0 -0
  97. data/lib/rex/mime.rb +0 -0
  98. data/lib/rex/mime/header.rb +0 -0
  99. data/lib/rex/mime/message.rb +0 -0
  100. data/lib/rex/mime/part.rb +0 -0
  101. data/lib/rex/nop/opty2.rb +0 -0
  102. data/lib/rex/nop/opty2.rb.ut.rb +0 -0
  103. data/lib/rex/nop/opty2_tables.rb +0 -0
  104. data/lib/rex/ole.rb +0 -0
  105. data/lib/rex/ole/clsid.rb +0 -0
  106. data/lib/rex/ole/difat.rb +0 -0
  107. data/lib/rex/ole/directory.rb +0 -0
  108. data/lib/rex/ole/direntry.rb +0 -0
  109. data/lib/rex/ole/docs/dependencies.txt +8 -0
  110. data/lib/rex/ole/docs/references.txt +1 -0
  111. data/lib/rex/ole/fat.rb +0 -0
  112. data/lib/rex/ole/header.rb +3 -3
  113. data/lib/rex/ole/minifat.rb +0 -0
  114. data/lib/rex/ole/storage.rb +4 -4
  115. data/lib/rex/ole/stream.rb +0 -0
  116. data/lib/rex/ole/substorage.rb +0 -0
  117. data/lib/rex/ole/util.rb +0 -0
  118. data/lib/rex/parser/arguments.rb +0 -0
  119. data/lib/rex/parser/arguments.rb.ut.rb +0 -0
  120. data/lib/rex/parser/ini.rb +0 -0
  121. data/lib/rex/parser/ini.rb.ut.rb +0 -0
  122. data/lib/rex/parser/nexpose_xml.rb +0 -0
  123. data/lib/rex/parser/nmap_xml.rb +0 -0
  124. data/lib/rex/payloads.rb +0 -0
  125. data/lib/rex/payloads/win32.rb +0 -0
  126. data/lib/rex/payloads/win32/common.rb +0 -0
  127. data/lib/rex/payloads/win32/kernel.rb +0 -0
  128. data/lib/rex/payloads/win32/kernel/common.rb +0 -0
  129. data/lib/rex/payloads/win32/kernel/migration.rb +0 -0
  130. data/lib/rex/payloads/win32/kernel/recovery.rb +0 -0
  131. data/lib/rex/peparsey.rb +0 -0
  132. data/lib/rex/peparsey/exceptions.rb +0 -0
  133. data/lib/rex/peparsey/pe.rb +7 -1
  134. data/lib/rex/peparsey/pe_memdump.rb +0 -0
  135. data/lib/rex/peparsey/pebase.rb +27 -2
  136. data/lib/rex/peparsey/section.rb +0 -0
  137. data/lib/rex/pescan.rb +0 -0
  138. data/lib/rex/pescan/analyze.rb +0 -0
  139. data/lib/rex/pescan/scanner.rb +0 -0
  140. data/lib/rex/pescan/search.rb +0 -0
  141. data/lib/rex/platforms.rb +0 -0
  142. data/lib/rex/platforms/windows.rb +0 -0
  143. data/lib/rex/poly.rb +0 -0
  144. data/lib/rex/poly/block.rb +0 -0
  145. data/lib/rex/poly/register.rb +0 -0
  146. data/lib/rex/poly/register/x86.rb +0 -0
  147. data/lib/rex/post.rb +0 -0
  148. data/lib/rex/post/dir.rb +0 -0
  149. data/lib/rex/post/file.rb +0 -0
  150. data/lib/rex/post/file_stat.rb +0 -0
  151. data/lib/rex/post/gen.pl +0 -0
  152. data/lib/rex/post/io.rb +0 -0
  153. data/lib/rex/post/meterpreter.rb +0 -0
  154. data/lib/rex/post/meterpreter/channel.rb +0 -0
  155. data/lib/rex/post/meterpreter/channel_container.rb +0 -0
  156. data/lib/rex/post/meterpreter/channels/pool.rb +0 -0
  157. data/lib/rex/post/meterpreter/channels/pools/file.rb +0 -0
  158. data/lib/rex/post/meterpreter/channels/pools/stream_pool.rb +0 -0
  159. data/lib/rex/post/meterpreter/channels/stream.rb +0 -0
  160. data/lib/rex/post/meterpreter/client.rb +3 -0
  161. data/lib/rex/post/meterpreter/client_core.rb +0 -0
  162. data/lib/rex/post/meterpreter/dependencies.rb +0 -0
  163. data/lib/rex/post/meterpreter/extension.rb +0 -0
  164. data/lib/rex/post/meterpreter/extensions/espia/espia.rb +0 -0
  165. data/lib/rex/post/meterpreter/extensions/espia/tlv.rb +0 -0
  166. data/lib/rex/post/meterpreter/extensions/incognito/incognito.rb +0 -0
  167. data/lib/rex/post/meterpreter/extensions/incognito/tlv.rb +0 -0
  168. data/lib/rex/post/meterpreter/extensions/networkpug/networkpug.rb +57 -0
  169. data/lib/rex/post/meterpreter/extensions/networkpug/tlv.rb +15 -0
  170. data/lib/rex/post/meterpreter/extensions/priv/fs.rb +0 -0
  171. data/lib/rex/post/meterpreter/extensions/priv/passwd.rb +0 -0
  172. data/lib/rex/post/meterpreter/extensions/priv/priv.rb +0 -0
  173. data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +0 -0
  174. data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +2 -1
  175. data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +12 -10
  176. data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +0 -0
  177. data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +0 -0
  178. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +31 -0
  179. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb +0 -0
  180. data/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb +0 -0
  181. data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +0 -0
  182. data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +0 -0
  183. data/lib/rex/post/meterpreter/extensions/stdapi/net/route.rb +0 -0
  184. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +0 -0
  185. data/lib/rex/post/meterpreter/extensions/{railgun → stdapi/railgun}/api_constants.rb +38106 -38105
  186. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_advapi32.rb +1804 -0
  187. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_iphlpapi.rb +96 -0
  188. data/lib/rex/post/meterpreter/extensions/{railgun → stdapi/railgun/def}/def_kernel32.rb +3848 -3678
  189. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ntdll.rb +153 -0
  190. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_shell32.rb +21 -0
  191. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_user32.rb +3169 -0
  192. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ws2_32.rb +599 -0
  193. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/model.rb +540 -0
  194. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb +308 -0
  195. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb +196 -0
  196. data/lib/rex/post/meterpreter/extensions/{railgun → stdapi/railgun}/tlv.rb +6 -9
  197. data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +5 -0
  198. data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +0 -0
  199. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +0 -0
  200. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +0 -0
  201. data/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb +0 -0
  202. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +0 -0
  203. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/image.rb +0 -0
  204. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/io.rb +0 -0
  205. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +0 -0
  206. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +0 -0
  207. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +0 -0
  208. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +0 -0
  209. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +0 -0
  210. data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +0 -0
  211. data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +6 -0
  212. data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +0 -0
  213. data/lib/rex/post/meterpreter/inbound_packet_handler.rb +0 -0
  214. data/lib/rex/post/meterpreter/object_aliases.rb +0 -0
  215. data/lib/rex/post/meterpreter/packet.rb +23 -1
  216. data/lib/rex/post/meterpreter/packet_dispatcher.rb +13 -2
  217. data/lib/rex/post/meterpreter/packet_parser.rb +0 -0
  218. data/lib/rex/post/meterpreter/packet_response_waiter.rb +17 -10
  219. data/lib/rex/post/meterpreter/ui/console.rb +0 -0
  220. data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +0 -0
  221. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +12 -7
  222. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/espia.rb +0 -0
  223. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +0 -0
  224. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/networkpug.rb +221 -0
  225. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv.rb +0 -0
  226. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +0 -0
  227. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb +0 -0
  228. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +0 -0
  229. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb +4 -3
  230. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb +0 -0
  231. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +56 -1
  232. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +22 -0
  233. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +0 -0
  234. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +0 -0
  235. data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +0 -0
  236. data/lib/rex/post/permission.rb +0 -0
  237. data/lib/rex/post/process.rb +0 -0
  238. data/lib/rex/post/thread.rb +0 -0
  239. data/lib/rex/post/ui.rb +0 -0
  240. data/lib/rex/proto.rb +0 -0
  241. data/lib/rex/proto.rb.ts.rb +0 -0
  242. data/lib/rex/proto/dcerpc.rb +0 -0
  243. data/lib/rex/proto/dcerpc.rb.ts.rb +0 -0
  244. data/lib/rex/proto/dcerpc/client.rb +3 -1
  245. data/lib/rex/proto/dcerpc/exceptions.rb +0 -0
  246. data/lib/rex/proto/dcerpc/handle.rb +0 -0
  247. data/lib/rex/proto/dcerpc/handle.rb.ut.rb +0 -0
  248. data/lib/rex/proto/dcerpc/ndr.rb +0 -0
  249. data/lib/rex/proto/dcerpc/ndr.rb.ut.rb +0 -0
  250. data/lib/rex/proto/dcerpc/packet.rb +0 -0
  251. data/lib/rex/proto/dcerpc/packet.rb.ut.rb +0 -0
  252. data/lib/rex/proto/dcerpc/response.rb.ut.rb +0 -0
  253. data/lib/rex/proto/dcerpc/uuid.rb +0 -0
  254. data/lib/rex/proto/dcerpc/uuid.rb.ut.rb +0 -0
  255. data/lib/rex/proto/dhcp.rb +7 -0
  256. data/lib/rex/proto/dhcp/constants.rb +33 -0
  257. data/lib/rex/proto/dhcp/server.rb +285 -0
  258. data/lib/rex/proto/drda.rb +0 -0
  259. data/lib/rex/proto/drda.rb.ts.rb +0 -0
  260. data/lib/rex/proto/drda/constants.rb +0 -0
  261. data/lib/rex/proto/drda/constants.rb.ut.rb +0 -0
  262. data/lib/rex/proto/drda/packet.rb +0 -0
  263. data/lib/rex/proto/drda/packet.rb.ut.rb +0 -0
  264. data/lib/rex/proto/drda/utils.rb +0 -0
  265. data/lib/rex/proto/drda/utils.rb.ut.rb +0 -0
  266. data/lib/rex/proto/http.rb +0 -0
  267. data/lib/rex/proto/http.rb.ts.rb +0 -0
  268. data/lib/rex/proto/http/client.rb +27 -2
  269. data/lib/rex/proto/http/client.rb.ut.rb +4 -2
  270. data/lib/rex/proto/http/handler.rb +0 -0
  271. data/lib/rex/proto/http/handler/erb.rb +0 -0
  272. data/lib/rex/proto/http/handler/erb.rb.ut.rb +0 -0
  273. data/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +0 -0
  274. data/lib/rex/proto/http/handler/proc.rb +6 -0
  275. data/lib/rex/proto/http/handler/proc.rb.ut.rb +0 -0
  276. data/lib/rex/proto/http/header.rb +0 -0
  277. data/lib/rex/proto/http/header.rb.ut.rb +0 -0
  278. data/lib/rex/proto/http/packet.rb +20 -19
  279. data/lib/rex/proto/http/packet.rb.ut.rb +0 -0
  280. data/lib/rex/proto/http/request.rb +0 -0
  281. data/lib/rex/proto/http/request.rb.ut.rb +0 -0
  282. data/lib/rex/proto/http/response.rb +0 -0
  283. data/lib/rex/proto/http/response.rb.ut.rb +0 -0
  284. data/lib/rex/proto/http/server.rb +5 -3
  285. data/lib/rex/proto/http/server.rb.ut.rb +0 -0
  286. data/lib/rex/proto/proxy/socks4a.rb +440 -0
  287. data/lib/rex/proto/smb.rb +0 -0
  288. data/lib/rex/proto/smb.rb.ts.rb +0 -0
  289. data/lib/rex/proto/smb/client.rb +110 -61
  290. data/lib/rex/proto/smb/client.rb.ut.rb +0 -0
  291. data/lib/rex/proto/smb/constants.rb +5 -3
  292. data/lib/rex/proto/smb/constants.rb.ut.rb +0 -0
  293. data/lib/rex/proto/smb/crypt.rb +0 -0
  294. data/lib/rex/proto/smb/crypt.rb.ut.rb +0 -0
  295. data/lib/rex/proto/smb/exceptions.rb +0 -0
  296. data/lib/rex/proto/smb/simpleclient.rb +0 -0
  297. data/lib/rex/proto/smb/simpleclient.rb.ut.rb +0 -0
  298. data/lib/rex/proto/smb/utils.rb +2 -0
  299. data/lib/rex/proto/smb/utils.rb.ut.rb +0 -0
  300. data/lib/rex/proto/sunrpc.rb +0 -0
  301. data/lib/rex/proto/sunrpc/client.rb +0 -0
  302. data/lib/rex/proto/tftp.rb +10 -1
  303. data/lib/rex/proto/tftp/constants.rb +5 -3
  304. data/lib/rex/proto/tftp/server.rb +79 -9
  305. data/lib/rex/script.rb +0 -0
  306. data/lib/rex/script/base.rb +0 -0
  307. data/lib/rex/script/meterpreter.rb +0 -0
  308. data/lib/rex/script/shell.rb +0 -0
  309. data/lib/rex/service.rb +0 -0
  310. data/lib/rex/service_manager.rb +0 -0
  311. data/lib/rex/service_manager.rb.ut.rb +0 -0
  312. data/lib/rex/services/local_relay.rb +0 -0
  313. data/lib/rex/socket.rb +6 -4
  314. data/lib/rex/socket.rb.ut.rb +0 -0
  315. data/lib/rex/socket/comm.rb +0 -0
  316. data/lib/rex/socket/comm/local.rb +0 -0
  317. data/lib/rex/socket/comm/local.rb.ut.rb +0 -0
  318. data/lib/rex/socket/ip.rb +0 -0
  319. data/lib/rex/socket/parameters.rb +0 -0
  320. data/lib/rex/socket/parameters.rb.ut.rb +0 -0
  321. data/lib/rex/socket/range_walker.rb +0 -0
  322. data/lib/rex/socket/range_walker.rb.ut.rb +0 -0
  323. data/lib/rex/socket/ssl_tcp.rb +1 -1
  324. data/lib/rex/socket/ssl_tcp.rb.ut.rb +0 -0
  325. data/lib/rex/socket/ssl_tcp_server.rb +0 -0
  326. data/lib/rex/socket/ssl_tcp_server.rb.ut.rb +0 -0
  327. data/lib/rex/socket/subnet_walker.rb +0 -0
  328. data/lib/rex/socket/subnet_walker.rb.ut.rb +0 -0
  329. data/lib/rex/socket/switch_board.rb.ut.rb +0 -0
  330. data/lib/rex/socket/tcp.rb +0 -0
  331. data/lib/rex/socket/tcp.rb.ut.rb +0 -0
  332. data/lib/rex/socket/tcp_server.rb +0 -0
  333. data/lib/rex/socket/tcp_server.rb.ut.rb +0 -0
  334. data/lib/rex/socket/udp.rb +0 -0
  335. data/lib/rex/socket/udp.rb.ut.rb +0 -0
  336. data/lib/rex/struct2.rb +0 -0
  337. data/lib/rex/struct2/c_struct.rb +0 -0
  338. data/lib/rex/struct2/c_struct_template.rb +0 -0
  339. data/lib/rex/struct2/constant.rb +0 -0
  340. data/lib/rex/struct2/element.rb +0 -0
  341. data/lib/rex/struct2/generic.rb +0 -0
  342. data/lib/rex/struct2/restraint.rb +0 -0
  343. data/lib/rex/struct2/s_string.rb +0 -0
  344. data/lib/rex/struct2/s_struct.rb +0 -0
  345. data/lib/rex/sync.rb +0 -0
  346. data/lib/rex/sync/event.rb +0 -0
  347. data/lib/rex/sync/read_write_lock.rb +0 -0
  348. data/lib/rex/sync/ref.rb +0 -0
  349. data/lib/rex/sync/thread_safe.rb +0 -0
  350. data/lib/rex/test.rb +0 -0
  351. data/lib/rex/text.rb +13 -3
  352. data/lib/rex/text.rb.ut.rb +9 -4
  353. data/lib/rex/time.rb +0 -0
  354. data/lib/rex/transformer.rb +0 -0
  355. data/lib/rex/transformer.rb.ut.rb +0 -0
  356. data/lib/rex/ui.rb +0 -0
  357. data/lib/rex/ui/interactive.rb +0 -0
  358. data/lib/rex/ui/output.rb +0 -0
  359. data/lib/rex/ui/output/none.rb +0 -0
  360. data/lib/rex/ui/progress_tracker.rb +0 -0
  361. data/lib/rex/ui/subscriber.rb +0 -0
  362. data/lib/rex/ui/text/color.rb +0 -0
  363. data/lib/rex/ui/text/color.rb.ut.rb +0 -0
  364. data/lib/rex/ui/text/dispatcher_shell.rb +0 -0
  365. data/lib/rex/ui/text/input.rb +0 -0
  366. data/lib/rex/ui/text/input/buffer.rb +0 -0
  367. data/lib/rex/ui/text/input/readline.rb +0 -0
  368. data/lib/rex/ui/text/input/socket.rb +0 -0
  369. data/lib/rex/ui/text/input/stdio.rb +0 -0
  370. data/lib/rex/ui/text/irb_shell.rb +0 -0
  371. data/lib/rex/ui/text/output.rb +0 -0
  372. data/lib/rex/ui/text/output/buffer.rb +0 -0
  373. data/lib/rex/ui/text/output/file.rb +0 -0
  374. data/lib/rex/ui/text/output/socket.rb +0 -0
  375. data/lib/rex/ui/text/output/stdio.rb +0 -0
  376. data/lib/rex/ui/text/progress_tracker.rb +0 -0
  377. data/lib/rex/ui/text/progress_tracker.rb.ut.rb +0 -0
  378. data/lib/rex/ui/text/shell.rb +9 -6
  379. data/lib/rex/ui/text/table.rb +5 -0
  380. data/lib/rex/ui/text/table.rb.ut.rb +0 -0
  381. data/lib/rex/zip.rb +0 -0
  382. data/lib/rex/zip/archive.rb +29 -1
  383. data/lib/rex/zip/blocks.rb +0 -0
  384. data/lib/rex/zip/entry.rb +5 -1
  385. metadata +369 -413
  386. data/README +0 -8
  387. data/lib/rex/post/meterpreter/extensions/railgun/api.rb +0 -9303
  388. data/lib/rex/post/meterpreter/extensions/railgun/railgun.rb +0 -815
  389. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/railgun.rb +0 -57
@@ -0,0 +1,540 @@
1
+ # Copyright (c) 2010, patrickHVE@googlemail.com
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ # * Redistributions of source code must retain the above copyright
7
+ # notice, this list of conditions and the following disclaimer.
8
+ # * Redistributions in binary form must reproduce the above copyright
9
+ # notice, this list of conditions and the following disclaimer in the
10
+ # documentation and/or other materials provided with the distribution.
11
+ # * The names of the author may not be used to endorse or promote products
12
+ # derived from this software without specific prior written permission.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ # DISCLAIMED. IN NO EVENT SHALL patrickHVE@googlemail.com BE LIABLE FOR ANY
18
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ require 'pp'
26
+ require 'enumerator'
27
+
28
+ module Rex
29
+ module Post
30
+ module Meterpreter
31
+ module Extensions
32
+ module Stdapi
33
+ module Railgun
34
+
35
+ #
36
+ # Manages our library of windows constants
37
+ #
38
+ class WinConstManager
39
+
40
+ def initialize()
41
+ @consts = {}
42
+ end
43
+
44
+ def add_const(name, value)
45
+ @consts[name] = value
46
+ end
47
+
48
+ # parses a string constaining constants and returns an integer
49
+ # the string can be either "CONST" or "CONST1 | CONST2"
50
+ #
51
+ # this function will NOT throw an exception but return "nil" if it can't parse a string
52
+ def parse(s)
53
+ if s.class != String
54
+ return nil # it's not even a string'
55
+ end
56
+ return_value = 0
57
+ for one_const in s.split('|')
58
+ one_const = one_const.strip()
59
+ if not @consts.has_key? one_const
60
+ return nil # at least one "Constant" is unknown to us
61
+ end
62
+ return_value |= @consts[one_const]
63
+ end
64
+ return return_value
65
+ end
66
+
67
+ def is_parseable(s)
68
+ return parse(s) != nil
69
+ end
70
+ end
71
+
72
+ #
73
+ # represents one function, e.g. MessageBoxW
74
+ #
75
+ class DLLFunction
76
+ attr_reader :return_type, :params, :windows_name
77
+
78
+ def initialize(return_type, params, windows_name)
79
+ check_return_type(return_type) # we do error checking as early as possible so the library is easier to use
80
+ check_params(params)
81
+ @return_type = return_type
82
+ @params = params
83
+ @windows_name = windows_name
84
+ end
85
+
86
+ @@directions = ["in", "out", "inout", "return"]
87
+
88
+ @@allowed_datatypes = {
89
+ "VOID" => ["return"],
90
+ "BOOL" => ["in", "return"],
91
+ "DWORD" => ["in", "return"],
92
+ "WORD" => ["in", "return"],
93
+ "BYTE" => ["in", "return"],
94
+ "LPVOID" => ["in", "return"], # sf: for specifying a memory address (e.g. VirtualAlloc/HeapAlloc/...) where we dont want ot back it up with actuall mem ala PBLOB
95
+ "HANDLE" => ["in", "return"],
96
+ "PDWORD" => ["in", "out", "inout"], # todo: support for functions that return pointers to strings
97
+ "PWCHAR" => ["in", "out", "inout"],
98
+ "PCHAR" => ["in", "out", "inout"],
99
+ "PBLOB" => ["in", "out", "inout"],
100
+ }
101
+
102
+ private
103
+
104
+ def check_type_exists (type)
105
+ if not @@allowed_datatypes.has_key?(type)
106
+ raise "Type unknown: #{type}. Allowed types: #{PP.pp(@@allowed_datatypes.keys, "")}"
107
+ end
108
+ end
109
+
110
+ def check_return_type (type)
111
+ check_type_exists(type)
112
+ if not @@allowed_datatypes[type].include?("return")
113
+ raise "#{type} is not allowed as a return type"
114
+ end
115
+ end
116
+
117
+ def check_params (params)
118
+ params.each do |param|
119
+ throw "each param must be descriped by a three-tuple [type,name,direction]" unless param.length == 3
120
+ type = param[0]
121
+ direction = param[2]
122
+ check_type_exists(type)
123
+ throw "invalid direction: #{direction}" unless @@directions.include?(direction)
124
+ throw "direction 'return' is only for the return value of the function." unless direction != "return"
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ #
131
+ #
132
+ #
133
+ class BufferItem
134
+
135
+ attr_reader :belongs_to_param_n, :addr, :length_in_bytes, :datatype
136
+
137
+ def initialize(belongs_to_param_n, addr, length_in_bytes, datatype)
138
+ @belongs_to_param_n = belongs_to_param_n
139
+ @addr = addr
140
+ @length_in_bytes = length_in_bytes
141
+ @datatype = datatype
142
+ end
143
+ end
144
+
145
+ #
146
+ # shared functions
147
+ #
148
+ module DLLHelper
149
+
150
+ # converts ruby string to zero-terminated ASCII string
151
+ def str_to_ascii_z(str)
152
+ return str+"\x00"
153
+ end
154
+
155
+ # converts 0-terminated ASCII string to ruby string
156
+ def asciiz_to_str(asciiz)
157
+ zero_byte_idx = asciiz.index("\x00")
158
+ if zero_byte_idx != nil
159
+ return asciiz[0, zero_byte_idx]
160
+ else
161
+ return asciiz
162
+ end
163
+ end
164
+
165
+ # converts ruby string to zero-terminated WCHAR string
166
+ def str_to_uni_z(str)
167
+ enc = str.unpack("C*").pack("v*")
168
+ enc += "\x00\x00"
169
+ return enc
170
+ end
171
+
172
+ # converts 0-terminated UTF16 to ruby string
173
+ def uniz_to_str(uniz)
174
+ uniz.unpack("v*").pack("C*").unpack("A*")[0]
175
+ end
176
+
177
+ # parses a number param and returns the value
178
+ # raises an exception if the param cannot be converted to a number
179
+ # examples:
180
+ # nil => 0
181
+ # 3 => 3
182
+ # "MB_OK" => 0
183
+ # "SOME_CONSTANT | OTHER_CONSTANT" => 17
184
+ # "tuna" => !!!!!!!!!!Exception
185
+ def param_to_number(v)
186
+ if v.class == NilClass then
187
+ return 0
188
+ elsif v.class == Fixnum then
189
+ return v # ok, it's already a number
190
+ elsif v.class == Bignum then
191
+ return v # ok, it's already a number
192
+ elsif v.class == String then
193
+ dw = @win_consts.parse(v) # might raise an exception
194
+ if dw != nil
195
+ return dw
196
+ else
197
+ raise "Param #{v} (class #{v.class}) cannot be converted to a number. It's a string but matches no constants I know."
198
+ end
199
+ else
200
+ raise "Param #{v} (class #{v.class}) should be a number but isn't"
201
+ end
202
+ end
203
+
204
+ # assembles the buffers "in" and "inout"
205
+ def assemble_buffer(direction, function, args)
206
+ layout = {} # paramName => BufferItem
207
+ blob = ""
208
+ #puts " building buffer: #{direction}"
209
+ function.params.each_with_index do |param_desc, param_idx|
210
+ #puts " processing #{param_desc[0]} #{param_desc[1]} #{param_desc[2]}"
211
+ # we care only about inout buffers
212
+ if param_desc[2] == direction
213
+ buffer = nil
214
+ # Special case:
215
+ # The user can choose to supply a Null pointer instead of a buffer
216
+ # in this case we don't need space in any heap buffer
217
+ if param_desc[0][0,1] == 'P' # type is a pointer
218
+ if args[param_idx] == nil
219
+ next
220
+ end
221
+ end
222
+
223
+ case param_desc[0] # required argument type
224
+ when "PDWORD"
225
+ dw = param_to_number(args[param_idx])
226
+ buffer = [dw].pack('V')
227
+ when "PWCHAR"
228
+ raise "param #{param_desc[1]}: string expected" unless args[param_idx].class == String
229
+ buffer = str_to_uni_z(args[param_idx])
230
+ when "PCHAR"
231
+ raise "param #{param_desc[1]}: string expected" unless args[param_idx].class == String
232
+ buffer = str_to_ascii_z(args[param_idx])
233
+ when "PBLOB"
234
+ raise "param #{param_desc[1]}: please supply your BLOB as string!" unless args[param_idx].class == String
235
+ buffer = args[param_idx]
236
+ # other types (non-pointers) don't reference buffers
237
+ # and don't need any treatment here
238
+ end
239
+
240
+ if buffer != nil
241
+ #puts " adding #{buffer.length} bytes to heap blob"
242
+ layout[param_desc[1]] = BufferItem.new(param_idx, blob.length, buffer.length, param_desc[0])
243
+ blob += buffer
244
+ # sf: force 8 byte alignment to satisfy x64, wont matter on x86.
245
+ while( blob.length % 8 != 0 )
246
+ blob += "\x00"
247
+ end
248
+ #puts " heap blob size now #{blob.length}"
249
+ end
250
+ end
251
+ end
252
+ #puts " built buffer: #{direction}"
253
+ return [layout, blob]
254
+ end
255
+
256
+ end
257
+
258
+ #
259
+ # represents a DLL, e.g. kernel32.dll
260
+ #
261
+ class DLL
262
+
263
+ include DLLHelper
264
+
265
+ attr_accessor :functions
266
+
267
+ def initialize(dll_path, client, win_consts) #
268
+ @dll_path = dll_path
269
+ @client = client
270
+ @win_consts = win_consts
271
+ if( @client.platform =~ /x64/i )
272
+ @native = 'Q'
273
+ else
274
+ @native = 'V'
275
+ end
276
+ self.functions = {}
277
+ end
278
+
279
+ # adds a function to the DLL
280
+ # syntax for params:
281
+ # add_function("MessageBoxW", # name
282
+ # "DWORD", # return value
283
+ # [["DWORD","hWnd","in"], # params
284
+ # ["PWCHAR","lpText","in"],
285
+ # ["PWCHAR","lpCaption","in"],
286
+ # ["DWORD","uType","in"],
287
+ # ])
288
+ #
289
+ # Every function argument is described by a tuple (type,name,direction)
290
+ #
291
+ # windows_name: Use it when the actual windows name is different from the ruby variable
292
+ # for example when the actual func name is myFunc@4
293
+ # or when you want to create an alternative version of an existing function
294
+ #
295
+ # When new function is called it will return a list containing the return value and all inout params
296
+ def add_function(name, return_type, params, windows_name=nil)
297
+ if windows_name == nil
298
+ windows_name = name
299
+ end
300
+ @functions[name] = DLLFunction.new(return_type, params, windows_name)
301
+ end
302
+
303
+ private
304
+
305
+ # called when a function like "MessageBoxW" is called
306
+ def process_function_call(function, args)
307
+ raise "#{function.params.length} arguments expected. #{args.length} arguments provided." unless args.length == function.params.length
308
+ #puts "process_function_call(function.windows_name,#{PP.pp(args, "")})"
309
+
310
+ # We transmit the immediate stack and three heap-buffers:
311
+ # in, inout and out. The reason behind the separation is bandwidth.
312
+ # We don't want to transmit uninitialized data in or no-longer-needed data out.
313
+
314
+ # out-only-buffers that are ONLY transmitted on the way BACK
315
+ out_only_layout = {} # paramName => BufferItem
316
+ out_only_size_bytes = 0
317
+ #puts " assembling out-only buffer"
318
+ function.params.each_with_index do |param_desc, param_idx|
319
+ #puts " processing #{param_desc[1]}"
320
+
321
+ # Special case:
322
+ # The user can choose to supply a Null pointer instead of a buffer
323
+ # in this case we don't need space in any heap buffer
324
+ if param_desc[0][0,1] == 'P' # type is a pointer
325
+ if args[param_idx] == nil
326
+ next
327
+ end
328
+ end
329
+
330
+ # we care only about out-only buffers
331
+ if param_desc[2] == "out"
332
+ raise "error in param #{param_desc[1]}: Out-only buffers must be described by a number indicating their size in bytes " unless args[param_idx].class == Fixnum
333
+ buffer_size = args[param_idx]
334
+ if param_desc[0] == "PDWORD"
335
+ # bump up the size for an x64 pointer
336
+ if( @native == 'Q' and buffer_size == 4 )
337
+ args[param_idx] = 8
338
+ buffer_size = args[param_idx]
339
+ end
340
+
341
+ if( @native == 'Q' )
342
+ raise "Please pass 8 for 'out' PDWORDS, since they require a buffer of size 8" unless buffer_size == 8
343
+ elsif( @native == 'V' )
344
+ raise "Please pass 4 for 'out' PDWORDS, since they require a buffer of size 4" unless buffer_size == 4
345
+ end
346
+ end
347
+
348
+ out_only_layout[param_desc[1]] = BufferItem.new(param_idx, out_only_size_bytes, buffer_size, param_desc[0])
349
+ out_only_size_bytes += buffer_size
350
+ end
351
+ end
352
+
353
+ tmp = assemble_buffer("in", function, args)
354
+ in_only_layout = tmp[0]
355
+ in_only_buffer = tmp[1]
356
+
357
+ tmp = assemble_buffer("inout", function, args)
358
+ inout_layout = tmp[0]
359
+ inout_buffer = tmp[1]
360
+
361
+ # now we build the stack
362
+ # every stack dword will be described by two dwords:
363
+ # first dword describes second dword:
364
+ # 0 - literal,
365
+ # 1 = relative to in-only buffer
366
+ # 2 = relative to out-only buffer
367
+ # 3 = relative to inout buffer
368
+
369
+ # (literal numbers and pointers to buffers we have created)
370
+ literal_pairs_blob = ""
371
+ #puts " assembling literal stack"
372
+ function.params.each_with_index do |param_desc, param_idx|
373
+ #puts " processing (#{param_desc[0]}, #{param_desc[1]}, #{param_desc[2]})"
374
+ buffer = nil
375
+ # is it a pointer to a buffer on our stack
376
+ if ["PDWORD", "PWCHAR", "PCHAR", "PBLOB"].include? param_desc[0]
377
+ #puts " pointer"
378
+ if args[param_idx] == nil # null pointer?
379
+ buffer = [0].pack(@native) # type: DWORD (so the dll does not rebase it)
380
+ buffer += [0].pack(@native) # value: 0
381
+ elsif param_desc[2] == "in"
382
+ buffer = [1].pack(@native)
383
+ buffer += [in_only_layout[param_desc[1]].addr].pack(@native)
384
+ elsif param_desc[2] == "out"
385
+ buffer = [2].pack(@native)
386
+ buffer += [out_only_layout[param_desc[1]].addr].pack(@native)
387
+ elsif param_desc[2] == "inout"
388
+ buffer = [3].pack(@native)
389
+ buffer += [inout_layout[param_desc[1]].addr].pack(@native)
390
+ else
391
+ raise "unexpected direction"
392
+ end
393
+ else
394
+ #puts " not a pointer"
395
+ # it's not a pointer (LPVOID is a pointer but is not backed by railgun memory, ala PBLOB)
396
+ buffer = [0].pack(@native)
397
+ case param_desc[0]
398
+ when "LPVOID", "HANDLE"
399
+ num = param_to_number(args[param_idx])
400
+ buffer += [num].pack(@native)
401
+ when "DWORD"
402
+ num = param_to_number(args[param_idx])
403
+ buffer += [num % 4294967296].pack(@native)
404
+ when "WORD"
405
+ num = param_to_number(args[param_idx])
406
+ buffer += [num % 65536].pack(@native)
407
+ when "BYTE"
408
+ num = param_to_number(args[param_idx])
409
+ buffer += [num % 256].pack(@native)
410
+ when "BOOL"
411
+ case args[param_idx]
412
+ when true
413
+ buffer += [1].pack(@native)
414
+ when false
415
+ buffer += [0].pack(@native)
416
+ else
417
+ raise "param #{param_desc[1]}: true or false expected"
418
+ end
419
+ else
420
+ raise "unexpected type for param #{param_desc[1]}"
421
+ end
422
+ end
423
+
424
+ #puts " adding pair to blob"
425
+ literal_pairs_blob += buffer
426
+ #puts " buffer size %X" % buffer.length
427
+ #puts " blob size so far: %X" % literal_pairs_blob.length
428
+ end
429
+
430
+ #puts "\n\nsending Stuff to meterpreter"
431
+ request = Packet.create_request('stdapi_railgun_api')
432
+ request.add_tlv(TLV_TYPE_RAILGUN_SIZE_OUT, out_only_size_bytes)
433
+
434
+ request.add_tlv(TLV_TYPE_RAILGUN_STACKBLOB, literal_pairs_blob)
435
+ request.add_tlv(TLV_TYPE_RAILGUN_BUFFERBLOB_IN, in_only_buffer)
436
+ request.add_tlv(TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT, inout_buffer)
437
+
438
+ request.add_tlv(TLV_TYPE_RAILGUN_DLLNAME, @dll_path )
439
+ request.add_tlv(TLV_TYPE_RAILGUN_FUNCNAME, function.windows_name)
440
+
441
+ response = @client.send_request(request)
442
+
443
+ #puts "receiving Stuff from meterpreter"
444
+ #puts "out_only_layout:"
445
+ #puts out_only_layout
446
+
447
+ rec_inout_buffers = response.get_tlv_value(TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_INOUT)
448
+ rec_out_only_buffers = response.get_tlv_value(TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_OUT)
449
+ rec_return_value = response.get_tlv_value(TLV_TYPE_RAILGUN_BACK_RET)
450
+ rec_last_error = response.get_tlv_value(TLV_TYPE_RAILGUN_BACK_ERR)
451
+
452
+ #puts "received stuff"
453
+ #puts "out_only_layout:"
454
+ #puts out_only_layout
455
+
456
+ # The hash the function returns
457
+ return_hash={"GetLastError" => rec_last_error}
458
+
459
+ #process return value
460
+ case function.return_type
461
+ when "LPVOID", "HANDLE"
462
+ if( @native == 'Q' )
463
+ return_hash["return"] = rec_return_value
464
+ else
465
+ return_hash["return"] = rec_return_value % 4294967296
466
+ end
467
+ when "DWORD"
468
+ return_hash["return"] = rec_return_value % 4294967296
469
+ when "WORD"
470
+ return_hash["return"] = rec_return_value % 65536
471
+ when "BYTE"
472
+ return_hash["return"] = rec_return_value % 256
473
+ when "BOOL"
474
+ return_hash["return"] = (rec_return_value != 0)
475
+ when "VOID"
476
+ return_hash["return"] = nil
477
+ else
478
+ raise "unexpected return type: #{function.return_type}"
479
+ end
480
+ #puts return_hash
481
+ #puts "out_only_layout:"
482
+ #puts out_only_layout
483
+
484
+
485
+ # process out-only buffers
486
+ #puts "processing out-only buffers:"
487
+ out_only_layout.each_pair do |param_name, buffer_item|
488
+ #puts " #{param_name}"
489
+ buffer = rec_out_only_buffers[buffer_item.addr, buffer_item.length_in_bytes]
490
+ case buffer_item.datatype
491
+ when "PDWORD"
492
+ return_hash[param_name] = buffer.unpack('V')[0]
493
+ when "PCHAR"
494
+ return_hash[param_name] = asciiz_to_str(buffer)
495
+ when "PWCHAR"
496
+ return_hash[param_name] = uniz_to_str(buffer)
497
+ when "PBLOB"
498
+ return_hash[param_name] = buffer
499
+ else
500
+ raise "unexpected type in out-only buffer of #{param_name}: #{buffer_item.datatype}"
501
+ end
502
+ end
503
+ #puts return_hash
504
+
505
+ # process in-out buffers
506
+ #puts "processing in-out buffers:"
507
+ inout_layout.each_pair do |param_name, buffer_item|
508
+ #puts " #{param_name}"
509
+ buffer = rec_inout_buffers[buffer_item.addr, buffer_item.length_in_bytes]
510
+ case buffer_item.datatype
511
+ when "PDWORD"
512
+ return_hash[param_name] = buffer.unpack('V')[0]
513
+ when "PCHAR"
514
+ return_hash[param_name] = asciiz_to_str(buffer)
515
+ when "PWCHAR"
516
+ return_hash[param_name] = uniz_to_str(buffer)
517
+ when "PBLOB"
518
+ return_hash[param_name] = buffer
519
+ else
520
+ raise "unexpected type in in-out-buffer of #{param_name}: #{buffer_item.datatype}"
521
+ end
522
+ end
523
+ #puts return_hash
524
+ #puts "finished"
525
+
526
+ return return_hash
527
+ end
528
+
529
+ # process_function_call
530
+
531
+ # we fake having methods like "MessageBoxW" by intercepting "method-not-found"-exceptions
532
+ def method_missing(func_symbol, *args)
533
+ func_name = func_symbol.to_s
534
+ raise "DLL-function #{func_name} not found. Known functions: #{PP.pp(@functions.keys, "")}" unless @functions.has_key? func_name
535
+ function = @functions[func_name]
536
+ return process_function_call(function, args)
537
+ end
538
+ end
539
+
540
+ end; end; end; end; end; end