Skip to content

Commit ebc6d1e

Browse files
committed
add explicit offset methods
1 parent 32b7d2e commit ebc6d1e

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

test/fake_code_signer.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ def initialize(input:, output:, padding: 4)
2828
def sign
2929
if pe_header.security_size !=0
3030
raise "Binary already signed, nothing to do!"
31-
elsif @input == @output
32-
raise "input and output files must be different!"
3331
end
3432

3533
# Below we access an instance of the IMAGE_DATA_DIRECTORY struct.
3634
# This instance is called IMAGE_DIRECTORY_ENTRY_SECURITY and it contains information about the digital signature
3735
# see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680305(v=vs.85).aspx
3836

3937
# write the offset (address) of the digital signature to the security header (VirtualAddress field)
40-
@image[pe_header.security_offset, 4] = raw_bytes(@image.size + @padding)
38+
@image[pe_header.security_address_offset, PEHeader::DWORD_SIZE] = raw_bytes(@image.size + @padding)
4139

4240
# write the size of the digital signature to the security header (Size field)
43-
@image[pe_header.security_offset + 4, 4] = raw_bytes(FAKE_SIG.size)
41+
@image[pe_header.security_size_offset, PEHeader::DWORD_SIZE] = raw_bytes(FAKE_SIG.size)
4442

4543
# append the "digital signature" to the end of the executable, complete with padding
4644
@image << padding_string << FAKE_SIG

test/fake_code_signer/pe_header.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ def security_offset
3939
image_data_directory_offset + DATA_DIRECTORY_ENTRY_SIZE * 4
4040
end
4141

42+
alias security_address_offset security_offset
43+
44+
def security_size_offset
45+
security_offset + DWORD_SIZE
46+
end
47+
4248
# location of the digital signature
4349
def security_address
44-
deref(security_offset)
50+
deref(security_address_offset)
4551
end
4652

4753
# size of the digital signature
4854
def security_size
49-
deref(security_offset + DWORD_SIZE)
55+
deref(security_size_offset)
5056
end
5157

5258
private

0 commit comments

Comments
 (0)