Convert xxd output to shellcode
Bash + coreutils + xxd, 73 71 69 bytes
printf \\x%s `xxd -r|xxd -p -s0x$1 -l$[(e=1+0x$2)?e-0x$1:-1]|fold -2`
Expects the hexdump on STDIN and start/end as command-line arguments.
This prints some warnings to STDERR, which is allowed by default.
Ruby: 90 89 87 79 63 bytes
-2 bytes thanks to @addison
-8 bytes thanks to @PiersMainwaring
->s,x,y{'\x'+s.scan(/(?<=.{9})\w\w(?=.* )/)[x.hex..y.hex]*'\x'}
See the tests on repl.it: https://repl.it/Cknc/5
JavaScript, 84 bytes
(s,f,t,u)=>s.replace(/.*:| .*\n?| /g,'').replace(/../g,'\\x$&').slice(f*4,++t*4||u)
Explanation: Removes all the unwanted parts of the dump, prepends \x
to each hex pair, then extracts the desired portion of the result. ||u
is used to convert the zero obtained by incrementing the -1
parameter into undefined
which is a magic value that causes slice
to slice to the end of the string. 101 bytes if f
and t
are strings of hex digits:
(s,f,t,u)=>s.replace(/.*:| .*\n?| /g,``).replace(/../g,`\\x$&`).slice(`0x${f}`*4,t<0?u:`0x${t}`*4+4)