Created
February 26, 2025 09:42
-
-
Save bulk88/ed00e7e242f585fa3419eb6796dd4267 to your computer and use it in GitHub Desktop.
ntdllcpan.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Config; | |
my $cc_out = qx'cl 2>&1'; | |
my $b = ($cc_out =~ /( for 80x86| for x86)/); | |
my $is_64bit_build = !scalar($b); | |
my $cpu = $is_64bit_build?'X64':'X86'; | |
my $is_msvc_compiler | |
= index($cc_out, 'Microsoft (R) C/C++ Optimizing Compiler') != -1 | |
|| index($cc_out, 'Microsoft (R) 32-bit C/C++ Optimizing Compiler') != -1; | |
die "fix GCC 64 det code if reused" if !$is_msvc_compiler; | |
#msxxxx.dll and not msvcrt.dll is bc VC 2008 is emitting "warning LINK4199 | |
#/DELAYLOAD:dllname ignored; no imports found" from dllname if its msvcrt.dll | |
#but not any other names, its probably special casing by MS | |
my $gen_msvcrtdec_def = 'echo LIBRARY msxxxx.dll>msvcrtdec.def & echo EXPORTS>> msvcrtdec.def' | |
.' & echo vsprintf>> msvcrtdec.def' | |
.' & echo sprintf>> msvcrtdec.def' | |
# .' & echo NtCreateIoCompletion@16 = NtCreateIoCompletion>> msvcrtdec.def' | |
.' & echo toupper>> msvcrtdec.def' | |
.' & echo vswprintf>> msvcrtdec.def' | |
.' & echo toupper>> msvcrtdec.def' | |
.' & echo swprintf>> msvcrtdec.def' | |
.' & echo _ultoa>> msvcrtdec.def' | |
.' & echo strrchr>> msvcrtdec.def' | |
.' & echo strchr>> msvcrtdec.def' | |
.' & echo strcmp>> msvcrtdec.def' | |
.' & echo wcsrchr>> msvcrtdec.def' | |
.' & echo strstr>> msvcrtdec.def' | |
.' & echo memcpy>> msvcrtdec.def' | |
.' & echo memmove>> msvcrtdec.def' | |
.' & echo memchr>> msvcrtdec.def' | |
.' & echo memcmp>> msvcrtdec.def' | |
.' & echo wcscmp>> msvcrtdec.def' | |
.' & echo wcschr>> msvcrtdec.def' | |
.' & echo swscanf_s>> msvcrtdec.def' | |
.' & echo memset>> msvcrtdec.def'; | |
if($is_msvc_compiler) { | |
system 'echo LIBRARY msxxxx.dll> msvcrtundec.def & echo EXPORTS>> msvcrtundec.def' | |
.' & echo vsprintf>> msvcrtundec.def' | |
.' & echo sprintf>> msvcrtundec.def' | |
# .' & echo NtCreateIoCompletion>> msvcrtundec.def' | |
.' & echo toupper>> msvcrtundec.def' | |
.' & echo swprintf>> msvcrtundec.def' | |
.' & echo vswprintf>> msvcrtundec.def' | |
.' & echo _ultoa>> msvcrtundec.def' | |
.' & echo strrchr>> msvcrtundec.def' | |
.' & echo strchr>> msvcrtundec.def' | |
.' & echo strcmp>> msvcrtundec.def' | |
.' & echo wcsrchr>> msvcrtundec.def' | |
.' & echo strstr>> msvcrtundec.def' | |
.' & echo memcpy>> msvcrtundec.def' | |
.' & echo memmove>> msvcrtundec.def' | |
.' & echo memchr>> msvcrtundec.def' | |
.' & echo memcmp>> msvcrtundec.def' | |
.' & echo wcscmp>> msvcrtundec.def' | |
.' & echo wcschr>> msvcrtundec.def' | |
.' & echo swscanf_s>> msvcrtundec.def' | |
.' & echo memset>> msvcrtundec.def'; | |
if($is_64bit_build) { | |
system 'lib /out:plmsvcrtx64.lib /def:msvcrtundec.def /machine:x64'; | |
} else { | |
system $gen_msvcrtdec_def; | |
system 'lib /out:msvcrtundec.lib /def:msvcrtundec.def /machine:X86'; | |
system 'lib /out:plmsvcrt.lib /def:msvcrtdec.def /machine:X86 msvcrtundec.lib'; | |
} | |
} else { | |
system $gen_msvcrtdec_def; | |
system 'dlltool -k -d msvcrtdec.def -l msvcrt.a'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment