Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch between methods' parameters' types and the declarations in Windows' headers #1

Open
revosw opened this issue Jan 22, 2023 · 1 comment
Labels
metadata-api Any issue relating to using the metadata API to parse winmd

Comments

@revosw
Copy link
Owner

revosw commented Jan 22, 2023

A whole load of errors related to incompatibility between types have to be sorted.

.\winmd.c(12456): error C2440: 'function': cannot convert from 'Array_voidptr' to 'mdEvent *'
.\winmd.c(12456): warning C4024: 'function through pointer': different types for formal and actual parameter 4
.\winmd.c(12461): warning C4133: 'function': incompatible types - from 'u32 *' to 'HCORENUM *'
.\winmd.c(12461): warning C4047: 'function': 'mdTypeDef' differs in levels of indirection from 'voidptr'
.\winmd.c(12461): warning C4024: 'function through pointer': different types for formal and actual parameter 3
.\winmd.c(12461): error C2440: 'function': cannot convert from 'Array_voidptr' to 'mdFieldDef *'
.\winmd.c(12461): warning C4024: 'function through pointer': different types for formal and actual parameter 4
.\winmd.c(12466): warning C4133: 'function': incompatible types - from 'u32 *' to 'HCORENUM *'
.\winmd.c(12466): warning C4047: 'function': 'mdTypeDef' differs in levels of indirection from 'voidptr'

In essence, this means you can't for example pass a string directly in FindAssembly's szAppBase parameter in the Windows API. You have to convert it to a c string with szAppBase.str

pub fn (md MetaDataDispenser) find_assembly(szAppBase string, szPrivateBin string, szBlobalBin string, szAssemblyName string, szName string, cchName u32, pchName &u32) u32 {
	return md.dispenser_ptr.lpVtbl.FindAssembly(md.dispenser_ptr, szAppBase, szPrivateBin, szBlobalBin,
		szAssemblyName, szName, cchName, pchName)
}
@revosw
Copy link
Owner Author

revosw commented Feb 5, 2023

The remaining warnings at line 7xxx are not affected by the winmd code. The warnings at 12xxx are about correctly const typing the IIDs and the lack of QueryInterface, AddRef and Release in the interface structs

wip.c(7578): warning C4047: 'function': 'DWORD64' differs in levels of indirection from 'voidptr'
wip.c(7578): warning C4024: 'SymFromAddr': different types for formal and actual parameter 2
wip.c(7578): warning C4133: 'function': incompatible types - from 'SymbolInfo *' to 'PSYMBOL_INFO'
wip.c(7581): warning C4047: 'function': 'DWORD64' differs in levels of indirection from 'voidptr'
wip.c(7581): warning C4024: 'SymGetLineFromAddr64': different types for formal and actual parameter 2
wip.c(7581): warning C4133: 'function': incompatible types - from 'u64 *' to 'PDWORD'
wip.c(7581): warning C4133: 'function': incompatible types - from 'Line64 *' to 'PIMAGEHLP_LINE64'
wip.c(7681): warning C4047: 'function': 'LPWSTR' differs in levels of indirection from 'u16 **'
wip.c(7681): warning C4024: 'FormatMessageW': different types for formal and actual parameter 5
wip.c(7681): warning C4047: 'initializing': 'voidptr' differs in levels of indirection from 'DWORD'
wip.c(12445): warning C4133: 'function': incompatible types - from 'metadata__Guid *' to 'const IID *const '
wip.c(12445): warning C4133: 'function': incompatible types - from 'IMetaDataImport2 **' to 'IUnknown **'
wip.c(12461): warning C4133: 'function': incompatible types - from 'metadata__Guid *' to 'const IID *const '
wip.c(12461): warning C4133: 'function': incompatible types - from 'IMetaDataTables2 **' to 'IUnknown **'
wip.c(12478): warning C4133: 'function': incompatible types - from 'metadata__Guid *' to 'const IID *const '
wip.c(12478): warning C4133: 'function': incompatible types - from 'IMetaDataAssemblyImport **' to 'IUnknown **'

Line 7578

if (SymFromAddr(handle, (*(frame_addr)), &offset, si) == 1) {

Line 7578 and 7581 with context

for (int i = 0; i < frames; ++i) {
    voidptr *frame_addr = HEAP(voidptr, (backtraces[v_fixed_index(i, 100)]));
    if (SymFromAddr(handle, (*(frame_addr)), &offset, si) == 1) { //7578
        int nframe = frames - i - 1;
        string lineinfo = _SLIT("");
        if (SymGetLineFromAddr64(handle, (*(frame_addr)), &offset, &sline64) == 1) { // 7581
            string file_name = tos3(sline64.f_file_name);
            u32 lnumber = sline64.f_line_number;
            lineinfo =  str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = file_name}}, {_SLIT(":"), /*117 &u32*/0xfe06, {.d_u32 = lnumber}}, {_SLIT0, 0, { .d_c = 0 }}}));
        } else {
            lineinfo =  str_intp(2, _MOV((StrIntpData[]){{_SLIT("?? : address = 0x"), /*120 &voidptr*/0x7000fe11, {.d_p = (void*)((&(*(frame_addr))))}}, {_SLIT0, 0, { .d_c = 0 }}}));
        }

line 7681

voidptr res = FormatMessage(((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM) | FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err_msg_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msgbuf, 0, NULL);

Line 7681 with context

string winapi_lasterr_str(void) {
	u32 err_msg_id = GetLastError();
	if (err_msg_id == 8U) {
		return _SLIT("insufficient memory");
	}
	u16* msgbuf = ((u16*)(0));
	voidptr res = FormatMessage(((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM) | FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err_msg_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msgbuf, 0, NULL);
	string err_msg = (res == 0 ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("Win-API error "), /*117 &u32*/0xfe06, {.d_u32 = err_msg_id}}, {_SLIT0, 0, { .d_c = 0 }}}))) : (string_from_wide(msgbuf)));
	return err_msg;
}

@revosw revosw added the metadata-api Any issue relating to using the metadata API to parse winmd label Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metadata-api Any issue relating to using the metadata API to parse winmd
Projects
None yet
Development

No branches or pull requests

1 participant