Friday, February 22, 2019

Convex Lens Simulation using Processing

Uses an ellipse as a convex lens to refract rays of light from a point source.

Simulating something that IRL seems so intuitive and mundane as the phenomenon of refraction in a lens was inordinately difficult. Reaching this point required multiple redos of the 'project' and three full days of wondering, scratching my head, sketching, scrapping, writing, deleting and rewriting - over and over. The main hurdles I faced are:
- Detecting accurately that a ray has hit the air-lens interface
- Figuring out whether the refracted ray should rise or drop
- The fact that vertically down is the direction of positive Y axis for computers. This probably constituted the biggest source of headache and confusion though I'm not sure if that was actually warranted.
- The fact that the Processing IDE is wanting in the most basic of features one expects of a typical IDE.

I'm NOT using Processing again for this kind of thing. Whew!
Anyway, I consider this one done:
Code

Sunday, January 20, 2019

Easy Nepali Calendar

I wanted to make something using Electron. So, I thought a Nepali calendar program for windows would be a good idea seeing how there's not many of those out there, especially ones with a 'modern feel'. The first version pulled the Nepali date from the web but I went on to use this module for the date logic instead in the second. I'm releasing only the second version here.
Here is how it looks on an empty desktop:
Download here

Tuesday, May 29, 2018

PUBG Mobile Mouse Helper

This is something I made a couple of days ago to enable me to rapid fire single shot weapons while negating recoils of most guns in PUBG Mobile's official PC version by Tencent. I first tried to achieve the same using AutoHotkey - but it, or perhaps my knowledge of it, quickly fell short. So, I decided to make something to the same effect in C. I did, but I wanted a nice GUI with the ability to modify the different parameters of the script. I thought my SimWin library could do the job but I decided trackbar controls would be better suited for the purpose of modulating the recoil parameters than some plain old textboxes, and unfortunately, I'd not implemented trackbars in SimWin yet. So, I decided .Net with P/Invoke would have to do. Two days later, here it is :


The primary goal and functionality of the program is quite simple but here are the major highlights :
  • Hold middle mouse button to auto fire single shot weapons
  • Allows modulation of four different parameters : i) Horizontal correction (dx) ii) Vertical correction (dy) iii) Sleep period between consecutive mouse moves during recoil correction* (WaitMs) iv) Delay period between consecutive shots fired (DelayMs)
  • Ability to save custom presets for different weapons along with six built-ins
  • Enter key switches between different presets when in monitoring mode for when within the game
  • Arrow keys modify the dx and dy parameters when in monitoring mode for when within the game
*The recoil correction has been implemented by basically holding and dragging the in-game cursor since the game crosshair doesn't correspond to the actual cursor position. And while the in-game cursor does correspond to the actual cursor position, it is constantly repositioned to somewhere near the center of the game window. So, a simple SetCursorPos() call doesn't do the trick (tried and failed). This is the reason mouse_event() calls have been used to simulate mouse movement in terms of x and y displacements - dx and dy - for recoil correction. Furthermore, looping through each of the dx and dy pixels without any artificially placed delays seems to be too quick for the game to register - the recoil correction stops working altogether. This is why a WaitMs delay is required.

The original C code that I experimented with is available here

Download the program here

Project @ GitHub

Note : .Net Framework 4.6.1 is required to run this program.

Update : Version 2.3 has been published on GitHub.

Friday, May 18, 2018

x64 inline hooking of ntdll functions

This is a 64-bit update to this code.
I learned a few things about 64-bit assembly and corresponding calling conventions during the writing of this fairly simple program. The code is self-explanatory and can be found here

Tuesday, January 9, 2018

Phone Monitor

I had made a basic phone monitoring program using B4A some years back just out of curiosity. I had a fairly good grasp of malware programming in Windows, so I had thought of giving my mobile phone's OS a try with it. Basic felt easy since it was the language I was most accustomed to using then, and it was Basic, for Android. The mobile OS itself was still not very mature so a lot more loopholes than now and certain things were more easily doable, not to mention the availability of third-party libraries for B4A. Anyway, I never released it; must be sitting around somewhere on my old desktop's hard disk.
The above program is not what this post is about though. This blog has seen me transform from a quick and dirty vb6 - read procedural - programmer to a relatively organized, more modular C# - say OOP - coder. I write OO programs now. I taught myself Java too, not too different from C#. So, about two weeks ago, I made up my mind about giving a new Android project a go, this time not in B4A, but in Java, the mainstream language that most Android apps are written in (that may change to Kotlin in the future, who knows), and in determining what, I figured why not make a better, updated, extended version of something cool I'd created before. The result is PhoneMonitor.
The old program was called SMSLogger because I'd built it up from exactly that, a program that would upload the target Android device's SMS messages to a specified FTP server. In its final form, it was capable of doing more than that of course, like recording phone conversations, listening for SMS based commands to do some fun stuff like vibrating the phone or more useful stuff like retrieving the phone's GPS coordinates, calling a specified number, messaging a specified number etc. So, this PhoneMonitor follows a similar development path but is more comprehensive and geared towards web panel based command and control rather than SMS'es (one of the reasons being the new security features concerning SMS write/broadcast permissions in Android KitKat and above. Life used to be easier back in the Gingerbread days.) The major functionalities include retrieving call logs, contacts, sms messages, device location (this too is harder than used to be), back and front camera pics, command to call, send an SMS, vibrate, enable Wifi - oh, and of course, it records phone conversations and uploads them to the specified FTP server.
The full source code for the app and the web panel along with some screenshots is available @ github

Tuesday, November 21, 2017

Unicode-Preeti-English Transliteration

Days ago I wrote python scripts for converting texts between Unicode, Preeti and English(transliteration). The initial motivation was to convert Unicode Nepali names in a database to their English transliterations for the ease of carrying out SQL queries. That led me to put together the first script. One or two days later, a friend of mine asked if I could write something for converting between Preeti and Unicode and so I gave it a try and consequently produced Preeti to Unicode and Unicode to Preeti scripts.
The above scripts at their core are mapping-dictionaries complemented with rules for outliers/exceptions that occur rather frequently during the conversion process. As a result, they probably aren't perfect but can certainly be refined to near that.
Now, the only thing missing is conversion from English to Unicode which I don't think is necessary because ... Google Input Tools - among other alternatives.
Oh, and while I was pushing revision commits to the Unicode to Preeti script on GitHub, I wondered if there already was a better, reliable program for it. So, I searched GitHub for any existing 'Unicode to Preeti converter', and among others, I landed upon this which is pretty good at its job.

Saturday, May 6, 2017

CSArp Netcut

I use Arcai's Netcut sometimes. It works. But sometimes, it abruptly crashes and doesn't go quite as easy as I would like it to. I found it to be a little too sluggish.
Then I thought to give SharpPcap a try, just to fool around, to see if I could capture some packets here and there, knowing that it must be such an insurmountable task to complete such a project, especially with the limited networking knowledge I have. But, one thing led to another and I had dived in too deep. On the first day, May 4, 2017, I tried using the GetIpNetTable API to get the ids of devices currently connected to my LAN. It was a tough thing for me to finally get something of some value that could accomplish some semblance of my goal. The entire day, I spent searching the internet for that one API and gluing together pieces to make it tick. And tick it did but I realised the system ARP table information it provided was little indication of all the devices of my LAN. Frustrated, I slept on it.
The next morning, I actually started fiddling with SharpPcap, it was a low level based high level API after all. I quite successfully and pretty quickly realised that capturing ARP packets with this .NET library was trivial and upon analysing numerous Debug.Print() outputs from my Visual Studio 2017's Output Window of the captured packets, and knitting them together with the information I gathered on ARP from the internet, I finally pieced together a method to produce a list of devices connected in the LAN. In short, I did it by basically sending ARP Request packets to every possible IP on a LAN that utilises the ipv4 protocol. Then, to actually perform an ARP spoofing/"cache poisoning" attack, I tried some 4-5 combinations of Requests/Response/To gateway/To target device/Broadcast/"Unicast"(targetted transmission) packets. That day, I was unable to make it work without raising alarms on the target device; for instance, when sending(Unicasting/Broadcasting) ARP packets(Request and/or Response) pretending to be sent by  the gateway device(router in my case), my desktop's ESET Smart Security 10 shouted at the screen non-stop and while it did work on my android phone, I wanted my program to work on every device, like Arcai's Netcut seemed to, so cleanly. It was yesterday.
Determined to get it right, today morning, I changed the code to send targetted ARP requests to the gateway, while pretending to be the target device. I ran it and voila! It worked perfectly. No alarm bells or warning signs. It just worked! With some cosmetic touches to the program(which took, as they always do, significant amount of time for the auxiliary function they serve) I uploaded the first version, 0, to GitHub. After that, I immediately thought of why I wanted so desperately a program like Arcai's Netcut in the first place and added some improvements/extra functionalities. And just some time ago, I published it in my GitHub repository for the program.
So.
Here it is, in its infant glory...


It may be brittle yet. But it works for me, and it's open source. So, feel free to do anything and everything with it.
Download here
GitHub @ here
PS: SharpPcap, used by this application, requires WinPCap to be installed. At the time of this writing, it can be downloaded from here