Catégories
Geek Hacking

friend class in PHP

SO, I wanted to use something like friend class from C++ in PHP.

I found PHP :: Request #34044 :: Support for friend classes, which worked for a simple example, but not for bigger ones, so I extended it.

First, I needed to extend it to work with methods and not just attributes, then with inherited classes, because I needed it in several classes and didn’t wanted to copy/paste the same code, so I started with some modification :

a) first implementation of the __call() magic method

+/- a new method, based on the one from the Feature Request

public function __call($name, $arguments)
{
$trace = debug_backtrace();
if(isset($trace[0]['class']) && in_array($trace[0]['class'], $this->__friends)) {
return call_user_func_array(array($this, $name), $this->arguments);
}
}

but it only worked for the same class, not with inherited ones. Code was copy/pasted for the __callStatic() magic method, with simple $this to get_class($his) change.

b) to access private attributes when not in the same class:

+/- inside the if of the __get() magic method

$rc=new ReflectionClass($this);
$prop=$rc->getProperty($key);
$prop->setAccessible(true);
$res=$prop->getValue($this);
return $res;

so now, it works for *THE* direct inherited classes, but not their own inherited classes. Code was copy/pasted for the __set() magic method, with simple getValue to setValue change.

c) to call private methods when not in the same class

+/- inside the if of the __call() magic method

$rc=new ReflectionClass($this);
$meth=$rc->getMethod($name);
$meth->setAccessible(true);
$res=$meth->invokeArgs($this, $arguments);
return $res;

Code was copy/pasted for the __callStatic() magic method, with simple $this to NULL change.

d) allow inherited classes to work

+/- in all __get __set __call __callStatic methods, until the if, included

$trace = debug_backtrace();
$frame=0;
while($frame<count($trace) && $trace[$frame]['class']==__CLASS__) $frame++;
if(isset($trace[$frame]['class']) && in_array($trace[$frame]['class'], $this->__friends)) {

Finally, it works when a private method access a private attribute & so forth, from friend classes only.

Code should be compatible with PHP 5+, preferably 5.1+. __callStatic was added in 5.3.

Catégories
Geek Hacking

How to debug .NET binaries with Visual Studio without the sources

First, we should configure Visual Studio as per [Reference Source Setup].

Second, we should add the symbol servers specified by [Symbol Source], adding « http://localhost:33417/ » in the « other symbol servers with sources » place, as per [JetBrains DotPeek]

Third, we can download the (free) DotPeek decompiler, and try to generate PDB for our binaries (or dll/others).

Fourth, if we get an error such as « Binary was not built with debug information.« , we can disassemble and reassembling it with ildasm and ilasm, as per [Debug and Conquer].

Done 🙂

Catégories
Geek Hacking

Group Policy Editor (gpedit) and Local Security Policy Editor (secpol) in Windows Home Edition

One of the major restriction windows home edition has, for me, is the lack of the 2 tools gpedit and secpol.

But thoses tools can easily be added, either by just copying a few files from a Pro or Enterprise version of Windows, which most do, or by a simple trick :

http://pastebin.com/Bj56B0sX

@echo off
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt
for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"C:\Windows\servicing\Packages\%%i"
pause

Afterwards, a few steps of sfc /scannow and dism /online /Cleanup-Image /scanhealth, dism /online /Cleanup-Image /checkhealth, dism /online /Cleanup-Image /restorehealth, possibly with a /source (global options), can check you have the right version, or possibly even « fix » it by replacing it with the correct version.

Merging several *.swm files into a .wim is done with
DISM /Export-Image /SWMFile:install*.swm /Sourceindex:1 /DestinationImageFile:installwim.wim(help), which is usefull for some installation support like the OEM ones.

Catégories
Geek Hacking

Firefox history

So, I wanted to block the history of firefox to forbid the user to empty it.

  1. I had to remove Tools > Clear Recent History by putting the following in the profile’s userChrome.css file :
    #sanitizeItem { display: none !important; }
  2. I had to remove Tools > Privacy > History :
    #historyGroup { display: none !important; }
  3. I had to remove the details in Clear Private Data :
    #detailsExpanderWrapper { display: none !important; }
    #detailsExpanderWrapper + #itemList { display: none !important; }
  4. I had to remove the CTRL+SHIFT+DELETE shortcut to Clear Private Data by installing keyconfig
  5. I had to specify the items i wanted to delete in about:config between :
    privacy.item.cache
    privacy.item.cookies
    privacy.item.downloads
    privacy.item.formdata
    privacy.item.history
    privacy.item.offlineApps
    privacy.item.passwords
    privacy.item.sessions
    privacy.item.siteprefs
    privacy.cpd.cache
    privacy.cpd.cookies
    privacy.cpd.downloads
    privacy.cpd.extensions-dta
    privacy.cpd.formdata
    privacy.cpd.history
    privacy.cpd.offlineApps
    privacy.cpd.passwords
    privacy.cpd.sessions
    privacy.cpd.siteSettings
    privacy.clearOnShutdown.cache
    privacy.clearOnShutdown.cookies
    privacy.clearOnShutdown.downloads
    privacy.clearOnShutdown.extensions-dta
    privacy.clearOnShutdown.formdata
    privacy.clearOnShutdown.history
    privacy.clearOnShutdown.offlineApps
    privacy.clearOnShutdown.passwords
    privacy.clearOnShutdown.sessions
    privacy.clearOnShutdown.siteSettings
    privacy.sanitize.sanitizeOnShutdown
    privacy.donottrackheader.enabled

PS : DOM Inspector was very usefull to know what to add in userChrome.css

Catégories
Geek Hacking

Opera

So, it’s been a long time since i used Opera, and I just installed 12.16 (last version with Presto engine), got annoyed by accidental tab stacking, so I used a patch [backup] (I used TinyPerl for it since I didn’t wanted to install perl just for that).

As the last time I used Opera, it works great and supports very well insane number of tabs, including tabs with hundreds/thousands of wallpaper-sized images (last time I used it, it was the ONLY browser supporting that, maybe things have changed since).

Concevoir un site comme celui-ci avec WordPress.com
Commencer