2011-06-16 23:55:20 +00:00
|
|
|
# IPXWrapper - Generate assembly stub functions
|
|
|
|
# Copyright (C) 2008-2011 Daniel Collins <solemnwarning@solemnwarning.net>
|
2008-12-09 21:36:07 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 as published by
|
|
|
|
# the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2011-09-11 13:28:41 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
if(@ARGV != 3) {
|
|
|
|
print STDERR "Usage: mkdll.pl <function list> <output file> <dll number>\n";
|
2008-12-09 21:36:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-09-11 13:28:41 +00:00
|
|
|
my $stub_file = $ARGV[0];
|
|
|
|
my $asm_file = $ARGV[1];
|
|
|
|
my $dllnum = $ARGV[2];
|
|
|
|
my $do_logging = ($dllnum != 0);
|
|
|
|
|
|
|
|
open(STUBS, "<$stub_file") or die("Cannot open $stub_file: $!");
|
|
|
|
open(CODE, ">$asm_file") or die("Cannot open $asm_file: $!");
|
2008-12-09 21:36:07 +00:00
|
|
|
|
2009-01-25 17:06:29 +00:00
|
|
|
my @stubs = ();
|
2011-09-11 13:28:41 +00:00
|
|
|
my @stubs_dll = ();
|
2008-12-09 21:36:07 +00:00
|
|
|
|
2009-01-25 17:06:29 +00:00
|
|
|
foreach my $line(<STUBS>) {
|
|
|
|
$line =~ s/[\r\n]//g;
|
|
|
|
|
|
|
|
if($line ne "") {
|
2011-09-11 13:28:41 +00:00
|
|
|
my ($func, $dn) = split(/:/, $line);
|
|
|
|
$dn = $dllnum if(!defined($dn));
|
|
|
|
|
|
|
|
my $sym = $func;
|
|
|
|
$sym =~ s/^r_//;
|
|
|
|
|
|
|
|
push(@stubs, {"name" => $func, "sym" => $sym, "dllnum" => $dn});
|
2009-01-25 17:06:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-09 21:36:07 +00:00
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "section .rdata:\n";
|
|
|
|
|
|
|
|
foreach my $func(@stubs) {
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\t".$func->{"name"}."_sym:\tdb\t'".$func->{"sym"}."', 0\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print CODE "\nsection .data\n";
|
|
|
|
|
|
|
|
foreach my $func(@stubs) {
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\t".$func->{"name"}."_addr:\tdd\t0\n";
|
2009-01-25 17:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print CODE "\nsection .text\n";
|
|
|
|
print CODE "\textern\t_find_sym\n";
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\textern\t_log_call\n" if($do_logging);
|
2009-01-25 17:06:29 +00:00
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
foreach my $func(@stubs) {
|
2011-09-11 13:28:41 +00:00
|
|
|
my $f_name = $func->{"name"};
|
2011-06-16 23:55:20 +00:00
|
|
|
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\nglobal\t_$f_name\n";
|
|
|
|
print CODE "_$f_name:\n";
|
|
|
|
|
|
|
|
if($do_logging) {
|
2012-10-20 19:21:59 +00:00
|
|
|
print CODE "\tpush\tdword ".$func->{"dllnum"}."\n";
|
2014-01-12 17:26:51 +00:00
|
|
|
print CODE "\tpush\t$f_name\_sym\n";
|
|
|
|
print CODE "\tpush\tdword $dllnum\n";
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\tcall\t_log_call\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\tcmp\tdword [$f_name\_addr], 0\n";
|
|
|
|
print CODE "\tjne\t$f_name\_jmp\n";
|
|
|
|
|
|
|
|
print CODE "\tpush\t$f_name\_sym\n";
|
|
|
|
print CODE "\tpush\tdword ".$func->{"dllnum"}."\n";
|
2009-01-25 17:06:29 +00:00
|
|
|
print CODE "\tcall\t_find_sym\n";
|
2011-09-11 13:28:41 +00:00
|
|
|
print CODE "\tmov\t[$f_name\_addr], eax\n";
|
|
|
|
|
|
|
|
print CODE "\t$f_name\_jmp:\n";
|
|
|
|
print CODE "\tjmp\t[$f_name\_addr]\n";
|
2008-12-09 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close(CODE);
|
|
|
|
close(STUBS);
|