binaryfiles

How can I exclude source file metadata from output when compiling?

拜拜、爱过 提交于 2019-12-24 12:26:05
问题 For example: $ gcc -O3 foobar.c -o foobar $ grep 'foobar\.c' foobar Binary file foobar matches How can I exclude such unnecessary and revealing metadata from the output of gcc and other compilers? It appears regardless of whether the output is an assembly file, object file, or executable. 回答1: man strip(1) > strip -s a.out 来源: https://stackoverflow.com/questions/28377292/how-can-i-exclude-source-file-metadata-from-output-when-compiling

Read binary file into vector of uint32_t

痴心易碎 提交于 2019-12-24 11:28:21
问题 There's a binary file words.bin containing multiple 4 byte integers. I want to read them from the file into a std::vector of corresponding size, which is uint32_t . Here's what I've tried first: #include <fstream> #include <iterator> #include <vector> #include <cstdint> int main(int argc, char* argv[]) { std::ifstream f("words.bin", std::ios::in | std::ios::binary); std::vector<uint32_t> wordvec(std::istreambuf_iterator<uint32_t>{f}, {}); return 0; } However, I get this error message: u32vec

Need for noskipws on stream with T=unsigned char in binary mode?

血红的双手。 提交于 2019-12-24 07:40:38
问题 I came across Reading the binary file into the vector of unsigned chars and tested the code discussed in the question. The code of interest is below: typedef unsigned char BYTE; std::ifstream file(filename, std::ios::binary); file.unsetf(std::ios::skipws); std::vector<BYTE> vec; vec.insert(vec.begin(), std::istream_iterator<BYTE>(file), std::istream_iterator<BYTE>()); According to Benjamin Lindley's answer at Why std::istream_iterator ignores newline characters?, istream::operator>>(char)

Writing a linked list to binary file(C)

余生长醉 提交于 2019-12-24 07:12:54
问题 So I have set up a linked list and read data from a file, done some calculation and manipulation and now I want to store the new list into a binary file. Here is my struct setup: typedef struct Comp{ char name[5]; char node1[5], node2[5]; float value; //value }ComponentType; typedef struct ListNodeT{ ComponentType Component; float voltage, power, current; struct ListNodeT *nextPtr; }ListNodeType; In a separate function I am trying to write to a a file: FILE *filePtr; char fileName[13] =

Reading binary and text from same file in Python

一笑奈何 提交于 2019-12-24 05:06:13
问题 How does one read binary and text from the same file in Python? I know how to do each separately, and can imagine doing both very carefully, but not both with the built-in IO library directly. So I have a file that has a format that has large chunks of UTF-8 text interspersed with binary data. The text does not have a length written before it or a special character like "\0" delineating it from the binary data, there is a large portion of text near the end when parsed means "we are coming to

Reading binary and text from same file in Python

ⅰ亾dé卋堺 提交于 2019-12-24 05:06:08
问题 How does one read binary and text from the same file in Python? I know how to do each separately, and can imagine doing both very carefully, but not both with the built-in IO library directly. So I have a file that has a format that has large chunks of UTF-8 text interspersed with binary data. The text does not have a length written before it or a special character like "\0" delineating it from the binary data, there is a large portion of text near the end when parsed means "we are coming to

What's a binary file and how do I create one?

ε祈祈猫儿з 提交于 2019-12-23 20:19:54
问题 I would like to create a binary file representing an integer. I think the file should be 4 bytes. I use linux. How to do that? Another question: How do I assign the content of that file to an integer in C? 回答1: In standard C, fopen() allows the mode "wb" to write (and "rb" to read) in binary mode, thus: #include <stdio.h> int main() { /* Create the file */ int x = 1; FILE *fh = fopen ("file.bin", "wb"); if (fh != NULL) { fwrite (&x, sizeof (x), 1, fh); fclose (fh); } /* Read the file back in

How to write/read binary files that represent objects?

坚强是说给别人听的谎言 提交于 2019-12-23 15:41:52
问题 I'm new to Java programming, and I ran into this problem: I'm creating a program that reads a .csv file, converts its lines into objects and then manipulate these objects. Being more specific, the application reads every line giving it an index and also reads certain values from those lines and stores them in TRIE trees. The application then can read indexes from the values stored in the trees and then retrieve the full information of the corresponding line. My problem is that, even though I

How to list all externally-undefined symbols of a static library on Linux?

試著忘記壹切 提交于 2019-12-23 15:11:57
问题 I have a static library libfoo.a , which is just a compression of multiple .o files. I am looking for a way to list all symbols that appear in the static library as UND have no definition in this static library So that I can find out all external symbol dependencies of this library. 回答1: You can use this method: ld -r -o deleteme.o --whole-archive libfoo.a nm -C --undefined-only deleteme.o # `-C` if you might have C++ archive members rm deleteme.o Demo : one.c extern void two(void); void one(

python: regular expression search pattern for binary files (half a byte)

↘锁芯ラ 提交于 2019-12-23 09:18:13
问题 I am using the following regular expression pattern for searching 0xDEAD4FAD in a binary file: my_pattern = re.compile(b"\xDE\xAD\x4F\xAD") but how do I generalize the search pattern for searching 0xDEAD4xxx? can't seem to cut through half a byte 回答1: Regular expressions do allow searching over ranges. Thus, to find a byte whose the first nibble is "4" use: pattern = re.compile(b"[\x40-\x4F]") The following test shows that it produces the desired output: >>> for byte in ('\x3f', '\x40', '\x42