#include #include #include #include void print_hex(const char *data, ssize_t len) { for (ssize_t i = 0; i < len; i++) { printf("%02X ", (unsigned char)data[i]); } printf("\n"); } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } const char *filename = argv[1]; ssize_t buffer_size = listxattr(filename, NULL, 0, XATTR_SHOWCOMPRESSION); if (buffer_size < 0) { perror("Failed to get size of xattr"); return 2; } if (buffer_size == 0) { printf("No extended attributes found.\n"); return 0; } char *buffer = malloc(buffer_size); if (buffer == NULL) { perror("Failed to allocate memory for xattr names"); return 3; } ssize_t ret = listxattr(filename, buffer, buffer_size, XATTR_SHOWCOMPRESSION); if (ret < 0) { perror("Failed to list xattrs"); free(buffer); return 4; } char *name = buffer; while (name < buffer + buffer_size) { ssize_t size = getxattr(filename, name, NULL, 0, 0, XATTR_SHOWCOMPRESSION); char *value = malloc(size + 1); if (value == NULL) { perror("Failed to allocate memory for xattr value"); continue; // Skip this attribute if allocation fails } if (getxattr(filename, name, value, size, 0, XATTR_SHOWCOMPRESSION) < 0) { perror("Failed to get xattr value"); } else { printf("Attribute: %s, Hex Value: ", name); print_hex(value, size); } free(value); name += strlen(name) + 1; } free(buffer); return 0; }