Skip to content

Commit

Permalink
cli: add --set-dll-char to patch dll characteristics
Browse files Browse the repository at this point in the history
  • Loading branch information
zed-0xff committed Apr 20, 2024
1 parent 857c707 commit 4359ae0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/pedump/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def run
opts.on "--set-os-version VER", "Patch OS version in PE header" do |ver|
@actions << [:set_os_version, ver]
end
opts.on "--set-dll-char X", "Patch IMAGE_OPTIONAL_HEADER32.DllCharacteristics" do |x|
@actions << [:set_dll_char, x]
end

opts.separator ''

Expand Down Expand Up @@ -343,6 +346,8 @@ def dump_action action, f
return extract action[1]
when :set_os_version
return set_os_version action[1]
when :set_dll_char
return set_dll_char action[1]
when :va2file
@pedump.sections(f)
va = action[1] =~ /(^0x)|(h$)/i ? action[1].to_i(16) : action[1].to_i
Expand Down Expand Up @@ -920,6 +925,14 @@ def extract_section id
_copy_stream @pedump.io, $stdout, section.SizeOfRawData, section.PointerToRawData
end
def set_dll_char x
@pedump.pe.image_optional_header.DllCharacteristics = x.to_i(0)
io = @pedump.io.reopen(@file_name,'rb+')
io.seek @pedump.pe.ioh_offset
io.write @pedump.pe.image_optional_header.pack
io.close
end
def set_os_version ver
raise "[!] invalid version #{ver.inspect}" unless ver =~ /\A(\d+)\.(\d+)\Z/
raise "[!] no IMAGE_OPTIONAL_HEADER" if @pedump.pe.ifh.SizeOfOptionalHeader.to_i == 0
Expand Down

0 comments on commit 4359ae0

Please sign in to comment.