2

I was handed a bat file with something like the below:

app -r "a://b.c" -f "WIN 11,265" -pp "/%nick%/" -C S:diboze -C S:%nick%^
 -C S:2.625 -C S:pbkdf2_sha256^$10000^$RGarixCRleJl^$4s8d4fsd4^
 /4Df4d/bEW9k= -T "m9z#$dO0qe@sMYxx34Rxe%"

I translated it into C# by replacing " with "" (using a @" string) then replacing %nick% with {0} in a String.Format. However the script does not work. What else do I need to escape? Is pbkdf2_sha256^$10000 actual code? I thought everything here should be raw text except for %nick% but it appears that I'm wrong.

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • Doesn't the batch file simply call a program called app with all of those switches? I would expect that things like pbkdf2_sha256^$10000 are simply arguments to the program called app that it can somehow parse and decipher. I do agree that the only thing that it looks like it is using is %nick% as an environment variable. However, given -pp uses it as well, maybe the program called app expects to be able to utilise that environment variable also. Maybe just try calling app /? or app --help from the command line to see if it tells you what the arguments are meant to represent. – Mr Moose Oct 27 '12 at 02:38
  • @MrMoose: Maybe, but I definately escaped " and nick properly, theres no '{' to mess up string.format. But the program is getting an error so there is definitely a difference i dont know about –  Oct 27 '12 at 02:40
  • Can you call app /? or app --help to find out what the arguments represent. Maybe then you could simply use Process to call app with the appropriate arguments as shown in [in this answer](http://stackoverflow.com/a/878660/685760). You would just need to work out how to get the value of %nick% and replace -C S:%nick% with -C S: – Mr Moose Oct 27 '12 at 02:45
  • 1
    Nevermind, there are a few problems. Like ^ is converted to $ and `xe%"` is actually `xe"`. I tested by having the bat call my app which shows me the args –  Oct 27 '12 at 02:53
  • ^ means take the next character literally in batch files. So 'echo ^$' will just print $. Similarly % is for delimiting variables, in this case it wasn't followed by a digit or another % so it just vanishes. Looks like the original batch file wouldn't do exactly what it was supposed to, assuming it was supposed to pass those characters through. – lessthanideal Nov 05 '12 at 17:13

1 Answers1

0

It's important, if your originak command was called from a batch file or from the cmd prompt.

app -r "a://b.c" -f "WIN 11,265" -pp "/%nick%/" -C S:diboze -C S:%nick%^
 -C S:2.625 -C S:pbkdf2_sha256^$10000^$RGarixCRleJl^$4s8d4fsd4^
 /4Df4d/bEW9k= -T "m9z#$dO0qe@sMYxx34Rxe%"

From a batch it's effectivly

app -r "a://b.c" -f "WIN 11,265" -pp "/%nick%/" -C S:diboze -C S:%nick% -C S:2.625 -C S:pbkdf2_sha256$10000$RGarixCRleJl$4s8d4fsd4 /4Df4d/bEW9k= -T "m9z#$dO0qe@sMYxx34Rxe"

As you can see, I removed the carets and the last percent sign.

From the command prompt it would be the same, but the last percent sign should be preserved.

jeb
  • 78,592
  • 17
  • 171
  • 225