如何在python中正确打印包含换行符的文件

时间:2018-10-11 16:52:32

标签: python file printing newline

我有一个以下格式的文件:

rule WannaCry_2 {\ n meta: \ n description = \ "file WannaCry-2.exe \" \ n author = \ "Autogen script \" \ n reference = \ "www.example.com \" \ n date = \ " 2018-10-11 \ "\ n hash1 = \" 9ee6b2a5535bbf60f4a3bc9405185f8bb80dc0f9ce2edfb5b061113caf5f0a21 \ "\ n strings: \ n $ s1 = \" & Microsoft Enhanced RSA and AES Cryptographic Provider \ "fullword ascii \ n $ s2 = \":% i: vnQ \ "fullword ascii \ n $ s3 = \" # gZ.) \ "fullword ascii \ n $ s4 = \" PPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDIN \ "ascii \ n $ s5 = \" m.wry {\ "fullword ascii \ n $ s6 = \ "c.wry! \" fullword ascii \ n $ s7 = \ "WANNACRY \" fullword ascii \ n \ n $ op0 = {83 c4 30 85 c0 74 68 8b 06 8b 40 34 2b 47 34 74} \ n $ op1 = {89 b5 70 ff ff ff 89 7d 8c 2b c1 89 55 ec 03 c7} \ n $ op2 = {c7 47 18 34 f4 40 00 89 46 20 8b 45 0c 6a fd 89} \ n condition: uint16 (0) == 0x5a4d and \ n filesize <700KB and \ n pe. imphash () == \ "e858a14f217810d78466806d95d7fceb \" and \ n (all of them) and all of ($ op *) \ n) or (all of them) \ n} \ n \ n

但是当尝试通过Python打印时,它返回的方式相同:

t = open ('out.txt', 'r')
print t.read ()

如果将变量放在字符串中,则打印正确:

t = WannaCry_2 {\ n description = \ "file WannaCry-2.exe \" \ n author = \ "Autogen script \" \ n reference = \ "www.example.com \" \ n date \ N $ s1 = \ "& Microsoft Enhanced RSA and AES Cryptographic Provider \" fullword ascii \ n $ s2 = \ ":% \ n \ i: VNQ \ "fullword ASCII \ $ n s3 = \" # GZ) \ "fullword ASCII \ n $ S4 = \" PPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDIN \ "ASCII \ n $ s5 = \" m.wry {\ "fullword ASCII \ n. $ s6 = \ "c.wry! \" fullword ascii \ n $ s7 = \ "WANNACRY \" fullword ascii \ n \ n $ op0 = {83 c4 30 85 c0 74 68 8b 06 8b 40 34 2b 47 34 74} \ n $ op1 = {89 b5 70 ff ff ff 89 7d 8c 2b c1 89 55 ec 03 c7} \ n $ op2 = {c7 47 18 34 f4 40 00 89 46 20 8b 45 0c 6a fd 89} \ n condition: \ n (uint16 (0) == 0x5a4d and \ n filesize <700KB and \ n \ n \ n (all of them) and all of ($ op *) \ n) or (all of them) \ n} \ n \ n
"
print t

结果(预期结果打印文件)

rule WannaCry_2 {
   goal:
      description = "file WannaCry-2.exe"
      author = "Autogen script"
      reference = "www.example.com"
      date = "2018-10-11"
      hash1 = "9ee6b2a5535bbf60f4a3bc9405185f8bb80dc0f9ce2edfb5b061113caf5f0a21"
   strings:
      $ s1 = "Microsoft Enhanced RSA and AES Cryptographic Provider" fullword ascii
      $ s2 = ":% i: vnQ" fullword ascii
      $ s3 = "# gZ.)" fullword ascii
      $ s4 = "PPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDIN" ascii
      $ s5 = "m.wry {" fullword ascii
      $ s6 = "c.wry!" fullword ascii
      $ s7 = "WANNACRY" fullword ascii

      $ op0 = {83 c4 30 85 c0 74 68 8b 06 8b 40 34 2b 47 34 74}
      $ op1 = {89 b5 70 ff ff ff 89 7d 8c 2b c1 89 55 ec 03 c7}
      $ op2 = {c7 47 18 34 f4 40 00 89 46 20 8b 45 0c 6a fd 89}
   condition:
      (uint16 (0) == 0x5a4d and
        filesize <700KB and
        pe.imphash () == "e858a14f217810d78466806d95d7fceb" and
        (all of them) and all of ($ op *)
      ) or (all of them)
}

0 个答案:

没有答案