Кодировать двоичный файл как текст в Windows 2000+ с помощью встроенных инструментов

1060
Knaģis

У меня есть удаленный доступ к рабочему столу через Citrix для удаленного сервера под управлением Windows 2000. Сервер не имеет какого-либо доступа к Интернету. Единственный способ передачи данных - это копирование текста через удаленный рабочий стол. По какой-то причине копирование файлов не работает, только текст, но работает как минимум до 10Мб.

Существуют ли какие-либо встроенные инструменты (в Windows 2000), которые позволили бы мне кодировать и декодировать двоичный файл в текст (Base64, uEncode, hex, что-нибудь ...)?

3
Нет; Там нет встроенных инструментов, как то, что вам нужно. Вам нужно будет разместить сторонний инструмент на сервере. Ramhound 10 лет назад 2
http://www.bastet.com/ Ƭᴇcʜιᴇ007 10 лет назад 0
Когда я сталкиваюсь с такими проблемами, я обычно «обманываю» и загружаю нужные мне файлы в «общедоступные» места (ftp и т. Д.), Видимые на удаленный сервер, и загружаю файлы оттуда (также решение для установки локального FTP-сервер и запуск только при подключении к удаленному ПК - так что это супер безопасно :) 10 лет назад 0
http://stackoverflow.com/questions/9304953/copy-files-from-remote-rdp-to-local-machine Ƭᴇcʜιᴇ007 10 лет назад 0
@ techie007 - эти решения не применимы к моему делу, потому что у меня Citrix посередине - в результате удаленный рабочий стол не видит диски на моем компьютере, а скорее некоторый промежуточный сервер, к которому у меня нет доступа. Knaģis 10 лет назад 0
@ Knaģis Доступен ли VBScript / JScript? and31415 10 лет назад 0
@ and31415 - так и должно быть. Knaģis 10 лет назад 0

2 ответа на вопрос

3
D Schlachter

Да, есть на самом деле .

Из cmd.exe,

Чтобы закодировать файл: certutil -encode inputFileName encodedOutputFileName

Чтобы декодировать файл: certutil -decode encodedInputFileName decodedOutputFileName

1
and31415

Here's a JScript-based script I've written which can translate a binary file to its hexadecimal representation, and vice-versa. Save the code as HexEncoder.js, or whatever you want as long it has the .js extension.

// Original script written by paulkienitz, 20110301 // http://www.codeproject.com/Messages/3718403/a-shorter-and-quicker-way-modified.aspx // Check the parameters count if (WScript.Arguments.length < 3) { WScript.Quit(2); } // Ensure the action parameter is long enough if (WScript.Arguments(0).length < 2) { WScript.Quit(3); } // Detect invalid characters var action = WScript.Arguments(0).toUpperCase().charCodeAt(1); switch (action) { // 'D' or 'E' case 0x44: case 0x45: break; default: WScript.Quit(3); break; } var fso = new ActiveXObject("Scripting.FileSystemObject"); var source = WScript.Arguments(1).replace("\\", "\\\\"); // Check whether the source file actually exists if (!fso.FileExists(source)) { WScript.Quit(4); } var dest = WScript.Arguments(2).replace("\\", "\\\\"); // When we read a binary stream as ISO 8859-1 (Latin 1), we should get a // string where each charCodeAt value matches the byte from the stream. // Unfortunately Windows won't give you Latin 1 -- when you ask for it, // you get code page 1252, which has extra characters stuck in for byte // values from 128 to 159. These two strings allow us to translate between // the bogus Windows characters and the original byte values. var bogusWindows1252Chars = "\u20AC\u201A\u0192\u201E\u2026\u2020\u2021" + "\u02C6\u2030\u0160\u2039\u0152\u017D" + "\u2018\u2019\u201C\u201D\u2022\u2013\u2014" + "\u02DC\u2122\u0161\u203A\u0153\u017E\u0178"; // No translation is necessary for characters 0x81, 0x8D, 0x8F, 0x90, or 0x9D var correctLatin1Chars = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087" + "\u0088\u0089\u008A\u008B\u008C\u008E" + "\u0091\u0092\u0093\u0094\u0095\u0096\u0097" + "\u0098\u0099\u009A\u009B\u009C\u009E\u009F"; if (action == 0x44) // D { decode(source, dest); } else if (action = 0x45) // E { encode(source, dest); } // This turns a string read as codepage 1252 into a boxed string with a // byteAt method. function binaryString(str) { // Always return an object with a .length var r = str ? new String(str) : new String(); r.byteAt = function(index) { var value = this.charCodeAt(index); // Translate character back to originating Windows-1252 byte value if (value > 0xff) { var p = bogusWindows1252Chars.indexOf(this.charAt(index)); value = correctLatin1Chars.charCodeAt(p); } // Convert the value to hexadecimal var hex = value.toString(16); return (hex.length == 2) ? hex : "0" + hex; }; return r; } // Does reverse translation from bytes back to Windows-1252 characters. function fromByte(hex) { var c = String.fromCharCode(parseInt(hex, 16)); var p = correctLatin1Chars.indexOf(c); return (p == -1) ? c : bogusWindows1252Chars.charAt(p); } function encode(source, dest) { var stream = new ActiveXObject("ADODB.Stream"); stream.Type = 2 // adTypeText stream.Charset = "iso-8859-1"; // actually Windows codepage 1252 stream.Open(); stream.LoadFromFile(source); var chunkSize = 4096; encodedFile = fso.OpenTextFile(dest, 2, true); // 2 = ForWriting while (!stream.EOS) { var s = binaryString(stream.ReadText(chunkSize)); var tempArray = new Array(); for (var i = 0; i < s.length; i++) { tempArray[i] = s.byteAt(i); } var hexString = tempArray.join(""); if (hexString.length > 0) { encodedFile.Write(hexString); } } encodedFile.Close(); stream.Close(); } function decode(source, dest) { var chunkSize = 8192; var encodedFile = fso.OpenTextFile(source, 1); // 1 = ForReading var decodedFile = fso.OpenTextFile(dest, 2, true); // 2 = ForWriting while (!encodedFile.AtEndOfStream) { var hexString = encodedFile.Read(chunkSize); var tempArray = new Array(); for (var i = 0; i < hexString.length; i += 2) { tempArray[i >> 1] = fromByte(hexString.substring(i, i + 2)); } var s = tempArray.join(""); if (s.length > 0) { decodedFile.Write(s); } } decodedFile.Close(); encodedFile.Close(); } 

Syntax

To encode a binary file:

cscript /nologo /e:jscript HexEncoder.js /e "binary file" "output file" 

To revert back:

cscript /nologo /e:jscript HexEncoder.js /d "encoded file" "binary file" 

Example usage

The following command will encode notepad.exe and save the output to the desktop:

cscript /nologo /e:jscript HexEncoder.js /e "%windir%\notepad.exe" "%userprofile%\Desktop\notepad.exe-hex.txt" 

Known limitations

  • Encoded files are twice the size of the original ones.
  • The script is best suited for small files, say under 1024 KiB.

    Eventually you could work around these limitations by using the script above to transfer some third party encoder.

Похожие вопросы