python 求组如何倒着读取window的系统日志,evtx文件?

新手上路,请多包涵

python读取window的日志文件(.evtx)的时候,如果是正常读会读到很久之前的日志。从第一行日志往后读的话会浪费很多时间因为用最近几天的日志,想问问各位大佬如何倒着读这个文档!

阅读 3.1k
1 个回答

示例文件 go.mod:

module daily/gui

go 1.20

require (
    github.com/ncruces/zenity v0.10.10
    gocv.io/x/gocv v0.33.0
)

require (
    github.com/akavel/rsrc v0.10.2 // indirect
    github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect
    github.com/josephspurrier/goversioninfo v1.4.0 // indirect
    github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
    github.com/stretchr/testify v1.8.0 // indirect
    golang.org/x/image v0.12.0 // indirect
    golang.org/x/sys v0.12.0 // indirect
)

示例代码:

import os


def readlines_reverse(filename):
    with open(filename, "r", encoding="utf-8") as f:
        f.seek(0, os.SEEK_END)  # move to end of file

        position = f.tell()
        line = ""

        while position >= 0:
            f.seek(position)  # move back one character
            next_char = f.read(1)
            if next_char == "\n":
                yield line[::-1]
                line = ""
            else:
                line += next_char

            position -= 1

        yield line[::-1]


if __name__ == "__main__":
    for line in readlines_reverse("./go.mod"):
        print(line)

结果:

)
        golang.org/x/sys v0.12.0 // indirect
        golang.org/x/image v0.12.0 // indirect
        github.com/stretchr/testify v1.8.0 // indirect
        github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
        github.com/josephspurrier/goversioninfo v1.4.0 // indirect
        github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect
        github.com/akavel/rsrc v0.10.2 // indirect
require (

)
        gocv.io/x/gocv v0.33.0
        github.com/ncruces/zenity v0.10.10
require (

go 1.20

module daily/gui
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏