Winject – can’t find my way home

Ah, a Blind Faith reference. It occurred to me that the black hat crowd knows all about injecting resources into an exe. Even white hats do too if you google properly. Long ago I had to debug binutils/bfd. I don’t remember what the problem was or even what the goal was. It’s hasn’t gotten easier, but I’m pretty sure I can restore (b)winject to it’s former glory, only it’s work

I would not have written it the way _why did, but you gotta go with what you have and my way would not be a cake walk. If it could be gemified, it might be useful to others … Thats just crazy talk.

I devised a better test that should have occurred to me earlier. I want to compare what winject does without injecting any thing just load and save, for the msvc stub (blank.exe) and the mingw stube (shoes-setup.exe). I uncommented _why’s printf’s and added some of own. And I don’t want to point and click through Shoes. Or get the printf stuck into the Shoes Console (which can’t copied to the system clipboard).

There is tip here for Shoes developers.

copy.rb:

require 'winject'

def pkgtest teststub
  $stdout.puts "Test: #{teststub}"
  begin
    exe = Winject::EXE.new(File.join(DIR, "static", "stubs", teststub))
    exe.save(teststub.gsub("/\.exe/", "-copy.exe")) do |rlen|
      $stdout.puts "callback #{teststub} #{rlen}"
    end
  rescue StandardError => e
    $stderr.puts "OOPS: #{e}"
  end    
end

exe = ARGV[0]
pkgtest exe

See the problem? DIR is a Shoes constant, it’s not in regular Ruby. winject isn’t a gem, it’s an extension and it’s only inside the Shoes.

Then copy.sh. I probably should have named in test-copy or something.

#! /bin/bash
../../dist/shoes --ruby copy.rb blank.exe >blank-copy.log
../../dist/shoes --ruby copy.rb shoes-stub.exe >shoes-stub-copy.log

../../dist/shoes is where the Shoes exe is, relative to the two scripts. I’m calling Shoes which initializes it’s internal Ruby (and gems and extensions) and then runs the script – without bringing up the GUI so it’s fast. Under a second to run that test instead of minutes to point and click.

Shoes will do this trick behind your back when you try to install a gem that needs to be compiled. Should work on Windows too. Pretty handy.

Leave a Reply

Your email address will not be published. Required fields are marked *