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.
|
|
|
|
|
|
|
|
if(@ARGV != 2 && @ARGV != 3) {
|
2009-01-25 17:06:29 +00:00
|
|
|
print STDERR "Usage: mkdll.pl <function list> <output code> [<dll name>]\n";
|
2008-12-09 21:36:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
open(STUBS, "<".$ARGV[0]) or die("Cannot open ".$ARGV[0].": $!");
|
|
|
|
open(CODE, ">".$ARGV[1]) or die("Cannot open ".$ARGV[1].": $!");
|
|
|
|
|
2009-01-25 17:06:29 +00:00
|
|
|
my @stubs = ();
|
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 "") {
|
|
|
|
push @stubs, $line;
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 21:36:07 +00:00
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "section .rdata:\n";
|
|
|
|
|
2008-12-09 21:36:07 +00:00
|
|
|
if(@ARGV == 3) {
|
2009-01-25 17:06:29 +00:00
|
|
|
print CODE "\tglobal\t_dllname\n";
|
2011-08-12 01:12:10 +00:00
|
|
|
print CODE "\tdllname_s:\tdb\t'".$ARGV[2]."', 0\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "\t_dllname:\tdd\tdllname_s\n";
|
2011-08-12 01:12:10 +00:00
|
|
|
print CODE "\tcall_fmt\tdb\t'\%s:\%s', 0\n";
|
2008-12-09 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
foreach my $func(@stubs) {
|
|
|
|
my $real_func = $func;
|
|
|
|
$real_func =~ s/^r_//;
|
2008-12-09 21:36:07 +00:00
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "\t$func\_sym:\tdb\t'$real_func', 0\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print CODE "\nsection .data\n";
|
|
|
|
|
|
|
|
if(@ARGV == 3) {
|
2011-08-11 20:36:35 +00:00
|
|
|
print CODE "\textern\t_log_calls\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $func(@stubs) {
|
|
|
|
print CODE "\t$func\_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-06-16 23:55:20 +00:00
|
|
|
if(@ARGV == 3) {
|
2011-08-11 20:36:35 +00:00
|
|
|
print CODE "\textern\t_log_printf\n";
|
2009-01-25 17:06:29 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 23:55:20 +00:00
|
|
|
foreach my $func(@stubs) {
|
|
|
|
print CODE "\nglobal\t_$func\n";
|
|
|
|
print CODE "_$func:\n";
|
|
|
|
|
|
|
|
if(@ARGV == 3) {
|
2011-08-11 20:36:35 +00:00
|
|
|
print CODE "\tcmp\tbyte [_log_calls], 0\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "\tje\t$func\_nolog\n";
|
|
|
|
|
2011-08-11 20:36:35 +00:00
|
|
|
# Write DLL and symbol name to log
|
2011-06-16 23:55:20 +00:00
|
|
|
#
|
|
|
|
print CODE "\tpush\t$func\_sym\n";
|
2011-08-11 20:36:35 +00:00
|
|
|
print CODE "\tpush\tdllname_s\n";
|
|
|
|
print CODE "\tpush\tcall_fmt\n";
|
|
|
|
print CODE "\tcall\t_log_printf\n";
|
|
|
|
print CODE "\tadd esp, 12\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
|
|
|
|
print CODE "\t$func\_nolog:\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print CODE "\tcmp\tdword [$func\_addr], 0\n";
|
|
|
|
print CODE "\tjne\t$func\_jmp\n";
|
|
|
|
print CODE "\tpush\t$func\_sym\n";
|
2009-01-25 17:06:29 +00:00
|
|
|
print CODE "\tcall\t_find_sym\n";
|
2011-06-16 23:55:20 +00:00
|
|
|
print CODE "\tmov\t[$func\_addr], eax\n";
|
|
|
|
print CODE "\t$func\_jmp:\n";
|
|
|
|
print CODE "\tjmp\t[$func\_addr]\n";
|
2008-12-09 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close(CODE);
|
|
|
|
close(STUBS);
|