While PowerBasic compiles PB source code into true 32-bit machine code not all compilers do. Many less advanced compilers can still create executables, but instead of translating the source to true machine code like PB does they simply embed the source within the executable, usually compressed or encrypted to protect the source code from casual viewing. The source is then decrypted at runtime, and the script engine built into the EXE runs it. However, virtually all such compilers of that nature are vulnerable to having source code revealed.
Here is a simple program to extract the original source code from any OBasic compiled executable (obasic.com), and as you can see it really is very simple. The same principle can be used on these sorts of 'scripted compilers' from all sorts of languages.
Here is a simple program to extract the original source code from any OBasic compiled executable (obasic.com), and as you can see it really is very simple. The same principle can be used on these sorts of 'scripted compilers' from all sorts of languages.
Code:
#COMPILE EXE 'PBCC #INCLUDE "win32api.inc" SUB KillProcess(BYVAL ProcID AS LONG) LOCAL hProc AS LONG hProc = OpenProcess(BYVAL %PROCESS_TERMINATE, BYVAL 1, BYVAL ProcID) IF hProc <> %NULL THEN TerminateProcess BYVAL hProc, BYVAL %NULL CloseHandle hProc END SUB SUB ObasicDebug(szEXE AS ASCIIZ) LOCAL DE AS DEBUG_EVENT, SI AS STARTUPINFO, PI AS PROCESS_INFORMATION LOCAL sTemp AS STRING, hFile AS DWORD, sBuf AS STRING, szCmdLine AS ASCIIZ * 1, lRes AS DWORD, szPtr AS ASCIIZ PTR sTemp = ENVIRON$("TEMP"): IF RIGHT$(sTemp,1) = "\" THEN sTemp = LEFT$(sTemp, LEN(sTemp) - 1) hFile = FREEFILE OPEN szExe FOR BINARY ACCESS READ LOCK SHARED AS #hFile GET$ #hFile, LOF(hFile), sBuf CLOSE #hFile IF INSTR(1, sBuf, "OBASIC") = 0 THEN STDOUT "Invalid OBasic executable" EXIT SUB END IF szPtr = STRPTR(sBuf) + INSTR(-1, sBuf, "OBASIC") + 21 STDOUT "Source Filename=" & @szPtr CreateProcess(szEXE, szCmdLine, BYVAL %NULL, BYVAL %NULL, 0, %DEBUG_PROCESS OR %NORMAL_PRIORITY_CLASS OR %PROCESS_VM_READ, BYVAL %NULL, BYVAL %NULL, SI, PI) DO lRes = WaitForDebugEvent(DE, %INFINITE) IF lRes <> 0 THEN IF DE.dwDebugEventCode = %LOAD_DLL_DEBUG_EVENT THEN IF DIR$(sTemp & "\" & @szPtr,39) <> "" THEN FILECOPY sTemp & "\" & @szPtr, szExe & "-source.txt" STDOUT "Saved to " & szExe & "-source.txt" KillProcess BYVAL PI.dwProcessID EXIT SUB END IF END IF ContinueDebugEvent DE.dwProcessID, DE.dwThreadID, %DBG_CONTINUE END IF LOOP END SUB FUNCTION PBMAIN() AS LONG LOCAL szEXE AS ASCIIZ * %MAX_PATH szEXE = COMMAND$ '// szEXE = "E:\obasic\test.exe" IF szEXE = "" THEN STDOUT "USAGE: obas2src <target.exe>": GOTO TheEnd END IF IF DIR$(szEXE, 39) = "" THEN STDOUT "File not found - " & szEXE: GOTO TheEnd END IF ObasicDebug szEXE TheEnd: STDOUT "Press any key to continue . . ."; WAITKEY$ END FUNCTION
Comment