2021-01-18 13:51:29 +00:00
using System ;
2021-01-18 06:20:17 +00:00
using System.Collections.Generic ;
2021-01-18 13:51:29 +00:00
using System.Diagnostics ;
2021-01-18 06:20:17 +00:00
using System.IO ;
2021-01-18 13:51:29 +00:00
using System.Runtime.InteropServices ;
2021-01-18 06:20:17 +00:00
using System.Security.AccessControl ;
using System.Security.Principal ;
using System.Windows.Forms ;
namespace DontTouchMyFlash
{
public partial class FlashPwner : Form
{
2021-01-18 13:51:29 +00:00
2021-01-18 06:20:17 +00:00
public FlashPwner ( )
{
InitializeComponent ( ) ;
}
public byte [ ] Timestamp = new byte [ ] { 0x00 , 0x00 , 0x40 , 0x46 , 0x3E , 0x6F , 0x77 , 0x42 } ;
public byte [ ] Infintiy = new byte [ ] { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0x7F } ;
public Int64 GetPositionAfterMatch ( byte [ ] data , byte [ ] pattern )
{
for ( Int64 i = 0 ; i < data . LongLength - pattern . LongLength ; i + + )
{
bool match = true ;
for ( Int64 k = 0 ; k < pattern . LongLength ; k + + )
{
if ( data [ i + k ] ! = pattern [ k ] )
{
match = false ;
break ;
}
}
if ( match )
{
return i ;
}
}
return - 1 ;
}
public void TakeOwn ( string filepath )
{
FileSecurity fileS = File . GetAccessControl ( filepath ) ;
2021-01-18 12:33:58 +00:00
SecurityIdentifier cu = WindowsIdentity . GetCurrent ( ) . User ;
SecurityIdentifier everyone = new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ;
2021-01-18 06:20:17 +00:00
2021-01-18 13:51:29 +00:00
try
{
Privileges . EnablePrivilege ( SecurityEntity . SE_TAKE_OWNERSHIP_NAME ) ;
}
catch ( Exception )
{
console . AppendText ( "Failed to get SeTakeOwnershipPrivledge\r\n" ) ;
}
2021-01-18 12:33:58 +00:00
fileS . SetOwner ( cu ) ;
2021-01-18 13:51:29 +00:00
File . SetAccessControl ( filepath , fileS ) ;
2021-01-18 12:33:58 +00:00
fileS . SetAccessRuleProtection ( false , false ) ;
fileS . RemoveAccessRuleAll ( new FileSystemAccessRule ( everyone , FileSystemRights . FullControl , AccessControlType . Deny ) ) ;
fileS . RemoveAccessRuleAll ( new FileSystemAccessRule ( cu , FileSystemRights . FullControl , AccessControlType . Deny ) ) ;
fileS . SetAccessRule ( new FileSystemAccessRule ( everyone , FileSystemRights . FullControl , AccessControlType . Allow ) ) ;
2021-01-18 13:51:29 +00:00
fileS . SetAccessRule ( new FileSystemAccessRule ( cu , FileSystemRights . FullControl , AccessControlType . Allow ) ) ;
2021-01-18 12:33:58 +00:00
File . SetAccessControl ( filepath , fileS ) ;
File . SetAttributes ( filepath , FileAttributes . Normal ) ;
2021-01-18 13:51:29 +00:00
2021-01-18 06:20:17 +00:00
}
2021-01-18 12:33:58 +00:00
2021-01-18 06:20:17 +00:00
public bool CheckFileAndAdd ( string filepath )
{
try
{
byte [ ] fileData = File . ReadAllBytes ( filepath ) ;
Int64 timestampLocation = GetPositionAfterMatch ( fileData , Timestamp ) ;
if ( timestampLocation ! = - 1 )
{
flashExes . Items . Add ( filepath ) ;
console . AppendText ( "Found killswitch timestamp in " + Path . GetFileName ( filepath ) + " @ 0x" + timestampLocation . ToString ( "X" ) + "\r\n" ) ;
return true ;
}
return false ;
}
catch ( Exception )
{
return false ;
}
}
public void ScanFolder ( string path )
{
if ( Directory . Exists ( path ) )
{
String [ ] fileList = Directory . GetFiles ( path , "*" , SearchOption . AllDirectories ) ;
foreach ( string file in fileList )
{
2021-01-18 08:03:16 +00:00
if ( file . ToLower ( ) . EndsWith ( ".ocx" ) | | file . ToLower ( ) . EndsWith ( ".dll" ) | | file . ToLower ( ) . EndsWith ( ".exe" ) )
2021-01-18 06:20:17 +00:00
{
CheckFileAndAdd ( file ) ;
}
}
}
}
2021-01-26 10:20:37 +00:00
public bool PatchExe ( string filepath )
2021-01-18 06:20:17 +00:00
{
try
{
2021-01-26 10:20:37 +00:00
Process [ ] lockingProcesses = FileUtil . WhoIsLocking ( filepath ) . ToArray ( ) ;
foreach ( Process proc in lockingProcesses )
{
DialogResult res = MessageBox . Show ( "Flash is currently in use by (" + proc . Id . ToString ( ) + ")" + proc . ProcessName + "\nEnd Process?" , "File in use :/" , MessageBoxButtons . YesNo , MessageBoxIcon . Information ) ;
if ( res = = DialogResult . Yes )
proc . Kill ( ) ; // DIE HHAHA
else
return true ;
}
2021-01-18 06:20:17 +00:00
byte [ ] fileData = File . ReadAllBytes ( filepath ) ;
Int64 timestampLocation = GetPositionAfterMatch ( fileData , Timestamp ) ;
2021-01-18 13:51:29 +00:00
2021-01-18 06:20:17 +00:00
TakeOwn ( filepath ) ;
FileStream fs = File . OpenWrite ( filepath ) ;
fs . Seek ( timestampLocation , SeekOrigin . Begin ) ;
fs . Write ( Infintiy , 0x00 , Infintiy . Length ) ;
fs . Close ( ) ;
2021-01-18 13:51:29 +00:00
2021-01-18 06:20:17 +00:00
console . AppendText ( "Patched: " + Path . GetFileName ( filepath ) + ".\r\n" ) ;
flashExes . Items . Remove ( filepath ) ;
Application . DoEvents ( ) ;
progressBar . Increment ( 1 ) ;
2021-01-26 10:20:37 +00:00
return false ;
2021-01-18 06:20:17 +00:00
}
catch ( Exception e )
{
MessageBox . Show ( e . Message , "ERROR" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
2021-01-26 10:20:37 +00:00
return true ;
2021-01-18 06:20:17 +00:00
}
}
public void LocateExes ( )
{
string windir = Environment . GetEnvironmentVariable ( "WINDIR" ) ;
string localappdata = Environment . GetEnvironmentVariable ( "LOCALAPPDATA" ) ;
string flashPath = Path . Combine ( windir , "System32" , "Macromed" , "Flash" ) ;
ScanFolder ( flashPath ) ;
flashPath = Path . Combine ( windir , "SysWOW64" , "Macromed" , "Flash" ) ;
ScanFolder ( flashPath ) ;
flashPath = Path . Combine ( localappdata , "Google" , "Chrome" , "User Data" , "PepperFlash" ) ;
ScanFolder ( flashPath ) ;
2021-01-18 08:03:16 +00:00
flashPath = Path . Combine ( localappdata , "Microsoft" , "Edge" , "User Data" , "PepperFlash" ) ;
ScanFolder ( flashPath ) ;
2021-01-18 06:20:17 +00:00
}
private void FlashPwner_Load ( object sender , EventArgs e )
{
LocateExes ( ) ;
}
private void defuseBomb_Click ( object sender , EventArgs e )
{
2021-01-26 10:21:49 +00:00
defuseBomb . Enabled = false ;
2021-01-18 06:20:17 +00:00
if ( flashExes . Items . Count > 0 )
{
progressBar . Maximum = flashExes . Items . Count ;
List < string > copyFlashExes = new List < string > ( ) ;
foreach ( string flashExe in flashExes . Items )
{
copyFlashExes . Add ( flashExe ) ;
}
2021-01-26 10:20:37 +00:00
bool errored = false ;
2021-01-18 06:20:17 +00:00
foreach ( string flashExe in copyFlashExes )
{
2021-01-26 10:20:37 +00:00
errored = PatchExe ( flashExe ) ;
2021-01-18 06:20:17 +00:00
}
2021-01-26 10:20:37 +00:00
if ( ! errored )
MessageBox . Show ( "Patched! Your flash should work again!!!" , "SUCCESS" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2021-01-18 06:20:17 +00:00
}
else
{
MessageBox . Show ( "No files to patch!" , "File Error" , MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
}
2021-01-26 10:21:49 +00:00
defuseBomb . Enabled = true ;
2021-01-18 06:20:17 +00:00
}
private void addFile_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
2021-01-26 10:20:37 +00:00
ofd . Title = "Flash Executable" ;
ofd . Filter = "PE Executables (*.exe, *.ocx, *.dll)|*.dll;*.exe;*.ocx|ELF Executables (*.so, *.elf, *.dylib)|*.so;*.elf;*.dylib" ;
DialogResult res = ofd . ShowDialog ( ) ;
if ( res = = DialogResult . OK )
2021-01-18 06:20:17 +00:00
{
2021-01-26 10:20:37 +00:00
if ( ! CheckFileAndAdd ( ofd . FileName ) )
{
MessageBox . Show ( "File selected does not contain the killswitch timestamp, cannot patch!" , "Timestamp Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2021-01-18 06:20:17 +00:00
}
2021-01-26 10:20:37 +00:00
2021-01-18 06:20:17 +00:00
}
2021-02-12 08:03:25 +00:00
private void patchProjetor ( string path )
{
byte [ ] projBytes = File . ReadAllBytes ( path ) ;
byte [ ] getUrlPattern = new byte [ ] { 0xF4 , 0xE8 , 0xBE , 0xFE , 0xFF , 0xFF } ;
2021-02-12 08:11:30 +00:00
byte [ ] nops = new byte [ ] { 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 } ;
2021-02-12 08:03:25 +00:00
Int64 getUrlLocation = GetPositionAfterMatch ( projBytes , getUrlPattern ) ;
2021-02-12 08:11:30 +00:00
if ( getUrlLocation = = - 1 )
return ;
2021-02-12 08:03:25 +00:00
FileStream fs = File . OpenWrite ( path ) ;
fs . Seek ( getUrlLocation + 1 , SeekOrigin . Begin ) ;
2021-02-12 08:11:30 +00:00
fs . Write ( nops , 0x00 , nops . Length ) ;
2021-02-12 08:03:25 +00:00
fs . Close ( ) ;
}
2021-01-18 06:20:17 +00:00
private void deleteFile_Click ( object sender , EventArgs e )
{
2021-01-26 10:20:37 +00:00
if ( flashExes . SelectedIndex > = 0 )
flashExes . Items . RemoveAt ( flashExes . SelectedIndex ) ;
2021-01-18 06:20:17 +00:00
}
2021-02-12 08:03:25 +00:00
private void projectorPatch_Click ( object sender , EventArgs e )
{
MessageBox . Show ( "This is a patch for the standalone \"projector\" program from adobe, it stops it opening your browser whenever a game tries to call javascript with getURL()\n\nNote: the projector DOES NOT HAVE A KILLSWITCH/TIMEBOMB and this is not needed to use the Flash Projector." , "Projector" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Title = "Flash Projector" ;
ofd . Filter = "PE Executables (*.exe)|*.exe;|ELF Executables (*.elf)|*.elf" ;
DialogResult res = ofd . ShowDialog ( ) ;
if ( res = = DialogResult . OK )
{
patchProjetor ( ofd . FileName ) ;
MessageBox . Show ( "Patched! Projector should no longer open the browser!!!" , "SUCCESS" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
}
2021-01-18 06:20:17 +00:00
}
}