#!/usr/bin/perl #################################################################################### #Description # Perl script to take a list of exported functions (as displayed by dumpbin) # and produce a list of linker directives suitable for use in a C/C++ DLL # project. Each listed function will be exported and point to a corresponding # function of the same name/ordinal in the specified DLL (). # #Usage # ./local.pl [output file] # # A text file containing the list of functions as displayed # by dumpbin. # # The DLL to which the functions will be forwarded to. # # [output file] Specifies the output file. If this parameter is not specified, # out.txt is used by default. # #Author # Craig Heffner # http://www.craigheffner.com # heffnercj [at] gmail.com # 10/28/2006 #################################################################################### #usage if(!$ARGV[1]){ print "\nUsage: ./linkout.pl [output file]\n\n is the name of a text file containing the exports list from dumpbin.\n\n is the name of the dll you wish to forward functions to.\n\n[output file] is the name of the file you want the results saved to.\n\nExample: ./linkout.pl dump.txt kernel32 output.txt\n"; exit; } if(!$ARGV[2]){ $file_out = "out.txt"; #default output file to use if one is not specified } else { $file_out = $ARGV[2]; } $file_in = $ARGV[0]; $dll = $ARGV[1]; $prepend = "#pragma comment(linker, \"/export:"; open(FILI,"<$file_in"); #input file open(FILO,">$file_out"); #output file foreach $line (){ if($line =~ m/\S+/){ #ignore blank lines chomp($line); @strin = split(m/\s+/,$line); #read each column in the text file into an array if(@strin[3] eq "[NONAME]"){ #is this function exported by ordinal only? $ord = @strin[1]; printf FILO $prepend . "ord$ord=$dll.#$ord,\@$ord,NONAME\")\n"; } else { $ord = @strin[1]; $name = @strin[4]; if($name =~ m/^_/){ #when creating the exported functions, VC++ removes one underscore from the beginning of functions that start with an underscore; let's add an extra one to combat this $name_in = "_" . $name; } else { $name_in = $name; } if($name eq "(forwarded"){ #is the original function forwarded to another DLL? chop(@strin[6]); #remove the trailing parentheses print FILO "$prepend@strin[3]=@strin[6],\@$ord\")\n"; } else { print FILO "$prepend$name_in=$dll.$name,\@$ord\")\n"; } } } } close(FILI); close(FILO); print "\nLinkout has finished. Results have been saved to: $file_out\n"; exit;