Code Monkey home page Code Monkey logo

Comments (11)

continue98 avatar continue98 commented on August 11, 2024

@stevemk14ebr ?

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

I assume you are trying to do an IAT hook. Import by ordinal is nor supported because i don't need it. If you want to look at the source and send a PR to improve the interface please do so. If you just want an inline hook just get the address of the recv and pass it to the constructor like any of the other examples

PLH::x86Detour detour((char*)&printf, (char*)h_hookPrintf, &hookPrintfTramp, dis);

from polyhook_2_0.

continue98 avatar continue98 commented on August 11, 2024

I am testing hook by x86 detour:

Unhandled exception thrown: read access violation.
this->m_disasm. was nullptr.

Code:

uint64_t g_hook_recv_tramp = NULL;
void hkRecv(SOCKET s, char* buf, int len, int flags)
{
	PLH::FnCast(g_hook_recv_tramp, &hkRecv)(s, buf, len, flags);
}
auto recv_addr = reinterpret_cast<uint64_t>(GetProcAddress(GetModuleHandleA("ws2_32.dll"), "recv"));
PLH::CapstoneDisassembler dis(PLH::Mode::x86);
PLH::x86Detour detour(recv_addr, (uint64_t)&hkRecv, &g_hook_recv_tramp, dis);
detour.hook();

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

you need to keep the disassembler in scope for as long as the detour object exists. The disassembler is captured by referenced so if it's destroyed before the detour the detour will attempt to use a destroyed object.

from polyhook_2_0.

continue98 avatar continue98 commented on August 11, 2024

you need to keep the disassembler in scope for as long as the detour object exists. The disassembler is captured by referenced so if it's destroyed before the detour the detour will attempt to use a destroyed object.

I make disassembler in global scope:

Unhandled exception thrown: read access violation.
_Ptr_user was 0xF000000.

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

Verify the address returned by getprocaddress is valid. Otherwise you need to debug this yourself

from polyhook_2_0.

continue98 avatar continue98 commented on August 11, 2024

Verify the address returned by getprocaddress is valid. Otherwise you need to debug this yourself

Address is valid (0x0000000076e11460). Crash in polyhook code (PLH::CapstoneDisassembler::disassemble)

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

Can you please debug the routine and determine where exactly inside that routine the crash occurs.

from polyhook_2_0.

continue98 avatar continue98 commented on August 11, 2024

Value by crash. Crash in capstone:

PLH::insts_t
PLH::CapstoneDisassembler::disassemble(uint64_t firstInstruction, uint64_t start, uint64_t End, const MemAccessor& accessor) {
	cs_insn* insInfo = cs_malloc(m_capHandle);
	insts_t insVec;
	m_branchMap.clear();

	uint64_t size = End - start;
	assert(size > 0);
	if (size <= 0)
		return insVec;

	// copy potentially remote memory to local buffer
	uint8_t* buf = new uint8_t[(uint32_t)size];

	// bufAddr updated by cs_disasm_iter
	uint64_t bufAddr = (uint64_t)buf;
	accessor.mem_copy((uint64_t)buf, firstInstruction, size);

	bool endHit = false;
	while (cs_disasm_iter(m_capHandle, (const uint8_t**)&bufAddr, (size_t*)&size, &start, insInfo)) {
		// Set later by 'SetDisplacementFields'
		Instruction::Displacement displacement = {};
		displacement.Absolute = 0;

		Instruction inst(insInfo->address,
						 displacement,
						 0,
						 false,
			             false,
						 insInfo->bytes,
						 insInfo->size,
						 insInfo->mnemonic,
						 insInfo->op_str,
						 m_mode);

		setDisplacementFields(inst, insInfo);
		if (endHit && !isPadBytes(inst))
			break;

		insVec.push_back(inst); // crash on push value in vector

		// searches instruction vector and updates references
		addToBranchMap(insVec, inst);

		if (isFuncEnd(inst))
			endHit = true;
	}
	delete[] buf;
	cs_free(insInfo, 1);
	return insVec;
}

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

I cannot reproduce this

from polyhook_2_0.

continue98 avatar continue98 commented on August 11, 2024

I am use struct member alignment 1 byte. Is it possible that this is because of this?

from polyhook_2_0.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.