« first day (1317 days earlier)      last day (1527 days later) » 

12:54 AM
@SAJW there are so many ways to do this, and it will depend on your specific needs. If you only need it there, it makes sense to have them local like that.
 
 
7 hours later…
7:30 AM
Is anyone here familiar with shunting yard algorithm?
 
 
3 hours later…
10:15 AM
This is not catching spaces (space bar) and the program crashes. if (isspace ( static_cast<unsigned char>( expr[i])))
Value of expr comes from cin
 
@northerner sounds to me like you didn't bounds-check expr[i]
 
@PeterT hmm shouldn't be the problem, also I tried replacing with expr.at(i) and no error message about anything thrown
 
what does "the program crashes" mean then?
 
10:34 AM
@PeterT seg fault
where as .at() would throw an out of range error
 
nwp
What is the cast for?
 
@nwp I saw it used in examples because isspace results in UB if the type isn't unsigned char.
It didn't seem to make a difference, I was just testing things to try to find the problem
 
nwp
> The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.. I don't know what "is representable" means here, but it feels like it should not be necessary to me.
Anyways, it was just a side remark. It probably has nothing to do with the crash.
 
10:54 AM
Strictly speaking does [ ] return a char or unsigned char? From the docs I'm guessing char en.cppreference.com/w/cpp/string/basic_string/operator_at
 
nwp
A char, yeah. But a function like std::isspace should really work on chars.
 
11:06 AM
@northerner I still think your issues is somewhere else, do you have more context for that snippet?
 
if you use a debugger you can at least see which line caused the segmentation fault
 
@PeterT it would seem mpz_class val2 = output.top(); caused it. I don't really see how though
 
nwp
output is empty?
 
@PeterT how exactly do you get the line which causes the seg fault? When I try to it opens up the library file (gmpxx.h)
 
11:16 AM
go up the callstack until you land in code you wrote
 
ya so it's output.top()...though that didn't give much insight into fixing the problem :P
 
right, look at the documentation for top, there's some preconditions
as nwp mentioned
 
Ok figured it out, if an operator (e.g. +) is processed just by itself, then the output stack is empty and that causes seg fault
So what exactly happens when cin splits a string up on the spaces? Is the rest of the program run on each segment?
For example
string x;
cin >> x
//user gives 'a b c'
foo(x);
would this mean foo gets called 3 times??
 
nwp
x becomes "a", foo is called once with "a", b c remain in the input buffer.
Unless you changed the delimiter for std::cin or something.
The key insight here is that when you read a string with std::cin you are meant to read a word. In this case a, b and c are each considered words and the spaces are not words.
You are probably better off with std::getline as mentioned above.
 
 
1 hour later…
12:45 PM
what the difference between a data engineer and what a web backend developer does?
 
Hello guys, can anyone look into this?
0
Q: Why is my ZwOpenKey function not returning a HANDLE?

CosmosI could be missing something obvious here but I've tried everything I could think of and still no luck. I'm trying to use ZwOpenKey and ZwCreateKey to add a value to the Run key in the registry. However, the ZwOpenKey never fills my RegKey HANDLE value and it instead returns STATUS_OBJECT_NA...

Any ideea?
 
nwp
I think you're putting way too much weight on those titles.
Did you get question blocked for that?
 
1:00 PM
No, I have encountered the same issue with a similar code
and i was wondering why no one answered that question?
It could help me as well.
Thank you.
 
nwp
The error seems straightforward. STATUS_OBJECT_NAME_NOT_FOUND, so it didn't find the name. And looking at "\\Registry\\User\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" that does indeed not look like a valid registry path at all.
 
What would be the correct registry path?
 
nwp
HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run exists on my machine. Open regedit to check.
 
Let me see.
However this is the standard path into registry
i though in c++ needs to be written that way
I was also tried with that path, but still not reaching thatif statement
 
hello, I don't know if i'm in the right channel but I believe in you :) I have question about regex.
 
nwp
1:08 PM
I haven't seen \\Registry used anywhere.
Omg the feeling when you try to look up the function on MSDN and you get a link back to stackoverflow.
 
i'm trying to match every thing betwen "@V" so I would match @BR1 and Short dress even if there are "@" or even "@K" in the value
 
@nwp why?
 
on @Kbrand@V@B@KR1@V@Kname@VShort dress@V the regex should produce @B@KR1 and Short dress
I tried (?<=\@V)(.*?)(?=\@V) but it match @Kname
 
nwp
@Permian Because titles are thrown around basically at random. Nobody ensures that the title fits the work. It might kinda sorta indicate a direction when you're applying for a job, but even then you can hardly draw conclusions about the actual work load.
@Neyoh What regex dialect is that? Why not just @V(.*)@V?
 
@nwp my title still contains references to mobile work because I haven't bothered to change it
7 messages moved from Lounge<C++>
 
1:23 PM
@nwp i know :))
 
your idea is ok
thank you
now I would like to match every string 'key' between @V@K and @V except for the beginning of the string
in the case of @Kbrand@V@B@KR1@V@Kname@VShort dress@V my regex (?<=\@V\@K)(.*?)(?=(\@V)) match everything except the first one (I mean @Kname but not @Kbrand
how to express that in regex ?
 
Still not working, so I have it like this:

My function:

NTSTATUS OpenKeyW(PHANDLE hKey, PWCHAR KeyName, ACCESS_MASK MaskType)
{

	UNICODE_STRING uKeyName;
	p->_RtlInitUnicodeString(&uKeyName, KeyName);

	POBJECT_ATTRIBUTES KeyAttributes;

	(KeyAttributes)->Length = sizeof(KeyAttributes);
	(KeyAttributes)->RootDirectory = NULL;
	(KeyAttributes)->Attributes = OBJ_CASE_INSENSITIVE;
	(KeyAttributes)->ObjectName = &uKeyName;
	(KeyAttributes)->SecurityDescriptor = NULL;
	(KeyAttributes)->SecurityQualityOfService = NULL;
And I call it like this:
WCHAR RegistryString[MAX_PATH];
if (wsprintfW(RegistryString, TEXT("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run")) != NULL)

{
HANDLE RegKey = NULL;
if (OpenKeyW(&RegKey, RegistryString, KEY_WRITE) != STATUS_SUCCESS)
{
if (CreateKeyW(&RegKey, RegistryString, KEY_WRITE) != STATUS_SUCCESS)
{

}
} }
HANDLE RegKey is never being populated
 
@Castiel why are you calling ZwOpenKey?
 
for ntdll
i want to work with nt apis
 
@Castiel rule #1 of windows programming in userspace: Don't reference NTDLL
it's not a stable API or ABI, MS reserves the right to change it at any time and does
 
1:35 PM
I know that, but I wanted to figure it out why doesn't working this function properly,or what am I missing
I used the OpenRegKeyX
that works perfectly.
I wanted to experiment with NTDLL
 
nwp
@Neyoh Use a site like regextester and put in your examples and mess with the regex until you got it.
 
13
A: Windows Native API: When and why use Zw vs Nt prefixed api calls?

user541686Update: Aside from Larry Osterman's answer (which you should definitely read), there's another thing I should mention: Since the NtXxx variants perform checks as though the call is coming from user-mode, this means that any buffers passed to the NtXxs function must reside in user-mode address...

 
@Mgetz Let me check this out. Thanks.
 
@Castiel and this is why you don't use NT or ZW APIs, they are not for usermode access except for drivers
 
I see, but does that forbidd to be used?
Since in my code the only issue is that the HANDLE remains always null, I was thinking only for this code to understand what am I missing
 
1:41 PM
@Castiel Unless you're writing a driver, basically yes. There are some odd corner cases but those are things you really shouldn't need to worry about and don't refer to this specific API
Technically the NT apis (Not ZW) can be called from usermode in theory, but they have quirks and oddnesses to them that make that very problematic
 
I know that,i have read about the instability of it
Back to my code, since I am using the above code, the error exception is that:
Access violation writing location 0x00000000.
Which means I am writing to something that is NULL
The error points to:

(KeyAttributes)->ObjectName = &uKeyName;
 
@nwp i tried but I did get it :D
 
The documentation specifically calls out you need to use that method to initialize that structure
 
@Mgetz I was thinking on that,but I rewrote it in the header like this:
 
1:49 PM
#define InitializeObjectAttributes (p, n, a, r, s) { \
	(p)->Length = sizeof(OBJECT_ATTRIBUTES); \
	(p)->RootDirectory = NULL; \
	(p)->Attributes = a; \
	(p)->ObjectName = n; \
	(p)->SecurityDescriptor = s; \
	(p)->SecurityQualityOfService = NULL; \
}
isn't that the same?
 
@Castiel don't rewrite it, use the defined one
 
what's the difference?
 
@Castiel it may be doing things you don't know about
don't assume just use the canonical version
 
I think I got it (the regex)
 
Ok let me check this.
 
1:52 PM
I can tell you right now your definition is wrong
> Note If the call to this function occurs in user mode, you should use the name "NtOpenKey" instead of "ZwOpenKey".
yeah that will fail regardless
 
Why would it fail?
 
because PreviousMode isn't Kernel
thus the call is insecure
 
nwp
Huh. I don't remember that from when I messed with registry key. Today I learned.
 
@Mgetz I stll want to use ZwOpenKey, but can
 
@nwp it's kernel/driver only
 
2:04 PM
but can't figure it out now the VOID InitializedAttributes where would it be defined and used this way as a void
 
so you'd have zero reason to ever look at it
 
why would I have zero?
 
Because RegOpenKey Exists and is much easier to use and supported? I was responding to nwp
 
@Mgetz Oh sorry,but i want to use ZwOpenKey for kernel/driver that's the reason
 
The only reason to ever use ZW functions AFAIK is in kernel mode
@Castiel then you should be including wdm.h and not importing the functions... which tells me you're in user mode
 
2:07 PM
I am in user mode, not sure how to "switch" to kernel mode
But why would be so important to include its library if it is already defined?
 
@Castiel you would have to write an actual driver using the windows driver kit, and turn off kernel mode driver signing on your machine
@Castiel because drivers are different and there are a lot of things you need to be aware of?
 
I understand now.
That means, to use these functions you need to include the wdm.h library ?
necessarily?
 
I'll check in in a bit,in the mean time, tell my why RbMM has succeeded to write something similary?
 
nor is it intended to be used from non-drivers
 
2:11 PM
2
Q: Obtaining handle to key with NtCreateKey/NtOpenKey

mike changPURPOSE I'm trying to make a function which will create a given sub key in the HKCU registry hive, or open the sub key if it already exists, then return TRUE. NOTES Let RegSidPath represent a fully qualified HKCU registry path with an user SID appended to it such as \\Registry\\User\\S-1-5-20-...

 
I think, possibility is infinite : ]]
 
 
3 hours later…
5:42 PM
"Read a sequence of double values into a vector. Think of each value as the distance between two cities along a given route. Compute and print the total distance (the sum of all distances). Fmd and print the smallest and greatest distance between two neighboring cities. Fmd and print the mean distance between two neighboring cities." from Programming Principles and Practice Using C++

Here is what I written in code: https://pastebin.com/MbafqjQi but I wonder if I took it too far with the single responsibility principle.
 

« first day (1317 days earlier)      last day (1527 days later) »