-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlist_project_files.cpp
More file actions
58 lines (49 loc) · 1.51 KB
/
Copy pathlist_project_files.cpp
File metadata and controls
58 lines (49 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2024-2026 Elias Bachaalany
// SPDX-License-Identifier: MPL-2.0
//
// list_project_files: import one or more binaries into a Ghidra project,
// start a managed headless libghidra host, and list project contents.
//
// Usage:
// list_project_files <ghidra_dir> <project_dir> <project_name> <binary> [binary...]
#include <iostream>
#include <string>
#include "libghidra/ghidra.hpp"
int main(int argc, char* argv[]) {
if (argc < 5) {
std::cerr << "Usage: " << argv[0]
<< " <ghidra_dir> <project_dir> <project_name> <binary> [binary...]\n";
return 1;
}
ghidra::HeadlessOptions opts;
opts.ghidra_dir = argv[1];
opts.project_dir = argv[2];
opts.project_name = argv[3];
opts.binary = argv[4];
for (int i = 5; i < argc; ++i) {
opts.binaries.emplace_back(argv[i]);
}
opts.port = 0;
opts.shutdown = "save";
try {
auto host = ghidra::launch_headless(std::move(opts));
libghidra::client::ListProjectFilesRequest req;
req.include_folders = true;
auto listed = host->ListProjectFiles(req);
if (!listed.ok()) {
std::cerr << "ListProjectFiles failed: " << listed.status.message << "\n";
return 1;
}
for (const auto& file : listed.value->files) {
std::cout << (file.is_folder ? "folder " : "file ")
<< (file.is_program ? "program " : " ")
<< file.path << "\n";
}
host.close(true);
}
catch (const std::exception& e) {
std::cerr << e.what() << "\n";
return 1;
}
return 0;
}