PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 13, 2022

[FIXED] How to append null (00 00 ect bytes) to a file until certain size via Python

 May 13, 2022     append, hex, null, python     No comments   

Issue

I have a file that I need to append NULL or 00 ~ ect bytes to the end of the file (in hex) so the file size would be 625423968.

Right now the file size is: 606256432

I tried:

with open(f, 'wb') as binfile:
    binfile.write(b'\x00' - 19167536)

but my file size becomes 0

Doing it manually in Hex Editor takes way too long

Greatly appreciate all the help!


Solution

You can seek your file and then write the last NULL.

with open(f, 'wb') as binfile:
    binfile.seek(625423968 - 1)
    binfile.write(b'\x00')

(Maybe you have to use file-mode "br+ when you write your file not from scratch in python. This will keep the content and append the NULLs.)



Answered By - Sven Eberth
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing