long AxProcessOneTextLine ( FILE *OutputFile, char *ThisSignature, unsigned int ThisTableBytesWritten) { size_t BytesWritten; size_t BytesConverted; /* Check for the end of this table data block */ if (AxIsEmptyLine (Gbl_LineBuffer) || (Gbl_LineBuffer[0] != ' ')) { printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); return (0); } /* Convert one line of ascii hex data to binary */ BytesConverted = AxConvertLine (Gbl_LineBuffer, Gbl_BinaryData); /* Write the binary data */ BytesWritten = fwrite (Gbl_BinaryData, 1, BytesConverted, OutputFile); if (BytesWritten != BytesConverted) { printf ("Error while writing file %s\n", Gbl_OutputFilename); return (-1); } return (BytesWritten); }
int AxIsDataBlockHeader ( void) { /* Ignore lines that are too short to be header lines */ if (strlen (Gbl_LineBuffer) < AX_MIN_BLOCK_HEADER_LENGTH) { return (0); } /* Ignore empty lines and lines that start with a space */ if (AxIsEmptyLine (Gbl_LineBuffer) || (Gbl_LineBuffer[0] == ' ')) { return (0); } /* * Ignore lines that are not headers of the form <sig> @ <addr>. * Basically, just look for the '@' symbol, surrounded by spaces. * * Examples of headers that must be supported: * * DSDT @ 0x737e4000 * XSDT @ 0x737f2fff * RSD PTR @ 0xf6cd0 * SSDT @ (nil) */ if (!strstr (Gbl_LineBuffer, " @ ")) { return (0); } AxNormalizeSignature (Gbl_LineBuffer); return (1); }
static unsigned int AxCountTableInstances ( char *InputPathname, char *Signature) { FILE *InputFile; unsigned int Instances = 0; InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open file %s\n", InputPathname); return (0); } /* Count the number of instances of this signature */ while (fgets (InstanceBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { /* Ignore empty lines and lines that start with a space */ if (AxIsEmptyLine (InstanceBuffer) || (InstanceBuffer[0] == ' ')) { continue; } AxNormalizeSignature (InstanceBuffer); if (ACPI_COMPARE_NAME (InstanceBuffer, Signature)) { Instances++; } } fclose (InputFile); return (Instances); }
int AxListTables ( char *InputPathname) { FILE *InputFile; size_t HeaderSize; unsigned char Header[48]; int TableCount = 0; ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header; /* Open input in text mode, output is in binary mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open file %s\n", InputPathname); return (-1); } /* Dump the headers for all tables found in the input file */ printf ("\nSignature Length Revision OemId OemTableId" " OemRevision CompilerId CompilerRevision\n\n"); while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { /* Ignore empty lines and lines that start with a space */ if (AxIsEmptyLine (LineBuffer) || (LineBuffer[0] == ' ')) { continue; } /* Get the 36 byte header and display the fields */ HeaderSize = AxGetTableHeader (InputFile, Header); if (HeaderSize < 16) { continue; } /* RSDP has an oddball signature and header */ if (!strncmp (TableHeader->Signature, "RSD PTR ", 8)) { AxCheckAscii ((char *) &Header[9], 6); printf ("%7.4s \"%6.6s\"\n", "RSDP", &Header[9]); TableCount++; continue; } /* Minimum size for table with standard header */ if (HeaderSize < sizeof (ACPI_TABLE_HEADER)) { continue; } /* Signature and Table length */ TableCount++; printf ("%7.4s 0x%8.8X", TableHeader->Signature, TableHeader->Length); /* FACS has only signature and length */ if (ACPI_COMPARE_NAME (TableHeader->Signature, "FACS")) { printf ("\n"); continue; } /* OEM IDs and Compiler IDs */ AxCheckAscii (TableHeader->OemId, 6); AxCheckAscii (TableHeader->OemTableId, 8); AxCheckAscii (TableHeader->AslCompilerId, 4); printf (" 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X \"%4.4s\" 0x%8.8X\n", TableHeader->Revision, TableHeader->OemId, TableHeader->OemTableId, TableHeader->OemRevision, TableHeader->AslCompilerId, TableHeader->AslCompilerRevision); } printf ("\nFound %u ACPI tables\n", TableCount); fclose (InputFile); return (0); }
int AxExtractTables ( char *InputPathname, char *Signature, unsigned int MinimumInstances) { FILE *InputFile; FILE *OutputFile = NULL; size_t BytesWritten; size_t TotalBytesWritten = 0; size_t BytesConverted; unsigned int State = AX_STATE_FIND_HEADER; unsigned int FoundTable = 0; unsigned int Instances = 0; unsigned int ThisInstance; char ThisSignature[4]; int Status = 0; /* Open input in text mode, output is in binary mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open file %s\n", InputPathname); return (-1); } if (Signature) { /* Are there enough instances of the table to continue? */ AxNormalizeSignature (Signature); Instances = AxCountTableInstances (InputPathname, Signature); if (Instances < MinimumInstances) { printf ("Table %s was not found in %s\n", Signature, InputPathname); Status = -1; goto CleanupAndExit; } if (Instances == 0) { goto CleanupAndExit; } } /* Convert all instances of the table to binary */ while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { switch (State) { case AX_STATE_FIND_HEADER: /* Ignore lines that are too short to be header lines */ if (strlen (LineBuffer) < AX_MIN_TABLE_NAME_LENGTH) { continue; } /* Ignore empty lines and lines that start with a space */ if (AxIsEmptyLine (LineBuffer) || (LineBuffer[0] == ' ')) { continue; } /* * Ignore lines that are not of the form <sig> @ <addr>. * Examples of lines that must be supported: * * DSDT @ 0x737e4000 * XSDT @ 0x737f2fff * RSD PTR @ 0xf6cd0 * SSDT @ (nil) */ if (!strstr (LineBuffer, " @ ")) { continue; } AxNormalizeSignature (LineBuffer); ACPI_MOVE_NAME (ThisSignature, LineBuffer); if (Signature) { /* Ignore signatures that don't match */ if (!ACPI_COMPARE_NAME (ThisSignature, Signature)) { continue; } } /* * Get the instance number for this signature. Only the * SSDT and PSDT tables can have multiple instances. */ ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); /* Build an output filename and create/open the output file */ if (ThisInstance > 0) { sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance); } else { sprintf (Filename, "%4.4s.dat", ThisSignature); } AxStrlwr (Filename); OutputFile = fopen (Filename, "w+b"); if (!OutputFile) { printf ("Could not open file %s\n", Filename); Status = -1; goto CleanupAndExit; } State = AX_STATE_EXTRACT_DATA; TotalBytesWritten = 0; FoundTable = 1; continue; case AX_STATE_EXTRACT_DATA: /* Empty line or non-data line terminates the data */ if (AxIsEmptyLine (LineBuffer) || (LineBuffer[0] != ' ')) { fclose (OutputFile); OutputFile = NULL; State = AX_STATE_FIND_HEADER; printf ("Acpi table [%4.4s] - %u bytes written to %s\n", ThisSignature, (unsigned int) TotalBytesWritten, Filename); continue; } /* Convert the ascii data (one line of text) to binary */ BytesConverted = AxConvertLine (LineBuffer, Data); /* Write the binary data */ BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile); if (BytesWritten != BytesConverted) { printf ("Error when writing file %s\n", Filename); fclose (OutputFile); OutputFile = NULL; Status = -1; goto CleanupAndExit; } TotalBytesWritten += BytesConverted; continue; default: Status = -1; goto CleanupAndExit; } } if (!FoundTable) { printf ("Table %s was not found in %s\n", Signature, InputPathname); } CleanupAndExit: if (OutputFile) { fclose (OutputFile); if (State == AX_STATE_EXTRACT_DATA) { /* Received an EOF while extracting data */ printf ("Acpi table [%4.4s] - %u bytes written to %s\n", ThisSignature, (unsigned int) TotalBytesWritten, Filename); } } fclose (InputFile); return (Status); }