A binary file opened by Sublime HexViewer is like
ffff 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000a
000b 000c 000d 000e 000f 0010 0011 0012 0013 0014 0015 0016
0017 0018 0019 .... eeee
Which has 12 columns. But I want to make all my binary files show like this when opened
ffff
0000 00010002
0003 00040005
0006 00070008
0009 000a000b
....
eeee
Is this possible?
I am using this code:
require 'benchmark'
LOOPS = 100_000_000
def while_loop
i = 0
while i < LOOPS do i += 1 end
end
def times_loop
i = 0
LOOPS.times { i += 1 }
end
Benchmark.benchmark do |b|
b.report('while') { while_loop }
b.report('times') { times_loop }
end
The output is (Ruby 2.6.0):
while 2.419529 0.000000 2.419529 ( 2.426470)
times 7.225500 0.005673 7.231173 ( 7.252794)
Why is while loop faster than others?
One of the reasons is because times - it's a block. And it introduces new local variable scope. And it creates some sort of local variable, look:
RubyVM::InstructionSequence.disasm(method(:times_loop)) returns
== disasm: #<ISeq:times_loop#1.rb:23 (23,0)-(26,3)>=====================
== catch table
| catch type: break st: 0003 ed: 0014 sp: 0000 cont: 0014
== disasm: #<ISeq:block in times_loop#1.rb:25 (25,14)-(25,24)>==========
== catch table
| catch type: redo st: 0001 ed: 0010 sp: 0000 cont: 0001
| catch type: next st: 0001 ed: 0010 sp: 0000 cont: 0010
|------------------------------------------------------------------------
0000 nop ( 25)[Bc]
0001 getlocal_OP__WC__1 i[Li]
0003 putobject_OP_INT2FIX_O_1_C_
0004 opt_plus <callinfo!mid:+, argc:1, ARGS_SIMPLE>, <callcache>
0007 dup
0008 setlocal_OP__WC__1 i
0010 leave [Br]
|------------------------------------------------------------------------
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1#-1, kwrest: -1])
[ 1] i
0000 putobject_OP_INT2FIX_O_0_C_ ( 24)[LiCa]
0001 setlocal_OP__WC__0 i
0003 getinlinecache 10, <is:0> ( 25)[Li]
0006 getconstant :LOOPS
0008 setinlinecache <is:0>
0010 send <callinfo!mid:times, argc:0>, <callcache>, block in times_loop
0014 leave ( 26)[Re]
There are two local variables (setlocal_OP__WC__1 and setlocal_OP__WC__0) in this case.
In opposite while use just one, RubyVM::InstructionSequence.disasm(method(:while_loop)) returns
== disasm: #<ISeq:while_loop#1.rb:15 (15,0)-(20,3)>=====================
== catch table
| catch type: break st: 0009 ed: 0032 sp: 0000 cont: 0032
| catch type: next st: 0009 ed: 0032 sp: 0000 cont: 0006
| catch type: redo st: 0009 ed: 0032 sp: 0000 cont: 0009
|------------------------------------------------------------------------
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1#-1, kwrest: -1])
[ 1] i
0000 putobject_OP_INT2FIX_O_0_C_ ( 16)[LiCa]
0001 setlocal_OP__WC__0 i
0003 jump 17 ( 17)[Li]
0005 putnil
0006 pop
0007 jump 17
0009 getlocal_OP__WC__0 i ( 18)[Li]
0011 putobject_OP_INT2FIX_O_1_C_
0012 opt_plus <callinfo!mid:+, argc:1, ARGS_SIMPLE>, <callcache>
0015 setlocal_OP__WC__0 i
0017 getlocal_OP__WC__0 i ( 17)
0019 getinlinecache 26, <is:0>
0022 getconstant :LOOPS
0024 setinlinecache <is:0>
0026 opt_lt <callinfo!mid:<, argc:1, ARGS_SIMPLE>, <callcache>
0029 branchif 9
0031 putnil
0032 leave ( 20)[Re]
I think that the reason is not the only one.
But setting/getting new local variable slow down operation.
How can I make a loop that increment a hexadecimal variable in expect ?
I would like something like that.
while min < max do
print hexValue
hexValue++
This:
#!/usr/bin/expect -f
set min 0x0000;
set max 0xFFFF ;
while {$min < $max } {
puts [format %04X $min]
sleep 1;
set min [expr $min+1];
}
Will output:
debian#debian:~/Desktop$ ./test.sh
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
Why is awk not working for the following command instead of sed:
su -c "stdbuf -i0 -o0 -e0 od --width=144 -x /dev/input/event3 | sed 's%^\([a-z0-9]\+ \)\{11\}%%;s%\(....\).*%\1%'"
This prints at every keypress the USB HID ID number of the key that was pressed.
Example output (0028 is for Return and 00e4 for Right-Ctrl):
0028
0028
0028
0028
0028
00e4
00e4
00e4
This are two lines of output without sed/cut/awk filtering when pressing Return two times. The USB HID ID number is in column 12:
0000000 2d6f 511e 0000 0000 051b 0007 0000 0000 0004 0004 0028 0007 2d6f 511e 0000 0000 051d 0007 0000 0000 0001 001c 0000 0000 2d6f 511e 0000 0000 051e 0007 0000 0000 0000 0000 0000 0000 2d73 511e 0000 0000 a150 0007 0000 0000 0004 0004 0028 0007 2d73 511e 0000 0000 a153 0007 0000 0000 0001 001c 0001 0000 2d73 511e 0000 0000 a154 0007 0000 0000 0000 0000 0000 0000
0000220 2d73 511e 0000 0000 9b5a 0008 0000 0000 0004 0004 0028 0007 2d73 511e 0000 0000 9b5d 0008 0000 0000 0001 001c 0000 0000 2d73 511e 0000 0000 9b5e 0008 0000 0000 0000 0000 0000 0000 2d74 511e 0000 0000 4f90 0005 0000 0000 0004 0004 0028 0007 2d74 511e 0000 0000 4f93 0005 0000 0000 0001 001c 0001 0000 2d74 511e 0000 0000 4f94 0005 0000 0000 0000 0000 0000 0000
I tried it with
su -c "stdbuf -i0 -o0 -e0 od --width=144 -x /dev/input/event3 | cut -d' ' -f12"
and it also works. But it only shows the keys pressed after the next two keypresses. stdbuf did not help here, although it should adjusts standard input/output/error stream buffering to 0.
My mawk command looked like this:
su -c "stdbuf -i0 -o0 -e0 od --width=$((48*3)) -x /dev/input/event3 | mawk '{ print $12 }'"
but it only showed me some twos and then some newlines and again twos. It seems very laggy/slow. When I press a key, nothing happens. After pressing different keys multiple times, I always get a bunch of twos and newlines. No matter which keys I pressed! Example:
2
2
2
2
2
2
2
2
2
2
2
2
How can I fix this? Why is this occurring?
Update
When I use gawk instead of mawk it does not lag any more (unbuffered). But I still don’t see the correct values which should be 0028 or 00e4 and so on for Return and Right-Ctrl as example keys.
With all the comments I came to the solution.
#Olivier Dulac brought me to the idea that there are different awk implementations, which solved the problem of the laggyness (using gawk instead of mawk). I don’t even need the stdbuf.
#Ed Morton’s idea brought me to a problem, because he used quotes " in his example. I already had quotes in my statement around the whole thing, because it was executed using su. So I had to escape them.
My whole statement looks like this (notice the escaped dollar sign in front of the 12):
su -c "od --width=144 -x /dev/input/event3 | awk '{ print \$12 }'"
and now it works as expected.
Camtasia Studio is a software package for recording screen captures. One thing it does, it records the mouse movement coordinates separately from the video of your screen. It does this so you can modify the appearance of the cursor after you are done recording.
Once you have recorded your screen, it has an option for exporting the raw components of your capture. One of the files contains the cursor coordinates which look like this...
4556 5453 0300 0000 0c00 0000 0c00 0000
ca00 0000 0c00 0000 0100 0000 0000 0000
8002 0000 e001 0000 1900 0000 cb00 0000
1900 0000 0100 0000 0000 0000 000c 0259
0000 0059 0014 0000 00e0 e8ab 096a 032d
08b8 0100 00c8 0000 0008 0000 0037 0000
00b0 feff ffef 0328 02d2 0100 00f0 0328
02d2 0100 00f1 0329 02e0 0100 00f2 032a
02e0 0100 00f5 032b 02ed 0100 00f8 032d
02ed 0100 00fb 032f 02fa 0100 0001 0432
02fa 0100 0007 0435 0208 0200 000e 043a
0208 0200 0018 043f 0215 0200 0023 0445
0215 0200 002e 044a 0215 0200 0039 0450
0215 0200 0046 0455 0215 0200 004f 0458
0215 0200 0056 045a 022c 0200 005d 045e
022c 0200 0063 0462 0242 0200 0068 0465
0242 0200 006f 046b 0258 0200 0072 046f
0258 0200 0079 0476 0280 0200 0082 047d
0280 0200 0089 0484 028c 0200 0091 048a
028c 0200 0098 0494 029a 0200 009e 049c
029a 0200 00a3 04a0 029a 0200 00a7 04a3
029a 0200 00aa 04a6 02aa 0200 00af 04ab
02bc 0200 00b2 04ae 02bc 0200 00b4 04b3
02bc 0200 00b8 04b7 02cc 0200 00be 04bd
02cc 0200 00c1 04bf 02dd 0200 00c3 04c1
02dd 0200 00c6 04c4 02f8 0200 00c9 04c6
02f8 0200 00cb 04c8 0205 0300 00cc 04c9
0213 0300 00cd 04c9 0213 0300 00cd 04ca
0220 0300 00ce 04cb 0221 0300 00ce 04cc
0221 0300 00ce 04cd 0236 0300 00ce 04ce
0236 0300 00cd 04cf 024d 0300 00cc 04d0
024d 0300 00cc 04d1 0262 0300 00cb 04d2
0262 0300 00cb 04d3 0279 0300 00ca 04d3
02a5 0300 00c9 04d3 0218 0000 0002 0000
000c 0000 0002 0000 0000 0000 0081 0404
0487 06a5 04a5 0300 00f8 0304 0487 06ba
040a 0000 0003 0000 000a 0000 0001 0000
0000 0000 0000 0008 0009 000c 0000 0001
0000 000c 0000 0001 0000 0000 0000 00ff
033b 027f 061b 040c 0000 0005 0000 000c
0000 0001 0000 0000 0000 0000 0000 00ff
ffff ff0c 0000 0004 0000 000c 0000 0001
0000 0000 0000 0001 0000 0000 0000 001c
0000 002d 0100 001c 0000 0001 0000 0090
0300 0000 0100 0079 0000 0044 0000 0000
0000 0000 0000 0000 0000 00
This is from a 1 second recording. The screen capture size was 640x480. I was moving the mouse from the top left corner to the bottom right corner.
So here is my question. Is there a way to translate this information to time and X, Y coordinates of the video? I guess I just don't understand the notation but I want to use this information for my own project. Can anyone make sense of this data?