如何.bat文件被'转换'没有第三方工具.exe文件? [英] How can a .bat file be 'converted' to .exe without third party tools?

查看:295
本文介绍了如何.bat文件被'转换'没有第三方工具.exe文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多理由要转换一蝙蝠的.exe - 隐藏/混淆实施,密码,道路资源,以创建批处理文件的服务......而主要是为了使你的工作看​​起来更加复杂和重要的比它确实是。

There are many reasons to want to 'convert' a .bat to .exe - to hide/obfuscate implementation, passwords, path to resources , to create a service from batch file ... and mainly to make your work to look more complicated and important than it really is.

也有很多理由不希望使用第三方工具。

There are also many reasons to not want to use third party tools.

所以如果你想'转换'批处理文件的.exe 无需外部软件? (转换是在引号,因为我不认为有真正的方法来编译一个批处理文件来执行。有广泛的应用太多的辱骂曲折的技术和错误和所有我知道其实创建一个临时 .BAT 文件,然后调用它)

So what if you want to 'convert' a batch file to .exe without external software? (convert is in quotes because I don't think there's really way to compile a batch file to executable. There are too many abusive twisty techniques and bugs used extensively and all the tools that I know in fact create a temporary .bat file and then call it )

推荐答案

一个非常明显的方法是使用的 IEX $ P $干燥综合征 - 古内置工具创建自解压包,并能够执行后提取命令。 因此,这里的 IEX $ P $干燥综合征 sed的指导性 /.bat创建自解压的.exe具有压缩.bat文件。 它接受两个参数 - 你要转换的.bat文件和目标可执行文件:

One very obvious approach is to use IEXPRESS - the ancient built-in tool that creates self-extracting packages and is capable to execute post extraction commands. So here's IEXPRESS sed-directive/.bat file that creates a self-extracting .exe with packed .bat. It accepts two arguments - the .bat file you want to convert and the target executable:

 ;@echo off
; rem https://github.com/npocmaka/batch.scripts/edit/master/hybrids/iexpress/bat2exeIEXP.bat
;if "%~2" equ "" (
; echo usage: %~nx0 batFile.bat target.Exe
;)
;set "target.exe=%__cd__%%~2"
;set "batch_file=%~f1"
;set "bat_name=%~nx1"
;set "bat_dir=%~dp1"

;copy /y "%~f0" "%temp%\2exe.sed" >nul

;(echo()>>"%temp%\2exe.sed"
;(echo(AppLaunched=cmd.exe /c "%bat_name%")>>"%temp%\2exe.sed"
;(echo(TargetName=%target.exe%)>>"%temp%\2exe.sed"
;(echo(FILE0="%bat_name%")>>"%temp%\2exe.sed"
;(echo([SourceFiles])>>"%temp%\2exe.sed"
;(echo(SourceFiles0=%bat_dir%)>>"%temp%\2exe.sed"
;(echo([SourceFiles0])>>"%temp%\2exe.sed"
;(echo(%%FILE0%%=)>>"%temp%\2exe.sed"


;iexpress /n /q /m %temp%\2exe.sed

;del /q /f "%temp%\2exe.sed"
;exit /b 0

[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=0
HideExtractAnimation=1
UseLongFileName=1
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles

[Strings]
InstallPrompt=
DisplayLicense=
FinishMessage=
FriendlyName=-
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=

例如:

bat2exeIEXP.bat  myBatFile.bat MyExecutable.exe

这应该工作几乎每一个Windows机器在那里上,但有一个主要的限制 - 不能传递参数给创建的.exe文件

This should work practically on every Windows machine out there but has one major limitation - you cannot pass arguments to the created .exe file

所以,另外一个可能的方法是看.NET编译器(同样应该适用于几乎所有的获胜机).I've选择的 Jscript.net 的。 这是一种混合 jscript.net / 蝙蝠脚本,将读取.batch文件content.Will创建其他的JScript 。.NET与.bat文件内容和编译后会产生INT临时文件夹一个新的批处理文件并调用it.And将接受命令行参数(解释可能看起来复杂,但实际上它很简单):

So one other possible approach is to look at the .NET compilers (again should be available on almost every win machine).I've choose Jscript.net . This is a hybrid jscript.net/.bat script that will read the .batch file content.Will create another jscript.net with the .bat file content and after the compilation will create a new bat file int the temp folder and will call it.And will accept command line arguments.(explained might look complex but in fact it's simple):

@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal

for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
   set "jsc=%%v"
)

if not exist "%~n0.exe" (
    "%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)

 %~n0.exe  "%jsc%" %*

endlocal & exit /b %errorlevel%


*/

//https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/bat2exe.bat
import System;
import System;
import System.IO;


var arguments:String[] = Environment.GetCommandLineArgs();
if (arguments.length<3){
    Console.WriteLine("Path to cmd\bat file not given");
    Environment.Exit(1);
}
//Console.WriteLine(arguments[2])
var binName=Path.GetFileName(arguments[2])+".exe";
var batchContent:byte[]= File.ReadAllBytes(arguments[2]);
var compilerLoc=arguments[1];
var content="["

for (var i=0;i<batchContent.length-1;i++){
    content=content+batchContent[i]+","
}
content=content+batchContent[batchContent.length-1]+"]";
var temp=Path.GetTempPath();
Console.WriteLine(temp);
var dt=(new Date()).getTime();
var tempJS=temp+"\\2exe"+dt+".js";

//File.WriteAllBytes("here",batchContent);


var toCompile="\r\n\
import System;\r\n\
import System.IO;\r\n\
var arguments:String[] = Environment.GetCommandLineArgs();\r\n\
//Remove the executable name from the command line\r\n\
var batCommandLIne=Environment.CommandLine.substring(arguments[0].length,Environment.CommandLine.length);\r\n\
var contet2:byte[]="+content+";\r\n\
var dt=(new Date()).getTime();\r\n\
var temp=Path.GetTempPath();\r\n\
var tempBatPath=Path.Combine(temp,arguments[0]+dt+'.bat');;\r\n\
File.WriteAllBytes(tempBatPath,contet2);\r\n\
System.Diagnostics.Process.Start('cmd.exe','/c '+' '+tempBatPath+' '+batCommandLIne);\r\n\
File.Delete(tempBatPath);\r\n\
";

File.WriteAllText(tempJS,toCompile);
System.Diagnostics.Process.Start(compilerLoc,'/nologo /out:'+binName+' '+tempJS);
File.Delete(tempJS);

这是相当一个POC,但.NET System.Diagnostics程序和System.IO库非常强大,足以增加功能,如隐蔽启动,enctiption和etc.You还可以检查器jsc.exe编译选项,看看还有什么能够(比如增加资源)。

It's rather a POC , but .NET System.Diagnostics and System.IO libraries are powerful enough to add features like hidden start , enctiption and etc.You can check also jsc.exe compiling options to see what else is capable of (like adding resources).

我答应了upvote每一个改进的.NET方法: - )

I promise an upvote to every improvement over the .NET method :-)

这篇关于如何.bat文件被'转换'没有第三方工具.exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆