pwntools 1.1.0 → 1.2.0

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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -3
  3. data/lib/pwn.rb +1 -0
  4. data/lib/pwnlib/abi.rb +1 -0
  5. data/lib/pwnlib/asm.rb +83 -42
  6. data/lib/pwnlib/constants/constant.rb +4 -1
  7. data/lib/pwnlib/constants/constants.rb +3 -0
  8. data/lib/pwnlib/constants/linux/amd64.rb +2 -0
  9. data/lib/pwnlib/constants/linux/i386.rb +2 -0
  10. data/lib/pwnlib/context.rb +10 -1
  11. data/lib/pwnlib/dynelf.rb +7 -2
  12. data/lib/pwnlib/elf/elf.rb +79 -6
  13. data/lib/pwnlib/errors.rb +3 -2
  14. data/lib/pwnlib/ext/array.rb +2 -1
  15. data/lib/pwnlib/ext/helper.rb +3 -2
  16. data/lib/pwnlib/ext/integer.rb +2 -1
  17. data/lib/pwnlib/ext/string.rb +3 -2
  18. data/lib/pwnlib/logger.rb +21 -1
  19. data/lib/pwnlib/memleak.rb +1 -0
  20. data/lib/pwnlib/pwn.rb +5 -1
  21. data/lib/pwnlib/reg_sort.rb +5 -0
  22. data/lib/pwnlib/runner.rb +53 -0
  23. data/lib/pwnlib/shellcraft/generators/amd64/common/common.rb +2 -0
  24. data/lib/pwnlib/shellcraft/generators/amd64/common/infloop.rb +1 -0
  25. data/lib/pwnlib/shellcraft/generators/amd64/common/memcpy.rb +5 -1
  26. data/lib/pwnlib/shellcraft/generators/amd64/common/mov.rb +4 -0
  27. data/lib/pwnlib/shellcraft/generators/amd64/common/nop.rb +2 -0
  28. data/lib/pwnlib/shellcraft/generators/amd64/common/popad.rb +1 -0
  29. data/lib/pwnlib/shellcraft/generators/amd64/common/pushstr.rb +3 -1
  30. data/lib/pwnlib/shellcraft/generators/amd64/common/pushstr_array.rb +1 -0
  31. data/lib/pwnlib/shellcraft/generators/amd64/common/ret.rb +1 -0
  32. data/lib/pwnlib/shellcraft/generators/amd64/common/setregs.rb +3 -2
  33. data/lib/pwnlib/shellcraft/generators/amd64/linux/cat.rb +3 -2
  34. data/lib/pwnlib/shellcraft/generators/amd64/linux/execve.rb +1 -0
  35. data/lib/pwnlib/shellcraft/generators/amd64/linux/exit.rb +1 -0
  36. data/lib/pwnlib/shellcraft/generators/amd64/linux/linux.rb +2 -0
  37. data/lib/pwnlib/shellcraft/generators/amd64/linux/ls.rb +1 -0
  38. data/lib/pwnlib/shellcraft/generators/amd64/linux/open.rb +1 -0
  39. data/lib/pwnlib/shellcraft/generators/amd64/linux/sh.rb +3 -2
  40. data/lib/pwnlib/shellcraft/generators/amd64/linux/sleep.rb +24 -0
  41. data/lib/pwnlib/shellcraft/generators/amd64/linux/syscall.rb +1 -0
  42. data/lib/pwnlib/shellcraft/generators/helper.rb +11 -2
  43. data/lib/pwnlib/shellcraft/generators/i386/common/common.rb +2 -0
  44. data/lib/pwnlib/shellcraft/generators/i386/common/infloop.rb +1 -0
  45. data/lib/pwnlib/shellcraft/generators/i386/common/memcpy.rb +34 -0
  46. data/lib/pwnlib/shellcraft/generators/i386/common/mov.rb +3 -0
  47. data/lib/pwnlib/shellcraft/generators/i386/common/nop.rb +2 -0
  48. data/lib/pwnlib/shellcraft/generators/i386/common/pushstr.rb +2 -0
  49. data/lib/pwnlib/shellcraft/generators/i386/common/pushstr_array.rb +1 -0
  50. data/lib/pwnlib/shellcraft/generators/i386/common/setregs.rb +3 -2
  51. data/lib/pwnlib/shellcraft/generators/i386/linux/cat.rb +3 -2
  52. data/lib/pwnlib/shellcraft/generators/i386/linux/execve.rb +1 -0
  53. data/lib/pwnlib/shellcraft/generators/i386/linux/exit.rb +1 -0
  54. data/lib/pwnlib/shellcraft/generators/i386/linux/linux.rb +2 -0
  55. data/lib/pwnlib/shellcraft/generators/i386/linux/ls.rb +1 -0
  56. data/lib/pwnlib/shellcraft/generators/i386/linux/open.rb +1 -0
  57. data/lib/pwnlib/shellcraft/generators/i386/linux/sh.rb +3 -2
  58. data/lib/pwnlib/shellcraft/generators/i386/linux/sleep.rb +24 -0
  59. data/lib/pwnlib/shellcraft/generators/i386/linux/syscall.rb +1 -0
  60. data/lib/pwnlib/shellcraft/generators/x86/common/common.rb +5 -3
  61. data/lib/pwnlib/shellcraft/generators/x86/common/infloop.rb +2 -0
  62. data/lib/pwnlib/shellcraft/generators/x86/common/memcpy.rb +17 -0
  63. data/lib/pwnlib/shellcraft/generators/x86/common/mov.rb +2 -0
  64. data/lib/pwnlib/shellcraft/generators/x86/common/pushstr.rb +2 -0
  65. data/lib/pwnlib/shellcraft/generators/x86/common/pushstr_array.rb +1 -0
  66. data/lib/pwnlib/shellcraft/generators/x86/common/setregs.rb +8 -6
  67. data/lib/pwnlib/shellcraft/generators/x86/linux/cat.rb +1 -0
  68. data/lib/pwnlib/shellcraft/generators/x86/linux/execve.rb +3 -0
  69. data/lib/pwnlib/shellcraft/generators/x86/linux/exit.rb +1 -0
  70. data/lib/pwnlib/shellcraft/generators/x86/linux/linux.rb +2 -0
  71. data/lib/pwnlib/shellcraft/generators/x86/linux/ls.rb +1 -0
  72. data/lib/pwnlib/shellcraft/generators/x86/linux/open.rb +1 -0
  73. data/lib/pwnlib/shellcraft/generators/x86/linux/sh.rb +1 -0
  74. data/lib/pwnlib/shellcraft/generators/x86/linux/sleep.rb +52 -0
  75. data/lib/pwnlib/shellcraft/generators/x86/linux/syscall.rb +10 -10
  76. data/lib/pwnlib/shellcraft/registers.rb +5 -1
  77. data/lib/pwnlib/shellcraft/shellcraft.rb +8 -3
  78. data/lib/pwnlib/timer.rb +6 -2
  79. data/lib/pwnlib/tubes/buffer.rb +4 -1
  80. data/lib/pwnlib/tubes/process.rb +2 -0
  81. data/lib/pwnlib/tubes/serialtube.rb +3 -1
  82. data/lib/pwnlib/tubes/sock.rb +7 -1
  83. data/lib/pwnlib/tubes/tube.rb +23 -3
  84. data/lib/pwnlib/ui.rb +21 -0
  85. data/lib/pwnlib/util/cyclic.rb +2 -0
  86. data/lib/pwnlib/util/fiddling.rb +37 -5
  87. data/lib/pwnlib/util/getdents.rb +1 -0
  88. data/lib/pwnlib/util/hexdump.rb +8 -5
  89. data/lib/pwnlib/util/lists.rb +3 -0
  90. data/lib/pwnlib/util/packing.rb +5 -2
  91. data/lib/pwnlib/util/ruby.rb +1 -0
  92. data/lib/pwnlib/version.rb +2 -1
  93. data/test/abi_test.rb +1 -0
  94. data/test/asm_test.rb +75 -85
  95. data/test/constants/constant_test.rb +1 -0
  96. data/test/constants/constants_test.rb +1 -0
  97. data/test/context_test.rb +1 -0
  98. data/test/data/assembly/aarch64.s +19 -0
  99. data/test/data/assembly/amd64.s +21 -0
  100. data/test/data/assembly/arm.s +9 -0
  101. data/test/data/assembly/i386.s +21 -0
  102. data/test/data/assembly/mips.s +16 -0
  103. data/test/data/assembly/mips64.s +6 -0
  104. data/test/data/assembly/powerpc.s +18 -0
  105. data/test/data/assembly/powerpc64.s +36 -0
  106. data/test/data/assembly/sparc.s +33 -0
  107. data/test/data/assembly/sparc64.s +5 -0
  108. data/test/data/assembly/thumb.s +37 -0
  109. data/test/data/echo.rb +1 -0
  110. data/test/dynelf_test.rb +3 -1
  111. data/test/elf/elf_test.rb +18 -0
  112. data/test/ext_test.rb +1 -0
  113. data/test/files/use_pwn.rb +1 -0
  114. data/test/files/use_pwnlib.rb +1 -0
  115. data/test/full_file_test.rb +6 -0
  116. data/test/logger_test.rb +24 -3
  117. data/test/memleak_test.rb +1 -0
  118. data/test/reg_sort_test.rb +1 -0
  119. data/test/runner_test.rb +32 -0
  120. data/test/shellcraft/infloop_test.rb +1 -0
  121. data/test/shellcraft/linux/cat_test.rb +1 -0
  122. data/test/shellcraft/linux/ls_test.rb +1 -0
  123. data/test/shellcraft/linux/sh_test.rb +1 -0
  124. data/test/shellcraft/linux/sleep_test.rb +68 -0
  125. data/test/shellcraft/linux/syscalls/execve_test.rb +1 -0
  126. data/test/shellcraft/linux/syscalls/exit_test.rb +1 -0
  127. data/test/shellcraft/linux/syscalls/open_test.rb +1 -0
  128. data/test/shellcraft/linux/syscalls/syscall_test.rb +1 -0
  129. data/test/shellcraft/memcpy_test.rb +20 -5
  130. data/test/shellcraft/mov_test.rb +1 -0
  131. data/test/shellcraft/nop_test.rb +1 -0
  132. data/test/shellcraft/popad_test.rb +1 -0
  133. data/test/shellcraft/pushstr_array_test.rb +1 -0
  134. data/test/shellcraft/pushstr_test.rb +1 -0
  135. data/test/shellcraft/registers_test.rb +1 -0
  136. data/test/shellcraft/ret_test.rb +1 -0
  137. data/test/shellcraft/setregs_test.rb +9 -8
  138. data/test/shellcraft/shellcraft_test.rb +1 -0
  139. data/test/test_helper.rb +28 -0
  140. data/test/timer_test.rb +2 -1
  141. data/test/tubes/buffer_test.rb +1 -0
  142. data/test/tubes/process_test.rb +8 -2
  143. data/test/tubes/serialtube_test.rb +1 -4
  144. data/test/tubes/sock_test.rb +1 -0
  145. data/test/tubes/tube_test.rb +10 -1
  146. data/test/ui_test.rb +18 -0
  147. data/test/util/cyclic_test.rb +1 -0
  148. data/test/util/fiddling_test.rb +8 -0
  149. data/test/util/getdents_test.rb +1 -0
  150. data/test/util/hexdump_test.rb +2 -1
  151. data/test/util/lists_test.rb +1 -0
  152. data/test/util/packing_test.rb +3 -2
  153. metadata +119 -59
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/helper'
2
4
 
3
5
  module Pwnlib
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/ls'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/open'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/sh'
@@ -11,9 +12,9 @@ module Pwnlib
11
12
  # @overload sh(argv: false)
12
13
  #
13
14
  # @see Generators::X86::Linux#sh
14
- def sh(*args)
15
+ def sh(**kwargs)
15
16
  context.local(arch: :amd64) do
16
- cat X86::Linux.sh(*args)
17
+ cat X86::Linux.sh(**kwargs)
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,24 @@
1
+ # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
3
+
4
+ require 'pwnlib/shellcraft/generators/amd64/linux/linux'
5
+ require 'pwnlib/shellcraft/generators/x86/linux/sleep'
6
+
7
+ module Pwnlib
8
+ module Shellcraft
9
+ module Generators
10
+ module Amd64
11
+ module Linux
12
+ # @overload sleep(seconds)
13
+ #
14
+ # @see Generators::X86::Linux#sleep
15
+ def sleep(*args)
16
+ context.local(arch: :amd64) do
17
+ cat X86::Linux.sleep(*args)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/amd64/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/syscall'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/abi'
2
4
  require 'pwnlib/constants/constants'
3
5
  require 'pwnlib/context'
@@ -31,6 +33,7 @@ module Pwnlib
31
33
  def typesetting
32
34
  indent = @_output.string.lines.map do |line|
33
35
  next line.strip + "\n" if label_str?(line.strip)
36
+
34
37
  line == "\n" ? line : ' ' * 2 + line.lstrip
35
38
  end
36
39
  indent.join
@@ -55,6 +58,7 @@ module Pwnlib
55
58
 
56
59
  def evaluate(item)
57
60
  return item if register?(item)
61
+
58
62
  Constants.eval(item)
59
63
  end
60
64
 
@@ -91,9 +95,14 @@ module Pwnlib
91
95
  # Each method runs in an independent 'runner', so methods would not effect each other.
92
96
  runner = Runner.new
93
97
  method = instance_method(m).bind(runner)
94
- define_singleton_method(m) do |*args|
98
+ define_singleton_method(m) do |*args, **kwargs|
95
99
  runner.clear
96
- method.call(*args)
100
+ # TODO(david942j): remove the check when we drop Ruby 2.6 support
101
+ if kwargs.empty?
102
+ method.call(*args)
103
+ else
104
+ method.call(*args, **kwargs)
105
+ end
97
106
  runner.typesetting
98
107
  end
99
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/helper'
2
4
 
3
5
  module Pwnlib
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/common/common'
4
5
  require 'pwnlib/shellcraft/generators/x86/common/infloop'
@@ -0,0 +1,34 @@
1
+ # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
3
+
4
+ require 'pwnlib/shellcraft/generators/i386/common/common'
5
+ require 'pwnlib/shellcraft/generators/i386/common/setregs'
6
+
7
+ module Pwnlib
8
+ module Shellcraft
9
+ module Generators
10
+ module I386
11
+ module Common
12
+ # Like +memcpy+ in glibc.
13
+ #
14
+ # Copy +n+ bytes from +src+ to +dst+.
15
+ #
16
+ # @param [String, Symbol, Integer] dst
17
+ # Destination.
18
+ # @param [String, Symbol, Integer] src
19
+ # Source to be copied.
20
+ # @param [Integer] n
21
+ # The number of bytes to be copied.
22
+ #
23
+ # @see Amd64::Common#memcpy
24
+ def memcpy(dst, src, n)
25
+ cat "/* memcpy(#{pretty(dst)}, #{pretty(src)}, #{pretty(n)}) */"
26
+ cat 'cld'
27
+ cat Common.setregs({ edi: dst, esi: src, ecx: n })
28
+ cat 'rep movsb'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/common/common'
4
5
 
@@ -12,8 +13,10 @@ module Pwnlib
12
13
  # See {Amd64::Common#mov} for parameters' details.
13
14
  def mov(dst, src, stack_allowed: true)
14
15
  raise ArgumentError, "#{dst} is not a register" unless register?(dst)
16
+
15
17
  dst = get_register(dst)
16
18
  raise ArgumentError, "cannot use #{dst} on i386" if dst.size > 32 || dst.is64bit
19
+
17
20
  if register?(src)
18
21
  src = get_register(src)
19
22
  raise ArgumentError, "cannot use #{src} on i386" if src.size > 32 || src.is64bit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/i386/common/common'
2
4
 
3
5
  module Pwnlib
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/common/common'
4
5
 
@@ -14,6 +15,7 @@ module Pwnlib
14
15
  # This will not affect callee's +str+.
15
16
  str += "\x00" if append_null && !str.end_with?("\x00")
16
17
  return if str.empty?
18
+
17
19
  padding = str[-1].ord >= 128 ? "\xff" : "\x00"
18
20
  cat "/* push #{str.inspect} */"
19
21
  group(4, str, underfull_action: :fill, fill_value: padding).reverse_each do |word|
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/common/common'
4
5
  require 'pwnlib/shellcraft/generators/x86/common/pushstr_array'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/common/common'
4
5
  require 'pwnlib/shellcraft/generators/x86/common/setregs'
@@ -11,9 +12,9 @@ module Pwnlib
11
12
  # @overload setregs(reg_context, stack_allowed: true)
12
13
  #
13
14
  # @see Generators::X86::Common#setregs
14
- def setregs(*args)
15
+ def setregs(*args, **kwargs)
15
16
  context.local(arch: :i386) do
16
- cat X86::Common.setregs(*args)
17
+ cat X86::Common.setregs(*args, **kwargs)
17
18
  end
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/cat'
@@ -11,9 +12,9 @@ module Pwnlib
11
12
  # @overload cat(filename, fd: 1)
12
13
  #
13
14
  # @see Generators::X86::Linux#cat
14
- def cat(*args)
15
+ def cat(*args, **kwargs)
15
16
  context.local(arch: :i386) do
16
- cat X86::Linux.cat(*args)
17
+ cat X86::Linux.cat(*args, **kwargs)
17
18
  end
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/execve'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/exit'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/helper'
2
4
 
3
5
  module Pwnlib
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/ls'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/open'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/sh'
@@ -11,9 +12,9 @@ module Pwnlib
11
12
  # @overload sh(argv: false)
12
13
  #
13
14
  # @see Generators::X86::Linux#sh
14
- def sh(*args)
15
+ def sh(**kwargs)
15
16
  context.local(arch: :i386) do
16
- cat X86::Linux.sh(*args)
17
+ cat X86::Linux.sh(**kwargs)
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,24 @@
1
+ # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
3
+
4
+ require 'pwnlib/shellcraft/generators/i386/linux/linux'
5
+ require 'pwnlib/shellcraft/generators/x86/linux/sleep'
6
+
7
+ module Pwnlib
8
+ module Shellcraft
9
+ module Generators
10
+ module I386
11
+ module Linux
12
+ # @overload sleep(seconds)
13
+ #
14
+ # @see Generators::X86::Linux#sleep
15
+ def sleep(*args)
16
+ context.local(arch: :i386) do
17
+ cat X86::Linux.sleep(*args)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/i386/linux/linux'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/syscall'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/helper'
2
4
 
3
5
  module Pwnlib
@@ -8,11 +10,11 @@ module Pwnlib
8
10
  module Common
9
11
  class << self
10
12
  def define_arch_dependent_method(method)
11
- define_method(method) do |*args|
13
+ define_method(method) do |*args, **kwargs|
12
14
  if context.arch == 'amd64'
13
- cat Amd64::Common.public_send(method, *args)
15
+ cat Amd64::Common.public_send(method, *args, **kwargs)
14
16
  elsif context.arch == 'i386'
15
- cat I386::Common.public_send(method, *args)
17
+ cat I386::Common.public_send(method, *args, **kwargs)
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/x86/common/common'
2
4
 
3
5
  module Pwnlib
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pwnlib/shellcraft/generators/amd64/common/memcpy'
4
+ require 'pwnlib/shellcraft/generators/i386/common/memcpy'
5
+ require 'pwnlib/shellcraft/generators/x86/common/common'
6
+
7
+ module Pwnlib
8
+ module Shellcraft
9
+ module Generators
10
+ module X86
11
+ module Common
12
+ define_arch_dependent_method :memcpy
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/common/mov'
2
4
  require 'pwnlib/shellcraft/generators/i386/common/mov'
3
5
  require 'pwnlib/shellcraft/generators/x86/common/common'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pwnlib/shellcraft/generators/amd64/common/pushstr'
2
4
  require 'pwnlib/shellcraft/generators/i386/common/pushstr'
3
5
  require 'pwnlib/shellcraft/generators/x86/common/common'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/x86/common/common'
4
5
  require 'pwnlib/shellcraft/generators/x86/common/mov'
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/x86/common/common'
4
5
 
@@ -13,25 +14,25 @@ module Pwnlib
13
14
  # The values of each registers to be set, see examples.
14
15
  # @param [Boolean] stack_allowed
15
16
  # If we can use stack for setting values.
16
- # With +stack_allowd+ equals +true+, shellcode would be shorter.
17
+ # With +stack_allowed+ equals +true+, shellcode would be shorter.
17
18
  #
18
19
  # @example
19
20
  # context.arch = 'i386'
20
- # puts shellcraft.setregs(rax: 'ebx', ebx: 'ecx', ecx: 0x123)
21
- # # mov rax, rbx
21
+ # puts shellcraft.setregs({ eax: 'ebx', ebx: 'ecx', ecx: 0x123 })
22
+ # # mov eax, ebx
22
23
  # # mov ebx, ecx
23
24
  # # xor ecx, ecx
24
25
  # # mov cx, 0x123
25
26
  # @example
26
27
  # context.arch = 'amd64'
27
- # puts shellcraft.setregs(rdi: 'rsi', rsi: 'rdi')
28
+ # puts shellcraft.setregs({ rdi: 'rsi', rsi: 'rdi' })
28
29
  # # xchg rdi, rsi
29
30
  #
30
- # puts shellcraft.setregs(rax: -1)
31
+ # puts shellcraft.setregs({ rax: -1 })
31
32
  # # push -1
32
33
  # # pop rax
33
34
  #
34
- # puts shellcraft.setregs({rax: -1}, stack_allowed: false)
35
+ # puts shellcraft.setregs({ rax: -1 }, stack_allowed: false)
35
36
  # # mov rax, -1
36
37
  def setregs(reg_context, stack_allowed: true)
37
38
  abi = ::Pwnlib::ABI::ABI.default
@@ -48,6 +49,7 @@ module Pwnlib
48
49
  cdq = false
49
50
  ev = lambda do |reg|
50
51
  return reg unless reg.is_a?(String)
52
+
51
53
  evaluate(reg)
52
54
  end
53
55
  eax = ev[eax]
@@ -1,4 +1,5 @@
1
1
  # encoding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pwnlib/shellcraft/generators/x86/common/pushstr'
4
5
  require 'pwnlib/shellcraft/generators/x86/linux/linux'