-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbit_enc.rb
More file actions
41 lines (29 loc) · 724 Bytes
/
bit_enc.rb
File metadata and controls
41 lines (29 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# This script encodes the raw payload as a sequence of 8 bytes (one byte per
# bit), where a bit being set is 0xfd and a bit being clear is 0xfe.
#
# Example output below:
#
# db 0xfd, 0xfd, 0xfd, 0xfe, 0xfd, 0xfe, 0xfe, 0xfe, ; e8
# db 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfe, ; 82
# db 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, ; 00
#
first = true
str = ''
if ARGV[0].nil?
puts "bit_enc.rb [raw payload file]"
exit
end
fd = File.open(ARGV[0], "rb")
fd.read.each_byte { |byte|
str << "\tdb "
7.downto(0) { |bit|
val = (((byte & (1 << (bit))) != 0) ? 0xfd : 0xfe)
val -= 1 if first
str << "0x%.2x, " % val
first = false
}
str << " ; %.2x\n" % byte
}
str << "\tdb 0xfc\n"
puts str