⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acpixtract.c

📁 acpi tools for linux include acpiexec and acpixtract
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        /* Ignore empty lines and lines that start with a space */        if ((Buffer[0] == ' ') ||            (Buffer[0] == '\n'))        {            continue;        }        NormalizeSignature (Buffer);        if (!strncmp (Buffer, Signature, 4))        {            Instances++;        }    }    fclose (InputFile);    return Instances;}/****************************************************************************** * * FUNCTION:    GetNextInstance * * DESCRIPTION: * ******************************************************************************/unsigned intGetNextInstance (    char                    *InputPathname,    char                    *Signature){    struct TableInfo        *Info;    Info = ListHead;    while (Info)    {        if (*(unsigned int *) Signature == Info->Signature)        {            break;        }        Info = Info->Next;    }    if (!Info)    {        Info = malloc (sizeof (struct TableInfo));        Info->Signature = *(unsigned int *) Signature;        Info->Instances = CountTableInstances (InputPathname, Signature);        Info->NextInstance = 1;        Info->Next = ListHead;        ListHead = Info;    }    if (Info->Instances > 1)    {        return (Info->NextInstance++);    }    return (0);}/****************************************************************************** * * FUNCTION:    ExtractTables * * DESCRIPTION: Convert text ACPI tables to binary * ******************************************************************************/intExtractTables (    char                    *InputPathname,    char                    *Signature,    unsigned int            MinimumInstances){    char                    Buffer[BUFFER_SIZE];    FILE                    *InputFile;    FILE                    *OutputFile = NULL;    size_t                  BytesWritten;    size_t                  TotalBytesWritten = 0;    size_t                  BytesConverted;    unsigned int            State = FIND_HEADER;    unsigned int            FoundTable = 0;    unsigned int            Instances = 0;    unsigned int            ThisInstance;    char                    ThisSignature[4];    /* Open input in text mode, output is in binary mode */    InputFile = fopen (InputPathname, "rt");    if (!InputFile)    {        printf ("Could not open %s\n", InputPathname);        return -1;    }    if (Signature)    {        /* Are there enough instances of the table to continue? */        NormalizeSignature (Signature);        Instances = CountTableInstances (InputPathname, Signature);        if (Instances < MinimumInstances)        {            printf ("Table %s was not found in %s\n", Signature, InputPathname);            return -1;        }        if (Instances == 0)        {            return 0;        }    }    /* Convert all instances of the table to binary */    while (fgets (Buffer, BUFFER_SIZE, InputFile))    {        switch (State)        {        case FIND_HEADER:            /* Ignore empty lines and lines that start with a space */            if ((Buffer[0] == ' ') ||                (Buffer[0] == '\n'))            {                continue;            }            NormalizeSignature (Buffer);            strncpy (ThisSignature, Buffer, 4);            if (Signature)            {                /* Ignore signatures that don't match */                if (strncmp (ThisSignature, Signature, 4))                {                    continue;                }            }            /* Get the instance # for this signature */            ThisInstance = GetNextInstance (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);            }            OutputFile = fopen (Filename, "w+b");            if (!OutputFile)            {                printf ("Could not open %s\n", Filename);                return -1;            }            State = EXTRACT_DATA;            TotalBytesWritten = 0;            FoundTable = 1;            continue;        case EXTRACT_DATA:            /* Empty line or non-data line terminates the data */            if ((Buffer[0] == '\n') ||                (Buffer[0] != ' '))            {                fclose (OutputFile);                OutputFile = NULL;                State = FIND_HEADER;                printf ("Acpi table [%4.4s] - % 6d bytes written to %s\n",                    ThisSignature, TotalBytesWritten, Filename);                continue;            }            /* Convert the ascii data (one line of text) to binary */            BytesConverted = ConvertLine (Buffer, Data);            /* Write the binary data */            BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile);            if (BytesWritten != BytesConverted)            {                printf ("Write error on %s\n", Filename);                fclose (OutputFile);                return -1;            }            TotalBytesWritten += BytesConverted;            continue;        default:            return -1;        }    }    if (!FoundTable)    {        printf ("Table %s was not found in %s\n", Signature, InputPathname);    }    if (OutputFile)    {        fclose (OutputFile);    }    fclose (InputFile);    return 0;}/****************************************************************************** * * FUNCTION:    ListTables * * DESCRIPTION: Display info for all ACPI tables found in input * ******************************************************************************/intListTables (    char                    *InputPathname){    FILE                    *InputFile;    char                    Buffer[BUFFER_SIZE];    size_t                  HeaderSize;    unsigned char           Header[48];    int                     TableCount = 0;    /* Open input in text mode, output is in binary mode */    InputFile = fopen (InputPathname, "rt");    if (!InputFile)    {        printf ("Could not open %s\n", InputPathname);        return -1;    }    printf ("\nSignature Length  OemId     OemTableId   OemRevision CompilerId CompilerRevision\n\n");    while (fgets (Buffer, BUFFER_SIZE, InputFile))    {        /* Ignore empty lines and lines that start with a space */        if ((Buffer[0] == ' ') ||            (Buffer[0] == '\n'))        {            continue;        }        /* Get the 36 byte header and display the fields */        HeaderSize = GetTableHeader (InputFile, Header);        if (HeaderSize < 16)        {            continue;        }        /* RSDP has an oddball signature and header */        if (!strncmp ((char *) Header, "RSD PTR ", 8))        {            CheckAscii (&Header[9], 6);            printf ("%8.4s          \"%6.6s\"\n", "RSDP", &Header[9]);            TableCount++;            continue;        }        /* Minimum size */        if (HeaderSize < 36)        {            continue;        }        /* Signature and Table length */        TableCount++;        printf ("%8.4s % 7d", Header, *(int *) &Header[4]);        /* FACS has only signature and length */        if (!strncmp ((char *) Header, "FACS", 4))        {            printf ("\n");            continue;        }        /* OEM IDs and Compiler IDs */        CheckAscii (&Header[10], 6);        CheckAscii (&Header[16], 8);        CheckAscii (&Header[28], 4);        printf ("  \"%6.6s\"  \"%8.8s\"    %8.8X    \"%4.4s\"     %8.8X\n",            &Header[10], &Header[16], *(int *) &Header[24],            &Header[28], *(int *) &Header[32]);    }    printf ("\nFound %d ACPI tables [%8.8X]\n", TableCount, VERSION);    fclose (InputFile);    return 0;}/****************************************************************************** * * FUNCTION:    main * * DESCRIPTION: C main function * ******************************************************************************/intmain (    int                     argc,    char                    *argv[]){    int                     Status;    if (argc < 2)    {        DisplayUsage ();        return 0;    }    if (argv[1][0] == '-')    {        if (argc < 3)        {            DisplayUsage ();            return 0;        }        switch (argv[1][1])        {        case 'a':            return (ExtractTables (argv[2], NULL, 0));        case 'l':            return (ListTables (argv[2]));        case 's':            return (ExtractTables (argv[2], &argv[1][2], 1));        default:            DisplayUsage ();            return 0;        }    }    /*     * Default output is the DSDT and all SSDTs. One DSDT is required,     * any SSDTs are optional.     */    Status = ExtractTables (argv[1], "DSDT", 1);    if (Status)    {        return Status;    }    Status = ExtractTables (argv[1], "SSDT", 0);    return (Status);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -