whatwillilearntoday
What Will I Learn TODAY?
8 posts
Curiousity keeps the mind alive
Don't wanna be here? Send us removal request.
whatwillilearntoday · 4 years ago
Text
Guest to Host Hyper-V KVP exchange from Ubuntu 18.04 using Bash
There is a magical way to communicate with VMs from Hyper-V. You can send 512 bytes worth of a key and 2048 byte long value. To learn more about this, here’s a good resource: https://www.altaro.com/hyper-v/key-value-pair-data-exchange-3-linux/. Oddly, there is no example on the internet (that I could find) of a how to write the key from the VM using bash. So I had to make my own. This is the bash script I used to write the KVP from inside the guest: 
#!/bin/bash filename="/var/lib/hyperv/.kvp_pool_1" echo -n key11 > $filename let N=512-5-1 for c in `seq 0 $N`; do echo -ne "\0" >> $filename done echo -n value11 >> $filename let N=2048-7-1 for c in `seq 0 $N`; do echo -ne "\0" >> $filename done
3 notes · View notes
whatwillilearntoday · 6 years ago
Text
How to seal evaporated milk can after opening
Today I discovered that the covers that came with my Glad mini storage sauce containers actually fit the evaporated milk can perfectly. The fit is so good that I can lift the entire can just by holding the cover once it’s on! Amazing discovery.
For reference, this is the milk can: Signature Kitchens Evaporated Milk 12 oz - https://www.instacart.com/safeway/products/4423-signature-kitchens-evaporated-milk-12-fl-oz
And this is the container: Glad Mini Round Food Storage Containers, 4 oz,  8/Pack -  https://www.officesupply.com/cleaning-breakroom/breakroom-supplies/food-service-supplies/food-storage/glad-mini-round-food-storage-containers-pack/p643372.html?mrkgcl=605&mrkgadid=3174563003&product_id=643372&adpos=1o3&creative=164947087363&device=c&matchtype=&network=g&ref=pla&gclid=CjwKCAjw7IbaBRBqEiwA6AyZgmXcCaNPU98y22sf-bpEp4jezkmYzrkFe3g6WPda36e-421mgQl1OhoCiIYQAvD_BwE
2 notes · View notes
whatwillilearntoday · 6 years ago
Text
Using C code from C++ code causes linker error -- and how to fix it
Recently, I came across a non-trivial linker error where GCC complained that “ld failed with exit code 1.″ It had very little information other than where the issue was. This was in some C++ code I had written which was trying to use a new function I had written. The new function was part of a C library.
Weirdly, the new C files I added were linking correctly in another project. The only noticeable difference between the two cases was that the other project was completely in C, while the project with the error was in C++. 
The learning here is that just because C++ compilers compile C, doesn’t mean that you can call into any function written in the other language for free. In my case, I had to declare the function I was trying to use from C in my C++ code with:
    extern “C”
So that means I added this at the top of my C++ file:
extern “C” my_c_function(void* arg1, void* arg2);
You can also enclose the headers in {} instead of starting each header line with extern “C”:
extern “C” {
    my_c_function_1( void* arg1, void* arg2);
    my_c_function_2( void* arg1, void* arg2);
}
Reading up more about using C++ code in C and vice versa, it made sense that you shouldn’t be able to use C++ directly in C, because C++ can have classes and member functions that C cannot. For that case, you have to write some intermediary code so that your C can call into the C++.  
0 notes
whatwillilearntoday · 6 years ago
Text
Good Practices for Working with a New Repo
There are a few steps you can do to save yourself from having to deal with unnecessary issues later on when contributing to a code base. If you’ve ever found yourself building and testing your code only to realize that you’re running into problems that make no sense and are seemingly unrelated to code that your wrote, you should read on.
1) Get the code.
2) Build it. Do this before doing any changes.
3) Run ALL the tests. Make sure these pass before you touch anything.
That’s it! Once you’re able to build and test without any of your changes, you have established a valid baseline for yourself to work from. Anything that goes wrong from this point on is probably related to something you did. 
Often times, by following these steps, you can even find and report bugs that exist in the code base without actually having made changes yourself. This is very valuable for your team.
1 note · View note
whatwillilearntoday · 7 years ago
Text
.htaccess redirection hack
Today a site I help manage got attacked with .htaccess redirection hack. What this means is that from any search engine listed in the attack, the site would redirect to some other, potentially malicious site. 
How it was done
The hackers got into the server and modified the .htaccess file to contain the following lines at the top:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^(.*)$ explicitness-culture.php?$1 [L]
The hackers added a bunch of php files onto the site itself so it looks like our site when the redirection happens! Sneaky. This went unnoticed for almost 2 months. The hacker went in and added the files on two different dates.
0 notes
whatwillilearntoday · 7 years ago
Text
How to use LibClang
After spending a lot of time trying to figure out how to use libclang in my C++ project in NetBeans, here’s the recipe that did it:
1) Install LLVM and Clang sources.
2) Build LLVM. This took about 3-4 hrs.
3) Include the library generated from clang:
- Go to Project Properties > Build > Linker.
- Add the path to libclang.so to the Libraries path using “Add Library File...” option.
- In case code editor is giving trouble, add the path to /include in the sources using Tools > Options > C/C++ > C++ Compiler > Add > <path to /include folder in llvm src>
And that is all! You’re set to use all of Clang’s functionality :)
0 notes
whatwillilearntoday · 8 years ago
Text
WinDBG for babies
If you’re just starting out with WinDBG, there are some commands you must know:
g - “go”, means to continue until the next breakpoint is hit
p - “proceed”, executes the statement that’s currently highlighted
gu - “go up”, means to step out of the current function
F9 - adds a break point: open up your source code, click on a line and hit this key
ld - “load”, load a module. To do this, you must be in a thread that uses that module
sxe - use it like this “sxe ld UnitTestDllNameHere” to break once  UnitTestDllNameHere is loaded
.sympath - shows you all the symbols that are within WinDBGs reach in an asterisk-separated list
Scenario: How I used WinDBG to debug a TAEF-based unit test written in C++
I had a test dll which contained a test I wanted to walk through with WinDBG because I was tired of using log statements. Side note: just do yourself a favor and set up WinDBG instead of adding logs, building code, testing it, changing another thing, building yet again, testing and so on with the unhealthy cycle. Anyhow. 
First, I made sure I had windbg installed and added to my System Path. Symbols next. Thankfully, at some earlier, blessed point in time, I had correctly set up the symbols so I didn’t need to bother about that part.
Then, I typed “windbg -o TestDllNameHere /name:TestNameHere”. 
-o - this flag means you want to break at each child process spawned off when this test dll is run. In a TAEF-based test, TE.exe which is the thread that kicks off the unit tests will be running first and it will spawn another thread for your TestDllNameHere dll. This is the thread you are interested in debugging.
/name - this flag can take regex so you can also do /name:*TestNa* and both TestNameHere and TestNameThere will be debugged.
Now windbg is up. But it’s broken at some weird point. 
Did 
“g” 
to continue to Te.exe. Now that it was in Te.exe, I did another 
“g” 
so that it tried to run the test. 
It broke at some point where it had a sense of what it meant to break upon loading TestDllNameHere. Then I typed:
“sxe ld TestNameDllHere”
No complaints. Whew. Then, 
“g” 
to go until TestNameDllHere was loaded. It broke into the first line of the dll. At this point, I told WinDBG to load symbols from the dll so it could understand the dll.
ld TestNameDllHere
No complaints. All was good. I proceeded to open up my source files (from the location in the repo where they were built from). Navigated to a line of interest and pressed
F9 
This highlighted the line to show that the breakpoint had been set. Did a 
bl - to list out the breakpoints I had set so far
All good. Then I opened up a view of all the local variables so I could see what each variable and pointer contained by doing:
View -> Locals
This view does all the nice casting so you can just see at a glance what is in your current context. 
Then I used navigation commands I summarized at the beginning of this post to see if the suspect line got hit or not. And if it did get hit, I analyzed the locals to see where I was seeing unexpected values.
And that’s how I used WinDBG to find my first code vs. expectation disparity :) 
1 note · View note
whatwillilearntoday · 8 years ago
Text
The Thing by Which You Think
Hello World! This is my first blog post.
To start things off: What’s the difference between Mind and Brain? Is there any?
0 notes