本文整理汇总了C++中SharedMemory::data方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::data方法的具体用法?C++ SharedMemory::data怎么用?C++ SharedMemory::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedMemory
的用法示例。
在下文中一共展示了SharedMemory::data方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_fatfs_readdir
static void test_fatfs_readdir()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
SharedMemory* cmi;
ASSERT_EQ(M_OK, fat->read_directory(root, &cmi));
ASSERT_TRUE(cmi != NULL);
int size = *(int*)cmi->data();
EXPECT_EQ(37, size);
monapi_directoryinfo* p = (monapi_directoryinfo*)&cmi->data()[sizeof(int)];
EXPECT_STR_EQ("TEST1.TXT", (const char*)CString(p[0].name));
for (int i = 0; i < size; i++) {
if (CString(p[i].name) == "SUBDIR") {
EXPECT_TRUE((p[i].attr & ATTRIBUTE_DIRECTORY) != 0);
}
}
delete cmi;
}
示例2: alloc_buffer_size
static SharedMemory* alloc_buffer_size(const char* message, int size)
{
SharedMemory* buffer = new SharedMemory(size);
buffer->map();
memcpy(buffer->data(), message, buffer->size());
return buffer;
}
示例3: test_fatfs_write_file_overwrite_expand
static void test_fatfs_write_file_overwrite_expand()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 1540;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0xce, BUFFER_SIZE);
buffer->data()[0] = 0xca;
buffer->data()[buffer->size() - 1] = 0xfe;
io::Context c;
c.offset = 513;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
ASSERT_EQ(2053, cmi->size());
EXPECT_EQ(0xde, cmi->data()[0]);
EXPECT_EQ(0xca, cmi->data()[513]);
EXPECT_EQ(0xfe, cmi->data()[513 + BUFFER_SIZE - 1]);
}
示例4: test_fatfs_write_file
static void test_fatfs_write_file()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 1029;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0, BUFFER_SIZE);
buffer->data()[0] = 0xde;
buffer->data()[BUFFER_SIZE - 1] = 0xad;
io::Context c;
c.offset = 0;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
ASSERT_EQ(BUFFER_SIZE, cmi->size());
EXPECT_TRUE(memcmp(buffer->data(), cmi->data(), BUFFER_SIZE) == 0);
}
示例5: send_data
void TcpServer::send_data(SharedMemory& data) {
try
{
write(
socket_,
boost::asio::buffer(data.data(), data.size()),
boost::asio::transfer_at_least(data.size()));
}
catch (std::exception& e){
printf("client disconnected\n");
accept_connection();
}
// async_write(
// socket_,
// boost::asio::buffer(data.data(), data.size()),
// boost::asio::transfer_at_least(data.size()),
// boost::bind(&TcpServer::handle_writer, this,
// boost::asio::placeholders::error,
// boost::asio::placeholders::bytes_transferred,
// data));
}
示例6: test_fatfs_write_file_overwrite
static void test_fatfs_write_file_overwrite()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 10;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0, BUFFER_SIZE);
for (int i = 0; i < BUFFER_SIZE; i++) {
buffer->data()[i] = i;
}
io::Context c;
c.offset = 513;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
EXPECT_EQ(0xde, cmi->data()[0]);
EXPECT_EQ(0xad, cmi->data()[cmi->size() -1]);
for (int i = 0; i < BUFFER_SIZE; i++) {
EXPECT_EQ(i, cmi->data()[513 + i]);
}
}
示例7: Load
bool Load()
{
uint32_t imageSize = 0;
uint32_t bootstrapSize = getBootstrapSize();
PEDataList::size_type len = this->list.size();
for (PEDataList::size_type i = 0; i < len; i++)
{
imageSize += this->list[i]->Parser.get_ImageSize();
}
imageSize += bootstrapSize;
SharedMemory* dst = new SharedMemory(imageSize);
if (dst->map(true) != M_OK)
{
delete dst;
this->Result = 3;
return false;
}
uint32_t addr = 0;
for (PEDataList::size_type i = 0; i < len; i++)
{
PEData* data = this->list[i];
uint8_t* ptr = &dst->data()[addr];
if (!data->Parser.Load(ptr))
{
if (this->prompt) _printf("%s: can not load: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
if (i > 0 && !data->Parser.Relocate(ptr, ORG + addr))
{
if (this->prompt) _printf("%s: can not relocate: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
addr += data->Parser.get_ImageSize();
}
addr = 0;
for (PEDataList::size_type i = 0; i < len; i++)
{
PEData* data = this->list[i];
int its = data->Parser.get_ImportTableCount();
for (int j = 0; j < its; j++)
{
CString dll = CString(data->Parser.GetImportTableName(j)).toUpper();
PEData* target = this->Find(dll);
if (target == NULL || !data->Parser.Link(&dst->data()[addr], j, &target->Parser))
{
if (this->prompt)
{
_printf("NG\n");
_printf("%s: can not link %s to %s!\n", SVR, (const char*)dll, (const char*)data->Name);
}
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
}
addr += data->Parser.get_ImageSize();
}
// make bootstrap code
uint8_t* bootstrap = &dst->data()[dst->size() - bootstrapSize];
uint8_t* start = &bootstrap[3];
bootstrap[0] = 0x55; // push ebp
bootstrap[1] = 0x89; // mov ebp
bootstrap[2] = 0xE5; // ,esp
PEDataList::size_type i;
//char buf[128];
const uint32_t CALL_CODE_SIZE = 13;
// dllmain construct
for (i = 0; i < dlls.size(); i++)
{
PEData* dll = dlls[i];
start[i * CALL_CODE_SIZE] = 0xB8; // mov eax
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = dll->Parser.get_EntryPoint(); // ,address
start[i * CALL_CODE_SIZE + 5] = 0x68; // push
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 6]) = 0; // 0x00000000 = argument of dllmain
start[i * CALL_CODE_SIZE + 10] = 0xFF; // call eax
start[i * CALL_CODE_SIZE + 11] = 0xD0; // call eax
start[i * CALL_CODE_SIZE + 12] = 0x58; // pop eax
}
PEData* exe = list[0];
start[i * CALL_CODE_SIZE + 0] = 0xB8; // mov eax
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = exe->Parser.get_EntryPoint();
start[i * CALL_CODE_SIZE + 5] = 0xFF;
start[i * CALL_CODE_SIZE + 6] = 0xD0;
start = &start[i * CALL_CODE_SIZE + 7];
// destruct
for (i = 0; i < dlls.size(); i++)
//.........这里部分代码省略.........