0

We have a .NET application in our enterprise that we bought and would like to distribute for all employees. However, it has an undesirable function that – from our point of view – is a data leak. The creator of the application, however, does not agree and refuses to provide a configuration option to disable/remove the function from the application.

Therefore, we were contemplating if it is possible to simply modify the provided .exe file such that the menu item is rendered inaccessible (i. e., disabled, removed or simply “broken”). I know from my limited background of Macintosh programming that their program files contain “resources” where these aspects are configured, which could be edited afterwards. Is something similar possible for a .NET application on Windows? If so, how?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
ilpssun
  • 348
  • 2
  • 7
  • When you have source code, you can put this in "post-build" event in Visual Studio. If you don't have source code, but have only .exe, and developer don't obfuscate solution, you can recreate source code by reflexion. In example, you can use: dotPeak (https://www.jetbrains.com/decompiler/) p.s. most licence don't allow to recreate source code. – zchpit Jan 21 '16 at 15:18
  • But note that reverse-engineering the application as suggested above almost certainly violates your license agreement; in the US, this would render you open to civil if not criminal legal action. – David Jan 21 '16 at 15:21
  • Windows does support resource files, but there's no guarantee that a menu is implemented as a resource. For example, Windows Forms (or WinForms) apps typically generate menus and other widgets in code: the "forms designer" is really a code generator. – David Jan 21 '16 at 15:23
  • If your users are administrators on their machines, an alternate approach to modifying the original application may be to create a launcher application that hides or disables the undesired menu item by setting its window style. – cokeman19 Jan 21 '16 at 16:18
  • @zchpit I didn’t know about dotPeek – it seems pretty powerful from my first impression. Unfortunately, as I commented below, the application is digitally signed. So although dotPeek helped me find the correct spot the edit, I didn’t solve the problem in the end. – ilpssun Jan 22 '16 at 06:59
  • @cokeman19 How would I do that in a launcher? Can you give a brief example? – ilpssun Jan 22 '16 at 07:00
  • If they use config-r configutation (https://github.com/config-r) it could be possible, but I think, they don't use it. – zchpit Jan 22 '16 at 10:40

2 Answers2

0

If it's a commercial application it is probably digitally signed. (At least I would hope so.)

In which case, while you could in theory hack the application to remove the feature in question, doing so would render the signature invalid ... at which point the application would (should) no longer run.

You're probably better off trying to work with the vendor; you may be able to negotiate access to the source code so you can customize the app as you see fit.

David
  • 2,226
  • 32
  • 39
  • Yes, you’re right. I found the “resource” in question, edited it and hit a snag when the application refused to load the manipulated `.dll` because of a mismatching signature. So thanks for the advice but it seems we’re out of luck for trying on our own. – ilpssun Jan 22 '16 at 06:55
  • You can register the assembly (exe) file for verification skipping in CLR and run it modified http://blogs.msdn.com/b/securitytools/archive/2009/12/30/how-to-turn-off-strong-name-validation.aspx – Mihail Shishkov Jan 22 '16 at 20:58
0

Here is an example of the basic idea, gleaned from this SO answer. This launches Notepad then removes the File>New sub-menu item.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

static class Program
{
    // https://stackoverflow.com/a/2862623

    [STAThread]
    static void Main()
    {
        RemoveMenuItem();
    }

    [DllImport("user32.dll")]
    static extern IntPtr GetMenu(IntPtr hWnd);

    [DllImport("user32.dll")]
    static extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);

    [DllImport("user32.dll")]
    static extern bool DrawMenuBar(IntPtr hWnd);

    [DllImport("user32.dll")]
    static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);

    const uint MF_BYPOSITION = 0x400;
    const uint MF_REMOVE = 0x1000;

    public static void RemoveMenuItem()
    {
        // Start Notepad
        Process notepad = Process.Start("notepad");
        // Wait for the main window to be created
        notepad.WaitForInputIdle();
        IntPtr pFoundWindow = notepad.MainWindowHandle;
        // Get main menu
        IntPtr hMenu = GetMenu(notepad.MainWindowHandle);
        // Get the File sub menu
        IntPtr hSubMenuFile = GetSubMenu(hMenu, 0);
        // Remove the first sub menu item (New)
        RemoveMenu(hSubMenuFile, 0, (MF_BYPOSITION | MF_REMOVE));
        // Force a redraw
        DrawMenuBar(notepad.MainWindowHandle);
    }
}
Community
  • 1
  • 1
cokeman19
  • 2,405
  • 1
  • 25
  • 40