Jump to content

Recommended Posts

all :hello: im looking for something that can replace a text line to hex line 1 to 1

that also distinguishes between capital to none capital letters in conversions.

here is an example of what i need

input:

HeLlOwOrLD

hOwArEyOUtOdAY

output:

480065004c006c004f0077004f0072004c0044

68004f00770041007200450079004f00550074004f006400410059

instead of spaces, use "00"

some editors tools .etc only offer hexdump

or

they will make conversion but all in one line none separated ..

.etc

what ill be interested is in a tool a batch that can possibly offer doing so through a command

also would be interested in some conversion tool that deals with splitting the lines .. can be a web tool too so long as it it outputs lines separately !

TIA

Edited by sweept
Link to comment
Share on other sites


Copy this script to a .js file. Drop the text file to be converted on it, and it will create a .hex file.

var fso = new ActiveXObject("Scripting.FileSystemObject");

function TextToHex( inputfile, outputfile )
{
  while( 1 )
  {
  try{
  var inputline = inputfile.ReadLine();
  var outputline = "-";
   
  for( var i=0; i<inputline.length; i++ )
  {
  var character = inputline.charAt( i );
  if( ' ' == character )
  {
  outputline += "00";
  continue;
  }
  outputline += inputline.charCodeAt( i ).toString(16);
  }
  outputfile.WriteLine( outputline );
  }
  catch( e )
  {
  return;
  }
  }
}

function Parse( objArgs )
{
  for( obj=0; obj<objArgs.length; obj++ )
  {
  try{  
  var inputfile = fso.OpenTextFile( objArgs( obj ), 1 );
  try{
  var outputfile = fso.CreateTextFile( objArgs( obj ) + ".hex", true );
  TextToHex( inputfile, outputfile );
  outputfile.Close();
  }
  catch( e )
  {
  WScript.Echo( "Could not create " + objArgs( obj ) + ".hex\n" + e );
  }
  inputfile.Close();  
  }
  catch( e )
  {
  WScript.Echo( "Could not open " + objArgs( obj ) + "\n" + e );
  }
  }
}

Parse( WScript.arguments );

Link to comment
Share on other sites

thanks Mijzelf this looks really clean by code as far as i can tell i checked it out and seems to be doing what i was looking for

now there are 2 request i have for you!

1) that "00" gets added after each letter in output i can see reference in the code for that but with out an impact

2) output without "-" @ the beginning of each line (ignore this if this turns a problem)

this i s great thanks a lot!

small question: using this in batch ..

on some machines that are picky on scripts using reg tweaks to disable *.js it gets impossible to share or use this!

so does this mean it needs another coding language compiled to exe

-or can these kind of script be compiled to exe strictly, meaning to avoid having restrictions on file extensions like *.js .etc

if there is a simple way to get around this , please someone explain

TIA

Link to comment
Share on other sites

1) that "00" gets added after each letter in output

Ideally you don't want that, but rather proper unicode support: that's where the 00's normally come from, it's not just padding (having 00's for no reason would be kind of dumb). This script doesn't return UTF-16 encoded strings, and if you try passing a unicode-encoded text file instead (probably not what you want in the first place), it only writes "0" instead of "00", plus, it writes the byte order mark and all that to the file too. It might be helpful to know what you're doing all this for.

2) output without "-" @ the beginning of each line

Then replace

var outputline = "-";

by

var outputline = "";

on some machines that are picky on scripts using reg tweaks to disable *.js it gets impossible to share or use this!

Why on earth would be .js files disabled? or .vbs files for that matter? All this accomplishes is making the scripting host useless... I can't think of a single good reason to do that.

One could "fix" the .js file for unicode encoded output, but seemingly you don't want a jscript file.

If you want a .exe, then yes, you'll have to use something else. Any other techs you can't use? This could easily be done in a dozen lines of C# (would be a .exe, but you'd need the .NET framework installed)

Edited by crahak
Link to comment
Share on other sites

1) that "00" gets added after each letter in output

Ideally you don't want that, but rather proper unicode support: that's where the 00's normally come from, it's not just padding (having 00's for no reason would be kind of dumb). This script doesn't return UTF-16 encoded strings, and if you try passing a unicode-encoded text file instead (probably not what you want in the first place), it only writes "0" instead of "00", plus, it writes the byte order mark and all that to the file too. It might be helpful to know what you're doing all this for.

the need of adding "00" to the right of each character is because some hex patching tools will do nothing without having those when using search or search replace by design. so if i know how to add it in the script that would help later

however I will be happy if this script can be further more perfecteed to my need

I would definitely settle having it convert anything between two quotes in a line that will act as margins for conversions & anything else on the line echo'd to the out put or use <...> <...>

for example:

"helloworld" this is a test "h l o r d" (&$^ " t esti ng"

68656c6c6f776f726c64 this is a test 68206c206f2020722064 (&$^ 20742065737469206e67

like this it can be possible to us a command line literally tho i would also settle for something without the echoing part

"helloworld" "h l o r d"

68656c6c6f776f726c64 68206c206f2020722064

thanks for your help

Link to comment
Share on other sites

the need of adding "00" to the right of each character is because some hex patching tools will do nothing without having those when using search or search replace by design. so if i know how to add it in the script that would help later
Change line
outputline += inputline.charCodeAt( i ).toString(16);

in

outputline += inputline.charCodeAt( i ).toString(16) + "00";

and maybe you should change

outputline += "00";

to

outputline += "0000"

?

I would definitely settle having it convert anything between two quotes in a line that will act as margins for conversions & anything else on the line echo'd to the out put or use <...> <...>

for example:

"helloworld" this is a test "h l o r d" (&$^ " t esti ng"

68656c6c6f776f726c64 this is a test 68206c206f2020722064 (&$^ 20742065737469206e67

I think that is a bit difficult with a script. The scripting host takes the commandline and cuts it to pieces on each space. Two spaces are treated like one, so the script can't get the exact commandline.
Link to comment
Share on other sites

the need of adding "00" to the right of each character is because some hex patching tools will do nothing without having those when using search or search replace by design.

That would be because it only does unicode searches then. So that's what I was thinking, it's not padding, it's just encoded this way. Arguably, one could say the real fix here is a hex editor that isn't limited in that way (perhaps I'm not getting the big picture, converting text to hex, to then do text searches with a hex editor?), but anyhow...

As for the searching between quotes, the simplest thing would be to use a regular expression for that (e.g. "[^"]*"), and replacing in the original string all the matches by their hex representation (of the byte array returned when UTF-16 encoding it).

Still simple to do. I'll try to find some time tonight to write you something simple in C# (should only take 5-10 mins really).

You could still do it in JScript too. The biggest issue I can think of, is that .toString(16) doesn't return zero padded numbers (easily solved too).

Link to comment
Share on other sites

Mijzelf thats perfect now, great programming thanks ! :)

crahak the padding part can be optional & predefined just so so the tool is more flexible

limiting it to do certain extra padding in patterns may help as well

text2hex.exe /p"00" strings.txt > Hex.txt returns "00" paddings

+ the others from here:

http://www.swingnote.com/tools/texttohex.php

this can be a simply good converter tool with the convert between quotes feature and the option to have the output padded as needed ....

thanks again for all the help, guys

Edited by sweept
Link to comment
Share on other sites

Sorry for the late reply, had a nap, and it was a LOT longer than expected :lol:

Try this app: http://www.zshare.net/download/1665788387ce49d0/

Syntax is: text2hex.exe sourcefile.txt destinationfile.txt

a input text file with:

"helloworld"  this is a test "h l o  r d" (&$^  " t esti ng"
"helloworld" "h l o r d"

in it, would create another text file with:

680065006C006C006F0077006F0072006C006400  this is a test 680020006C0020006F0020002000720020006400 (&$^  200074002000650073007400690020006E006700
680065006C006C006F0077006F0072006C006400 680020006C0020006F0020002000720020006400

Which is exactly what you wanted if I understood what you wanted. Everything is proper unicode, and only the stuff between quotes is turned into hex.

If you want something else than a command line app, it would also be trivial to make it into an app with a GUI where you can paste strings into and have it convert them (or even a web app)... Anything else just ask. It could be turned into a jscript too. I'll post the final source code when you're happy with it...

Link to comment
Share on other sites

crahak i tried it out in various ways and it works perfectly.

finally there is a tool that can do a simple conversion without needing to look for combination ways or shareware tools, that still don't offer the simple conversion of getting the lines correct, the capital to none capital correct in translations .etc not to mention the padding aspect

what infact makes me sorry I'm not knowledgeable enough for coding , but Im happy proud and appropriative for the great help that went on this one...

there might be 2 things that comes to mind as to what exceptions this probably will need

* something for making quotes exceptional so it can have an output if needed

maybe by having a back slash attached to it

\" so it outputs "

\" = "

or any other workaround to adjust this

as to padding

I'd keep it simple by giving it some additional switch to have \no padding since the 16 bit "00" padding is default right now

i think it pretty much serves what i was looking for exactly!

turned out to be a real gem. :thumbup!

Edited by sweept
Link to comment
Share on other sites

* something for making quotes exceptional so it can have an output if needed

An option so it will ignore quotes and output *everything* in hex? Or an option to use a different character to delimit what is to be converted?

As for the zeros (everything being unicode), that could be optional if you wanted (I thought that's what you wanted in the first place). Simple to do anyways.

Just let me know exactly what you want, and I'll make the changes.

Link to comment
Share on other sites

allow me to emphasize that the goal has been reached & for what i needed of course

so the the 2 extra suggestions I had are maybe good in helping it become more of a qualified unix command line tool which i definitely wouldn't mind

but i can do without those side features added for now.

thanks again for the help i think you guys do amazing work

Edited by sweept
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...