How does regedit.exe create empty binary values - winapi

I opened up regedit and made an empty binary value monitoring it using ProcessMonitor.exe. I set up a filter so that it included anything mentioning the registry path of the empty binary value's key and excluded everything else. When making a new binary value, it creates the unnamed one, then when I rename it to something else it deletes the unnamed one. However, it doesn't set anything with the new name, it just queries the value which returns an error until after I close the key in regedit then open it again and it now queries successfully the empty REG_BINARY.
At no point do I see any set value calls, and I looked on msdn, it doesn't say querying non-existing values creates them. How does it make the new value?

Doing this on XP, you can also get the RegMon output, and that lists SetValue:
ProcMon:
"Sequence","Time of Day","Process Name","PID","Operation","Path","Result","Detail","Event Class"
"8456","20:15:47,6493609","regedit.exe","420","RegQueryValue","HKCU\Software\test\New Value #1","NAME NOT FOUND","Length: 144","Registry"
"8559","20:15:51,2066619","regedit.exe","420","RegQueryValue","HKCU\Software\test\foo","NAME NOT FOUND","Length: 144","Registry"
"8560","20:15:51,2066761","regedit.exe","420","RegQueryValue","HKCU\Software\test\New Value #1","SUCCESS","Type: REG_BINARY, Length: 0","Registry"
"8561","20:15:51,2066864","regedit.exe","420","RegQueryValue","HKCU\Software\test\New Value #1","SUCCESS","Type: REG_BINARY, Length: 0","Registry"
"8562","20:15:51,2075572","regedit.exe","420","RegDeleteValue","HKCU\Software\test\New Value #1","SUCCESS","","Registry"
"8618","20:15:52,9198131","regedit.exe","420","RegCloseKey","HKCU\Software\test","SUCCESS","","Registry"
RegMon:
1 2.38380957 regedit.exe:420 QueryValue HKCU\Software\test\New Value #1 NOT FOUND
2 2.38436174 regedit.exe:420 SetValue HKCU\Software\test\New Value #1 SUCCESS
3 5.36779499 regedit.exe:420 QueryValue HKCU\Software\test\foo NOT FOUND
4 5.36780643 regedit.exe:420 QueryValue HKCU\Software\test\New Value #1 SUCCESS
5 5.36781597 regedit.exe:420 QueryValue HKCU\Software\test\New Value #1 SUCCESS
6 5.36884880 regedit.exe:420 SetValue HKCU\Software\test\foo SUCCESS
7 5.36890793 regedit.exe:420 DeleteValueKey HKCU\Software\test\New Value #1 SUCCESS
8 9.04430676 regedit.exe:420 CloseKey HKCU\Software\test SUCCESS
The regmon output looks like a rename operation to me (QV,QVx2,SV,DV) Maybe regmon uses hooking and procmon uses the documented registry monitor api (Or maybe a procmon bug?)
I tested both the latest and a older version on procmon; v1.37 (The older versions don't have a huge ETW delay when you toggle monitoring on/off on XP)

Related

Multiaddress utility in front-end-template

Extending the front end template to do some new things and running into issues with multiaddress lookup functionality as specified in our chain here: https://github.com/Greenetwork/BLX_chain/blob/f14ad8705debcc8033069b4fdda046271e1b61f1/pallets/allocator/src/lib.rs#L140
So it seems that the issue is that we are missing one piece of data that the extrinsic (tradeTokens) wants (the piece that defines which "type" for fromapn:Source and toapn:Source)
You can see below that the using the dropdown menus to select Address32 in polkadot js apps yields a 3 being populated in the encoded call data (Address32 is the 3rd entry in the Source enum)
and further here that 3 is shown as ‘snip< Address32: >snip’
Currently as the code in our front-end-template:
https://github.com/Greenetwork/BLX_frontend_new/blob/afe6f9f256e6c9c2a3164f72cf80d4a9057bb893/src/Transfer.js#L71-L72
the error is:
Unhandled Rejection (Error): createType(Call):: Call: failed decoding allocator.tradeTokens:: Struct: failed on args: {"asset_id":"AssetId","fromapn":"Source","toapn":"Source","amt":"Balance1"}:: Struct: failed on fromapn: {"_enum":{"Id":"AccountId","Index":"AccountIndex","Raw":"Bytes","Address32":"[u8;32]","Address20":"[u8;20]"}}:: Invalid AccountId provided, expected 32 bytes, found 31
I think the issue is that the extrinsic is reading the first (or second, see call data in first picture) value of the data being submitted to fromapn as the index of Source, in the current case, that is 0, so it is proceeding to treat the remainder of the data that it was passed as an AccountId.
It is failing on the fact that by using one of the values as the index of Source so we are only left with 31 bytes instead of 32. AccountId is also 32 bytes i think.
Do we need another helper function to append that extra piece of data which specifies the type? Or is there another path?
pre-pended Address32 with and index character to make it 33 bytes:
https://github.com/Greenetwork/BLX_frontend_new/blob/71a0fbee21c08b2374bddfcdca0fe204d3e36aa7/src/helpers.js#L39-L51

Reading barcode in datawindow (powerbuilder)

I have like a POS application where I work, and I added new code to read barcodes in a datawindow, but been having some problems to use it correctly. The process needs to read the barcode and automatically search for the product, and insert it in another datawindow with the info regarding the product.
The problem is that I have the code in the editchanged event, and that the barcodes have different lenght; so, every time a number of the barcode is read, the search function is called, here is the code for that function:
ll_rtn = dw_search.Retrieve()
If ll_rtn = 1 Then
is_code = dw_search.GetItemString(1,'barcode')
wf_insert(False)
End If
If for example, a product of 10 digits is read and at length 5 the product is found, it's inserted but the editchanged is still running because the barcode is length 10, and depends of the search, might find it again with the last digits and insert it again.
I don't know how to stop reading after I find the product. Hope I explain it right.
Can you check if the barcode scanner can be configured to pass carriage return / Enter, upon scanning the barcode and this way you can move your code to itemchanged event
Bar Code Config
An editchanged event is fired for each keystroke in the control. You probably want to either move the code to the itemchanged event or to a totally separate event which is posted from the itemchanged event.
If you absolutely have to have the code in the editchanged event you need to set a boolean instance variable on the window which is set TRUE once the product is found. If it's true then don't search. Remember to reset the variable to FALSE prior to any new search.

Has the behavior of the Array() function changed? [duplicate]

This question already has answers here:
Sending object array to variant works before August 2019 Windows update, but fails after update
(3 answers)
Closed 3 years ago.
I have a problem in some old VB6 code which appears to be related to creating an empty array by calling the Array() function with an empty parameter list.
The help for VBA indicates that this is legal operation:
The required arglist argument is a comma-delimited list of values that
are assigned to the elements of the array contained within the
Variant. If no arguments are specified, an array of zero length is
created.
The bones of the function which causes the error are shown below.
The function creates an empty array, adds zero or more elements to the array, and then returns it to the caller.
In this specfic case, it does not add any elements to the array, and therefore tries to return an empty array.
Private Function GetActiveRestrictionArray(ByVal Restrictions As String) As Variant
Dim Result As Variant
Result = Array()
'Do some stuff which might call "Redim"
'but in this case does not.
GetActiveRestrictionArray = Result
End Function
The line GetActiveRestrictionArray = Result is now generating the error 'Invalid procedure call or argument'.
A user has reported that this error occurs under Windows 10 after performing a Windows update. The same user has reported, that if he reverts this update, then the error disappears. I don't know exactly what update that was.
However, I can now generate the same error in VB6 on a Virtual Machine running Windows 7.
In fact, immediately after the line Result = Array(), if I hold the mouse over the variable Result, it shows the message 'Invalid procedure call or argument' as a tooltip (in this case in German).
Honestly, I don't know how this code ever worked, but apparently it did.
Is it possible that the behavior of the VB6 Array() function has changed, specifically when it is called with an empty argument list?
This is probably caused by the August 2019 patch from Microsoft. MS has issued some additional updates that addresses this on some of the versions of Windows.
See:
https://learn.microsoft.com/en-us/windows/release-information/status-windows-10-1903#629msgdesc
https://support.microsoft.com/en-us/help/4512508/windows-10-update-kb4512508
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2019-1182
Subsequent updates:
Windows 7 x64: https://support.microsoft.com/en-us/help/4517297/windows-7-update-kb4517297
Windows 10 version 1709: https://support.microsoft.com/en-us/help/4512494/windows-10-update-kb4512494
Windows 10 version 1809: https://support.microsoft.com/en-us/help/4512534

RegGetValue for value that may be either REG_SZ or REG_EXPAND_SZ

I'm trying to get the data for a value that is normally of type REG_SZ but I also want to support the possibility that it is REG_EXPAND_SZ.
I tried this:
RegGetValue(HKEY_LOCAL_MACHINE, subkey, valueName, RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ, NULL, buffer, &bufferSize)
but it returns 87 ("Incorrect parameter").
It works fine if I pass either RRF_RT_REG_SZ or RRF_RT_REG_EXPAND_SZ on its own, but not when I specify both. I don't want to restrict my check to one specific type. The MSDN says I can use "one or more of the following" for that parameter.
Why am I getting this error and how can I solve it?
I have confirmed that this is a Windows 7 bug. In Windows 7 and earlier versions, the implementation of the RegGetValue function contains the following code:
if (((dwFlags & RRF_RT_ANY) != RRF_RT_ANY) &&
(dwFlags & RRF_RT_REG_EXPAND_SZ) &&
!(dwFlags & RRF_NOEXPAND))
{
return ERROR_INVALID_PARAMETER;
}
Therefore, even using only the RRF_RT_REG_EXPAND_SZ flag will produce the "invalid parameter" error (error code 87).
This bug has been fixed starting from Windows 8.1. On both Windows 8.1 and Windows 10, I have confirmed that RRF_RT_REG_SZ|RRF_RT_REG_EXPAND_SZ works without errors.
If you need to target Windows 7 and earlier versions, you can work around the problem by adding the RRF_NOEXPAND flag. In other words, if you pass the following combination of flags:
RRF_RT_REG_SZ|RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND
Of course, this means that values of type "expand_sz" will not be expanded for you—to do that, you need to follow up with a direct call to ExpandEnvironmentStrings. Also, you will need to use the dwType parameter to determine exactly which type of data you have, since you allowed more than one type in the mask.

How to retrieve or enumerate ISO-3166 numeric codes?

With EnumSystemLocalesEx I can enumerate supported countries and get the ISO-3166-Alpha 2 code.
With GetLocaleInfoEx I can retrieve the language name and the ISO-3166-Alpha 3 code. The list of information I can get does not contain the ISO-3166 numeric value, or I missed it and it hides behind a value I can't understand.
I found LOCALE_SISO3166CTRYNAME, LOCALE_SISO3166CTRYNAME2.
Is there a way to to retrieve the ISO-3166-Numeric value with any of the Windows API function too, when I have a given ISO Alpha 2 or Alpha 3 code?
Edit: Code should work for Windows Vista and later!

Resources