.Net on x64 menu

User Tag List

Thread: .Net on x64

Results 1 to 5 of 5
  1. #1
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .Net on x64

    Hopefully this will help some folks.

    By default, .Net assemblies are compiled in what is known as "platform neutral" fashion. This means that the assembly should run on an x86 machine or an x64 (64 bit) machine equally well. When you actually run the "platform neutral" process (assembly), the CLR (.Net runtime) chooses the "correct" architecture to bind to based upon your current architecture. Usually, this is harmless (and, indeed, beneficial) behavior, since it means you really don't need to know what platform you're on.

    However, whenever you're doing p/invoke, things get more complicated, because the native OS is NOT architecture-neutral. For instance, while there's a 64 bit version of GetThreadContext() there is NO 64 bit port of the function GetThreadSelectorEntry(). Per MSDN: "GetThreadSelectorEntry is only functional on x86-based systems. For systems that are not x86-based, the function returns FALSE." What this means to you is that if you run an architecturally-neutral .Net assembly that p/invokes to GetThreadSelectorEntry() (critical for the "correct" way to get the fs segment base, which in turn is critical for WoW hacking) on x64, it will always fail and may leave you scratching your head.

    There are two ways to fix this. If you control the source code (you DO control the source code, right?), you can just tweak the project target for your .Net project. If you're using the full version of VS, you can change targets in the project properties. On VC# Express, you have to tweak the csproj properties manually. Open up the .csproj file, and look for a block of XML that looks like this:

    Code:
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    (this is your "Debug" target for "AnyCPU" -- note that "AnyCPU" in this case is just for show; it doesn't control the compilation settings; you can change it to x86 if you'd like, though).

    At the end of this xml block (IE, before the closing "</PropertyGroup>"), add:

    Code:
    <PlatformTarget>x86</PlatformTarget>
    Do this for both the "Release" and "Debug" targets, and reload your project. Then when you build, you'll be creating an architecture-specific (x86) assembly. Now things like GetThreadSelectorEntry() should start working properly again, and you no longer have to worry about pointer widths, and so on.

    Another option, if you have a bit of compiled .Net code that is an .exe, is just to run the platform neutral ("AnyCPU") assembly in an x86 wrapper. This will force the CLR to load the AnyCPU assembly as x86.

    Note that this doesn't actually require .Net. If you wanted to write a C/C++ app that was bound to x86, and use it to shell execute your .Net assembly, that would work too (and be more generally applicable). However, CreateProcess is annoying, so here's the .Net version.

    FWIW, I use this to launch IronPython (a Python interpreter that's natively bound to .Net) as a 32-bit process for teh WoW hacking, without having to build separate architecture-bound versions of ipy.exe. Works a treat...

    To do this, you'll need to compile a small .Net exe (as x86 -- see above!), and then when you launch the AnyCPU target, launch it through this wrapper exe. Instead of MyApp.exe, do RunAs32Bit.exe MyApp.exe.

    Here's the source code to RunAs32Bit.exe. Remember, you MUST compile this as x86-targeted code for it to be of any use. See the above instructions for how to do this! The benefit of this method is you only have to do it once. The main drawback is that your target has to be an .exe.

    Code:
    using System;
    using System.IO;
    
    namespace RunAs32Bit
    {
        class Program
        {
            static void ExitUsage(int exitCode)
            {
                Console.WriteLine("\nUSAGE: RunAs32Bit <dot_net_assemblyname>");
                Console.WriteLine("       Attempts to run the platform-neutral .Net assembly EXE");
                Console.WriteLine("       inside a 32-bit wrapper process (thus forcing the wrapped");
                Console.WriteLine("       assembly to be 32 bits.)  USE WITH CARE!\n");
    
                Environment.Exit(exitCode);
            }
    
            static void Main(string[] args)
            {
                if (args.Length == 0)
                {
                    ExitUsage(1);
                }
                else
                {
                    string fileName = args[0];
                    if (!File.Exists(fileName))
                    {
                        Console.WriteLine("Could not find file \"{0}\" fileName.", fileName);
                        ExitUsage(2);
                    }
    
                    string fullPath = Path.GetFullPath(fileName);
                    string containingFolder = Path.GetDirectoryName(fullPath);
                    if (String.IsNullOrEmpty(containingFolder))
                    {
                        containingFolder = Path.GetPathRoot(fullPath);
                    }
    
                    AppDomainSetup setup = new AppDomainSetup();
                    setup.ApplicationBase = containingFolder;
                    setup.PrivateBinPath = containingFolder;
    
                    AppDomain newAD = AppDomain.CreateDomain("WrapperDomain", null, setup);
    
                    Console.WriteLine("-- Executing {0} as 32-bit wrapped assembly...", fullPath);
                    newAD.ExecuteAssembly(fullPath);
                }
            }
        }
    }
    The moral of this story is that just because .Net abstracts you away from the "metal" (the actual processor achitecture), that doesn't mean it's always a good thing.

    .Net on x64
  2. #2
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of editing the project files, VS allows you to set the preferred architecture straight from the IDE. (As well as a slew of other things.)

    Just check the properties for the project/solution.

  3. #3
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sadly, the Express edition doesn't let you manually choose any target besides "AnyCPU"... one of the lovely little limitations built in by Microsoft to point you towards the full version.

    /platform (Specify Output Platform) (C#)

    Note /platform is not available in the development environment in Visual C# Express.

    For information on how to set this compiler option programmatically, see PlatformTarget.

  4. #4
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another reason why I don't use VS Express.

    Just be like the rest of the internet population, pirate it.

  5. #5
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's odd... I used to work on the Visual Studio team. Maybe it's some misplaced sense of loyalty?

    But mostly I use Express because it does almost everything that the full version does, and it's waaaaaaaaaaaay less bloated. There are a few annoyances, tho...

Similar Threads

  1. hijack net-op teacher
    By WoWLegend in forum Community Chat
    Replies: 9
    Last Post: 03-08-2007, 03:15 PM
  2. Wowhints.net guide
    By warlord251 in forum World of Warcraft General
    Replies: 1
    Last Post: 01-30-2007, 11:25 AM
  3. BEWARE of KEYLOGGERS on WORLDOFWAR.NET TEMPORARILY!
    By agrestic in forum World of Warcraft General
    Replies: 4
    Last Post: 12-22-2006, 03:00 AM
  4. about "worldofwarcraftgoldhack.net"
    By KuRIoS in forum World of Warcraft General
    Replies: 6
    Last Post: 12-17-2006, 12:09 AM
  5. Anyone playing Starcraft Broodwar battle net.?
    By Datonking in forum Gaming Chat
    Replies: 7
    Last Post: 09-13-2006, 08:18 AM
All times are GMT -5. The time now is 11:44 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search