从LevelDB“ .ldb”文件中恢复数据

I'm trying to extract data from an .ldb file. The Chrome extension OneTab glitched on me and I'm trying to recover the links it had saved. I believe I've found a solution from an old blog post, but I don't know enough about coding to figure out how to follow along.

Here is the link to the blog post: https://antimatter15.com/2015/12/recovering-deleted-data-from-leveldb/

I believe I've done everything correctly to build the Go application as he suggests. It created a file named "ldbdump" without a file extension. The next step is where I have trouble. I tried to run his Python code within Jupyter Notebook (it's the only software I have experience with for Python, and limited experience at that) but would only get errors.

The original code I'm working from can be found at the above link under the "Recovery" heading. I changed the definition of "base" from "test-stuff copy" to point to a folder with both the .ldb files I'm trying to read as well as the "ldbdump" file. I also changed the syntax of the print command at the bottom after getting errors. Everything else was left alone.

base = "D:\\Downloads\\ldb archive"

import os
from subprocess import Popen, PIPE
import json
import ast

for f in os.listdir(base):
  if f.endswith(".ldb"):
    process = Popen(["ldbdump", os.path.join(base, f)], stdout=PIPE)
    (output, err) = process.communicate()
    exit_code = process.wait()
    for line in (output.split("
")[1:]):
      if line.strip() == "": continue
      parsed = ast.literal_eval("{" + line + "}")
      key = parsed.keys()[0]
      print(json.dumps({ "key": key.encode('string-escape'), "value": parsed[key] }))

If I understand the blog post correctly, this should print the contents of the .ldb file after converting its contents into a JSON file (though I'm not sure where that JSON file would be saved). After that, I can move on to the next step that would clean up the results to be more readable. Instead, I get an error. I can't tell what I'm doing wrong since I barely know what I'm doing in the first place. All I really understand is "file not found" at the top. It looks like this:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-26ff29e32d63> in <module>
      1 for f in os.listdir(base):
      2   if f.endswith(".ldb"):
----> 3     process = Popen(["ldbdump", os.path.join(base, f)], stdout=PIPE)
      4     (output, err) = process.communicate()
      5     exit_code = process.wait()

~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    767                                 c2pread, c2pwrite,
    768                                 errread, errwrite,
--> 769                                 restore_signals, start_new_session)
    770         except:
    771             # Cleanup if the child failed starting.

~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1170                                          env,
   1171                                          os.fspath(cwd) if cwd is not None else None,
-> 1172                                          startupinfo)
   1173             finally:
   1174                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

Like I said, I'm not sure what it is I'm doing wrong. My best guesses are that I'm either not modifying the blog post's code correctly to point it to the files on my PC or that the original code incorrectly assumes something about my machine (meaning I have the wrong OS, I shouldn't be running it in a notebook, I'm missing some dependencies, etc.)

For reference, I'm using a desktop PC running Windows 10, I'm trying to run this code with Jupyter Notebook 5.7.4, I don't have any other packages imported other than the ones listed in the section of code above, and I barely know what I'm doing. I'm sorry. Please help.

1个回答



在我的研究中,我添加了一些修复程序</ p>

  import os 
import子进程
import json
import ast
for os.listdir(base)中的f:
如果f.endswith(“。ldb”):
process = subprocess.Popen([“ ldbdump”,os.path.join(base,f )],stdout = subprocess.PIPE,shell = True)
(输出,错误)= process.communicate()
exit_code = process.wait()
输入(output.split(“
”) [1:]):
如果line.strip()==“”:继续
已解析= ast.literal_eval(“ {” + line +“}”)
键=已解析.keys()[0]

打印json.dumps({“ key”:key.encode('string-escape'),“ value”:parsed [key]})
</ code> </ pre>
</ div>

展开原文

原文

in my research i added some fixes

import os
import subprocess
import json
import ast
for f in os.listdir(base):
  if f.endswith(".ldb"):
    process = subprocess.Popen(["ldbdump", os.path.join(base, f)], stdout=subprocess.PIPE, shell = True)
    (output, err) = process.communicate()
    exit_code = process.wait()
    for line in (output.split("
")[1:]):
      if line.strip() == "": continue
      parsed = ast.literal_eval("{" + line + "}")
      key = parsed.keys()[0]
      print json.dumps({ "key": key.encode('string-escape'), "value": parsed[key] })

dongzhuonao8429
dongzhuonao8429 我清楚地指出了像subprocess.Popen和subprocess.PIPE这样的进程的库。 另外我在函数声明中添加了shell = True。 您可以在这里了解更多有关此的信息:stackoverflow.com/questions/43143743/…
大约一年之前 回复
douxian6694
douxian6694 您能否解释一下为解决该问题而实施的修复程序?
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐