Procedure.l ReadLongX(BaseAddress.l)
  xLong4.l = ((256 + PeekB(BaseAddress)) & 255)
  xLong3.l = ((256 + PeekB(BaseAddress + 1)) & 255)
  xLong2.l = ((256 + PeekB(BaseAddress + 2)) & 255)
  xLong1.l = ((256 + PeekB(BaseAddress + 3)) & 255)
  xLong1 = ((xLong1 * 256 + xLong2) * 256 + xLong3) * 256 + xLong4
  ProcedureReturn xLong1
  EndProcedure

Procedure OutIt(xChar1.s)
  PrintN ("UnVeriSign: " + xChar1)
  Debug (xChar1)
  EndProcedure

OpenConsole()
;PrintN("UnVeriSign 1.00, Copyright 2006 by Jan Vorel; See 'UnVeriSign.txt' for details")

xChar1.s = ProgramParameter()
If xChar1 = ""
  OutIt("Please specify file")
  Else
  xFile.l = ReadFile(#PB_Any, xChar1)
  If xFile
    xLong1.l = Lof()
    *Buffer = AllocateMemory(xLong1)
    If *Buffer
      If ReadData(*Buffer, xLong1) = xLong1
        For xLong2 = 0 To 128
          If ReadLongX(*Buffer + xLong2 * 4) = 17744
            OutIt("ExeHeader at " + Right("0000000" + Hex(xLong2 * 128), 8))
            xLong2 * 4 + 152
            xLong3.l = ReadLongX(*Buffer + xLong2)
            xLong4.l = ReadLongX(*Buffer + xLong2 + 4)
            If xLong3 = 0 And xLong4 = 0
              OutIt("No VeriSign Signature found")
              ElseIf (xLong3 = 0 Or xLong4 = 0)
              OutIt("VeriSign Signature damaged")
              Else
              If xLong3 + xLong4 = xLong1
                PokeL(*Buffer + xLong2, 0)
                PokeL(*Buffer + xLong2 + 4, 0)
                CloseFile(xFile)
                xFile = 0
                xChar2.s = Left(xChar1, Len(xChar1) - 3) + "bak"
                DeleteFile(xChar2)
                OutIt("Creating backup...")
                If CopyFile(xChar1, xChar2)
                  OutIt("ReCreating file...")
                  ;CloseFile(xFile)
                  xFile = CreateFile(#PB_Any, xChar1)
                  If xFile
                    ;If WriteData(*Buffer, xLong3) = xLong3
                    WriteData(*Buffer, xLong3)
                      OutIt("ok")
                    ;  Else
                    ;  OutIt("Cannot write to file (" + xChar1 + ")")
                    ;  EndIf
                    Else
                    OutIt("Cannot create file (" + xChar1 + ")")
                    EndIf
                  Else
                  OutIt("Cannot create backup")
                  EndIf
                Else
                OutIt("Cannot remove Signature (Signature is not at fileend)")
                EndIf
              EndIf
            Goto EndIt
            EndIf
          Next
        OutIt("ExeHeader not found")
        Else
        OutIt("Cannot read from file (" + xChar1 + ")")
        EndIf
      Else
      OutIt("Out of memory")
      EndIf
    CloseFile(xFile)
    Else
    OutIt("Cannot open file")
    EndIf
  EndIf

EndIt:
If xFile
  CloseFile(xFile)
  EndIf
CloseConsole()
; IDE Options = PureBasic v3.94 (Windows - x86)
; ExecutableFormat = Console
; CursorPosition = 15
; FirstLine = 9
; Folding = -
; Executable = UnVeriSign.exe
; CommandLine = e:\pbasic\UnVeriSign\procexp.exe
; DisableDebugger
; IncludeVersionInfo
; VersionField0 = 1,0,0,0
; VersionField1 = 1,0,0,0
; VersionField2 = ctuser.net
; VersionField3 = UnVerisign
; VersionField4 = 1,00
; VersionField5 = 1,00
; VersionField6 = Removes Verisign Signatures from executables
; VersionField7 = UnVerisign
; VersionField8 = UnVerisign.exe
; VersionField9 = Copyright 2006 by Jan Vorel
; VersionField16 = VFT_APP
; VersionField17 = 0409 English (United States)