Advertisement
Guest User

bggp4 by fliermate

a guest
Jan 3rd, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | Source Code | 0 0
  1. ;BGGP4 (Late Entry, 528-byte EXE) - Jan 3, 2024
  2. ;Modified by FlierMate from Tomasz Grysztar's PE template
  3. ;
  4. ;Compile with FASMG
  5. ;Name the EXE file as "BGGP.EXE"
  6. ;
  7. ;Noticeable changes are:
  8. ;-FileAlignment set to 16 instead of 512
  9. ;-SectionAlignment set to 16 instead of 4096
  10. ;-DataDirectory size kept to 2 instead of 16
  11. ;
  12. ;The remaining header fields are kept unmodified as in original BASIC.ASM (PE template)
  13. ;
  14. ;Thank you to @netspooky and their team for the wonderful BGGP!
  15. ;My previous PE entry was a 1024-byte EXE (no header tweaks, just a single section 512 bytes with headers 512 bytes)
  16.  
  17. format binary as "exe"
  18.  
  19. macro align? pow2*,value:?
  20. db (-$) and (pow2-1) dup value
  21. end macro
  22.  
  23. include '80386.inc'
  24. use32
  25.  
  26. IMAGE_BASE := 0x400000
  27. org IMAGE_BASE
  28.  
  29. FILE_ALIGNMENT := 16
  30. SECTION_ALIGNMENT := 16
  31.  
  32. Stub:
  33. .Signature dw "MZ"
  34. .BytesInLastSector dw SIZE_OF_STUB mod 512
  35. .NumberOfSectors dw (SIZE_OF_STUB-1)/512 + 1
  36. .NumberOfRelocations dw 0
  37. .NumberOfHeaderParagraphs dw SIZE_OF_STUB_HEADER / 16
  38. db 0x3C - ($-Stub) dup 0
  39. .NewHeaderOffset dd Header-IMAGE_BASE
  40.  
  41. align 16
  42.  
  43. SIZE_OF_STUB_HEADER := $ - Stub
  44.  
  45. ; The code of a DOS program would go here.
  46.  
  47. SIZE_OF_STUB := $ - Stub
  48.  
  49. align 8
  50.  
  51. Header:
  52. .Signature dw "PE",0
  53. .Machine dw 0x14C ; IMAGE_FILE_MACHINE_I386
  54. .NumberOfSections dw NUMBER_OF_SECTIONS
  55. .TimeDateStamp dd %t
  56. .PointerToSymbolTable dd 0
  57. .NumberOfSymbols dd 0
  58. .SizeOfOptionalHeader dw SectionTable - OptionalHeader
  59. .Characteristics dw 0x102 ; IMAGE_FILE_32BIT_MACHINE + IMAGE_FILE_EXECUTABLE_IMAGE
  60.  
  61. OptionalHeader:
  62. .Magic dw 0x10B
  63. .MajorLinkerVersion db 0
  64. .MinorLinkerVersion db 0
  65. .SizeOfCode dd 0
  66. .SizeOfInitializedData dd 0
  67. .SizeOfUninitializedData dd 0
  68. .AddressOfEntryPoint dd EntryPoint-IMAGE_BASE
  69. .BaseOfCode dd 0
  70. .BaseOfData dd 0
  71. .ImageBase dd IMAGE_BASE
  72. .SectionAlignment dd SECTION_ALIGNMENT
  73. .FileAlignment dd FILE_ALIGNMENT
  74. .MajorOperatingSystemVersion dw 3
  75. .MinorOperatingSystemVersion dw 10
  76. .MajorImageVersion dw 0
  77. .MinorImageVersion dw 0
  78. .MajorSubsystemVersion dw 3
  79. .MinorSubsystemVersion dw 10
  80. .Win32VersionValue dd 0
  81. .SizeOfImage dd SIZE_OF_IMAGE
  82. .SizeOfHeaders dd SIZE_OF_HEADERS
  83. .CheckSum dd 0
  84. .Subsystem dw 2 ; IMAGE_SUBSYSTEM_WINDOWS_GUI
  85. .DllCharacteristics dw 0
  86. .SizeOfStackReserve dd 4096
  87. .SizeOfStackCommit dd 4096
  88. .SizeOfHeapReserve dd 65536
  89. .SizeOfHeapCommit dd 0
  90. .LoaderFlags dd 0
  91. .NumberOfRvaAndSizes dd NUMBER_OF_RVA_AND_SIZES
  92.  
  93. RvaAndSizes:
  94. .Export.Rva dd 0
  95. .Export.Size dd 0
  96. .Import.Rva dd ImportTable-IMAGE_BASE
  97. .Import.Size dd ImportTable.End-ImportTable
  98. ;.Resource.Rva dd 0
  99. ;.Resource.Size dd 0
  100. ;.Exception.Rva dd 0
  101. ;.Exception.Size dd 0
  102. ;.Certificate.Rva dd 0
  103. ;.Certificate.Size dd 0
  104. ;.BaseRelocation.Rva dd 0
  105. ;.BaseRelocation.Size dd 0
  106. ;.Debug.Rva dd 0
  107. ;.Debug.Size dd 0
  108. ;.Architecture.Rva dd 0
  109. ;.Architecture.Size dd 0
  110. ;.GlobalPtr.Rva dd 0
  111. ;.GlobalPtr.Size dd 0
  112. ;.TLS.Rva dd 0
  113. ;.TLS.Size dd 0
  114. ;.LoadConfig.Rva dd 0
  115. ;.LoadConfig.Size dd 0
  116. ;.BoundImport.Rva dd 0
  117. ;.BoundImport.Size dd 0
  118. ;.IAT.Rva dd 0
  119. ;.IAT.Size dd 0
  120. ;.DelayImport.Rva dd 0
  121. ;.DelayImport.Size dd 0
  122. ;.COMPlus.Rva dd 0
  123. ;.COMPlus.Size dd 0
  124. ;.Reserved.Rva dd 0
  125. ;.Reserved.Size dd 0
  126.  
  127. SectionTable:
  128.  
  129. .1.Name dq +'.text'
  130. .1.VirtualSize dd Section.1.End - Section.1
  131. .1.VirtualAddress dd Section.1 - IMAGE_BASE
  132. .1.SizeOfRawData dd Section.1.SIZE_IN_FILE
  133. .1.PointerToRawData dd Section.1.OFFSET_IN_FILE
  134. .1.PointerToRelocations dd 0
  135. .1.PointerToLineNumbers dd 0
  136. .1.NumberOfRelocations dw 0
  137. .1.NumberOfLineNumbers dw 0
  138. .1.Characteristics dd 0x60000000 ; IMAGE_SCN_MEM_EXECUTE + IMAGE_SCN_MEM_READ
  139.  
  140. .2.Name dq +'.rdata'
  141. .2.VirtualSize dd Section.2.End - Section.2
  142. .2.VirtualAddress dd Section.2 - IMAGE_BASE
  143. .2.SizeOfRawData dd Section.2.SIZE_IN_FILE
  144. .2.PointerToRawData dd Section.2.OFFSET_IN_FILE
  145. .2.PointerToRelocations dd 0
  146. .2.PointerToLineNumbers dd 0
  147. .2.NumberOfRelocations dw 0
  148. .2.NumberOfLineNumbers dw 0
  149. .2.Characteristics dd 0x40000000 ; IMAGE_SCN_MEM_READ
  150.  
  151. SectionTable.End:
  152.  
  153. NUMBER_OF_RVA_AND_SIZES := (SectionTable-RvaAndSizes)/8
  154. NUMBER_OF_SECTIONS := (SectionTable.End-SectionTable)/40
  155. SIZE_OF_HEADERS := Section.1.OFFSET_IN_FILE
  156.  
  157. align SECTION_ALIGNMENT
  158. Section.1:
  159.  
  160. section $%%
  161. align FILE_ALIGNMENT,0
  162. Section.1.OFFSET_IN_FILE:
  163.  
  164. section Section.1
  165.  
  166. EntryPoint:
  167.  
  168. push 0
  169. push DestFileName
  170. push SourceFileName
  171. call [CopyFileA]
  172.  
  173. push 0
  174. push CaptionString
  175. push MessageString
  176. push 0
  177. call [MessageBoxA]
  178.  
  179. push 0
  180. call [ExitProcess]
  181.  
  182. Section.1.End:
  183.  
  184. align SECTION_ALIGNMENT
  185. Section.2:
  186.  
  187. section $%%
  188. align FILE_ALIGNMENT,0
  189. Section.1.SIZE_IN_FILE := $ - Section.1.OFFSET_IN_FILE
  190. Section.2.OFFSET_IN_FILE:
  191.  
  192. section Section.2
  193.  
  194. ImportTable:
  195.  
  196. .1.ImportLookupTableRva dd KernelLookupTable-IMAGE_BASE
  197. .1.TimeDateStamp dd 0
  198. .1.ForwarderChain dd 0
  199. .1.NameRva dd KernelDLLName-IMAGE_BASE
  200. .1.ImportAddressTableRva dd KernelAddressTable-IMAGE_BASE
  201.  
  202. .2.ImportLookupTableRva dd UserLookupTable-IMAGE_BASE
  203. .2.TimeDateStamp dd 0
  204. .2.ForwarderChain dd 0
  205. .2.NameRva dd UserDLLName-IMAGE_BASE
  206. .2.ImportAddressTableRva dd UserAddressTable-IMAGE_BASE
  207.  
  208. dd 0,0,0,0,0
  209.  
  210. KernelLookupTable:
  211. dd ExitProcessLookup-IMAGE_BASE
  212. dd CopyFileALookup-IMAGE_BASE
  213. dd 0
  214. KernelAddressTable:
  215. ExitProcess dd ExitProcessLookup-IMAGE_BASE ; this is going to be replaced with the address of the function
  216. CopyFileA dd CopyFileALookup-IMAGE_BASE ; this is going to be replaced with the address of the function
  217. dd 0
  218.  
  219. UserLookupTable:
  220. dd MessageBoxALookup-IMAGE_BASE
  221. dd 0
  222. UserAddressTable:
  223. MessageBoxA dd MessageBoxALookup-IMAGE_BASE ; this is going to be replaced with the address of the function
  224. dd 0
  225.  
  226. align 2
  227. ExitProcessLookup:
  228. .Hint dw 0
  229. .Name db 'ExitProcess',0
  230. align 2
  231.  
  232. MessageBoxALookup:
  233. .Hint dw 0
  234. .Name db 'MessageBoxA',0
  235.  
  236. CopyFileALookup:
  237. .Hint dw 0
  238. .Name db 'CopyFileA',0
  239.  
  240. KernelDLLName db 'KERNEL32.DLL',0
  241. UserDLLName db 'USER32.DLL',0
  242.  
  243. ImportTable.End:
  244.  
  245. CaptionString db "BGGP",0
  246. MessageString db "4",0
  247. SourceFileName db ".\BGGP.EXE",0
  248. DestFileName db ".\4",0
  249.  
  250. Section.2.End:
  251.  
  252. align SECTION_ALIGNMENT
  253. SIZE_OF_IMAGE := $ - IMAGE_BASE
  254.  
  255. section $%%
  256. align FILE_ALIGNMENT,0
  257. Section.2.SIZE_IN_FILE := $ - Section.2.OFFSET_IN_FILE
Tags: bggp4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement