Jump to content

FileRead won't read this text file (in whole)


Recommended Posts

I'm trying to capture the output of the Win2k3 tool cmdkey so that I can automate the process of deleting stored usernames and passwords under WinXP.

I'm using the command:

C:\CMDKEY\cmdkey.exe /list>C:\cmdkey.txt

at the command line but the text file that I get is a bit weird. Whatever method I use to try and read the entire file, I just get the first line. There must be some strange character hidden somewhere or some weird formatting because I had to hexedit the file just to star out the usernames (if I changed it in notepad and then saved, I could read the file properly).

Can anyone explain why this text file doesn't read in whole and how I can overcome this? TIA.

cmdkey.txt

Link to comment
Share on other sites

I'm trying to capture the output of the Win2k3 tool cmdkey so that I can automate the process of deleting stored usernames and passwords under WinXP.

I'm using the command:

C:\CMDKEY\cmdkey.exe /list>C:\cmdkey.txt

at the command line but the text file that I get is a bit weird. Whatever method I use to try and read the entire file, I just get the first line. There must be some strange character hidden somewhere or some weird formatting because I had to hexedit the file just to star out the usernames (if I changed it in notepad and then saved, I could read the file properly).

Can anyone explain why this text file doesn't read in whole and how I can overcome this? TIA.

$FILE = FileOpen("C:\cmdkey.txt",0)
$READ = FileRead($FILE)
FileClose($FILE)
MsgBox(0,"RESULT",$READ)

When the words fail... music speaks.

Link to comment
Share on other sites

$FILE = FileOpen("C:\cmdkey.txt",0)
$READ = FileRead($FILE)
FileClose($FILE)
MsgBox(0,"RESULT",$READ)
Thanks but I'm afraid that doesn't work, the output I get is just the first line. Like I said, I've tried all the obvious methods, I even dabbled with converting binary, removing chunks and then converting back, nothing works. Edited by idbirch
Link to comment
Share on other sites

Thanks but I'm afraid that doesn't work, the output I get is just the first line. Like I said, I've tried all the obvious methods, I even dabbled with converting binary, removing chunks and then converting back, nothing works.

please upload cmdkey.txt

When the words fail... music speaks.

Link to comment
Share on other sites

The problem is chars after target name and begin types. If you delete this chars, you can read file.

Currently stored credentials:

     Target:  uksthisa    Type: Domain Password
     User: uk\xxxxxxx
     
     Target:  UKSTHMSX005.uk.xxx.xx.xxx   Type: Domain Password
     User: uk\xxxxxxx
     
     Target:  groupshare.xxx.xx.xxx   Type: Domain Password
     User: uk\xxxxxxx
     
     Target:  uknthdra001.uk.xxx.xx.com   Type: Domain Password
     User: uk\xxxxxxx
     
     Target:  dasst107638     Type: Domain Password
     User: uk\xxxxxxxxxx
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

  • Moderators

Try opening and reading the file in binary, then StringReplace the hex values for the non printable chars from the binary string.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Here:

$FILE = FileOpen("C:\cmdkey.txt",16)
$DATA = FileRead($FILE)
$DATA = StringReplace($DATA,"0D","20")
FileClose($FILE)
MsgBox(-1,"",BinaryToString($DATA))
LOL... Well... at least you put what I said into code, I haven't looked at the file, but I find it very hard to believe that a carriage return if making it impossible to read past the first line of the file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

LOL... Well... at least you put what I said into code, I haven't looked at the file, but I find it very hard to believe that a carriage return if making it impossible to read past the first line of the file.

Binary it`s only mode to read this file.

And yes Chr(13) is problem. muttley

When the words fail... music speaks.

Link to comment
Share on other sites

  • Moderators

Binary it`s only mode to read this file.

And yes Chr(13) is problem. muttley

Nah, you're wrong, there are several null characters in the file that prevent you from being able to read it properly.

All strings are terminated with a null character... so as soon as one is reached, the string ends.

Proof in the pudding:

Local $h_open = FileOpen("cmdkey.txt", 16)
Local $s_binary = FileRead($h_open)
FileClose($h_open)
Local $i
For $i = 1 To BinaryLen($s_binary)
    If Execute(BinaryMid($s_binary, $i, 1)) = 0 Then
        MsgBox(16, "Oops", "Character: " & $i & " is a NULL char.")
    EndIf
Next

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

Binary it`s only mode to read this file.

And yes Chr(13) is problem. :)

Don't think so. The file contains a NULL character which is the reason it doesn't work:

0D 0A 43 75 72 72 65 6E 74 6C 79 20 73 74 6F 72 65 64 20 63 72 65 64 65 6E 74 69 61 6C 73 3A 0D 0A 0D 0A 00 20 20 20 20 54 61 72 67 65 74 3A 20

So as Smoke_N suggested, read the file in Binary mode and get rid of the 00's.

Jos

EDIT: And confirmed just before me muttley

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Thanks for trying but the new example you supplied still doesn't work. I did have a go with binary, as mentioned in the original post, but I'm in over my head.

Here you go bud...
Local $hopen = FileOpen(@DesktopDir & "\cmdkey.txt", 16)
Local $s_binary = FileRead($hopen)
FileClose($hopen)
Local $i, $s_hold, $n_mid
For $i = 1 To BinaryLen($s_binary)
    $n_mid = Execute(BinaryMid($s_binary, $i, 1))
    If $n_mid <> 0 Then
        $s_hold &= Chr($n_mid)
    EndIf
Next
MsgBox(64, "New value", $s_hold)oÝ÷ ÛMú²%v¬Ê«ì/j[Â+a¢ëgºYªì:·¯z{'zȦ¦XçZºÚ"µÍØØ[  ÌÍÚÜ[H[SÜ[ÚÝÜ   [È ][ÝÉÌLØÛYÙ^K  ][ÝËMBØØ[   ÌÍÜ×Ø[HH[TXY
    ÌÍÚÜ[B[PÛÜÙJ ÌÍÚÜ[BÌÍÜ×ÚÛH[UÔÝ[ÊÝ[ÔYÑ^XÙJ   ÌÍÜ×Ø[K    ][ÝÊÌJJ
J][ÝË ][ÝÉÌLÌI][ÝÊJBÙÐÞ
    ][ÝÓ]È[YI][ÝË  ÌÍÜ×ÚÛ
I think the regular expression is good.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here you go bud...

Local $hopen = FileOpen(@DesktopDir & "\cmdkey.txt", 16)
Local $s_binary = FileRead($hopen)
FileClose($hopen)
Local $i, $s_hold, $n_mid
For $i = 1 To BinaryLen($s_binary)
    $n_mid = Execute(BinaryMid($s_binary, $i, 1))
    If $n_mid <> 0 Then
        $s_hold &= Chr($n_mid)
    EndIf
Next
MsgBox(64, "New value", $s_hold)oÝ÷ ÛMú²%v¬Ê«ì/j[Â+a¢ëgºYªì:·¯z{'zȦ¦XçZºÚ"µÍØØ[  ÌÍÚÜ[H[SÜ[ÚÝÜ   [È ][ÝÉÌLØÛYÙ^K  ][ÝËMBØØ[   ÌÍÜ×Ø[HH[TXY
    ÌÍÚÜ[B[PÛÜÙJ ÌÍÚÜ[BÌÍÜ×ÚÛH[UÔÝ[ÊÝ[ÔYÑ^XÙJ   ÌÍÜ×Ø[K    ][ÝÊÌJJ
J][ÝË ][ÝÉÌLÌI][ÝÊJBÙÐÞ

    ][ÝÓ]È[YI][ÝË  ÌÍÜ×ÚÛ
I think the regular expression is good.
What is char with problem? Your script work fine. muttley 0? Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Here you go bud...

Local $hopen = FileOpen(@DesktopDir & "\cmdkey.txt", 16)
Local $s_binary = FileRead($hopen)
FileClose($hopen)
Local $i, $s_hold, $n_mid
For $i = 1 To BinaryLen($s_binary)
    $n_mid = Execute(BinaryMid($s_binary, $i, 1))
    If $n_mid <> 0 Then
        $s_hold &= Chr($n_mid)
    EndIf
Next
MsgBox(64, "New value", $s_hold)
Great! Thanks very much for helping me out. Just before I came back to check for replies, I had discovered that replacing the "0D" in Andreik's script with "00" got me slightly further i.e. I got one more line on my output - wow(!) Now that I see your code, I think I understand. Replacing all occurances of '00' with '20' would produce yet more null characters where there weren't before! And if I'm understanding your code correctly, you're reading in the binary 2 chars at a time? Which means no overlapping '00's being detected and no new ones being created?

Thanks again.

Link to comment
Share on other sites

  • Moderators

What is char with problem? Your script work fine. muttley 0?

Great! Thanks very much for helping me out. Just before I came back to check for replies, I had discovered that replacing the "0D" in Andreik's script with "00" got me slightly further i.e. I got one more line on my output - wow(!) Now that I see your code, I think I understand. Replacing all occurances of '00' with '20' would produce yet more null characters where there weren't before! And if I'm understanding your code correctly, you're reading in the binary 2 chars at a time? Which means no overlapping '00's being detected and no new ones being created?

Thanks again.

For both of you:

Char zero is a "NULL" char. In a string, it represents the end of it. I could have 0x610061, which is "a" NULL "a" and all I'm going to get as an output is "a" because of the char zero.

If you take a look at the ascii table provided for you in the help file, you can see the ascii value, the decimal value, and the hex value for all 255 characters.

What I did was replace all the "00" with nothing, I just either skipped it in the first example, and only put printable characters in my variable loop, or in the 2nd example with the regular expression, I went 2 chars checked in front of those two chars to see if there was a null 00 value, if there was, I simply just removed it from the binary string (the hexed string).

The binary example isn't going two characters, look at mid, I'm going character by character 1 character at a time until I reach the value of zero which is of course the null character we want to avoid.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
 Share

  • Recently Browsing   0 members

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