Author Topic: h2incX vs translatorus headinc - WinCrypt.h  (Read 277 times)

LiaoMi

  • Member
  • ****
  • Posts: 872
h2incX vs translatorus headinc - WinCrypt.h
« on: May 23, 2021, 07:27:08 PM »
Hi Biterider, TouEnMasm, Nidud, Rsala  :biggrin:

why are the structures so different? And the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB in both converters??

@Biterider h2incX doesn't handle multilevel arrays?

h2incX
Code: [Select]
  EncryptionState BYTE 16 dup (?)
  DecryptionState BYTE 16 dup (?)
vs
headinc
Code: [Select]
EncryptionState BYTE 15 dup (16 dup (?)) ; 14 rounds + 1
DecryptionState BYTE 15 dup (16 dup (?))
vs
asmc
Code: [Select]
EncryptionState db 16*15 dup(?)
DecryptionState db 16*15 dup(?)
vs
EasyCode
Code: [Select]
    EncryptionState DB 240 DUP(?)
    DecryptionState DB 240 DUP(?)

@Biterider is the size of this structure correct?
Code: [Select]
CRYPT_INTEGER_BLOB struct
  cbData DWORD ?
  __field_bcount typedef proto stdcall :cbData
  pbData POINTER ?
CRYPT_INTEGER_BLOB ends

@TouEnMasm __field_bcount(cbData)pbData XMASM ? - Parentheses in the text can create a compilation error or I'm wrong?


@Nidud What converter are you using? Your results are completely different!  :rolleyes:

@Rsala Same question, what converter are you using?  :biggrin:


@to All

Orig -    __field_bcount(cbData)  BYTE    *pbData;
AsmC -  pbData LPBYTE ?
h2incX - __field_bcount typedef proto stdcall :cbData
  pbData POINTER ?
Headinc - __field_bcount(cbData)pbData XMASM ?
EasyCode - pbData XPTR ?

Original header: struct _CRYPT_AES_128_KEY_STATE, struct _CRYPT_AES_256_KEY_STATE, struct _CRYPTOAPI_BLOB
Code: [Select]
typedef struct _CRYPT_AES_128_KEY_STATE {
    unsigned char Key[16];
    unsigned char IV[16];
    unsigned char EncryptionState[11][16];      // 10 rounds + 1
    unsigned char DecryptionState[11][16];
    unsigned char Feedback[16];
} CRYPT_AES_128_KEY_STATE, *PCRYPT_AES_128_KEY_STATE;

typedef struct _CRYPT_AES_256_KEY_STATE {
    unsigned char Key[32];
    unsigned char IV[16];
    unsigned char EncryptionState[15][16];      // 14 rounds + 1
    unsigned char DecryptionState[15][16];
    unsigned char Feedback[16];
} CRYPT_AES_256_KEY_STATE, *PCRYPT_AES_256_KEY_STATE;

//+-------------------------------------------------------------------------
//  CRYPTOAPI BLOB definitions
//--------------------------------------------------------------------------
// certenrolls_begin -- *_BLOB

typedef struct _CRYPTOAPI_BLOB {
                            DWORD   cbData;
    __field_bcount(cbData)  BYTE    *pbData;
} CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
CERT_NAME_BLOB, *PCERT_NAME_BLOB,
CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
CERT_BLOB, *PCERT_BLOB,
CRL_BLOB, *PCRL_BLOB,
DATA_BLOB, *PDATA_BLOB,
CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;

h2incX the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB
Code: [Select]
CRYPT_AES_128_KEY_STATE struct
  Key BYTE 16 dup (?)
  IV BYTE 16 dup (?)
  EncryptionState BYTE 16 dup (?)
  DecryptionState BYTE 16 dup (?)
  Feedback BYTE 16 dup (?)
CRYPT_AES_128_KEY_STATE ends

PCRYPT_AES_128_KEY_STATE typedef ptr CRYPT_AES_128_KEY_STATE

CRYPT_AES_256_KEY_STATE struct
  Key BYTE 32 dup (?)
  IV BYTE 16 dup (?)
  EncryptionState BYTE 16 dup (?)
  DecryptionState BYTE 16 dup (?)
  Feedback BYTE 16 dup (?)
CRYPT_AES_256_KEY_STATE ends

PCRYPT_AES_256_KEY_STATE typedef ptr CRYPT_AES_256_KEY_STATE

CRYPT_INTEGER_BLOB struct
  cbData DWORD ?
  __field_bcount typedef proto stdcall :cbData
  pbData POINTER ?
CRYPT_INTEGER_BLOB ends

PCRYPT_INTEGER_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_UINT_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_UINT_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_OBJID_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_OBJID_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_NAME_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_NAME_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_RDN_VALUE_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_RDN_VALUE_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRL_BLOB typedef CRYPT_INTEGER_BLOB
PCRL_BLOB typedef ptr CRYPT_INTEGER_BLOB
DATA_BLOB typedef CRYPT_INTEGER_BLOB
PDATA_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DATA_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DATA_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_HASH_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_HASH_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DIGEST_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DIGEST_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DER_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DER_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_ATTR_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_ATTR_BLOB typedef ptr CRYPT_INTEGER_BLOB


;Errors: 0

translatorus headinc the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB
Code: [Select]
CRYPT_AES_128_KEY_STATE STRUCT DEFALIGNMASM
Key BYTE 16 dup (?)
IV BYTE 16 dup (?)
EncryptionState BYTE 11 dup (16 dup (?)) ; 10 rounds + 1
DecryptionState BYTE 11 dup (16 dup (?))
Feedback BYTE 16 dup (?)
CRYPT_AES_128_KEY_STATE ENDS



CRYPT_AES_256_KEY_STATE STRUCT DEFALIGNMASM
Key BYTE 32 dup (?)
IV BYTE 16 dup (?)
EncryptionState BYTE 15 dup (16 dup (?)) ; 14 rounds + 1
DecryptionState BYTE 15 dup (16 dup (?))
Feedback BYTE 16 dup (?)
CRYPT_AES_256_KEY_STATE ENDS


CRYPT_INTEGER_BLOB STRUCT DEFALIGNMASM
cbData DWORD ?
__field_bcount(cbData)pbData XMASM ?
CRYPT_INTEGER_BLOB ENDS


CRYPT_UINT_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_OBJID_BLOB EQU <CRYPT_INTEGER_BLOB>

CERT_NAME_BLOB EQU <CRYPT_INTEGER_BLOB>

CERT_RDN_VALUE_BLOB EQU <CRYPT_INTEGER_BLOB>

CERT_BLOB EQU <CRYPT_INTEGER_BLOB>

CRL_BLOB EQU <CRYPT_INTEGER_BLOB>

DATA_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_DATA_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_HASH_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_DIGEST_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_DER_BLOB EQU <CRYPT_INTEGER_BLOB>

CRYPT_ATTR_BLOB EQU <CRYPT_INTEGER_BLOB>


EasyCode the correct conversion looks like
Code: [Select]
CRYPT_AES_128_KEY_STATE STRUCT ALIGNMODE
    Key             DB 16 DUP(?)
    IV              DB 16 DUP(?)
    EncryptionState DB 176 DUP(?)
    DecryptionState DB 176 DUP(?)
    Feedback        DB 16 DUP(?)
CRYPT_AES_128_KEY_STATE ENDS

CRYPT_AES_256_KEY_STATE STRUCT ALIGNMODE
    Key             DB 32 DUP(?)
    IV              DB 16 DUP(?)
    EncryptionState DB 240 DUP(?)
    DecryptionState DB 240 DUP(?)
    Feedback        DB 16 DUP(?)
CRYPT_AES_256_KEY_STATE ENDS

CRYPTOAPI_BLOB STRUCT ALIGNMODE
    cbData DD   ?
    pbData XPTR ?
CRYPTOAPI_BLOB ENDS

CRYPT_BIT_BLOB STRUCT ALIGNMODE
    cbData      DD   ?
    pbData      XPTR ?
    cUnusedBits DD   ?
CRYPT_BIT_BLOB ENDS

CRYPT_INTEGER_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_UINT_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_OBJID_BLOB EQU <CRYPTOAPI_BLOB>
CERT_NAME_BLOB EQU <CRYPTOAPI_BLOB>
CERT_RDN_VALUE_BLOB EQU <CRYPTOAPI_BLOB>
CERT_BLOB EQU <CRYPTOAPI_BLOB>
CRL_BLOB EQU <CRYPTOAPI_BLOB>
DATA_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_DATA_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_HASH_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_DIGEST_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_DER_BLOB EQU <CRYPTOAPI_BLOB>
CRYPT_ATTR_BLOB EQU <CRYPTOAPI_BLOB>

asmc the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB, there are no other errors, pbData LPBYTE ? - What size LPBYTE has?
Code: [Select]
CRYPT_AES_128_KEY_STATE STRUC
Key db 16 dup(?)
IV db 16 dup(?)
EncryptionState db 16*11 dup(?)
DecryptionState db 16*11 dup(?)
Feedback db 16 dup(?)
CRYPT_AES_128_KEY_STATE ENDS
PCRYPT_AES_128_KEY_STATE typedef ptr CRYPT_AES_128_KEY_STATE

CRYPT_AES_256_KEY_STATE STRUC
Key db 32 dup(?)
IV db 16 dup(?)
EncryptionState db 16*15 dup(?)
DecryptionState db 16*15 dup(?)
Feedback db 16 dup(?)
CRYPT_AES_256_KEY_STATE ENDS
PCRYPT_AES_256_KEY_STATE typedef ptr CRYPT_AES_256_KEY_STATE
endif

CRYPT_INTEGER_BLOB STRUC
cbData dd ?
pbData LPBYTE ?
CRYPT_INTEGER_BLOB ENDS

PCRYPT_INTEGER_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_UINT_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_UINT_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_OBJID_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_OBJID_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_NAME_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_NAME_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_RDN_VALUE_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_RDN_VALUE_BLOB typedef ptr CRYPT_INTEGER_BLOB
CERT_BLOB typedef CRYPT_INTEGER_BLOB
PCERT_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRL_BLOB typedef CRYPT_INTEGER_BLOB
PCRL_BLOB typedef ptr CRYPT_INTEGER_BLOB
DATA_BLOB typedef CRYPT_INTEGER_BLOB
PDATA_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DATA_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DATA_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_HASH_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_HASH_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DIGEST_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DIGEST_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_DER_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_DER_BLOB typedef ptr CRYPT_INTEGER_BLOB
CRYPT_ATTR_BLOB typedef CRYPT_INTEGER_BLOB
PCRYPT_ATTR_BLOB typedef ptr CRYPT_INTEGER_BLOB
endif

The main gap is that this type of structure is converted with an incorrect name, which leads to the fact that the structures cannot be found!

Biterider

  • Member
  • ****
  • Posts: 704
  • ObjAsm Developer
    • ObjAsm
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #1 on: May 23, 2021, 08:59:35 PM »
Hi LiaoMi
Quote
why are the structures so different? And the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB in both converters??
MS decided to do so. Check WinCrypt.inc (_CRYPTOAPI_BLOB typedef CRYPT_INTEGER_BLOB)

Quote
@Biterider h2incX doesn't handle multilevel arrays?
Unfortunately no. HSE pointed that out some days ago. I put it in the todo list for the next release.

Code: [Select]
CRYPT_INTEGER_BLOB struct
  cbData DWORD ?
  __field_bcount typedef proto stdcall :cbData
  pbData POINTER ?
CRYPT_INTEGER_BLOB ends

seems to be wrong
What would be the correct translation?

Biterider
« Last Edit: May 24, 2021, 12:37:32 AM by Biterider »

LiaoMi

  • Member
  • ****
  • Posts: 872
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #2 on: May 23, 2021, 10:10:47 PM »
Hi LiaoMi
Quote
why are the structures so different? And the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB in both converters??
MS decided to do so. Check WinCript.h (_CRYPTOAPI_BLOB typedef CRYPT_INTEGER_BLOB)

Quote
@Biterider h2incX doesn't handle multilevel arrays?
Unfortunately no. HSE pointed that out some days ago. I put it in the todo list for the next release.

Code: [Select]
CRYPT_INTEGER_BLOB struct
  cbData DWORD ?
  __field_bcount typedef proto stdcall :cbData
  pbData POINTER ?
CRYPT_INTEGER_BLOB ends

seems to be wrong
What would be the correct translation?

Biterider

I could not find a similar "_CRYPTOAPI_BLOB typedef CRYPT_INTEGER_BLOB" definition from visual studio 2013 to 2019  :undecided:

Quote
What would be the correct translation?
If I understand the record correctly, then this is a byte pointer (PTR, XMASM, XPTR), and the bit capacity in each mode will be different, i.e. different size.

#define __field_bcount(size)                _SAL1_Source_(__field_bcount, (size),  __notnull __byte_writableTo(size))
#define _SAL1_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1") _GrouP_(annotes _SAL_nop_impl_)
#define _SA_annotes3(n,pp1,pp2,pp3)    [SAL_annotes(Name=#n, p1=_SA_SPECSTRIZE(pp1), p2=_SA_SPECSTRIZE(pp2), p3=_SA_SPECSTRIZE(pp3))]

declspec SAL like __field_bcount, used to describe the extent of a fixed-size buffer in a struct or on the stack.

This structure is used for an arbitrary array of bytes. It provides flexibility for objects that can contain various data types.
typedef struct _CRYPTOAPI_BLOB {  DWORD cbData;  BYTE* pbData;}

Members
cbData
Count of bytes in the buffer pointed to by pbData.
pbData
Pointer to a block of data bytes.

######################################

LPBYTE   
A pointer to a BYTE.

This type is declared in WinDef.h as follows:

typedef BYTE far *LPBYTE;

######################################

EasyCode, AsmC versions have identified the correct type. translatorus headinc did not simplify the macro and did not remove the parentheses __field_bcount(cbData). h2incX also correctly defined the type, but didn't simplify the macro __field_bcount typedef proto stdcall :cbData.

The correct translation should be like:
Code: [Select]
CRYPT_INTEGER_BLOB struct
  cbData DWORD ?
  pbData POINTER ?
CRYPT_INTEGER_BLOB ends

nidud

  • Member
  • *****
  • Posts: 2170
    • https://github.com/nidud/asmc
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #3 on: May 23, 2021, 10:48:45 PM »
@Nidud What converter are you using? Your results are completely different!  :rolleyes:

I use my own version as Asmc handles enum, define, [if] defined, COM interface and class differently in addition to keywords like name, page, title, low, high, size, length, this, mask, width and type.

Quote
AsmC -  pbData LPBYTE ?

asmc the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB, there are no other errors, pbData LPBYTE ? - What size LPBYTE has?

A pointer is a pointer so the size is always the same, same as size_t.

As for structure names:

typedef struct tagBLOB {
} BLOB;
typedef struct _tagpropertykey {
} PROPERTYKEY;
typedef struct _CRYPT_INTERFACE_REG {
} CRYPT_INTERFACE_REG, *PCRYPT_INTERFACE_REG;

BLOB, PROPERTYKEY, and CRYPT_INTERFACE_REG will be used.

TouEnMasm

  • Member
  • *****
  • Posts: 1679
    • EditMasm
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #4 on: May 23, 2021, 11:41:03 PM »
All translates who give the correct size are good.
After it's a question of syntax.
Headinc had followed the syntax given byThe Programmer's Guid for MASM 6.1  in 12 .doc with five appendice.
The c more often get the last name of a structure to use ii,but not always..As an automatised translate couldn't be random,it is always the last who is used by headinc.
You are exact assuming than annotations can create errors if the sdk_egales.txt isn't up to date.I am correcting this slowly,No urgence.An update of sdk_egales.txt is enough to solve the problem.

The MASM guid chapter 5 show:
Quote
You can also declare an array with the DUP operator. This operator works with any of the data allocation directives described in “Allocating Memory for Integer Variables” in Chapter 4. In the syntax
count DUP (initialvalue [[, initialvalue]]...)
the count value sets the number of times to repeat all values within the parentheses. The initialvalue can be an integer, character constant, or another DUP operator, and must always appear within parentheses. For example, the statement
barray  BYTE    5 DUP (1)

allocates the integer 1 five times for a total of 5 bytes.
The following examples show various ways to allocate data elements with the DUP operator:
array   DWORD   10 DUP (1)                    ; 10 doublewords
                                              ;   initialized to 1
buffer  BYTE    256 DUP (?)                   ; 256-byte buffer

masks   BYTE    20 DUP (040h, 020h, 04h, 02h) ; 80-byte buffer
                                              ;   with bit masks
three_d DWORD   5 DUP (5 DUP (5 DUP (0)))     ; 125 doublewords
                                              ;   initialized to 0



Fa is a musical note to play with CL

Biterider

  • Member
  • ****
  • Posts: 704
  • ObjAsm Developer
    • ObjAsm
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #5 on: May 24, 2021, 12:48:36 AM »
Hi LiaoMi
Check the file ...\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h lines 1049-1052.
It defines the structure and the alias

Code: [Select]
typedef struct _CRYPTOAPI_BLOB {
                            DWORD   cbData;
    _Field_size_bytes_(cbData)  BYTE    *pbData;
} CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,

Biterider


rsala

  • Member
  • ***
  • Posts: 329
    • Easy Code
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #6 on: May 24, 2021, 12:51:13 AM »
Hi LiaoMi,

I am not using a converter, I just take the structures from MSDN and manually convert them to assembly syntax.
EC coder

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8354
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #7 on: May 24, 2021, 01:33:58 AM »
I think that is the most reliable way to get the structure definitions.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

rsala

  • Member
  • ***
  • Posts: 329
    • Easy Code
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #8 on: May 24, 2021, 01:43:22 AM »
Thanks Hutch!
EC coder

LiaoMi

  • Member
  • ****
  • Posts: 872
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #9 on: May 24, 2021, 01:50:59 AM »
Hi LiaoMi
Check the file ...\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h lines 1049-1052.
It defines the structure and the alias

Code: [Select]
typedef struct _CRYPTOAPI_BLOB {
                            DWORD   cbData;
    _Field_size_bytes_(cbData)  BYTE    *pbData;
} CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,

Biterider

Hi Biterider,

I'm confused by the fact that access to these structures will be through the stub structure _CRYPTOAPI_BLOB, not through aliases, but through this structure.

https://en.cppreference.com/w/cpp/language/typedef
Code: [Select]
// common C idiom to avoid having to write "struct S"
typedef struct {
int a;
 int b;
} S, *pS;
 
// the following two objects have the same type
pS ps1;
S* ps2;

It would be more logical to do something like (this was done in EasyCode):
#######################################################
CRYPTOAPI_BLOB struct
  cbData DWORD ?
  pbData POINTER ?
CRYPTOAPI_BLOB ends

//CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB, <- Orig
//CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB, <- Orig

CRYPT_INTEGER_BLOB  typedef ptr CRYPTOAPI_BLOB <- This line has been removed by the translator.
PCRYPT_INTEGER_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_UINT_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_UINT_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_OBJID_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_OBJID_BLOB typedef ptr CRYPTOAPI_BLOB
CERT_NAME_BLOB typedef CRYPTOAPI_BLOB
PCERT_NAME_BLOB typedef ptr CRYPTOAPI_BLOB
CERT_RDN_VALUE_BLOB typedef CRYPTOAPI_BLOB
PCERT_RDN_VALUE_BLOB typedef ptr CRYPTOAPI_BLOB
CERT_BLOB typedef CRYPTOAPI_BLOB
PCERT_BLOB typedef ptr CRYPTOAPI_BLOB
CRL_BLOB typedef CRYPTOAPI_BLOB
PCRL_BLOB typedef ptr CRYPTOAPI_BLOB
DATA_BLOB typedef CRYPTOAPI_BLOB
PDATA_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_DATA_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_DATA_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_HASH_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_HASH_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_DIGEST_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_DIGEST_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_DER_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_DER_BLOB typedef ptr CRYPTOAPI_BLOB
CRYPT_ATTR_BLOB typedef CRYPTOAPI_BLOB
PCRYPT_ATTR_BLOB typedef ptr CRYPTOAPI_BLOB
#######################################################

Since, based on the construction CRYPT_INTEGER_BLOB, it is the same alias as other records. Otherwise, it turns out that the alias was turned into the original structure. This can be done, provided that the original structure is preserved as a duplicate.

LiaoMi

  • Member
  • ****
  • Posts: 872
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #10 on: May 24, 2021, 02:05:07 AM »
Hi LiaoMi,

I am not using a converter, I just take the structures from MSDN and manually convert them to assembly syntax.

Hi Rsala,

thanks for the info, it was hard work  :thumbsup:

LiaoMi

  • Member
  • ****
  • Posts: 872
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #11 on: May 24, 2021, 02:14:23 AM »
All translates who give the correct size are good.
After it's a question of syntax.
Headinc had followed the syntax given byThe Programmer's Guid for MASM 6.1  in 12 .doc with five appendice.
The c more often get the last name of a structure to use ii,but not always..As an automatised translate couldn't be random,it is always the last who is used by headinc.
You are exact assuming than annotations can create errors if the sdk_egales.txt isn't up to date.I am correcting this slowly,No urgence.An update of sdk_egales.txt is enough to solve the problem.

The MASM guid chapter 5 show:
Quote
You can also declare an array with the DUP operator. This operator works with any of the data allocation directives described in “Allocating Memory for Integer Variables” in Chapter 4. In the syntax
count DUP (initialvalue [[, initialvalue]]...)
the count value sets the number of times to repeat all values within the parentheses. The initialvalue can be an integer, character constant, or another DUP operator, and must always appear within parentheses. For example, the statement
barray  BYTE    5 DUP (1)

allocates the integer 1 five times for a total of 5 bytes.
The following examples show various ways to allocate data elements with the DUP operator:
array   DWORD   10 DUP (1)                    ; 10 doublewords
                                              ;   initialized to 1
buffer  BYTE    256 DUP (?)                   ; 256-byte buffer

masks   BYTE    20 DUP (040h, 020h, 04h, 02h) ; 80-byte buffer
                                              ;   with bit masks
three_d DWORD   5 DUP (5 DUP (5 DUP (0)))     ; 125 doublewords
                                              ;   initialized to 0


Thanks, variable sizes seem to be correct for everyone. There is a difference in the type assignment syntax here, I could not find a reason why CRYPTOAPI_BLOB should be renamed to CRYPT_INTEGER_BLOB. I am sure there are other similar errors in the names  :tongue:

C++
https://en.cppreference.com/w/cpp/language/typedef
Code: [Select]
// common C idiom to avoid having to write "struct S"
typedef struct {
int a;
 int b;
} S, *pS;
 
// the following two objects have the same type
pS ps1;
S* ps2;

Microsoft Macro Assembler
Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Macro Assembler Reference (1992, Microsoft Corporation)
name TYPEDEF type
Defines a new type called name, which is equivalent to type.

Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Programmers Guide (1992, Microsoft Corporation)
The TYPEDEF directive can define types for pointer variables. A type so defined
is considered the same as the intrinsic types provided by the assembler and can be
used in the same contexts. When used to define pointers, the syntax for TYPEDEF
is:
typename TYPEDEF [[distance]] PTR qualifiedtype
The typename is the name assigned to the new type. The distance can be NEAR,
FAR, or any distance modifier. The qualifiedtype can be any previously intrinsic or
defined MASM type, or a type previously defined with TYPEDEF. (For a full
definition of qualifiedtype, see “Data Types” in Chapter 1.)
Here are some examples of user-defined types:
PBYTE TYPEDEF PTR BYTE ; Pointer to bytes
NPBYTE TYPEDEF NEAR PTR BYTE ; Near pointer to bytes
FPBYTE TYPEDEF FAR PTR BYTE ; Far pointer to bytes
PWORD TYPEDEF PTR WORD ; Pointer to words
NPWORD TYPEDEF NEAR PTR WORD ; Near pointer to words
FPWORD TYPEDEF FAR PTR WORD ; Far pointer to words
PPBYTE TYPEDEF PTR PBYTE ; Pointer to pointer to bytes
; (in C, an array of strings)
PVOID TYPEDEF PTR ; Pointer to any type of data
PERSON STRUCT ; Structure type
name BYTE 20 DUP (?)
num WORD ?
PERSON ENDS
PPERSON TYPEDEF PTR PERSON ; Pointer to structure type

MSDN The structure definition includes aliases appropriate to the various functions that use it.

P.S. In general, this mod is not important, this little bithack does not change anything. But the structure discussed here can no longer be used directly.  :eusa_boohoo:

LiaoMi

  • Member
  • ****
  • Posts: 872
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #12 on: May 24, 2021, 02:51:14 AM »
@Nidud What converter are you using? Your results are completely different!  :rolleyes:

I use my own version as Asmc handles enum, define, [if] defined, COM interface and class differently in addition to keywords like name, page, title, low, high, size, length, this, mask, width and type.

Quote
AsmC -  pbData LPBYTE ?

asmc the _CRYPTOAPI_BLOB structure is renamed to CRYPT_INTEGER_BLOB, there are no other errors, pbData LPBYTE ? - What size LPBYTE has?

A pointer is a pointer so the size is always the same, same as size_t.

As for structure names:

typedef struct tagBLOB {
} BLOB;
typedef struct _tagpropertykey {
} PROPERTYKEY;
typedef struct _CRYPT_INTERFACE_REG {
} CRYPT_INTERFACE_REG, *PCRYPT_INTERFACE_REG;

BLOB, PROPERTYKEY, and CRYPT_INTERFACE_REG will be used.

Hi nidud,

thanks for the review! Apparently the only reason why this structure disappears is the type definition at the beginning of the structure.

Explanation
The typedef specifier, when used in a declaration, specifies that the declaration is a typedef declaration rather than a variable or function declaration. Typically, the typedef specifier appears at the start of the declaration, though it is permitted to appear after the type specifiers, or between two type specifiers.

But the compiler  :biggrin: perfectly understands that such a structure exists, which means it is defined in the code. https://godbolt.org/
Code: [Select]
// common C idiom to avoid having to write "struct S"
typedef struct BLOB {int a; int b;} S, *pS;
struct Hello {int a; int b;};

void Array() {
   
// the following two objects have the same type
pS ps1 = 0;
S* ps2 = 0;

Hello hl;

hl.a = 5;
ps1->a = 5;

BLOB blo;

blo.a = 5;

}

Code: [Select]
ps1$ = 0
ps2$ = 8
hl$ = 16
blo$ = 24
void Array(void) PROC                                  ; Array
$LN3:
        sub     rsp, 40                             ; 00000028H
        mov     QWORD PTR ps1$[rsp], 0
        mov     QWORD PTR ps2$[rsp], 0
        mov     DWORD PTR hl$[rsp], 5
        mov     rax, QWORD PTR ps1$[rsp]
        mov     DWORD PTR [rax], 5
        mov     DWORD PTR blo$[rsp], 5
        add     rsp, 40                             ; 00000028H
        ret     0
void Array(void) ENDP                                  ; Array

TouEnMasm

  • Member
  • *****
  • Posts: 1679
    • EditMasm
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #13 on: May 24, 2021, 03:19:14 AM »
Quote
Thanks, variable sizes seem to be correct for everyone. There is a difference in the type assignment syntax here, I could not find a reason why CRYPTOAPI_BLOB should be renamed to CRYPT_INTEGER_BLOB. I am sure there are other similar errors in the names
Here the reason:
define from micrososoft
Quote
typedef struct _CRYPTOAPI_BLOB {  DWORD cbData;  BYTE* pbData;} CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB, CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB, CRYPT_OBJID
as you can  see,microsoft itself when he designe pointers use CRYPT_INTEGER_BLOB as a reference,not _CRYPTOAPI_BLOB.
 :rolleyes:




Fa is a musical note to play with CL

rsala

  • Member
  • ***
  • Posts: 329
    • Easy Code
Re: h2incX vs translatorus headinc - WinCrypt.h
« Reply #14 on: May 24, 2021, 03:52:25 AM »
Yeah, hard work but good results.  :thumbsup:
EC coder