ASN.1 Decoder UNIX Code

Kindly help i need to write a code for Decode/Compile the ASN.1 which is found in javascript or C language if any got a final working Code:D

A quick Internet search will point you to the source code for many ASN.1 tools. Is there any reason that you cannot use an existing compiler or decompiler whose source code is publicly available?

Here is a pointer to ASN1 code I use on a regular basis: UEFI-Utilities/listcerts at master · fpmurphy/UEFI-Utilities · GitHub

1 Like

Kindly find me another code as this one doesnt work :frowning:

What do you mean it does not work?

It requires the Grammer file = asn schema
hdr file = input file binary coded
what about the c file the third input in the script

---------- Post updated at 06:57 AM ---------- Previous update was at 05:28 AM ----------

which one i compile , ill use gcc -o for which C file then it reply with efi.h not found + i cant make it work or see output file KINDLY HELP

You obviously need to modify the C code to suit YOUR particular purposes. That is something I am not going to do for you.

efi.h is not required unless you are compiling for (U)EFI firmware.

my case i got a schema and a binary file , i need to decode it (thats simply)

sorry for asking alot :smiley: . so i need the decoder , while i gcc for the decoder it got error related to the efi.h , kindly help

Sorry but I am not going to do all your work for you. As I said to you before you need to remove or replace the EFI related code. That is something you are expected to be capable of doing. If you do not wish to do that, simply find other source code for an ASN.1 decoder. A simple Internet search will return many sources of ASN.1 decoder source code.

seem you don't know how to use it and you cant know how to reply me ,, i got a schema and binary file
my target is to decode this binary file with the given schema , how would i use this thing
by gcc -o any xxx.c getting errors including header after including header in compiling it get errors related to the code , what part to change or what i can do i dont any and you just say i wont do yr work , any tool got steps or any details how to use it the only file can be compiled its the x509.asn , what can i do with it nothing

Thread moved to programming... has nothing to do with shell scripting stuff...

ok , shall any one reply me how to use it

Given your apparent difficulties following my GNU_EFI ASN.1 X.509 parser code, here is an example of another way to parse X509 .pem files using the OpenSSL development library.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>


int 
main(int argc, char *argv[])
{
    FILE *fp = NULL;
    char *filename;
    struct stat fstat;

    if (argc != 2) {
        fprintf(stdout, "ERROR - No filename provided\n");
        exit(1);
    }

    filename = argv[1];

    if ((stat(filename, &fstat) != 0) || (fp = fopen(filename, "r")) == NULL) {
        fprintf(stdout, "ERROR - File could not be opened\n");
        exit(1);
    }

    // parse certificate
    X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
    if (!cert) {
        fprintf(stderr, "ERROR - Unable to parse certificate\n");
        fclose(fp);
        exit(1);
    }
    
    // version number
    int version = ((int) X509_get_version(cert)) + 1;
    printf("Version: %d\n", version);

    // serial number
    ASN1_INTEGER *serial = X509_get_serialNumber(cert);
    
    BIGNUM *bn = ASN1_INTEGER_to_BN(serial, NULL);
    if (!bn) {
        fprintf(stderr, "ERROR - Unable to convert ASN1INTEGER to BN\n");
        exit(1);
    }
    
    char *tmp = BN_bn2dec(bn);
    if (!tmp) {
        fprintf(stderr, "ERROR - Unable to convert BN to decimal string\n");
        BN_free(bn);
        exit(1);
    }
    
    printf("Serial Number: %s\n", tmp);

    BN_free(bn);
    OPENSSL_free(tmp);

    // subject
    tmp = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
    printf("Subject: %s\n", tmp);
    OPENSSL_free(tmp);

    // issuer
    tmp = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
    printf("Issuer: %s\n", tmp);
    OPENSSL_free(tmp);

    // signature algorithm
    int pkey_nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
    if (pkey_nid == NID_undef) {
        fprintf(stderr, "ERROR - Signature algorithm name\n");
        exit(1);
    }

    const char* buf  = OBJ_nid2ln(pkey_nid);
    printf("Algorithm: %s\n", buf);

    X509_free(cert);
    fclose(fp);
}
1 Like

thanks alot , but if this code is in a file named code.c , how will i use it
i got a schema and binary.air file
shall i gcc -o code.sh code.c
then code.sh binary schema > output

kindly tell me if you dont understand what i want

I have no idea what you want as you never bothered to explain it to us in detail. It seems that you now wish to decode an Abobe AIR binary using an ASN.1 schema. Is this correct?

Vague query:

Just having a schema is not sufficient to decode a binary file. That is only the start of the required work. That is just a blueprint for the layout of the various elements that make up the binary file.

You need to provide specific information on what you want if you want specific answers. Vague information leads to vague answers. What schema? What type of binary file? What language do you wish to code in?

I wanna the code on command line unix any (perl - c - shell script )
I got binary files from charging system .air and got its schema , but I can't decode it , kindly reply fast I'm online
Help me plz

what is a "system .air"?

Kindly it's like any binary encoded files x.dat so kindly proceed