SourceFormatX

Overview

Features

Why Use It

Formatting Show

Integration

Screenshots

Documentation

FAQs & Tips

Update History

Award Gallery

Testimonials

License Policy

CodeMorph

CodeToHtml

C/C++ Source Code Obfuscation Show


SourceFormatX is not only the multi-language code formatter but also a code obfuscator that can obfuscate your C and C++ source code for the purposes of source code security and intellectual property protection.

C/C++ Java C# Delphi (Pascal)
PHP JSP JavaScript HTML Components
CORBA IDL


  C/C++ Source Code Obfuscation Examples:     Example 1   |   Example 2   |   Example 3

The purpose of this C code obfuscating sample is to show the power of SourceFormatX C/C++ Code Formatter's syntax parse engine.

  /* Before Code Obfuscating */

  #include "stdafx.h"
  #include "DirectSound.h"

  #ifndef DSBLOCK_ENTIREBUFFER
    #define DSBLOCK_ENTIREBUFFER 0x00000002
  #endif

  #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #define new DEBUG_NEW
  #endif

  BOOL CDirectSound::CreateSoundBuffer(WAVEFORMATEX *pcmwf)
  {
    DSBUFFERDESC dsbdesc;

    memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
    dsbdesc.dwSize = sizeof(DSBUFFERDESC);
    dsbdesc.dwFlags = DSBCAPS_STATIC;
    dsbdesc.dwBufferBytes = m_dwTheSound;
    dsbdesc.lpwfxFormat = pcmwf;
    HRESULT hRes;
    if (DS_OK != (hRes = m_lpDirectSound->CreateSoundBuffer(&dsbdesc, &m_pDsb, 0)))
    {
      DSError(hRes);
      m_pDsb = 0;
      return FALSE;
    }
    return TRUE;
  }

  BOOL CDirectSound::SetSoundData(void *pSoundData, DWORD dwSoundSize)
  {
    LPVOID lpvPtr1;
    DWORD dwBytes1;
    HRESULT hr = m_pDsb->Lock(0, 0, &lpvPtr1, &dwBytes1, 0, 0,
                              DSBLOCK_ENTIREBUFFER);
    if (DSERR_BUFFERLOST == hr)
    {
      m_pDsb->Restore();
      hr = m_pDsb->Lock(0, 0, &lpvPtr1, &dwBytes1, 0, 0, DSBLOCK_ENTIREBUFFER);
    }
    if (DS_OK == hr)
    {
      ::CopyMemory(lpvPtr1, pSoundData, dwBytes1);
      hr = m_pDsb->Unlock(lpvPtr1, dwBytes1, 0, 0);
      if (DS_OK == hr)
        return TRUE;
    }
    return FALSE;
  }

  void CDirectSound::Play(DWORD dwStartPosition, BOOL bLoop)
  {
    if (!IsValid() || !IsEnabled())
      return;

    if (dwStartPosition > m_dwTheSound)
      dwStartPosition = m_dwTheSound;
    m_pDsb->SetCurrentPosition(dwStartPosition);
    if (DSERR_BUFFERLOST == m_pDsb->Play(0, 0, bLoop ? DSBPLAY_LOOPING : 0))
    {
      SetSoundData(m_pTheSound, m_dwTheSound);
      m_pDsb->Play(0, 0, bLoop ? DSBPLAY_LOOPING : 0);
    }
  }

  void CDirectSound::Stop()
  {
    if (IsValid())
      m_pDsb->Stop();
  }

  void CDirectSound::Pause()
  {
    Stop();
  }

  void CDirectSound::Continue()
  {
    if (IsValid())
    {
      DWORD dwPlayCursor, dwWriteCursor;
      m_pDsb->GetCurrentPosition(&dwPlayCursor, &dwWriteCursor);
      Play(dwPlayCursor);
    }
  }

  BOOL CDirectSound::IsValid()const
  {
    return (m_lpDirectSound && m_pDsb && m_pTheSound && m_dwTheSound) ? TRUE : FALSE;
  }


  /* After Code Obfuscating */

  #include "stdafx.h"
  #include "DirectSound.h"
  #ifndef DSBLOCK_ENTIREBUFFER
  #define DSBLOCK_ENTIREBUFFER 0x00000002
  #endif
  #ifdef _DEBUG
  #undef THIS_FILE
  static char THIS_FILE[]=__FILE__;
  #define new DEBUG_NEW
  #endif
  BOOL CDirectSound::CreateSoundBuffer(WAVEFORMATEX*pcmwf){DSBUFFERDESC dsbdesc;
  memset(&dsbdesc,0,sizeof(DSBUFFERDESC));dsbdesc.dwSize=sizeof(DSBUFFERDESC);
  dsbdesc.dwFlags=DSBCAPS_STATIC;dsbdesc.dwBufferBytes=m_dwTheSound;
  dsbdesc.lpwfxFormat=pcmwf;HRESULT hRes;if(DS_OK!=(hRes=m_lpDirectSound->
  CreateSoundBuffer(&dsbdesc,&m_pDsb,0))){DSError(hRes);m_pDsb=0;return FALSE;}
  return TRUE;}BOOL CDirectSound::SetSoundData(void*pSoundData,DWORD dwSoundSize)
  {LPVOID lpvPtr1;DWORD dwBytes1;HRESULT hr=m_pDsb->Lock(0,0,&lpvPtr1,&dwBytes1,0
  ,0,DSBLOCK_ENTIREBUFFER);if(DSERR_BUFFERLOST==hr){m_pDsb->Restore();hr=m_pDsb->
  Lock(0,0,&lpvPtr1,&dwBytes1,0,0,DSBLOCK_ENTIREBUFFER);}if(DS_OK==hr){::
  CopyMemory(lpvPtr1,pSoundData,dwBytes1);hr=m_pDsb->Unlock(lpvPtr1,dwBytes1,0,0)
  ;if(DS_OK==hr)return TRUE;}return FALSE;}void CDirectSound::Play(DWORD
  dwStartPosition,BOOL bLoop){if(!IsValid()||!IsEnabled())return;if(
  dwStartPosition>m_dwTheSound)dwStartPosition=m_dwTheSound;m_pDsb->
  SetCurrentPosition(dwStartPosition);if(DSERR_BUFFERLOST==m_pDsb->Play(0,0,bLoop
  ?DSBPLAY_LOOPING:0)){SetSoundData(m_pTheSound,m_dwTheSound);m_pDsb->Play(0,0,
  bLoop?DSBPLAY_LOOPING:0);}}void CDirectSound::Stop(){if(IsValid())m_pDsb->Stop(
  );}void CDirectSound::Pause(){Stop();}void CDirectSound::Continue(){if(IsValid(
  )){DWORD dwPlayCursor,dwWriteCursor;m_pDsb->GetCurrentPosition(&dwPlayCursor,&
  dwWriteCursor);Play(dwPlayCursor);}}BOOL CDirectSound::IsValid()const{return(
  m_lpDirectSound&&m_pDsb&&m_pTheSound&&m_dwTheSound)?TRUE:FALSE;}

Example 1   |   Example 2   |   Example 3

  Download SourceFormatX C/C++ Code Formatter to format and obfuscate your C and C++ source code files today!