-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlist_project_files.cpp
More file actions
67 lines (57 loc) · 1.85 KB
/
Copy pathlist_project_files.cpp
File metadata and controls
67 lines (57 loc) · 1.85 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
59
60
61
62
63
64
65
66
67
// Copyright (c) 2024-2026 Elias Bachaalany
// SPDX-License-Identifier: LicenseRef-Human-Origin-Source-1.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::HeadlessProjectOptions opts;
opts.ghidra_dir = argv[1];
opts.project_dir = argv[2];
opts.project_name = argv[3];
opts.port = 0;
opts.shutdown = "save";
try {
auto host = ghidra::launch_headless_project(std::move(opts));
for (int i = 4; i < argc; ++i) {
ghidra::ImportProgramRequest import;
import.source_path = argv[i];
import.overwrite = true;
import.analyze = false;
auto imported = host->ImportProgram(import);
if (!imported.ok()) {
std::cerr << "ImportProgram failed for " << argv[i] << ": "
<< imported.status.message << "\n";
return 1;
}
}
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;
}