Original Post
By "dirty", I mean brute forcing something to work just because you can't find an easy solution. Obviously the world isn't going to end if you brute force something, but I'm wondering if it would be best to just find a good solution, or if it's fine to brute force it to work. An example (although not a very good one) would be if you wanted to access a private member of a class that you knew the offset of within the class:
Let's say that "_randomString" is the variable that you want to return, but perhaps you have no way of modifiying the "Brute" class to allow you access to this variable. Would it be a bad idea to create a function like this:
I wouldn't write code like the above because it's really mess, but it should get the job done. Is it a bad idea to implement such types of methods if your code is only going to be used by your own team, and not released to public?
I really don't even want to post it because I feel like it seems like a silly question that undoubtedly has an obvious answer, I'm just curious of your opinion on the matter. If it works, it should be fine to use it, but I'm sure someone has a really good reason why it is a bad idea to use brute force coding.
class Brute
{
private:
int _randomInt;
int _otherRandomInt;
char* _randomString;
};
Let's say that "_randomString" is the variable that you want to return, but perhaps you have no way of modifiying the "Brute" class to allow you access to this variable. Would it be a bad idea to create a function like this:
char *getBruteString(Brute *b_Ptr)
{
char *s_Ptr = (char*)b_Ptr;
//Get the address of _randomString by getting the address of the char at the 8th index in s_Ptr
char** c_Ptr = (char**)&s_Ptr[8];
return *c_Ptr;
}
I wouldn't write code like the above because it's really mess, but it should get the job done. Is it a bad idea to implement such types of methods if your code is only going to be used by your own team, and not released to public?
I really don't even want to post it because I feel like it seems like a silly question that undoubtedly has an obvious answer, I'm just curious of your opinion on the matter. If it works, it should be fine to use it, but I'm sure someone has a really good reason why it is a bad idea to use brute force coding.