Skip to content

Commit 71f7235

Browse files
author
Alan Jowett
committed
PR feedback
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
1 parent 82d8538 commit 71f7235

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

libs/api/ebpf_api.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ _ebpf_pe_get_map_definitions(
26002600
// at other times, they are 16-byte-aligned. Skip over them looking for the
26012601
// map_entry_t which starts with an 8-byte-aligned NULL pointer where the previous
26022602
// byte (if any) is also 00, and the following 8 bytes are also NULL. The next 8 bytes
2603-
// are not not NULL though.
2603+
// are not NULL though.
26042604
uint32_t map_offset = 0;
26052605
uint64_t zero = 0;
26062606
while (map_offset + 24 < section_header.Misc.VirtualSize &&
@@ -5256,7 +5256,7 @@ ebpf_map_set_wait_handle(fd_t map_fd, uint64_t index, ebpf_handle_t handle) NO_E
52565256
}
52575257
CATCH_NO_MEMORY_EBPF_RESULT
52585258

5259-
// Context structure for section data extraction
5259+
// Context structure for section data extraction.
52605260
typedef struct _ebpf_section_data_context
52615261
{
52625262
const char* section_name;
@@ -5265,7 +5265,7 @@ typedef struct _ebpf_section_data_context
52655265
const uint8_t* section_data;
52665266
} ebpf_section_data_context_t;
52675267

5268-
// Callback function for PE section iteration
5268+
// Callback function for PE section iteration.
52695269
static int
52705270
_ebpf_pe_find_section(
52715271
_Inout_ void* context,
@@ -5283,9 +5283,9 @@ _ebpf_pe_find_section(
52835283
ctx->section_found = true;
52845284
ctx->section_size = buffer->bufLen;
52855285
ctx->section_data = buffer->buf;
5286-
return 1; // Stop iteration
5286+
return 1; // Stop iteration.
52875287
}
5288-
return 0; // Continue iteration
5288+
return 0; // Continue iteration.
52895289
}
52905290
CATCH_NO_MEMORY_INT(1)
52915291

@@ -5302,7 +5302,7 @@ ebpf_api_get_data_section(
53025302
EBPF_RETURN_RESULT(EBPF_INVALID_ARGUMENT);
53035303
}
53045304

5305-
// Determine file type by extension
5305+
// Determine file type by extension.
53065306
std::string path(file_path);
53075307
bool is_pe_file = false;
53085308
if (path.size() > 4) {
@@ -5316,14 +5316,14 @@ ebpf_api_get_data_section(
53165316
ebpf_result_t result = EBPF_SUCCESS;
53175317

53185318
if (is_pe_file) {
5319-
// Parse PE file using pe-parse library
5319+
// Parse PE file using pe-parse library.
53205320
std::scoped_lock pe_parse_lock(_pe_parse_mutex);
53215321
parsed_pe* pe = ParsePEFromFile(file_path);
53225322
if (pe == nullptr) {
53235323
EBPF_RETURN_RESULT(EBPF_INVALID_OBJECT);
53245324
}
53255325

5326-
// Set up context for section search
5326+
// Set up context for section search.
53275327
ebpf_section_data_context_t section_context = {
53285328
.section_name = section_name, .section_found = false, .section_size = 0, .section_data = nullptr};
53295329

@@ -5334,47 +5334,47 @@ ebpf_api_get_data_section(
53345334
EBPF_RETURN_RESULT(EBPF_OBJECT_NOT_FOUND);
53355335
}
53365336

5337-
// Check buffer size
5337+
// Check buffer size.
53385338
if (data == nullptr) {
5339-
// Just return the size
5339+
// Just return the size.
53405340
*data_size = section_context.section_size;
53415341
} else if (*data_size < section_context.section_size) {
5342-
// Buffer too small
5342+
// Buffer too small.
53435343
*data_size = section_context.section_size;
53445344
DestructParsedPE(pe);
53455345
EBPF_RETURN_RESULT(EBPF_INSUFFICIENT_BUFFER);
53465346
} else {
5347-
// Copy data to buffer
5347+
// Copy data to buffer.
53485348
memcpy(data, section_context.section_data, section_context.section_size);
53495349
*data_size = section_context.section_size;
53505350
}
53515351

53525352
DestructParsedPE(pe);
53535353
} else {
5354-
// Parse ELF file using ELFIO library
5354+
// Parse ELF file using ELFIO library.
53555355
ELFIO::elfio reader;
53565356
if (!reader.load(file_path)) {
53575357
EBPF_RETURN_RESULT(EBPF_INVALID_OBJECT);
53585358
}
53595359

5360-
// Find the section by name
5360+
// Find the section by name.
53615361
ELFIO::section* section = reader.sections[section_name];
53625362
if (section == nullptr || section->get_data() == nullptr) {
53635363
EBPF_RETURN_RESULT(EBPF_OBJECT_NOT_FOUND);
53645364
}
53655365

53665366
size_t section_size = section->get_size();
53675367

5368-
// Check buffer size
5368+
// Check buffer size.
53695369
if (data == nullptr) {
5370-
// Just return the size
5370+
// Just return the size.
53715371
*data_size = section_size;
53725372
} else if (*data_size < section_size) {
5373-
// Buffer too small
5373+
// Buffer too small.
53745374
*data_size = section_size;
53755375
EBPF_RETURN_RESULT(EBPF_INSUFFICIENT_BUFFER);
53765376
} else {
5377-
// Copy data to buffer
5377+
// Copy data to buffer.
53785378
memcpy(data, section->get_data(), section_size);
53795379
*data_size = section_size;
53805380
}

libs/ebpfnetsh/netsh_hash.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <string>
1313
#include <vector>
1414

15-
// The following function uses windows specific type as an input to match
16-
// definition of "FN_HANDLE_CMD" in public file of NetSh.h
15+
// The following function uses Windows-specific types as an input to match
16+
// definition of "FN_HANDLE_CMD" in public file of NetSh.h.
1717
unsigned long
1818
handle_ebpf_show_hash(
1919
IN LPCWSTR machine,
@@ -63,7 +63,7 @@ handle_ebpf_show_hash(
6363
return status;
6464
}
6565

66-
// First get the size of the hash section
66+
// First get the size of the hash section.
6767
size_t hash_size = 0;
6868
ebpf_result_t result = ebpf_api_get_data_section(filename.c_str(), "hash", nullptr, &hash_size);
6969

@@ -83,7 +83,7 @@ handle_ebpf_show_hash(
8383
return ERROR_SUPPRESS_OUTPUT;
8484
}
8585

86-
// Allocate buffer and get the hash data
86+
// Allocate buffer and get the hash data.
8787
std::vector<uint8_t> hash_data(hash_size);
8888
result = ebpf_api_get_data_section(filename.c_str(), "hash", hash_data.data(), &hash_size);
8989

@@ -92,28 +92,28 @@ handle_ebpf_show_hash(
9292
return ERROR_SUPPRESS_OUTPUT;
9393
}
9494

95-
// Truncate hash to size of a SHA-256 hash if larger
95+
// Truncate hash to size of a SHA-256 hash if larger.
9696
if (hash_size > 32) {
9797
hash_size = 32;
9898
}
9999

100-
// Resize vector to actual hash size
100+
// Resize vector to actual hash size.
101101
hash_data.resize(hash_size);
102102

103103
if (hash_only) {
104-
// Print hash in PowerShell Get-FileHash format (uppercase, no spaces)
104+
// Print hash in PowerShell Get-FileHash format (uppercase, no spaces).
105105
for (size_t i = 0; i < hash_size; i++) {
106106
std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0')
107107
<< static_cast<unsigned int>(hash_data[i]);
108108
}
109-
std::cout << std::dec << std::nouppercase << std::endl; // Reset formatting
109+
std::cout << std::dec << std::nouppercase << std::endl; // Reset formatting.
110110
} else {
111-
// Print detailed hash information
111+
// Print detailed hash information.
112112
std::cout << "Hash for " << filename << ":" << std::endl;
113113
std::cout << "Size: " << hash_size << " bytes" << std::endl;
114114
std::cout << "Data: ";
115115

116-
// Print hash in hexadecimal format with spaces
116+
// Print hash in hexadecimal format with spaces.
117117
for (size_t i = 0; i < hash_size; i++) {
118118
if (i > 0 && i % 16 == 0) {
119119
std::cout << std::endl << " ";
@@ -123,7 +123,7 @@ handle_ebpf_show_hash(
123123
std::cout << " ";
124124
}
125125
}
126-
std::cout << std::dec << std::endl; // Reset to decimal format
126+
std::cout << std::dec << std::endl; // Reset to decimal format.
127127
}
128128

129129
return NO_ERROR;

tests/end_to_end/end_to_end.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,66 +3578,66 @@ TEST_CASE("ebpf_api_get_data_section", "[end_to_end]")
35783578
_test_helper_end_to_end test_helper;
35793579
test_helper.initialize();
35803580

3581-
// Test with PE files that exists (from the build output)
3581+
// Test with PE files that exist (from the build output).
35823582
const char* pe_file_path = "map.sys";
35833583
std::vector<uint8_t> data;
35843584
size_t data_size = 0;
35853585
ebpf_result_t result;
35863586

3587-
// Test 1: Valid PE file with nonexistent section (should return EBF_SUCCESS with the size of > 0)
3587+
// Test 1: Valid PE file with existing section (should return EBPF_SUCCESS with the size > 0).
35883588
result = ebpf_api_get_data_section(pe_file_path, "hash", nullptr, &data_size);
35893589
REQUIRE(result == EBPF_SUCCESS);
35903590
REQUIRE(data_size > 0);
35913591

3592-
// Allocate buffer and get the data
3592+
// Allocate buffer and get the data.
35933593
data.resize(data_size);
35943594
size_t buffer_size = data_size;
35953595
result = ebpf_api_get_data_section(pe_file_path, "hash", data.data(), &buffer_size);
35963596
REQUIRE(result == EBPF_SUCCESS);
35973597
REQUIRE(buffer_size == data_size);
35983598

3599-
// Test 2: Invalid file path (should return EBPF_FILE_NOT_FOUND or EBPF_INVALID_OBJECT)
3599+
// Test 2: Invalid file path (should return EBPF_INVALID_OBJECT).
36003600
result = ebpf_api_get_data_section("nonexistent_file.sys", "hash", nullptr, &data_size);
36013601
REQUIRE(result == EBPF_INVALID_OBJECT);
36023602

3603-
// Test 3: Try another PE file with nonexistent section
3603+
// Test 3: Try another PE file with nonexistent section.
36043604
const char* pe_file_path2 = "ebpfcore.sys";
36053605
result = ebpf_api_get_data_section(pe_file_path2, "hash", nullptr, &data_size);
36063606
REQUIRE(result == EBPF_OBJECT_NOT_FOUND);
36073607

3608-
// Test 4: Valid ELF file with valid section
3608+
// Test 4: Valid ELF file with valid section.
36093609
const char* elf_file_path = "map.o";
36103610
result = ebpf_api_get_data_section(elf_file_path, "maps", nullptr, &data_size);
36113611
REQUIRE(result == EBPF_SUCCESS);
36123612

3613-
// Allocate buffer and get the data
3613+
// Allocate buffer and get the data.
36143614
data.resize(data_size);
36153615
buffer_size = data_size;
36163616
result = ebpf_api_get_data_section(elf_file_path, "maps", data.data(), &buffer_size);
36173617
REQUIRE(result == EBPF_SUCCESS);
36183618
REQUIRE(buffer_size == data_size);
36193619

3620-
// Test 5: Valid ELF file with nonexistent section
3620+
// Test 5: Valid ELF file with nonexistent section.
36213621
result = ebpf_api_get_data_section(elf_file_path, "nonexistent_section", nullptr, &data_size);
36223622
REQUIRE(result == EBPF_OBJECT_NOT_FOUND);
36233623

3624-
// Test 6: Invalid ELF file path
3624+
// Test 6: Invalid ELF file path.
36253625
result = ebpf_api_get_data_section("nonexistent_file.o", "maps", nullptr, &data_size);
36263626
REQUIRE(result == EBPF_INVALID_OBJECT);
36273627

3628-
// Test 7: Input buffer too small (ELF)
3628+
// Test 7: Input buffer too small (ELF).
36293629
result = ebpf_api_get_data_section(elf_file_path, "maps", nullptr, &data_size);
36303630
REQUIRE(result == EBPF_SUCCESS);
36313631

3632-
data.resize(data_size - 1); // Intentionally make buffer smaller
3632+
data.resize(data_size - 1); // Intentionally make buffer smaller.
36333633
buffer_size = data_size - 1;
36343634
result = ebpf_api_get_data_section(elf_file_path, "maps", data.data(), &buffer_size);
36353635
REQUIRE(result == EBPF_INSUFFICIENT_BUFFER);
36363636

3637-
// Test: 8 Input buffer too small (PE)
3637+
// Test 8: Input buffer too small (PE).
36383638
result = ebpf_api_get_data_section(pe_file_path, "hash", nullptr, &data_size);
36393639
REQUIRE(result == EBPF_SUCCESS);
3640-
data.resize(data_size - 1); // Intentionally make buffer smaller
3640+
data.resize(data_size - 1); // Intentionally make buffer smaller.
36413641
buffer_size = data_size - 1;
36423642
result = ebpf_api_get_data_section(pe_file_path, "hash", data.data(), &buffer_size);
36433643
REQUIRE(result == EBPF_INSUFFICIENT_BUFFER);

tests/end_to_end/netsh_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ _test_pin_unpin_map(ebpf_execution_type_t execution_type)
10351035

10361036
DECLARE_ALL_TEST_CASES("pin/unpin map", "[netsh][pin]", _test_pin_unpin_map);
10371037

1038-
// Test cases for show hash functionality
1038+
// Test cases for show hash functionality.
10391039
TEST_CASE("show hash nosuchfile.o", "[netsh][hash]")
10401040
{
10411041
_test_helper_netsh test_helper;
@@ -1064,7 +1064,7 @@ TEST_CASE("show hash PE file with hash section", "[netsh][hash]")
10641064
test_helper.initialize();
10651065

10661066
int result;
1067-
// Test with a PE file that has a hash section
1067+
// Test with a PE file that has a hash section.
10681068
std::string output = _run_netsh_command(handle_ebpf_show_hash, L"map_reuse_um.dll", nullptr, nullptr, &result);
10691069
REQUIRE(result == ERROR_SUCCESS);
10701070
REQUIRE(output.find("Hash for map_reuse_um.dll:") != std::string::npos);
@@ -1078,7 +1078,7 @@ TEST_CASE("show hash PE file without hash section", "[netsh][hash]")
10781078
test_helper.initialize();
10791079

10801080
int result;
1081-
// Test with a PE file that doesn't have a hash section
1081+
// Test with a PE file that doesn't have a hash section.
10821082
std::string output = _run_netsh_command(handle_ebpf_show_hash, L"EbpfApi.dll", nullptr, nullptr, &result);
10831083
REQUIRE(result == ERROR_SUPPRESS_OUTPUT);
10841084
REQUIRE(output == "No hash section found in EbpfApi.dll\n");
@@ -1090,20 +1090,20 @@ TEST_CASE("show hash PE file with hash section hashonly", "[netsh][hash]")
10901090
test_helper.initialize();
10911091

10921092
int result;
1093-
// Test with a PE file that has a hash section, hashonly format
1093+
// Test with a PE file that has a hash section, hashonly format.
10941094
std::string output = _run_netsh_command(handle_ebpf_show_hash, L"map_reuse_um.dll", L"hashonly", nullptr, &result);
10951095
REQUIRE(result == ERROR_SUCCESS);
10961096

1097-
// Verify output is exactly 64 hex characters (32 bytes) + newline, all uppercase, no spaces
1097+
// Verify output is exactly 64 hex characters (32 bytes) + newline, all uppercase, no spaces.
10981098
REQUIRE(output.length() == 65); // 64 characters + newline
10991099
REQUIRE(output[64] == '\n');
11001100

1101-
// Check that all characters are uppercase hex
1101+
// Check that all characters are uppercase hex.
11021102
for (int i = 0; i < 64; i++) {
11031103
REQUIRE(((output[i] >= '0' && output[i] <= '9') || (output[i] >= 'A' && output[i] <= 'F')));
11041104
}
11051105

1106-
// Verify no spaces in the hash
1106+
// Verify no spaces in the hash.
11071107
REQUIRE(output.find(' ') == std::string::npos);
11081108
}
11091109

@@ -1113,7 +1113,7 @@ TEST_CASE("show hash PE file without hash section hashonly", "[netsh][hash]")
11131113
test_helper.initialize();
11141114

11151115
int result;
1116-
// Test with a PE file that doesn't have a hash section, hashonly format
1116+
// Test with a PE file that doesn't have a hash section, hashonly format.
11171117
std::string output = _run_netsh_command(handle_ebpf_show_hash, L"EbpfApi.dll", L"hashonly", nullptr, &result);
11181118
REQUIRE(result == ERROR_SUPPRESS_OUTPUT);
11191119
REQUIRE(output == "No hash section found in EbpfApi.dll\n");

0 commit comments

Comments
 (0)