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

EventLog

So, I wanted to monitor a machine : when it’s powered on, powered off, when i log in, when i log off, when i lock my session and when i unlock it.

Using the EventLog Viewer, I can create personalized filters.
But some event aren’t loggued by default, including when I lock or unlock a session, be it directly or through the screensaver.

So first, I must activate thoses log.

If you’re lucky and have a professionnal/enterprise version (or higher) of windows, you can do it directly in
Group Policy
by going to
Computer Configuration/Windows Settings/Security Settings/Local Policies/Audit Policy
and log success/failure for
Audit Logon
Audit Logoff
Audit Other Logon/Logoff Events

If you’re not lucky and have a home version (or similar), you can:
get the events with
wevtutil gp Microsoft-Windows-Security-Auditing /ge /gm:true
activating them with
auditpol /set /category:"Logon/Logoff" /success:enable /failure:enable
or through the registry:
psexec -s -i regedit
then go to
HKLM\SECURITY\Policy\PolAdtEv
and edit the hexadecimal data of the default key:
offsets 16, 18 and 24 should have "03" to log both success (&01) and failure(&02)
a reboot is necessary

Then, you can request against thoses events, using either WMI/WQL (thanks wbemtest/wmic), or XML filters/queries for the eventlog.
With the first choice, it’s not possible/pratical to make query for some specific attributes which are in array datatype, which WQL don’t support queries against.
With the second choice, you can do it easily.

Here’s my 3 filters:
1) startup / shutdown
<QueryList>
<Query Id="0" Path="System">
<Select Path="Security">*[System[(EventID=1100 or EventID=4608)]]</Select>
<Select Path="System">*[System[(Provider[(@Name!="SNMP" and @Name!="Microsoft-Windows-UserModePowerService")]) and (EventID=12 or EventID=13 or EventID=41 or EventID=1001 or EventID=6005 or EventID=6006 or EventID=6008 or EventID=6009)]]</Select>
</Query>
</QueryList>

2) lock / unlock
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4800 or EventID=4801 or EventID=4802 or EventID=4803)]]</Select>
</Query>
</QueryList>

3) login / logoff
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=528 or EventID=529 or EventID=538 or EventID=540 or EventID=551 or EventID=672 or EventID=680 or EventID=4624 or EventID=4625 or EventID=4634 or EventID=4647 or EventID=4648 or EventID=4672 or EventID=4768 or EventID=4776 or EventID=7001 or EventID=7002)] and EventData[(Data[@Name="TargetUserName"]="sebbu" or Data[@Name="TargetUserName"]="zsbe17fr@yahoo.fr")]]</Select>
<Suppress Path="Security">*[EventData[Data[@Name="IpAddress"] = "-"]]</Suppress>
</Query>
</QueryList>

Yes, both the username and the email (for Microsoft Account) can be found, depending on the EventID.

Now I just have to click on the filtered view, and I only see the events I’m interested in.
Maybe I’ll make a GUI for it later.

Catégories
Geek

X11 Forwarding & X tools

Configuration

  1. First, you need an X server installed (outside of the scope of this article), or at least some of the libs, to be able to run the apps.
    You also need xauth and maybe xhost (in the package x11-xserver-utils)
  2. Second, you need ssh to accept X Forwarding (in /etc/ssh/sshd_config):
    X11Forwarding yes
    X11UseLocalhost yes
    X11DisplayOffset 10
  3. Third, you need a real X server to display the X apps on the client (XMing, Cygwin/X, VcXsrv, etc...)
  4. so that you can do export DISPLAY=localhost:10.0 and run X apps

Tools

  • x11-apps
    xclock, rendercheck
  • nux-tools
    unity_support_test
  • x11-utils
    xdpyinfo, xdriinfo, xvinfo, xwininfo
  • mesa-utils
    glxinfo, glxgears
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).

Catégories
Geek

single executable jar with dependencies

For my personal project oracle_sql ( which will allow me to export & import an oracle database to a .sql file ), i would have liked having an executable file ( a .jar in my case ) that doesn’t need any other files.

I tried to check the output of netbeans or eclipse, but they pass too many arguments to the java binary. Then I tried to create a manifest.mf to specify my classpath, but it doesn’t support jar inside jar. I tried to cheat using jar: syntax, but that’s a dead-end.

I finally found 2 projects to allow what I wanted :
One-Jar, which use a class loader,
and JarJar, which use bytecode transformations

I’ll have to watch how they work and choose the one I prefer.
If you have another solution, feel free to make a comment about it.

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