Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Tuesday, August 4, 2015

The scary Virtual Machine

Sorry for the cheesy thread title, but I had no idea what to put there.

But anyway, I recently came across more virtual machines, and honestly, when you get to the jist of it, they aren't all that difficult to understand nor implement.

For instance, this guy here wrote his own C compiler for the C89 standard, and made it work for his own custom virtual CPU, for which he wrote several "emulators"(emulator;virtual machine it's all the same in this context) in C, Java and finally, Javascript. This actually gave me an idea to implement some VMs in Javascript as well, I mean you can run the thing in your browser.

Now, Virtual Machines like VirtualBox, VMWare and QEMU are different, they try to emulate a whole computer with the peripherals and also takes advantage of a CPU's special virtualization options for HW virtualization, they are indeed harder to write and understand and I myself couldn't even begin to comprehend VirtualBox's code.

But we aren't interested in those(or at least I am not) right now, we just want to emulate a CPU, or even create our own, the sky is the limit.

Monday, February 2, 2015

Back to the Roots.

Initially this blog was about compiling stuff for Windows, then I turned it into a RE blog, but today I plan to go back to the roots and post some stuff about compilation.

The goal was to cross-compile MySQL from Linux x86_64 to Android, ARM-v7a. But there are a few problems here.
1.) Google's NDK offers a very slimmed-down version of GCC and they provide their own standard C library called Bionic which is missing a ton of stuff, widechar support being one of them among many missing headers.
2.) The Crystax NDK does not add these missing headers, so the only option left was to compile my own GCC with GLIBC. I did that nearly 2 years ago with crosstool-ng and have successfully compiled php like that(but not with all features).
3.) Some targets built by the CMake system have to be run, this isn't possible when cross-compiling, so you need to first build MySQL for the host, and then gather the tools you need further increasing the complexity of the task of compiling MySQL for Android.
4.) Static linking of GLIBC, this is the most important part, as it needs to be set  in the CMAKE_C_FLAGS before you build(and it takes a while)

Needless to say I managed to compile it, with default features, but I forgot to statically link GLIBC, and mysql did not run.

Sunday, September 14, 2014

I have not posted in a few days. The reason is because I was preoccupied by SecuROM, for two days straight since my last post I had been working on my dumped exe, figuring out why it crashed beyond a certain point. It took me 2 days, almost sleepless and not eating at all to figure out the problem.

It was difficult as my trace was inconclusive, it showed the main thread simply continuing execution to some invalid address. After working on it for days, I found out that my trace was being b0rked by OllyExt, a plugin for Ollydbg 2.01, so I disabled that and found my problem.

The offending code was a huge jump table, I guess at some point execution jumped to that location, but the jump table itself had unfilled addresses to pointers to the FMOD Sound System.

From then on because of my poor pointer arithmetic skills and almost no knowledge of the PE format, it was a whole day before I wrote a small tool to identify the pointers in the original exe to those in the FMOD Sound system DLL(s). This was further delayed by some unknown bug where the index of an exported function did not match the index of the name array, if it was a C unmangled exported function. All C++ mangled/decorated functions's indexes into the name array were correct.

Then I generated my own table of GetProcAddress-es to include in my stub. After that execution of the exe continued, till I stumbled on another problematic area, of some address not being correct, one that is filled by the SecuROM VM before OEP is reached.

So thats going to take some more days.

Friday, August 15, 2014

CarpVM, a Virtual Machine in C

Finally, somebody went and wrote it. Link to GitHub. This VM can be used as an obfuscation technique. I was building my own, but things got sidetracked. But this one is on another level.