Skip to content

Commit 11ff58f

Browse files
committed
1.0 of Bitness, included old MouseSpeed repo.
1 parent 31be96a commit 11ff58f

File tree

13 files changed

+486
-0
lines changed

13 files changed

+486
-0
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

Bitness/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

Bitness/Bitness.csproj

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{26DC4DFB-F0B0-421A-AAAD-CA225C762AFF}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Bitness</RootNamespace>
11+
<AssemblyName>Bitness</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
54+
Other similar extension points exist, see Microsoft.Common.targets.
55+
<Target Name="BeforeBuild">
56+
</Target>
57+
<Target Name="AfterBuild">
58+
</Target>
59+
-->
60+
</Project>

Bitness/Program.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace Bitness
7+
{
8+
class Program
9+
{
10+
11+
/// <summary>
12+
/// Source: https://docs.microsoft.com/en-gb/windows/desktop/debug/pe-format
13+
/// </summary>
14+
private static Dictionary<Int32, string> MachineType = new Dictionary<Int32, string>()
15+
{
16+
{0x0000, "The contents of this field are assumed to be applicable to any machine type"},
17+
{0x01d3, "Matsushita AM33"},
18+
{0x8664, "x64"},
19+
{0x01c0, "ARM little endian"},
20+
{0xaa64, "ARM64 little endian"},
21+
{0x01c4, "ARM Thumb-2 little endian"},
22+
{0x0ebc, "EFI byte code"},
23+
{0x014c, "Intel 386 or later processors and compatible processors"},
24+
{0x0200, "Intel Itanium processor family"},
25+
{0x9041, "Mitsubishi M32R little endian"},
26+
{0x0266, "MIPS16"},
27+
{0x0366, "MIPS with FPU"},
28+
{0x0466, "MIPS16 with FPU"},
29+
{0x01f0, "Power PC little endian"},
30+
{0x01f1, "Power PC with floating point support"},
31+
{0x0166, "MIPS little endian"},
32+
{0x5032, "RISC-V 32-bit address space"},
33+
{0x5064, "RISC-V 64-bit address space"},
34+
{0x5128, "RISC-V 128-bit address space"},
35+
{0x01a2, "Hitachi SH3"},
36+
{0x01a3, "Hitachi SH3 DSP"},
37+
{0x01a6, "Hitachi SH4"},
38+
{0x01a8, "Hitachi SH5"},
39+
{0x01c2, "Thumb"},
40+
{0x0169, "MIPS little-endian WCE v2"}
41+
};
42+
43+
static void Main(string[] args)
44+
{
45+
// Initial checks.
46+
if (args.Length != 1) { Environment.Exit(0); } // Wrong args (probably none). Just get out of here.
47+
if (!File.Exists(args[0])) { Environment.Exit(2); } // File not found
48+
49+
// File exists. Get PE offset from position 0x3c. FileShare.ReadWrite means we can read the file even if it's in use.
50+
var Stream = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
51+
byte[] PeOffset = new byte[2];
52+
Stream.Seek(0x3c, SeekOrigin.Begin);
53+
Stream.Read(PeOffset, 0, 2);
54+
55+
// Jump to offset specified in MS-DOS stub and read the PE signature.
56+
Stream.Seek(PeOffset[0] | PeOffset[1] << 8, SeekOrigin.Begin);
57+
byte[] Values = new byte[4];
58+
Stream.Read(Values, 0, 4);
59+
60+
// For sanity's sake, make sure we've got an actual PE signature - "P E NULL NULL"?
61+
if (Values.SequenceEqual(new byte[] { 0x50, 0x45, 0x00, 0x00 }))
62+
{
63+
// Machine type is the next 2 bytes after the signature.
64+
Stream.Read(Values, 0, 2);
65+
Int32 TypeId = Values[0] | Values[1] << 8;
66+
string TypeName;
67+
if (MachineType.TryGetValue(TypeId, out TypeName))
68+
{
69+
Console.WriteLine("This assembly is compiled for {0}.", TypeName);
70+
}
71+
else
72+
{
73+
Console.WriteLine("Machine type could not be determined for this assembly.");
74+
}
75+
}
76+
else
77+
{
78+
Console.WriteLine("Machine type could not be determined for this assembly.");
79+
}
80+
Console.WriteLine("Press any key to exit.");
81+
Console.ReadKey();
82+
}
83+
}
84+
}

Bitness/Properties/AssemblyInfo.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Bitness")]
9+
[assembly: AssemblyDescription("Determine machine type for a Windows assembly.")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Bitness")]
13+
[assembly: AssemblyCopyright("Copyright © 2019 Daniel Price and contributors")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("26dc4dfb-f0b0-421a-aaad-ca225c762aff")]
24+
25+
[assembly: AssemblyVersion("1.0.*")]

MouseSpeed/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
5+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
6+
</configuration>

MouseSpeed/MouseOptions.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace MouseSpeed
5+
{
6+
public class MouseOptions
7+
{
8+
9+
/// <summary>
10+
/// Use System Parameters Info from User32 to get the current mouse speed.
11+
/// </summary>
12+
/// <returns>Current mouse speed.</returns>
13+
public static int GetMouseSpeed()
14+
{
15+
IntPtr Ptr;
16+
Ptr = Marshal.AllocCoTaskMem(4);
17+
SPI.SystemParametersInfo(SPI.SPI_GETMOUSESPEED, 0, Ptr, 0);
18+
int Speed = Marshal.ReadInt32(Ptr);
19+
Marshal.FreeCoTaskMem(Ptr);
20+
21+
return Speed;
22+
}
23+
24+
/// <summary>
25+
/// Use System Parameters Info to set the mouse speed to a new value.
26+
/// </summary>
27+
/// <param name="speed">Value to set the mouse speed to. Accepts integers from 1 to 20.</param>
28+
/// <returns>True if speed was changed successfully.</returns>
29+
public static bool SetMouseSpeed(int speed)
30+
{
31+
// Range of values allowed by Windows is 1 to 20.
32+
if (speed < 1 || speed > 20)
33+
{
34+
throw new ArgumentOutOfRangeException("Valid speeds are integer values from 1 to 20.");
35+
}
36+
37+
IntPtr ptr = new IntPtr(speed);
38+
return SPI.SystemParametersInfo(SPI.SPI_SETMOUSESPEED, 0, ptr, SPI.SPIF_SENDWININICHANGE);
39+
}
40+
}
41+
}
42+

MouseSpeed/MouseSpeed.csproj

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{AC97B715-0D18-4C7E-A991-1F53C2CDF921}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>MouseSpeed</RootNamespace>
10+
<AssemblyName>MouseSpeed</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>false</Deterministic>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
37+
<Prefer32Bit>true</Prefer32Bit>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Compile Include="MouseOptions.cs" />
41+
<Compile Include="Program.cs" />
42+
<Compile Include="Properties\AssemblyInfo.cs" />
43+
<Compile Include="SPI.cs" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<None Include="App.config" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
</Project>

MouseSpeed/Program.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
3+
namespace MouseSpeed
4+
{
5+
partial class Program
6+
{
7+
static unsafe void Main(string[] args)
8+
{
9+
int NewSpeed;
10+
11+
// A single cmd line argument? Set speed and exit if it's an integer.
12+
if (args.Length == 1 && int.TryParse(args[0], out NewSpeed))
13+
{
14+
if (MouseOptions.SetMouseSpeed(NewSpeed))
15+
{
16+
Console.WriteLine("Mouse speed changed to {0}", NewSpeed);
17+
Environment.Exit(0);
18+
}
19+
}
20+
21+
// Otherwise, tell the user the existing speed and prompt for a new one.
22+
Console.WriteLine("Mouse speed is currently set to {0}.", MouseOptions.GetMouseSpeed());
23+
Console.WriteLine("Enter a new speed [1..20] to set the speed, or any other value to exit.");
24+
string Entry = Console.ReadLine();
25+
if (int.TryParse(Entry, out NewSpeed))
26+
{
27+
if (NewSpeed > 0 && NewSpeed < 21)
28+
{
29+
bool Success = MouseOptions.SetMouseSpeed(NewSpeed);
30+
if (Success)
31+
{
32+
Console.WriteLine("Speed changed to {0}", NewSpeed);
33+
}
34+
else
35+
{
36+
Console.WriteLine("Unable to set speed.");
37+
}
38+
Console.WriteLine("Press any key to exit.");
39+
Console.ReadKey();
40+
}
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)